use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method scan.
public List<Result> scan(Scan scan) throws CrudException {
throwIfTransactionFinished();
ResponseOrError responseOrError = sendRequest(TwoPhaseCommitTransactionRequest.newBuilder().setScanRequest(ScanRequest.newBuilder().setScan(ProtoUtils.toScan(scan))).build());
throwIfErrorForCrud(responseOrError);
TableMetadata tableMetadata = getTableMetadata(scan);
return responseOrError.getResponse().getScanResponse().getResultList().stream().map(r -> ProtoUtils.toResult(r, tableMetadata)).collect(Collectors.toList());
}
use of com.scalar.db.api.TableMetadata 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();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class DistributedStorageService method get.
@Override
public void get(GetRequest request, StreamObserver<GetResponse> responseObserver) {
execute(() -> {
TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getGet().getNamespace(), request.getGet().getTable());
if (metadata == null) {
throw new IllegalArgumentException("the specified table is not found");
}
Get get = ProtoUtils.toGet(request.getGet(), metadata);
Optional<Result> result = storage.get(get);
GetResponse.Builder builder = GetResponse.newBuilder();
result.ifPresent(r -> builder.setResult(ProtoUtils.toResult(r)));
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}, responseObserver, "get");
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class SchemaOperatorTest method createTables_WithTransactionalTables_ShouldCallProperMethods.
@Test
public void createTables_WithTransactionalTables_ShouldCallProperMethods() throws Exception {
// Arrange
List<TableSchema> tableSchemaList = Arrays.asList(tableSchema, tableSchema, tableSchema);
when(tableSchema.getNamespace()).thenReturn("ns");
when(tableSchema.getOptions()).thenReturn(options);
when(tableSchema.isTransactionalTable()).thenReturn(true);
when(tableSchema.getTable()).thenReturn("tb");
TableMetadata tableMetadata = mock(TableMetadata.class);
when(tableSchema.getTableMetadata()).thenReturn(tableMetadata);
// Act
operator.createTables(tableSchemaList);
// Assert
verify(admin, times(3)).createNamespace("ns", true, options);
verify(admin, times(3)).tableExists("ns", "tb");
verify(consensusCommitAdmin, times(3)).createTable("ns", "tb", tableMetadata, options);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class SchemaOperatorTest method createTables_WithNonTransactionalTables_ShouldCallProperMethods.
@Test
public void createTables_WithNonTransactionalTables_ShouldCallProperMethods() throws Exception {
// Arrange
List<TableSchema> tableSchemaList = Arrays.asList(tableSchema, tableSchema, tableSchema);
when(tableSchema.getNamespace()).thenReturn("ns");
when(tableSchema.getOptions()).thenReturn(options);
when(tableSchema.isTransactionalTable()).thenReturn(false);
when(tableSchema.getTable()).thenReturn("tb");
TableMetadata tableMetadata = mock(TableMetadata.class);
when(tableSchema.getTableMetadata()).thenReturn(tableMetadata);
// Act
operator.createTables(tableSchemaList);
// Assert
verify(admin, times(3)).createNamespace("ns", true, options);
verify(admin, times(3)).tableExists("ns", "tb");
verify(admin, times(3)).createTable("ns", "tb", tableMetadata, options);
}
Aggregations