use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithNullValue_shouldNotThrowAnyException.
@Test
public void whenCheckingPutOperationWithNullValue_shouldNotThrowAnyException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new PutIfNotExists();
Put put = new Put(partitionKey, clusteringKey).withValue(COL1, 1).withValue(COL2, 0.1D).withBooleanValue(COL3, null).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException();
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcDatabaseTest method whenPutOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException.
@Test
public void whenPutOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException() throws Exception {
// Arrange
when(jdbcService.put(any(), any())).thenThrow(sqlException);
// Act Assert
assertThatThrownBy(() -> {
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.put(put);
}).isInstanceOf(ExecutionException.class);
verify(connection).close();
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcDatabaseTest method whenPutOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException.
@Test
public void whenPutOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException() throws Exception {
// Arrange
when(jdbcService.put(any(), any())).thenReturn(false);
// Act Assert
assertThatThrownBy(() -> {
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()).forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.put(put);
}).isInstanceOf(NoMutationException.class);
verify(connection).close();
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcDatabaseTest method whenPutOperationExecuted_shouldCallJdbcService.
@Test
public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception {
// Arrange
when(jdbcService.put(any(), any())).thenReturn(true);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.put(put);
// Assert
verify(jdbcService).put(any(), any());
verify(connection).close();
}
use of com.scalar.db.api.Put 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();
}
Aggregations