yuqi1129 commented on code in PR #9201:
URL: https://github.com/apache/gravitino/pull/9201#discussion_r2563653572


##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceNamespaceOperations.java:
##########
@@ -665,4 +668,108 @@ void testDescribeTable() {
     Assertions.assertEquals("Runtime exception", errorResp.getError());
     Assertions.assertEquals(RuntimeException.class.getSimpleName(), 
errorResp.getType());
   }
+
+  @Test
+  void testTableExists() {
+    String tableIds = "catalog.scheme.table_exists";
+    String delimiter = ".";
+
+    doReturn(true).when(tableOps).tableExists(any(), any());
+
+    Response resp =
+        target(String.format("/v1/table/%s/exists", tableIds))
+            .queryParam("delimiter", delimiter)
+            .request(MediaType.APPLICATION_JSON_TYPE)
+            .post(null);
+
+    Assertions.assertEquals(Response.Status.OK.getStatusCode(), 
resp.getStatus());
+
+    // test throw exception
+    doThrow(
+            LanceNamespaceException.notFound(
+                "Table not found", "NoSuchTableException", tableIds, ""))
+        .when(tableOps)
+        .tableExists(any(), any());
+    resp =
+        target(String.format("/v1/table/%s/exists", tableIds))
+            .queryParam("delimiter", delimiter)
+            .request(MediaType.APPLICATION_JSON_TYPE)
+            .post(null);
+
+    Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), 
resp.getStatus());
+    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
+
+    ErrorResponse errorResp = resp.readEntity(ErrorResponse.class);
+    Assertions.assertEquals(404, errorResp.getCode());
+    Assertions.assertEquals("Table not found", errorResp.getError());
+    Assertions.assertEquals("NoSuchTableException", errorResp.getType());
+
+    // Test runtime exception
+    Mockito.reset(tableOps);
+    doThrow(new RuntimeException("Runtime 
exception")).when(tableOps).tableExists(any(), any());
+    resp =
+        target(String.format("/v1/table/%s/exists", tableIds))
+            .queryParam("delimiter", delimiter)
+            .request(MediaType.APPLICATION_JSON_TYPE)
+            .post(null);
+    Assertions.assertEquals(
+        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), 
resp.getStatus());
+    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
+  }

Review Comment:
   It can't return false, as we have checked the existence of the table before 
dropping it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to