Search in sources :

Example 71 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DynamoAdminTest method createTable_tableMetadataWithBooleanSecondaryIndexGiven_ShouldThrowIllegalArgumentException.

@Test
public void createTable_tableMetadataWithBooleanSecondaryIndexGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    TableMetadata metadata = TableMetadata.newBuilder().addPartitionKey("c1").addColumn("c1", DataType.INT).addColumn("c2", DataType.BOOLEAN).addSecondaryIndex("c2").build();
    // Act Assert
    assertThatThrownBy(() -> admin.createTable(NAMESPACE, TABLE, metadata)).isInstanceOf(IllegalArgumentException.class);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 72 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DynamoOperationCheckerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    openMocks(this).close();
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(PKEY1, DataType.INT).addColumn(COL1, DataType.INT).addColumn(COL2, DataType.DOUBLE).addPartitionKey(PKEY1).addSecondaryIndex(COL1).build();
    when(metadataManager.getTableMetadata(any())).thenReturn(tableMetadata);
    operationChecker = new DynamoOperationChecker(metadataManager);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 73 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class CosmosAdminTest method createTable_WithBlobClusteringKey_ShouldThrowIllegalArgumentException.

@Test
public void createTable_WithBlobClusteringKey_ShouldThrowIllegalArgumentException() {
    // Arrange
    String namespace = "ns";
    String table = "sample_table";
    TableMetadata metadata = TableMetadata.newBuilder().addPartitionKey("c3").addClusteringKey("c1").addColumn("c1", DataType.BLOB).addColumn("c2", DataType.BIGINT).addColumn("c3", DataType.BOOLEAN).build();
    // Act Assert
    assertThatThrownBy(() -> admin.createTable(namespace, table, metadata)).isInstanceOf(IllegalArgumentException.class);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 74 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class TableMetadataManagerTest method getTableMetadata_CalledOnce_ShouldCallDistributedStorageAdminOnce.

@Test
public void getTableMetadata_CalledOnce_ShouldCallDistributedStorageAdminOnce() throws ExecutionException {
    // Arrange
    TableMetadataManager tableMetadataManager = new TableMetadataManager(admin, -1);
    TableMetadata expectedTableMetadata = TableMetadata.newBuilder().addColumn("c1", DataType.INT).addColumn("c2", DataType.INT).addPartitionKey("c1").build();
    when(admin.getTableMetadata(anyString(), anyString())).thenReturn(expectedTableMetadata);
    // Act
    TableMetadata actualTableMetadata = tableMetadataManager.getTableMetadata(new Get(new Key("c1", "aaa")).forNamespace("ns").forTable("tbl"));
    // Assert
    verify(admin).getTableMetadata(anyString(), anyString());
    assertThat(actualTableMetadata).isEqualTo(expectedTableMetadata);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 75 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class GrpcTransactionOnBidirectionalStream method get.

public Optional<Result> get(Get get) throws CrudException {
    throwIfTransactionFinished();
    ResponseOrError responseOrError = sendRequest(TransactionRequest.newBuilder().setGetRequest(GetRequest.newBuilder().setGet(ProtoUtils.toGet(get))).build());
    throwIfErrorForCrud(responseOrError);
    GetResponse getResponse = responseOrError.getResponse().getGetResponse();
    if (getResponse.hasResult()) {
        TableMetadata tableMetadata = getTableMetadata(get);
        return Optional.of(ProtoUtils.toResult(getResponse.getResult(), tableMetadata));
    }
    return Optional.empty();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetResponse(com.scalar.db.rpc.TransactionResponse.GetResponse)

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)101 Test (org.junit.jupiter.api.Test)39 Get (com.scalar.db.api.Get)11 PreparedStatement (java.sql.PreparedStatement)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Key (com.scalar.db.io.Key)6 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)6 Mutation (com.scalar.db.api.Mutation)5 Result (com.scalar.db.api.Result)5 GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)5 ResultSet (java.sql.ResultSet)5 Nonnull (javax.annotation.Nonnull)5 HashMap (java.util.HashMap)4 Options (com.datastax.driver.core.schemabuilder.Create.Options)3 KeyspaceOptions (com.datastax.driver.core.schemabuilder.KeyspaceOptions)3 TableOptions (com.datastax.driver.core.schemabuilder.TableOptions)3 ScanAll (com.scalar.db.api.ScanAll)3 NoMutationException (com.scalar.db.exception.storage.NoMutationException)3