Search in sources :

Example 56 with Key

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

the class ConsensusCommitIntegrationTestBase method preparePut.

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

Example 57 with Key

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

the class ConsensusCommitIntegrationTestBase method populateRecords.

private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
    ConsensusCommit 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);
        transaction.put(put);
    }));
    transaction.commit();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) DatabaseConfig(com.scalar.db.config.DatabaseConfig) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) 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) Mockito.spy(org.mockito.Mockito.spy) 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) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestUtils(com.scalar.db.storage.TestUtils) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) Before(org.junit.Before) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) NoMutationException(com.scalar.db.exception.storage.NoMutationException) TransactionState(com.scalar.db.api.TransactionState) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Put(com.scalar.db.api.Put) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) Mockito.verify(org.mockito.Mockito.verify) DistributedStorage(com.scalar.db.api.DistributedStorage) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Selection(com.scalar.db.api.Selection) Scan(com.scalar.db.api.Scan) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) Optional(java.util.Optional) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Example 58 with Key

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

the class BatchHandlerTest method handle_MultiPartitionOperationsGiven_ShouldCallTransactWriteItems.

@Test
public void handle_MultiPartitionOperationsGiven_ShouldCallTransactWriteItems() {
    // Arrange
    when(client.transactWriteItems(any(TransactWriteItemsRequest.class))).thenReturn(transactWriteResponse);
    Put put1 = preparePut();
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_3);
    Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3);
    Put put2 = new Put(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME).withValue(ANY_NAME_3, ANY_INT_1).withValue(ANY_NAME_4, ANY_INT_2);
    // Act Assert
    assertThatCode(() -> handler.handle(Arrays.asList(put1, put2))).doesNotThrowAnyException();
    // Assert
    verify(client).transactWriteItems(any(TransactWriteItemsRequest.class));
}
Also used : TransactWriteItemsRequest(software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsRequest) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 59 with Key

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

the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method prepareDelete.

private Delete prepareDelete(int id, int type, String namespace, 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 60 with Key

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

the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method preparePut.

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

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