Search in sources :

Example 61 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method populateRecords.

private void populateRecords() throws TransactionException {
    GrpcTransaction transaction = manager.start();
    IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
        Key partitionKey = new Key(ACCOUNT_ID, i);
        Key clusteringKey = new Key(ACCOUNT_TYPE, j);
        Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE).withValue(BALANCE, INITIAL_BALANCE);
        try {
            transaction.put(put);
        } catch (CrudException e) {
            throw new RuntimeException(e);
        }
    }));
    transaction.commit();
}
Also used : IntStream(java.util.stream.IntStream) IntValue(com.scalar.db.io.IntValue) BeforeClass(org.junit.BeforeClass) Consistency(com.scalar.db.api.Consistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) StorageFactory(com.scalar.db.service.StorageFactory) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) TableMetadata(com.scalar.db.api.TableMetadata) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) Result(com.scalar.db.api.Result) GrpcTransactionManager(com.scalar.db.transaction.rpc.GrpcTransactionManager) DataType(com.scalar.db.io.DataType) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Before(org.junit.Before) GrpcConfig(com.scalar.db.storage.rpc.GrpcConfig) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) IOException(java.io.IOException) Test(org.junit.Test) Put(com.scalar.db.api.Put) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) List(java.util.List) Scan(com.scalar.db.api.Scan) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 62 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method prepareDelete.

static Delete prepareDelete(int id, int type, String table) {
    Key partitionKey = new Key(ACCOUNT_ID, id);
    Key clusteringKey = new Key(ACCOUNT_TYPE, type);
    return new Delete(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key)

Example 63 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method put_MultiplePutWithDifferentPartitionsWithIfNotExistsGiven_ShouldThrowIllegalArgumentException.

@Test
public void put_MultiplePutWithDifferentPartitionsWithIfNotExistsGiven_ShouldThrowIllegalArgumentException() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    puts.get(0).withCondition(new PutIfNotExists());
    puts.get(3).withCondition(new PutIfNotExists());
    puts.get(6).withCondition(new PutIfNotExists());
    // Act
    assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(3), puts.get(6)))).isInstanceOf(IllegalArgumentException.class);
    // Assert
    List<Result> results;
    results = scanAll(new Scan(new Key(COL_NAME1, 0)));
    assertThat(results.size()).isEqualTo(0);
    results = scanAll(new Scan(new Key(COL_NAME1, 3)));
    assertThat(results.size()).isEqualTo(0);
    results = scanAll(new Scan(new Key(COL_NAME1, 6)));
    assertThat(results.size()).isEqualTo(0);
}
Also used : Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 64 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues.

@Test
public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
    // Arrange
    for (int i = 0; i < 345; i++) {
        Key partitionKey = new Key(COL_NAME1, i % 4);
        Key clusteringKey = new Key(COL_NAME4, i);
        storage.put(new Put(partitionKey, clusteringKey).withBlobValue(COL_NAME6, new byte[5000]));
    }
    Scan scan = new ScanAll();
    // Act
    List<Result> results = scanAll(scan);
    // Assert
    List<ExpectedResult> expectedResults = new ArrayList<>();
    for (int i = 0; i < 345; i++) {
        Key partitionKey = new Key(COL_NAME1, i % 4);
        Key clusteringKey = new Key(COL_NAME4, i);
        expectedResults.add(new ExpectedResultBuilder().partitionKey(partitionKey).clusteringKey(clusteringKey).nonKeyColumns(Arrays.asList(TextColumn.ofNull(COL_NAME2), IntColumn.ofNull(COL_NAME3), BooleanColumn.ofNull(COL_NAME5), BlobColumn.of(COL_NAME6, new byte[5000]))).build());
    }
    assertResultsContainsExactlyInAnyOrder(results, expectedResults);
}
Also used : ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ArrayList(java.util.ArrayList) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 65 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method prepareDeletes.

private List<Delete> prepareDeletes() {
    List<Delete> deletes = new ArrayList<>();
    IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
        Key partitionKey = new Key(COL_NAME1, i);
        Key clusteringKey = new Key(COL_NAME4, j);
        Delete delete = new Delete(partitionKey, clusteringKey);
        deletes.add(delete);
    }));
    return deletes;
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) IntColumn(com.scalar.db.io.IntColumn) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TestUtils.assertResultsAreASubsetOf(com.scalar.db.util.TestUtils.assertResultsAreASubsetOf) TextValue(com.scalar.db.io.TextValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) StorageFactory(com.scalar.db.service.StorageFactory) BooleanColumn(com.scalar.db.io.BooleanColumn) TextColumn(com.scalar.db.io.TextColumn) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) Order(com.scalar.db.api.Scan.Ordering.Order) Map(java.util.Map) DataType(com.scalar.db.io.DataType) Key(com.scalar.db.io.Key) Properties(java.util.Properties) Iterator(java.util.Iterator) NoMutationException(com.scalar.db.exception.storage.NoMutationException) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) IOException(java.io.IOException) TestUtils.assertResultsContainsExactlyInAnyOrder(com.scalar.db.util.TestUtils.assertResultsContainsExactlyInAnyOrder) Test(org.junit.jupiter.api.Test) List(java.util.List) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Ordering(com.scalar.db.api.Scan.Ordering) Optional(java.util.Optional) BlobColumn(com.scalar.db.io.BlobColumn) BooleanValue(com.scalar.db.io.BooleanValue) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key)

Aggregations

Key (com.scalar.db.io.Key)603 Test (org.junit.jupiter.api.Test)391 Put (com.scalar.db.api.Put)211 Scan (com.scalar.db.api.Scan)145 Get (com.scalar.db.api.Get)134 Delete (com.scalar.db.api.Delete)118 Result (com.scalar.db.api.Result)94 Test (org.junit.Test)90 TextValue (com.scalar.db.io.TextValue)88 IntValue (com.scalar.db.io.IntValue)81 BooleanValue (com.scalar.db.io.BooleanValue)51 HashMap (java.util.HashMap)42 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)40 ArrayList (java.util.ArrayList)39 Value (com.scalar.db.io.Value)38 DoubleValue (com.scalar.db.io.DoubleValue)35 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)29 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)27 ByteBuffer (java.nio.ByteBuffer)27