Search in sources :

Example 41 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateCommittedAndRolledForwardByAnother_ShouldRollforwardProperly.

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

Example 42 with Get

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

the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateAbortedAndRolledBackByAnother_ShouldRollbackProperly.

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

Example 43 with Get

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

the class JdbcTransactionIntegrationTest method get_GetGivenForCommittedRecord_ShouldReturnRecord.

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

Example 44 with Get

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

the class JdbcTransactionIntegrationTest method prepareTransfer.

private JdbcTransaction prepareTransfer(int fromId, int toId, int amount) throws TransactionException {
    JdbcTransaction transaction = manager.start();
    List<Get> gets = prepareGets(NAMESPACE, TABLE);
    Optional<Result> fromResult = transaction.get(gets.get(fromId));
    assertThat(fromResult.isPresent()).isTrue();
    IntValue fromBalance = new IntValue(BALANCE, getBalance(fromResult.get()) - amount);
    Optional<Result> toResult = transaction.get(gets.get(toId));
    assertThat(toResult.isPresent()).isTrue();
    IntValue toBalance = new IntValue(BALANCE, getBalance(toResult.get()) + amount);
    List<Put> puts = preparePuts(NAMESPACE, TABLE);
    puts.get(fromId).withValue(fromBalance);
    puts.get(toId).withValue(toBalance);
    transaction.put(puts.get(fromId));
    transaction.put(puts.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 45 with Get

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

the class JdbcTransactionIntegrationTest method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.

@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws TransactionException {
    // Arrange
    populateRecords();
    Get get = prepareGet(0, 0, NAMESPACE, TABLE);
    Delete delete = prepareDelete(0, 0, NAMESPACE, TABLE);
    JdbcTransaction transaction = manager.start();
    // Act
    Optional<Result> result = transaction.get(get);
    transaction.delete(delete);
    transaction.commit();
    // Assert
    assertThat(result.isPresent()).isTrue();
    JdbcTransaction another = manager.start();
    Optional<Result> result1 = another.get(get);
    another.commit();
    assertThat(result1.isPresent()).isFalse();
}
Also used : Delete(com.scalar.db.api.Delete) 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