use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithPutIfExistsCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithPutIfExistsCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new PutIfExists();
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class ConditionalQueryBuilderTest method visit_PutIfExistsAcceptCalled_ShouldNotCallWhere.
@Test
public void visit_PutIfExistsAcceptCalled_ShouldNotCallWhere() {
// Arrange
PutIfExists condition = new PutIfExists();
ConditionalQueryBuilder builder = new ConditionalQueryBuilder(select);
// Act
condition.accept(builder);
// Assert
verify(select, never()).and(any(Condition.class));
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class JdbcServiceTest method whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCallQueryBuilder.
@Test
public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.update(any(), any(), any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.set(any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.where(any(), any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.build()).thenReturn(updateQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeUpdate()).thenReturn(0);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.put(put, connection);
// Assert
assertThat(ret).isFalse();
verify(operationChecker).check(any(Put.class));
verify(queryBuilder).update(any(), any(), any());
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class PutStatementHandlerTest method handle_PutIfExistsGiven_ShouldCallUpdateItemWithCondition.
@Test
public void handle_PutIfExistsGiven_ShouldCallUpdateItemWithCondition() {
// Arrange
when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse);
Put put = preparePut().withCondition(new PutIfExists());
DynamoMutation dynamoMutation = new DynamoMutation(put, metadata);
Map<String, AttributeValue> expectedKeys = dynamoMutation.getKeyMap();
String updateExpression = dynamoMutation.getUpdateExpression();
String expectedCondition = dynamoMutation.getIfExistsCondition();
Map<String, AttributeValue> expectedBindMap = dynamoMutation.getValueBindMap();
// Act Assert
assertThatCode(() -> handler.handle(put)).doesNotThrowAnyException();
// Assert
ArgumentCaptor<UpdateItemRequest> captor = ArgumentCaptor.forClass(UpdateItemRequest.class);
verify(client).updateItem(captor.capture());
UpdateItemRequest actualRequest = captor.getValue();
assertThat(actualRequest.key()).isEqualTo(expectedKeys);
assertThat(actualRequest.updateExpression()).isEqualTo(updateExpression);
assertThat(actualRequest.conditionExpression()).isEqualTo(expectedCondition);
assertThat(actualRequest.expressionAttributeValues()).isEqualTo(expectedBindMap);
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class PutStatementHandlerTest method handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMutationException.
@Test
public void handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMutationException() {
// Arrange
ConditionalCheckFailedException toThrow = mock(ConditionalCheckFailedException.class);
doThrow(toThrow).when(client).updateItem(any(UpdateItemRequest.class));
Put put = preparePut().withCondition(new PutIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(put)).isInstanceOf(NoMutationException.class);
}
Aggregations