use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method scan_DeleteCalledBefore_ShouldReturnEmpty.
@Test
public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionException {
// Arrange
GrpcTransaction transaction = manager.start();
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction.commit();
// Act
GrpcTransaction transaction1 = manager.start();
Scan scan = prepareScan(0, 0, 0, TABLE_1);
List<Result> resultBefore = transaction1.scan(scan);
transaction1.delete(prepareDelete(0, 0, TABLE_1));
List<Result> resultAfter = transaction1.scan(scan);
assertThatCode(transaction1::commit).doesNotThrowAnyException();
// Assert
assertThat(resultBefore.size()).isEqualTo(1);
assertThat(resultAfter.size()).isEqualTo(0);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method scan_ScanGiven_ShouldCallCrudHandlerScan.
@Test
public void scan_ScanGiven_ShouldCallCrudHandlerScan() throws CrudException {
// Arrange
Scan scan = prepareScan();
TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
TransactionResult result = mock(TransactionResult.class);
List<Result> results = Collections.singletonList(result);
when(crud.scan(scan)).thenReturn(results);
when(crud.getSnapshot()).thenReturn(snapshot);
// Act
List<Result> actual = transaction.scan(scan);
// Assert
assertThat(actual.size()).isEqualTo(1);
verify(crud).scan(scan);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method scan_withConflictError_shouldThrowCrudConflictException.
@Test
public void scan_withConflictError_shouldThrowCrudConflictException() throws SQLException, ExecutionException {
// Arrange
when(jdbcService.scan(any(), any())).thenThrow(sqlException);
when(sqlException.getErrorCode()).thenReturn(1213);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.scan(scan);
}).isInstanceOf(CrudConflictException.class);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenScanOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException.
@Test
public void whenScanOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThrowCrudException() throws Exception {
// Arrange
when(jdbcService.scan(any(), any())).thenThrow(sqlException);
// Act Assert
assertThatThrownBy(() -> {
JdbcTransaction transaction = manager.start();
Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
transaction.scan(scan);
}).isInstanceOf(CrudException.class);
}
use of com.scalar.db.api.Scan 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();
}
Aggregations