Search in sources :

Example 1 with GetTableMetadataResponse

use of com.scalar.db.rpc.GetTableMetadataResponse in project scalardb by scalar-labs.

the class DistributedTransactionAdminService method getTableMetadata.

@Override
public void getTableMetadata(GetTableMetadataRequest request, StreamObserver<GetTableMetadataResponse> responseObserver) {
    execute(() -> {
        TableMetadata tableMetadata = admin.getTableMetadata(request.getNamespace(), request.getTable());
        GetTableMetadataResponse.Builder builder = GetTableMetadataResponse.newBuilder();
        if (tableMetadata != null) {
            builder.setTableMetadata(ProtoUtils.toTableMetadata(tableMetadata));
        }
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }, responseObserver, "get_table_metadata");
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse)

Example 2 with GetTableMetadataResponse

use of com.scalar.db.rpc.GetTableMetadataResponse in project scalardb by scalar-labs.

the class GrpcAdminTest method getTableMetadata_CalledWithProperArguments_MetadataManagerShouldBeCalledProperly.

@Test
public void getTableMetadata_CalledWithProperArguments_MetadataManagerShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    String namespace = "namespace";
    String table = "table";
    GetTableMetadataResponse response = mock(GetTableMetadataResponse.class);
    when(stub.getTableMetadata(any())).thenReturn(response);
    when(response.hasTableMetadata()).thenReturn(true);
    when(response.getTableMetadata()).thenReturn(com.scalar.db.rpc.TableMetadata.newBuilder().putColumn("col1", com.scalar.db.rpc.DataType.DATA_TYPE_INT).putColumn("col2", com.scalar.db.rpc.DataType.DATA_TYPE_INT).putColumn("col3", com.scalar.db.rpc.DataType.DATA_TYPE_INT).addPartitionKeyName("col1").addClusteringKeyName("col2").putClusteringOrder("col2", com.scalar.db.rpc.Order.ORDER_DESC).build());
    // Act
    TableMetadata tableMetadata = admin.getTableMetadata(namespace, table);
    // Assert
    verify(stub).getTableMetadata(GetTableMetadataRequest.newBuilder().setNamespace(namespace).setTable(table).build());
    assertThat(tableMetadata).isEqualTo(TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addColumn("col3", DataType.INT).addPartitionKey("col1").addClusteringKey("col2", Scan.Ordering.Order.DESC).build());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse) Test(org.junit.jupiter.api.Test)

Example 3 with GetTableMetadataResponse

use of com.scalar.db.rpc.GetTableMetadataResponse in project scalardb by scalar-labs.

the class GrpcTransactionAdminTest method getTableMetadata_CalledWithProperArguments_MetadataManagerShouldBeCalledProperly.

@Test
public void getTableMetadata_CalledWithProperArguments_MetadataManagerShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    String namespace = "namespace";
    String table = "table";
    GetTableMetadataResponse response = mock(GetTableMetadataResponse.class);
    when(stub.getTableMetadata(any())).thenReturn(response);
    when(response.hasTableMetadata()).thenReturn(true);
    when(response.getTableMetadata()).thenReturn(com.scalar.db.rpc.TableMetadata.newBuilder().putColumn("col1", com.scalar.db.rpc.DataType.DATA_TYPE_INT).putColumn("col2", com.scalar.db.rpc.DataType.DATA_TYPE_INT).putColumn("col3", com.scalar.db.rpc.DataType.DATA_TYPE_INT).addPartitionKeyName("col1").addClusteringKeyName("col2").putClusteringOrder("col2", com.scalar.db.rpc.Order.ORDER_DESC).build());
    // Act
    TableMetadata tableMetadata = admin.getTableMetadata(namespace, table);
    // Assert
    verify(stub).getTableMetadata(GetTableMetadataRequest.newBuilder().setNamespace(namespace).setTable(table).build());
    assertThat(tableMetadata).isEqualTo(TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addColumn("col3", DataType.INT).addPartitionKey("col1").addClusteringKey("col2", Scan.Ordering.Order.DESC).build());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse) Test(org.junit.jupiter.api.Test)

Example 4 with GetTableMetadataResponse

use of com.scalar.db.rpc.GetTableMetadataResponse in project scalardb by scalar-labs.

the class DistributedStorageAdminServiceTest method getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly.

@Test
public void getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    GetTableMetadataRequest request = GetTableMetadataRequest.newBuilder().setNamespace("namespace").setTable("table").build();
    @SuppressWarnings("unchecked") StreamObserver<GetTableMetadataResponse> responseObserver = mock(StreamObserver.class);
    // Act
    adminService.getTableMetadata(request, responseObserver);
    // Assert
    verify(admin).getTableMetadata(any(), any());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse) GetTableMetadataRequest(com.scalar.db.rpc.GetTableMetadataRequest) Test(org.junit.jupiter.api.Test)

Example 5 with GetTableMetadataResponse

use of com.scalar.db.rpc.GetTableMetadataResponse in project scalardb by scalar-labs.

the class DistributedTransactionAdminServiceTest method getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly.

@Test
public void getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    GetTableMetadataRequest request = GetTableMetadataRequest.newBuilder().setNamespace("namespace").setTable("table").build();
    @SuppressWarnings("unchecked") StreamObserver<GetTableMetadataResponse> responseObserver = mock(StreamObserver.class);
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addColumn("col3", DataType.TEXT).addPartitionKey("col1").addClusteringKey("col2").build();
    when(admin.getTableMetadata("namespace", "table")).thenReturn(tableMetadata);
    // Act
    adminService.getTableMetadata(request, responseObserver);
    // Assert
    verify(admin).getTableMetadata(any(), any());
    verify(responseObserver).onNext(GetTableMetadataResponse.newBuilder().setTableMetadata(ProtoUtils.toTableMetadata(tableMetadata)).build());
    verify(responseObserver).onCompleted();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse) GetTableMetadataRequest(com.scalar.db.rpc.GetTableMetadataRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)7 TableMetadata (com.scalar.db.api.TableMetadata)5 Test (org.junit.jupiter.api.Test)4 GetTableMetadataRequest (com.scalar.db.rpc.GetTableMetadataRequest)2 Test (org.junit.Test)1