use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly.
@Test
public void put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
storage.put(puts.get(1));
puts.get(0).withCondition(new PutIfNotExists());
puts.get(1).withCondition(new PutIf(new ConditionalExpression(columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
// Act
assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(new Scan(new Key(columnName1, 0)));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1);
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_MultipleMutationsGiven_ShouldCallTransactWriteItems.
@Test
public void handle_MultipleMutationsGiven_ShouldCallTransactWriteItems() {
// Arrange
when(client.transactWriteItems(any(TransactWriteItemsRequest.class))).thenReturn(transactWriteResponse);
Put put1 = preparePut();
Put put2 = preparePut().withCondition(new PutIfNotExists());
Delete delete1 = prepareDelete();
Delete delete2 = prepareDelete().withCondition(new DeleteIfExists());
DynamoMutation dynamoMutation1 = new DynamoMutation(put1, metadata);
DynamoMutation dynamoMutation2 = new DynamoMutation(put2, metadata);
DynamoMutation dynamoMutation3 = new DynamoMutation(delete1, metadata);
DynamoMutation dynamoMutation4 = new DynamoMutation(delete2, metadata);
// Act Assert
assertThatCode(() -> handler.handle(Arrays.asList(put1, put2, delete1, delete2))).doesNotThrowAnyException();
// Assert
ArgumentCaptor<TransactWriteItemsRequest> captor = ArgumentCaptor.forClass(TransactWriteItemsRequest.class);
verify(client).transactWriteItems(captor.capture());
List<TransactWriteItem> items = captor.getValue().transactItems();
assertThat(items.size()).isEqualTo(4);
assertThat(items.get(0).update().key()).isEqualTo(dynamoMutation1.getKeyMap());
assertThat(items.get(0).update().expressionAttributeNames()).isEqualTo(dynamoMutation1.getColumnMapWithKey());
assertThat(items.get(0).update().expressionAttributeValues()).isEqualTo(dynamoMutation1.getValueBindMapWithKey());
assertThat(items.get(0).update().conditionExpression()).isNull();
assertThat(items.get(1).update().key()).isEqualTo(dynamoMutation2.getKeyMap());
assertThat(items.get(1).update().expressionAttributeNames()).isEqualTo(dynamoMutation2.getColumnMapWithKey());
assertThat(items.get(1).update().expressionAttributeValues()).isEqualTo(dynamoMutation2.getValueBindMapWithKey());
assertThat(items.get(1).update().conditionExpression()).isEqualTo(dynamoMutation2.getIfNotExistsCondition());
assertThat(items.get(2).delete().key()).isEqualTo(dynamoMutation3.getKeyMap());
assertThat(items.get(2).delete().conditionExpression()).isNull();
assertThat(items.get(3).delete().key()).isEqualTo(dynamoMutation4.getKeyMap());
assertThat(items.get(3).delete().conditionExpression()).isEqualTo(dynamoMutation4.getIfExistsCondition());
}
Aggregations