Search in sources :

Example 6 with Get

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

the class StorageIntegrationTestBase method operation_NoTargetGiven_ShouldThrowIllegalArgumentException.

@Test
public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    storage.with(null, TABLE);
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    Get get = new Get(partitionKey, clusteringKey);
    // Act Assert
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 7 with Get

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

the class StorageIntegrationTestBase method operation_WrongTableGiven_ShouldThrowIllegalArgumentException.

@Test
public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    // a wrong table
    storage.with(namespace, "wrong_" + TABLE);
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    Get get = new Get(partitionKey, clusteringKey);
    // Act Assert
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 8 with Get

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

the class StorageIntegrationTestBase method put_PutWithoutValuesGivenTwice_ShouldStoreProperly.

@Test
public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    // Act
    assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
    assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
    // Assert
    Optional<Result> result = storage.get(new Get(partitionKey, clusteringKey));
    assertThat(result).isPresent();
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 9 with Get

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

the class StorageIntegrationTestBase method get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues.

@Test
public void get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    // Act
    Get get = prepareGet(pKey, cKey);
    get.withProjection(COL_NAME1).withProjection(COL_NAME2).withProjection(COL_NAME3);
    Optional<Result> actual = storage.get(get);
    // Assert
    assertThat(actual.isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
    assertThat(actual.get().getValue(COL_NAME2)).isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey))));
    assertThat(actual.get().getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey)));
    // since it's clustering key
    assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME5).isPresent()).isFalse();
}
Also used : TextValue(com.scalar.db.io.TextValue) Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 10 with Get

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

the class StorageIntegrationTestBase method put_PutWithIfExistsGivenWhenSuchRecordExists_ShouldUpdateRecord.

@Test
public void put_PutWithIfExistsGivenWhenSuchRecordExists_ShouldUpdateRecord() throws ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Get get = prepareGet(pKey, cKey);
    // Act Assert
    storage.put(puts.get(0));
    puts.get(0).withCondition(new PutIfExists());
    puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE);
    assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException();
    // Assert
    Optional<Result> actual = storage.get(get);
    assertThat(actual.isPresent()).isTrue();
    Result result = actual.get();
    assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
    assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey)));
    assertThat(result.getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, Integer.MAX_VALUE)));
}
Also used : Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) PutIfExists(com.scalar.db.api.PutIfExists) 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