use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class ConditionExpressionBuilderTest method visit_PutIfNotExistsAcceptCalled_ShouldReturnEmpty.
@Test
public void visit_PutIfNotExistsAcceptCalled_ShouldReturnEmpty() {
// Arrange
PutIfNotExists condition = new PutIfNotExists();
ConditionExpressionBuilder builder = new ConditionExpressionBuilder(DynamoOperation.CONDITION_COLUMN_NAME_ALIAS, DynamoOperation.CONDITION_VALUE_ALIAS);
// Act
condition.accept(builder);
String actual = builder.build();
// Assert
assertThat(actual).isEqualTo("");
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class PutStatementHandlerTest method handle_PutIfNotExistsGiven_ShouldCallUpdateItemWithCondition.
@Test
public void handle_PutIfNotExistsGiven_ShouldCallUpdateItemWithCondition() {
// Arrange
when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse);
Put put = preparePut().withCondition(new PutIfNotExists());
DynamoMutation dynamoMutation = new DynamoMutation(put, metadata);
Map<String, AttributeValue> expectedKeys = dynamoMutation.getKeyMap();
String updateExpression = dynamoMutation.getUpdateExpressionWithKey();
String expectedCondition = dynamoMutation.getIfNotExistsCondition();
Map<String, AttributeValue> expectedBindMap = dynamoMutation.getValueBindMapWithKey();
// 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.PutIfNotExists in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithPutIfNotExistsCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithPutIfNotExistsCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new PutIfNotExists();
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.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method handle_WTEWithCasThrown_ShouldThrowProperExecutionException.
@Test
public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() {
// Arrange
put = preparePutWithClusteringKey();
put.withCondition(new PutIfNotExists());
spy = prepareSpiedInsertStatementHandler();
WriteTimeoutException toThrow = mock(WriteTimeoutException.class);
when(toThrow.getWriteType()).thenReturn(WriteType.CAS);
doThrow(toThrow).when(spy).handleInternal(put);
// Act Assert
assertThatThrownBy(() -> spy.handle(put)).isInstanceOf(RetriableExecutionException.class).hasCause(toThrow);
}
use of com.scalar.db.api.PutIfNotExists in project scalardb by scalar-labs.
the class InsertStatementHandlerTest method handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException.
@Test
public void handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException() {
// Arrange
put = preparePutWithClusteringKey();
put.withCondition(new PutIfNotExists());
spy = prepareSpiedInsertStatementHandler();
WriteTimeoutException toThrow = mock(WriteTimeoutException.class);
when(toThrow.getWriteType()).thenReturn(WriteType.SIMPLE);
doThrow(toThrow).when(spy).handleInternal(put);
// Act Assert
assertThatThrownBy(() -> spy.handle(put)).isInstanceOf(ReadRepairableExecutionException.class).hasCause(toThrow);
}
Aggregations