use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcDatabaseTest method whenDeleteOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException.
@Test
public void whenDeleteOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException() throws Exception {
// Arrange
when(jdbcService.delete(any(), any())).thenThrow(sqlException);
// Act Assert
assertThatThrownBy(() -> {
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.delete(delete);
}).isInstanceOf(ExecutionException.class);
verify(connection).close();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcDatabaseTest method mutate_withConflictError_shouldThrowRetriableExecutionException.
@Test
public void mutate_withConflictError_shouldThrowRetriableExecutionException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.mutate(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.mutate(Arrays.asList(put, delete));
}).isInstanceOf(RetriableExecutionException.class);
verify(connection).close();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithInvalidDeleteIfConditionWithIsNotNull_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithInvalidDeleteIfConditionWithIsNotNull_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = ConditionBuilder.deleteIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)).build();
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.Delete in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithInvalidDeleteIfConditionWithIsNull_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithInvalidDeleteIfConditionWithIsNull_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = ConditionBuilder.deleteIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NULL)).build();
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.Delete in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, "c3", "val1");
MutationCondition condition = new DeleteIfExists();
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
Aggregations