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");
}
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());
}
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());
}
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();
}
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();
}
Aggregations