Search in sources :

Example 21 with Get

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

the class StorageWithReservedKeywordIntegrationTestBase method get_GetWithReservedKeywordAndPartitionKeyAndClusteringKeyGiven_ShouldRetrieveSingleResult.

@Test
public void get_GetWithReservedKeywordAndPartitionKeyAndClusteringKeyGiven_ShouldRetrieveSingleResult() throws ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act
    Get get = prepareGet(pKey, 0);
    Optional<Result> actual = storage.get(get);
    // Assert
    assertThat(actual.isPresent()).isTrue();
    assertThat(actual.get().getValue(columnName1)).isEqualTo(Optional.of(new IntValue(columnName1, pKey)));
    assertThat(actual.get().getValue(columnName4)).isEqualTo(Optional.of(new IntValue(columnName4, 0)));
}
Also used : Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 22 with Get

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

the class ConsensusCommitIntegrationTestBase method get_DeleteCalledBefore_ShouldReturnEmpty.

@Test
public void get_DeleteCalledBefore_ShouldReturnEmpty() throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    ConsensusCommit transaction = manager.start();
    transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
    transaction.commit();
    // Act
    ConsensusCommit transaction1 = manager.start();
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    Optional<Result> resultBefore = transaction1.get(get);
    transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1));
    Optional<Result> resultAfter = transaction1.get(get);
    assertThatCode(transaction1::commit).doesNotThrowAnyException();
    // Assert
    assertThat(resultBefore.isPresent()).isTrue();
    assertThat(resultAfter.isPresent()).isFalse();
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 23 with Get

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

the class ConsensusCommitIntegrationTestBase method commit_DeleteGivenForNonExisting_ShouldThrowIllegalArgumentException.

@Test
public void commit_DeleteGivenForNonExisting_ShouldThrowIllegalArgumentException() throws CrudException {
    // Arrange
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    Delete delete = prepareDelete(0, 0, namespace1, TABLE_1);
    ConsensusCommit transaction = manager.start();
    // Act Assert
    transaction.get(get);
    transaction.delete(delete);
    assertThatCode(transaction::commit).isInstanceOf(CommitException.class).hasCauseInstanceOf(IllegalArgumentException.class);
}
Also used : Delete(com.scalar.db.api.Delete) CommitException(com.scalar.db.exception.transaction.CommitException) Get(com.scalar.db.api.Get) Test(org.junit.Test)

Example 24 with Get

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

the class ConsensusCommitIntegrationTestBase method delete_PutCalledBefore_ShouldDelete.

@Test
public void delete_PutCalledBefore_ShouldDelete() throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    ConsensusCommit transaction = manager.start();
    transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
    transaction.commit();
    // Act
    ConsensusCommit transaction1 = manager.start();
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    Optional<Result> resultBefore = transaction1.get(get);
    transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2));
    transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1));
    assertThatCode(transaction1::commit).doesNotThrowAnyException();
    // Assert
    ConsensusCommit transaction2 = manager.start();
    Optional<Result> resultAfter = transaction2.get(get);
    transaction2.commit();
    assertThat(resultBefore.isPresent()).isTrue();
    assertThat(resultAfter.isPresent()).isFalse();
}
Also used : Get(com.scalar.db.api.Get) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 25 with Get

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

the class ConsensusCommitIntegrationTestBase method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.

@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    populateRecords(namespace1, TABLE_1);
    Get get = prepareGet(0, 0, namespace1, TABLE_1);
    Delete delete = prepareDelete(0, 0, namespace1, TABLE_1);
    ConsensusCommit transaction = manager.start();
    // Act
    Optional<Result> result = transaction.get(get);
    transaction.delete(delete);
    transaction.commit();
    // Assert
    assertThat(result.isPresent()).isTrue();
    ConsensusCommit another = manager.start();
    assertThat(another.get(get).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