use of com.scalar.db.transaction.rpc.GrpcTransaction 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.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method putAndCommit_PutGivenForNonExisting_ShouldCreateRecord.
@Test
public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord() throws TransactionException {
// Arrange
int expected = INITIAL_BALANCE;
Put put = preparePut(0, 0, TABLE_1).withValue(BALANCE, expected);
GrpcTransaction transaction = manager.start();
// Act
transaction.put(put);
transaction.commit();
// Assert
Get get = prepareGet(0, 0, TABLE_1);
GrpcTransaction another = manager.start();
Optional<Result> result = another.get(get);
another.commit();
assertThat(result).isPresent();
assertThat(getBalance(result.get())).isEqualTo(expected);
}
use of com.scalar.db.transaction.rpc.GrpcTransaction 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.transaction.rpc.GrpcTransaction 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.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method scan_NonOverlappingPutGivenBefore_ShouldScan.
@Test
public void scan_NonOverlappingPutGivenBefore_ShouldScan() throws TransactionException {
// Arrange
GrpcTransaction transaction = manager.start();
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
// Act
Scan scan = prepareScan(0, 1, 1, TABLE_1);
Throwable thrown = catchThrowable(() -> transaction.scan(scan));
transaction.commit();
// Assert
assertThat(thrown).doesNotThrowAnyException();
}
Aggregations