use of com.scalar.db.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method commit_DeleteGivenWithoutRead_ShouldThrowCommitException.
@Test
public void commit_DeleteGivenWithoutRead_ShouldThrowCommitException() throws TransactionException {
// Arrange
Delete delete = prepareDelete(0, 0, TABLE_1);
GrpcTransaction transaction = manager.start();
// Act Assert
transaction.delete(delete);
assertThatCode(transaction::commit).isInstanceOf(CommitException.class);
}
use of com.scalar.db.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method scan_ScanGivenForCommittedRecord_ShouldReturnRecord.
@Test
public void scan_ScanGivenForCommittedRecord_ShouldReturnRecord() throws TransactionException {
// Arrange
populateRecords(TABLE_1);
GrpcTransaction transaction = manager.start();
Scan scan = prepareScan(0, 0, 0, TABLE_1);
// Act
List<Result> results = transaction.scan(scan);
transaction.commit();
// Assert
assertThat(results.size()).isEqualTo(1);
}
use of com.scalar.db.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method getState_forSuccessfulTransaction_ShouldReturnCommittedState.
@Test
public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() throws TransactionException {
// Arrange
GrpcTransaction transaction = manager.start();
transaction.get(prepareGet(0, 0, TABLE_1));
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction.commit();
// Act
TransactionState state = manager.getState(transaction.getId());
// Assert
assertThat(state).isEqualTo(TransactionState.COMMITTED);
}
use of com.scalar.db.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method get_GetGivenForNonExisting_ShouldReturnEmpty.
@Test
public void get_GetGivenForNonExisting_ShouldReturnEmpty() throws TransactionException {
// Arrange
populateRecords(TABLE_1);
GrpcTransaction transaction = manager.start();
Get get = prepareGet(0, 4, TABLE_1);
// Act
Optional<Result> result = transaction.get(get);
transaction.commit();
// Assert
assertThat(result.isPresent()).isFalse();
}
use of com.scalar.db.transaction.rpc.GrpcTransaction in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method commit_ConflictingDeletesGivenForExisting_ShouldCommitOneAndAbortTheOther.
private void commit_ConflictingDeletesGivenForExisting_ShouldCommitOneAndAbortTheOther(String table1, String table2) throws TransactionException {
// Arrange
boolean differentTables = !table1.equals(table2);
int account1 = 0;
int account2 = NUM_TYPES;
int account3 = NUM_TYPES * 2;
populateRecords(table1);
if (differentTables) {
populateRecords(table2);
}
// Act
GrpcTransaction transaction = prepareDeletes(account1, table1, account2, table2);
assertThatCode(() -> prepareDeletes(account2, table2, account3, table1).commit()).doesNotThrowAnyException();
assertThatThrownBy(transaction::commit).isInstanceOf(CommitException.class);
// Assert
List<Get> gets1 = prepareGets(table1);
List<Get> gets2 = differentTables ? prepareGets(table2) : gets1;
GrpcTransaction another = manager.start();
Optional<Result> result = another.get(gets1.get(account1));
assertThat(result).isPresent();
assertThat(getBalance(result.get())).isEqualTo(INITIAL_BALANCE);
assertThat(another.get(gets2.get(account2)).isPresent()).isFalse();
assertThat(another.get(gets1.get(account3)).isPresent()).isFalse();
another.commit();
}
Aggregations