This is an automated email from the ASF dual-hosted git repository.

yuqi4733 pushed a commit to branch issue_9043
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit 5c4035afbbc17fbc55c050566d8fddb15e8fc11b
Merge: 25774a63d4 ea3eb770aa
Author: yuqi <[email protected]>
AuthorDate: Thu Nov 13 10:59:33 2025 +0800

    Merge branch 'branch-lance-namespace-dev' of github.com:apache/gravitino 
into issue_9043

 .../lance/service/rest/LanceTableOperations.java   |  1 +
 .../service/rest/TestLanceTableOperations.java     | 42 ++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --cc 
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java
index 9187a7da93,0fc4df9cfd..c59159c0ea
--- 
a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java
+++ 
b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java
@@@ -19,6 -19,9 +19,7 @@@
  package org.apache.gravitino.lance.service.rest;
  
  import static org.mockito.ArgumentMatchers.any;
+ import static org.mockito.ArgumentMatchers.eq;
 -import static org.mockito.Mockito.doNothing;
 -import static org.mockito.Mockito.doThrow;
  import static org.mockito.Mockito.mock;
  import static org.mockito.Mockito.when;
  
@@@ -378,112 -665,4 +379,153 @@@ public class TestLanceTableOperations e
      Assertions.assertEquals("Runtime exception", errorResp.getError());
      Assertions.assertEquals(RuntimeException.class.getSimpleName(), 
errorResp.getType());
    }
 +
 +  @Test
 +  void testCreateTableIndex() {
 +    String tableIds = "catalog.scheme.to_create_index_table";
 +    String delimiter = ".";
 +
 +    // Test normal
 +    CreateTableIndexRequest tableRequest = new CreateTableIndexRequest();
 +
 +    CreateTableIndexResponse response = new CreateTableIndexResponse();
 +    response.setProperties(ImmutableMap.of("key", "value"));
 +    when(tableOps.createTableIndex(any(), any(), any())).thenReturn(response);
 +
 +    Response resp =
 +        target(String.format("/v1/table/%s/create_index", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +
 +    Assertions.assertEquals(Response.Status.OK.getStatusCode(), 
resp.getStatus());
 +    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
 +    response = resp.readEntity(CreateTableIndexResponse.class);
 +    Assertions.assertEquals(response.getProperties(), 
response.getProperties());
 +
 +    Mockito.reset(tableOps);
 +    // Test illegal argument
 +    when(tableOps.createTableIndex(any(), any(), any()))
 +        .thenThrow(new IllegalArgumentException("Illegal argument"));
 +
 +    resp =
 +        target(String.format("/v1/table/%s/create_index", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +    Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), 
resp.getStatus());
 +    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
 +
 +    // Test runtime exception
 +    Mockito.reset(tableOps);
 +    when(tableOps.createTableIndex(any(), any(), any()))
 +        .thenThrow(new RuntimeException("Runtime exception"));
 +    resp =
 +        target(String.format("/v1/table/%s/create_index", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +
 +    Assertions.assertEquals(
 +        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), 
resp.getStatus());
 +    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
 +    ErrorResponse errorResp = resp.readEntity(ErrorResponse.class);
 +    Assertions.assertEquals("Runtime exception", errorResp.getError());
 +    Assertions.assertEquals(RuntimeException.class.getSimpleName(), 
errorResp.getType());
 +  }
 +
 +  @Test
 +  void testListTableIndices() {
 +    String tableIds = "catalog.scheme.to_list_index_table";
 +    String delimiter = ".";
 +
 +    ListTableIndicesRequest tableRequest = new ListTableIndicesRequest();
 +
 +    ListTableIndicesResponse response = new ListTableIndicesResponse();
 +    IndexContent indexContent = new IndexContent();
 +    indexContent.setIndexName("test_index");
 +    indexContent.setColumns(List.of("col1"));
 +    response.setIndexes(List.of(indexContent));
 +    when(tableOps.listTableIndices(any(), any(), any())).thenReturn(response);
 +
 +    Response resp =
 +        target(String.format("/v1/table/%s/index/list", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +
 +    Assertions.assertEquals(Response.Status.OK.getStatusCode(), 
resp.getStatus());
 +    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
 +    ListTableIndicesResponse actualResponse = 
resp.readEntity(ListTableIndicesResponse.class);
 +    Assertions.assertEquals(1, actualResponse.getIndexes().size());
 +    Assertions.assertEquals("test_index", 
actualResponse.getIndexes().get(0).getIndexName());
 +    Assertions.assertEquals(List.of("col1"), 
actualResponse.getIndexes().get(0).getColumns());
 +
 +    Mockito.reset(tableOps);
 +
 +    // Test illegal argument
 +    when(tableOps.listTableIndices(any(), any(), any()))
 +        .thenThrow(new IllegalArgumentException("Illegal argument"));
 +    resp =
 +        target(String.format("/v1/table/%s/index/list", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +    Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), 
resp.getStatus());
 +    Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, 
resp.getMediaType());
 +
 +    // Test
 +    Mockito.reset(tableOps);
 +    when(tableOps.listTableIndices(any(), any(), any()))
 +        .thenThrow(
 +            LanceNamespaceException.notFound(
 +                "Table not found", "NoSuchTableException", tableIds, ""));
 +    resp =
 +        target(String.format("/v1/table/%s/index/list", tableIds))
 +            .queryParam("delimiter", delimiter)
 +            .request(MediaType.APPLICATION_JSON_TYPE)
 +            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
 +    Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), 
resp.getStatus());
 +  }
++
++  @Test
++  void testRegisterTableSetsRegisterPropertyToTrue() {
++    String tableIds = "catalog.scheme.register_table_with_property";
++    String delimiter = ".";
++
++    // Reset mock to clear any previous test state
++    Mockito.reset(tableOps);
++
++    // Test that the "register" property is set to "true"
++    RegisterTableResponse registerTableResponse = new RegisterTableResponse();
++    registerTableResponse.setLocation("/path/to/registered_table");
++    registerTableResponse.setProperties(ImmutableMap.of("key", "value", 
"register", "true"));
++    when(tableOps.registerTable(any(), any(), any(), 
any())).thenReturn(registerTableResponse);
++
++    RegisterTableRequest tableRequest = new RegisterTableRequest();
++    tableRequest.setLocation("/path/to/registered_table");
++    tableRequest.setMode(RegisterTableRequest.ModeEnum.CREATE);
++    tableRequest.setProperties(ImmutableMap.of("custom-key", "custom-value"));
++
++    Response resp =
++        target(String.format("/v1/table/%s/register", tableIds))
++            .queryParam("delimiter", delimiter)
++            .request(MediaType.APPLICATION_JSON_TYPE)
++            .post(Entity.entity(tableRequest, 
MediaType.APPLICATION_JSON_TYPE));
++
++    Assertions.assertEquals(Response.Status.OK.getStatusCode(), 
resp.getStatus());
++
++    // Verify that registerTable was called with properties containing 
"register": "true"
++    Mockito.verify(tableOps)
++        .registerTable(
++            eq(tableIds),
++            eq(RegisterTableRequest.ModeEnum.CREATE),
++            eq(delimiter),
++            Mockito.argThat(
++                props ->
++                    props != null
++                        && "true".equals(props.get("register"))
++                        && 
"/path/to/registered_table".equals(props.get("location"))
++                        && "custom-value".equals(props.get("custom-key"))));
++  }
  }

Reply via email to