use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method put_TwoPutsGiven_ShouldCallCrudHandlerPutTwice.
@Test
public void put_TwoPutsGiven_ShouldCallCrudHandlerPutTwice() {
// Arrange
Put put = preparePut();
TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
when(crud.getSnapshot()).thenReturn(snapshot);
// Act
transaction.put(Arrays.asList(put, put));
// Assert
verify(crud, times(2)).put(put);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method preparePut.
private Put preparePut() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Put(partitionKey, clusteringKey).withValue(ANY_NAME_3, ANY_TEXT_3).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method mutate_PutAndDeleteGiven_ShouldCallCrudHandlerPutAndDelete.
@Test
public void mutate_PutAndDeleteGiven_ShouldCallCrudHandlerPutAndDelete() {
// Arrange
Put put = preparePut();
Delete delete = prepareDelete();
TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
when(crud.getSnapshot()).thenReturn(snapshot);
// Act
transaction.mutate(Arrays.asList(put, delete));
// Assert
verify(crud).put(put);
verify(crud).delete(delete);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method mutate_withConflictError_shouldThrowCrudConflictException.
@Test
public void mutate_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.put(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
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);
transaction.mutate(Arrays.asList(put, delete));
}).isInstanceOf(CrudConflictException.class);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenMutateOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException.
@Test
public void whenMutateOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException() throws Exception {
// Arrange
when(jdbcService.put(any(), any())).thenThrow(sqlException);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
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);
transaction.mutate(Arrays.asList(put, delete));
}).isInstanceOf(CrudException.class);
}
Aggregations