use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class PutStatementHandlerTest method handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException.
@Test
public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException() {
// Arrange
when(container.getScripts()).thenReturn(cosmosScripts);
when(cosmosScripts.getStoredProcedure(anyString())).thenReturn(storedProcedure);
CosmosException toThrow = mock(CosmosException.class);
doThrow(toThrow).when(storedProcedure).execute(anyList(), any(CosmosStoredProcedureRequestOptions.class));
when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.PRECONDITION_FAILED.get());
Put put = preparePut().withCondition(new PutIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(put)).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class ConditionExpressionBuilderTest method visit_PutIfExistsAcceptCalled_ShouldReturnEmpty.
@Test
public void visit_PutIfExistsAcceptCalled_ShouldReturnEmpty() {
// Arrange
PutIfExists condition = new PutIfExists();
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.PutIfExists in project scalardb by scalar-labs.
the class DynamoMutationTest method getValueBindMap_PutWithPutIfExistsGiven_ShouldReturnBindMap.
@Test
public void getValueBindMap_PutWithPutIfExistsGiven_ShouldReturnBindMap() {
// Arrange
Put put = preparePut().withCondition(new PutIfExists());
Map<String, AttributeValue> expected = new HashMap<>();
expected.put(DynamoOperation.VALUE_ALIAS + "0", AttributeValue.builder().n(String.valueOf(ANY_INT_1)).build());
expected.put(DynamoOperation.VALUE_ALIAS + "1", AttributeValue.builder().n(String.valueOf(ANY_INT_2)).build());
DynamoMutation dynamoMutation = new DynamoMutation(put, metadata);
// Act
Map<String, AttributeValue> actual = dynamoMutation.getValueBindMap();
// Assert
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class DynamoMutationTest method getUpdateExpression_PutWithIfExistsGiven_ShouldReturnExpression.
@Test
public void getUpdateExpression_PutWithIfExistsGiven_ShouldReturnExpression() {
// Arrange
Put put = preparePut().withCondition(new PutIfExists());
DynamoMutation dynamoMutation = new DynamoMutation(put, metadata);
// Act
String actual = dynamoMutation.getUpdateExpression();
// Assert
assertThat(actual).isEqualTo("SET " + DynamoOperation.COLUMN_NAME_ALIAS + "0 = " + DynamoOperation.VALUE_ALIAS + "0, " + DynamoOperation.COLUMN_NAME_ALIAS + "1 = " + DynamoOperation.VALUE_ALIAS + "1");
}
use of com.scalar.db.api.PutIfExists in project scalardb by scalar-labs.
the class UpdateStatementHandlerTest method prepare_PutOperationWithIfExistsGiven_ShouldPrepareProperQuery.
@Test
public void prepare_PutOperationWithIfExistsGiven_ShouldPrepareProperQuery() {
// Arrange
String expected = Joiner.on(" ").skipNulls().join(new String[] { "UPDATE", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "SET", ANY_NAME_3 + "=?", "WHERE", ANY_NAME_1 + "=?", "AND", ANY_NAME_2 + "=?", "IF EXISTS;" });
configureBehavior(expected);
put = preparePutWithClusteringKey();
put.withCondition(new PutIfExists());
// Act
handler.prepare(put);
// Assert
verify(session).prepare(expected);
}
Aggregations