use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenRollbackFails_shouldThrowAbortException.
@Test
public void whenRollbackFails_shouldThrowAbortException() throws Exception {
// Arrange
doThrow(sqlException).when(connection).rollback();
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.get(get);
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
transaction.put(put);
transaction.abort();
}).isInstanceOf(AbortException.class);
verify(connection).close();
}
use of com.scalar.db.api.Get 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.Get in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException.
@Test
public void whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException() throws Exception {
// Arrange
when(jdbcService.get(any(), any())).thenThrow(sqlException);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.get(get);
}).isInstanceOf(CrudException.class);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method get_withConflictError_shouldThrowCrudConflictException.
@Test
public void get_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.get(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.get(get);
}).isInstanceOf(CrudConflictException.class);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance.
@Test
public void copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance() {
// Arrange
Get get = new Get(new Key("c1", "v1"));
// Act
Get actual = ScalarDbUtils.copyAndSetTargetToIfNot(get, NAMESPACE, TABLE);
// Assert
assertThat(actual == get).isFalse();
assertThat(get.forNamespace()).isNotPresent();
assertThat(get.forTable()).isNotPresent();
assertThat(actual.forNamespace()).isEqualTo(NAMESPACE);
assertThat(actual.forTable()).isEqualTo(TABLE);
}
Aggregations