Search in sources :

Example 36 with Get

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

the class JdbcTransactionIntegrationTest method get_GetGivenForNonExisting_ShouldReturnEmpty.

@Test
public void get_GetGivenForNonExisting_ShouldReturnEmpty() throws TransactionException {
    // Arrange
    populateRecords();
    JdbcTransaction transaction = manager.start();
    Get get = prepareGet(0, 4, NAMESPACE, TABLE);
    // Act
    Optional<Result> result = transaction.get(get);
    transaction.commit();
    // Assert
    assertThat(result.isPresent()).isFalse();
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 37 with Get

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

the class ConsensusCommitIntegrationTestBase method prepareTransfer.

private ConsensusCommit prepareTransfer(int fromId, String fromNamespace, String fromTable, int toId, String toNamespace, String toTable, int amount) throws CrudException {
    boolean differentTables = toNamespace.equals(fromNamespace) || !toTable.equals(fromTable);
    ConsensusCommit transaction = manager.start();
    List<Get> fromGets = prepareGets(fromNamespace, fromTable);
    List<Get> toGets = differentTables ? prepareGets(toNamespace, toTable) : fromGets;
    Optional<Result> fromResult = transaction.get(fromGets.get(fromId));
    assertThat(fromResult).isPresent();
    IntValue fromBalance = new IntValue(BALANCE, getBalance(fromResult.get()) - amount);
    Optional<Result> toResult = transaction.get(toGets.get(toId));
    assertThat(toResult).isPresent();
    IntValue toBalance = new IntValue(BALANCE, getBalance(toResult.get()) + amount);
    List<Put> fromPuts = preparePuts(fromNamespace, fromTable);
    List<Put> toPuts = differentTables ? preparePuts(toNamespace, toTable) : fromPuts;
    fromPuts.get(fromId).withValue(fromBalance);
    toPuts.get(toId).withValue(toBalance);
    transaction.put(fromPuts.get(fromId));
    transaction.put(toPuts.get(toId));
    return transaction;
}
Also used : Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result)

Example 38 with Get

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

the class ConsensusCommitIntegrationTestBase method get_CalledTwice_ShouldReturnFromSnapshotInSecondTime.

@Test
public void get_CalledTwice_ShouldReturnFromSnapshotInSecondTime() throws CrudException, ExecutionException, CommitException, UnknownTransactionStatusException {
    // Arrange
    populateRecords(namespace1, TABLE_1);
    ConsensusCommit transaction = manager.start();
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    // Act
    Optional<Result> result1 = transaction.get(get);
    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 39 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForPreparedWhenCoordinatorStateAbortedAndRolledBackByAnother_ShouldRollbackProperly.

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

Example 40 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForNonExisting_ShouldReturnEmpty.

@Test
public void get_GetGivenForNonExisting_ShouldReturnEmpty() throws CrudException, CommitException, UnknownTransactionStatusException {
    // Arrange
    populateRecords(namespace1, TABLE_1);
    ConsensusCommit transaction = manager.start();
    Get get = prepareGet(0, 4, namespace1, TABLE_1);
    // Act
    Optional<Result> result = transaction.get(get);
    // Assert
    assertThat(result.isPresent()).isFalse();
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

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