Search in sources :

Example 1 with PutIfExists

use of com.scalar.db.api.PutIfExists 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)

Example 2 with PutIfExists

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

the class UpdateStatementHandlerTest method prepare_PutOperationWithIfExistsGiven_ShouldCallAccept.

@Test
public void prepare_PutOperationWithIfExistsGiven_ShouldCallAccept() {
    // Arrange
    configureBehavior(null);
    put = preparePutWithClusteringKey();
    PutIfExists putIfExists = Mockito.spy(new PutIfExists());
    put.withCondition(putIfExists);
    // Act
    handler.prepare(put);
    // Assert
    verify(putIfExists).accept(any(ConditionSetter.class));
}
Also used : PutIfExists(com.scalar.db.api.PutIfExists) Test(org.junit.jupiter.api.Test)

Example 3 with PutIfExists

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, "c3", "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = new PutIfExists();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) PutIfExists(com.scalar.db.api.PutIfExists) Test(org.junit.jupiter.api.Test)

Example 4 with PutIfExists

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue("v4", true));
    MutationCondition condition = new PutIfExists();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) PutIfExists(com.scalar.db.api.PutIfExists) Test(org.junit.jupiter.api.Test)

Example 5 with PutIfExists

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, "c3", "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = new PutIfExists();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) PutIfExists(com.scalar.db.api.PutIfExists) Test(org.junit.jupiter.api.Test)

Aggregations

PutIfExists (com.scalar.db.api.PutIfExists)21 Test (org.junit.jupiter.api.Test)18 Put (com.scalar.db.api.Put)15 Key (com.scalar.db.io.Key)6 MutationCondition (com.scalar.db.api.MutationCondition)5 IntValue (com.scalar.db.io.IntValue)4 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)3 BooleanValue (com.scalar.db.io.BooleanValue)3 DoubleValue (com.scalar.db.io.DoubleValue)3 TextValue (com.scalar.db.io.TextValue)3 Value (com.scalar.db.io.Value)3 CosmosException (com.azure.cosmos.CosmosException)2 Get (com.scalar.db.api.Get)2 Result (com.scalar.db.api.Result)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)2 UpdateItemRequest (software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest)2 BatchStatement (com.datastax.driver.core.BatchStatement)1 BoundStatement (com.datastax.driver.core.BoundStatement)1