Search in sources :

Example 31 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldNotAbortTransaction.

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

Example 32 with Get

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

the class ConsensusCommitIntegrationTestBase method get_CalledTwiceAndAnotherTransactionCommitsInBetween_ShouldReturnFromSnapshotInSecondTime.

@Test
public void get_CalledTwiceAndAnotherTransactionCommitsInBetween_ShouldReturnFromSnapshotInSecondTime() throws CrudException, ExecutionException, CommitException, UnknownTransactionStatusException {
    // Arrange
    ConsensusCommit transaction = manager.start();
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    // Act
    Optional<Result> result1 = transaction.get(get);
    populateRecords(namespace1, TABLE_1);
    Optional<Result> result2 = transaction.get(get);
    // Assert
    verify(storage).get(any(Get.class));
    assertThat(result1).isEqualTo(result2);
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 33 with Get

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

the class TwoPhaseConsensusCommitIntegrationTest method put_DeleteCalledBefore_ShouldThrowIllegalArgumentException.

@Test
public void put_DeleteCalledBefore_ShouldThrowIllegalArgumentException() throws TransactionException {
    // Arrange
    TwoPhaseConsensusCommit transaction = manager.start();
    transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
    transaction.prepare();
    transaction.commit();
    // Act
    TwoPhaseConsensusCommit transaction1 = manager.start();
    Get get = prepareGet(0, 0, TABLE_1);
    transaction1.get(get);
    transaction1.delete(prepareDelete(0, 0, TABLE_1));
    Throwable thrown = catchThrowable(() -> transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)));
    transaction1.rollback();
    // Assert
    assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 34 with Get

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

the class TwoPhaseConsensusCommitIntegrationTest method get_PutCalledBefore_ShouldGet.

@Test
public void get_PutCalledBefore_ShouldGet() throws CrudException {
    // Arrange
    TwoPhaseConsensusCommit transaction = manager.start();
    // Act
    transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
    Get get = prepareGet(0, 0, TABLE_1);
    Optional<Result> result = transaction.get(get);
    assertThatCode(() -> {
        transaction.prepare();
        transaction.commit();
    }).doesNotThrowAnyException();
    // Assert
    assertThat(result).isPresent();
    assertThat(getBalance(result.get())).isEqualTo(1);
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 35 with Get

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

the class JdbcTransactionIntegrationTest 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