use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.
@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws TransactionException {
// Arrange
populateRecords(TABLE_1);
Get get = prepareGet(0, 0, TABLE_1);
Delete delete = prepareDelete(0, 0, TABLE_1);
GrpcTransaction transaction = manager.start();
// Act
Optional<Result> result = transaction.get(get);
transaction.delete(delete);
transaction.commit();
// Assert
assertThat(result.isPresent()).isTrue();
GrpcTransaction another = manager.start();
assertThat(another.get(get).isPresent()).isFalse();
another.commit();
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method prepareDeletes.
private GrpcTransaction prepareDeletes(int one, String table, int another, String anotherTable) throws TransactionException {
boolean differentTables = !table.equals(anotherTable);
GrpcTransaction transaction = manager.start();
List<Get> gets = prepareGets(table);
List<Get> anotherGets = differentTables ? prepareGets(anotherTable) : gets;
transaction.get(gets.get(one));
transaction.get(anotherGets.get(another));
List<Delete> deletes = prepareDeletes(table);
List<Delete> anotherDeletes = differentTables ? prepareDeletes(anotherTable) : deletes;
transaction.delete(deletes.get(one));
transaction.delete(anotherDeletes.get(another));
return transaction;
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method prepareGet.
private Get prepareGet() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Get(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitTest method get_GetForUncommittedRecordGiven_ShouldRecoverRecord.
@Test
public void get_GetForUncommittedRecordGiven_ShouldRecoverRecord() throws CrudException {
// Arrange
Get get = prepareGet();
TwoPhaseConsensusCommit transaction = new TwoPhaseConsensusCommit(crud, commit, recovery, false);
TransactionResult result = mock(TransactionResult.class);
UncommittedRecordException toThrow = mock(UncommittedRecordException.class);
when(crud.get(get)).thenThrow(toThrow);
when(crud.getSnapshot()).thenReturn(snapshot);
when(toThrow.getResults()).thenReturn(Collections.singletonList(result));
// Act
assertThatThrownBy(() -> transaction.get(get)).isInstanceOf(UncommittedRecordException.class);
// Assert
verify(recovery).recover(get, result);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class JdbcTransactionManagerTest method whenCommitFails_shouldThrowCommitExceptionAndRollback.
@Test
public void whenCommitFails_shouldThrowCommitExceptionAndRollback() throws Exception {
// Arrange
doThrow(sqlException).when(connection).commit();
// 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.commit();
}).isInstanceOf(CommitException.class);
verify(connection).rollback();
verify(connection).close();
}
Aggregations