Search in sources :

Example 26 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward.

@Test
public void get_GetGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward() throws ExecutionException, CoordinatorException, CrudException {
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    selection_SelectionGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward(get);
}
Also used : Get(com.scalar.db.api.Get) Test(org.junit.Test)

Example 27 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback.

@Test
public void get_GetGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback() throws ExecutionException, CoordinatorException, CrudException {
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    selection_SelectionGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback(get);
}
Also used : Get(com.scalar.db.api.Get) Test(org.junit.Test)

Example 28 with Get

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

the class ConsensusCommitIntegrationTestBase method commit_WriteSkewOnExistingRecordsWithSerializableWithExtraRead_OneShouldCommitTheOtherShouldThrowCommitConflictException.

private void commit_WriteSkewOnExistingRecordsWithSerializableWithExtraRead_OneShouldCommitTheOtherShouldThrowCommitConflictException(String namespace1, String table1, String namespace2, String table2) throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    List<Put> puts = Arrays.asList(preparePut(0, 0, namespace1, table1).withValue(BALANCE, 1), preparePut(0, 1, namespace2, table2).withValue(BALANCE, 1));
    ConsensusCommit transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    transaction.put(puts);
    transaction.commit();
    // Act
    ConsensusCommit transaction1 = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    ConsensusCommit transaction2 = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    Get get1_1 = prepareGet(0, 1, namespace2, table2);
    Optional<Result> result1 = transaction1.get(get1_1);
    assertThat(result1).isPresent();
    int current1 = getBalance(result1.get());
    Get get1_2 = prepareGet(0, 0, namespace1, table1);
    transaction1.get(get1_2);
    Get get2_1 = prepareGet(0, 0, namespace1, table1);
    Optional<Result> result2 = transaction2.get(get2_1);
    assertThat(result2).isPresent();
    int current2 = getBalance(result2.get());
    Get get2_2 = prepareGet(0, 1, namespace2, table2);
    transaction2.get(get2_2);
    Put put1 = preparePut(0, 0, namespace1, table1).withValue(BALANCE, current1 + 1);
    transaction1.put(put1);
    Put put2 = preparePut(0, 1, namespace2, table2).withValue(BALANCE, current2 + 1);
    transaction2.put(put2);
    transaction1.commit();
    Throwable thrown = catchThrowable(transaction2::commit);
    // Assert
    transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
    result1 = transaction.get(get1_1);
    assertThat(result1).isPresent();
    assertThat(getBalance(result1.get())).isEqualTo(1);
    result2 = transaction.get(get2_1);
    assertThat(result2).isPresent();
    assertThat(getBalance(result2.get())).isEqualTo(2);
    assertThat(thrown).isInstanceOf(CommitConflictException.class);
}
Also used : Get(com.scalar.db.api.Get) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result)

Example 29 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward.

@Test
public void get_GetGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward() throws ExecutionException, CoordinatorException, CrudException {
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    selection_SelectionGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward(get);
}
Also used : Get(com.scalar.db.api.Get) Test(org.junit.Test)

Example 30 with Get

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

the class ConsensusCommitIntegrationTestBase method prepareGet.

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

Aggregations

Get (com.scalar.db.api.Get)286 Test (org.junit.jupiter.api.Test)130 Result (com.scalar.db.api.Result)129 Key (com.scalar.db.io.Key)126 Test (org.junit.Test)88 Put (com.scalar.db.api.Put)86 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)32 Delete (com.scalar.db.api.Delete)28 IntValue (com.scalar.db.io.IntValue)28 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)21 TextValue (com.scalar.db.io.TextValue)16 ConditionalExpression (com.scalar.db.api.ConditionalExpression)13 PartitionKey (com.azure.cosmos.models.PartitionKey)12 TableMetadata (com.scalar.db.api.TableMetadata)10 BooleanValue (com.scalar.db.io.BooleanValue)10 PutIf (com.scalar.db.api.PutIf)8 BigIntValue (com.scalar.db.io.BigIntValue)7 HashMap (java.util.HashMap)7 BlobValue (com.scalar.db.io.BlobValue)6 DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet (com.scalar.db.server.DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet)6