use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method populateRecords.
private void populateRecords() throws TransactionException {
GrpcTransaction transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE).withValue(BALANCE, INITIAL_BALANCE);
try {
transaction.put(put);
} catch (CrudException e) {
throw new RuntimeException(e);
}
}));
transaction.commit();
}
use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class CrudHandlerTest method get_KeyNotExistsInCrudSetAndExceptionThrownInStorage_ShouldThrowCrudException.
@Test
public void get_KeyNotExistsInCrudSetAndExceptionThrownInStorage_ShouldThrowCrudException() throws CrudException, ExecutionException {
// Arrange
Get get = prepareGet();
when(snapshot.get(new Snapshot.Key(get))).thenReturn(Optional.empty());
ExecutionException toThrow = mock(ExecutionException.class);
when(storage.get(get)).thenThrow(toThrow);
// Act Assert
assertThatThrownBy(() -> handler.get(get)).isInstanceOf(CrudException.class).hasCause(toThrow);
}
use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class CrudHandlerTest method get_KeyNotExistsInSnapshotAndRecordInStorageCommitted_ShouldReturnFromStorageAndUpdateSnapshot.
@Test
public void get_KeyNotExistsInSnapshotAndRecordInStorageCommitted_ShouldReturnFromStorageAndUpdateSnapshot() throws CrudException, ExecutionException {
// Arrange
Get get = prepareGet();
Optional<Result> expected = Optional.of(prepareResult(TransactionState.COMMITTED));
Snapshot.Key key = new Snapshot.Key(get);
when(snapshot.containsKeyInReadSet(key)).thenReturn(false);
doNothing().when(snapshot).put(any(Snapshot.Key.class), ArgumentMatchers.<Optional<TransactionResult>>any());
when(storage.get(get)).thenReturn(expected);
when(snapshot.get(key)).thenReturn(expected.map(e -> (TransactionResult) e));
// Act
Optional<Result> result = handler.get(get);
// Assert
assertThat(result).isEqualTo(Optional.of(new FilteredResult(expected.get(), Collections.emptyList(), TABLE_METADATA)));
verify(storage).get(get);
verify(snapshot).put(key, Optional.of((TransactionResult) expected.get()));
}
use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionIntegrationTestBase method populateRecords.
private void populateRecords() throws TransactionException {
TwoPhaseCommitTransaction transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(TABLE).withIntValue(BALANCE, INITIAL_BALANCE).withIntValue(SOME_COLUMN, i * j);
try {
transaction.put(put);
} catch (CrudException e) {
throw new RuntimeException(e);
}
}));
transaction.prepare();
transaction.validate();
transaction.commit();
}
use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class JdbcTransaction method delete.
@Override
public void delete(Delete delete) throws CrudException {
delete = copyAndSetTargetToIfNot(delete);
// Ignore the condition in the delete
if (delete.getCondition().isPresent()) {
LOGGER.warn("ignoring the condition of the mutation: {}", delete);
delete.withCondition(null);
}
try {
jdbcService.delete(delete, connection);
} catch (SQLException e) {
throw createCrudException(e, "delete operation failed");
} catch (ExecutionException e) {
throw new CrudException("delete operation failed", e);
}
}
Aggregations