use of com.scalar.db.api.MutationCondition 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);
}
use of com.scalar.db.api.MutationCondition 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.MutationCondition in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = null;
List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = new PutIfNotExists();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.MutationCondition in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_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(COL3, true));
MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)).build();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.MutationCondition in project scalardb by scalar-labs.
the class CosmosMutation method getMutationType.
@Nonnull
public MutationType getMutationType() {
Mutation mutation = (Mutation) getOperation();
if (!mutation.getCondition().isPresent()) {
if (mutation instanceof Put) {
return MutationType.PUT;
} else {
return MutationType.DELETE_IF;
}
}
MutationCondition condition = mutation.getCondition().get();
if (condition instanceof PutIfNotExists) {
return MutationType.PUT_IF_NOT_EXISTS;
} else if (condition instanceof PutIfExists || condition instanceof PutIf) {
return MutationType.PUT_IF;
} else {
return MutationType.DELETE_IF;
}
}
Aggregations