use of com.scalar.db.api.Delete 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.Delete 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.Delete 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);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenSomeOperationsExecutedAndCommit_shouldCallJdbcService.
@Test
public void whenSomeOperationsExecutedAndCommit_shouldCallJdbcService() throws Exception {
// Arrange
when(jdbcService.scan(any(), any())).thenReturn(Collections.emptyList());
when(jdbcService.put(any(), any())).thenReturn(true);
when(jdbcService.delete(any(), any())).thenReturn(true);
// Act
JdbcTransaction transaction = manager.start();
Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.get(get);
Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.scan(scan);
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
transaction.put(put);
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.delete(delete);
transaction.mutate(Arrays.asList(put, delete));
transaction.commit();
// Assert
verify(jdbcService).get(any(), any());
verify(jdbcService).scan(any(), any());
verify(jdbcService, times(2)).put(any(), any());
verify(jdbcService, times(2)).delete(any(), any());
verify(connection).commit();
verify(connection).close();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance.
@Test
public void copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance() {
// Arrange
Put put = new Put(new Key("c1", "v1"));
Delete delete = new Delete(new Key("c1", "v1"));
List<Mutation> mutations = Arrays.asList(put, delete);
// Act
List<Mutation> actual = ScalarDbUtils.copyAndSetTargetToIfNot(mutations, NAMESPACE, TABLE);
// Assert
assertThat(actual == mutations).isFalse();
assertThat(actual.get(0) == put).isFalse();
assertThat(actual.get(1) == delete).isFalse();
assertThat(put.forNamespace()).isNotPresent();
assertThat(put.forTable()).isNotPresent();
assertThat(delete.forNamespace()).isNotPresent();
assertThat(delete.forTable()).isNotPresent();
assertThat(actual.get(0).forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.get(0).forTable()).isEqualTo(TABLE);
assertThat(actual.get(1).forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.get(1).forTable()).isEqualTo(TABLE);
}
Aggregations