Search in sources :

Example 26 with GrpcTransaction

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);
}
Also used : Delete(com.scalar.db.api.Delete) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Test(org.junit.Test)

Example 27 with GrpcTransaction

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);
}
Also used : Scan(com.scalar.db.api.Scan) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 28 with GrpcTransaction

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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Test(org.junit.Test)

Example 29 with GrpcTransaction

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();
}
Also used : Get(com.scalar.db.api.Get) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 30 with GrpcTransaction

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();
}
Also used : Get(com.scalar.db.api.Get) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Result(com.scalar.db.api.Result)

Aggregations

GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)52 Result (com.scalar.db.api.Result)41 Test (org.junit.Test)37 Get (com.scalar.db.api.Get)34 Put (com.scalar.db.api.Put)19 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)13 Scan (com.scalar.db.api.Scan)9 Delete (com.scalar.db.api.Delete)8 DistributedTransactionServiceWithConsensusCommitIntegrationTest.preparePut (com.scalar.db.server.DistributedTransactionServiceWithConsensusCommitIntegrationTest.preparePut)7 TransactionState (com.scalar.db.api.TransactionState)4 IntValue (com.scalar.db.io.IntValue)4 DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet (com.scalar.db.server.DistributedTransactionServiceWithConsensusCommitIntegrationTest.prepareGet)4 Consistency (com.scalar.db.api.Consistency)2 DistributedStorageAdmin (com.scalar.db.api.DistributedStorageAdmin)2 TableMetadata (com.scalar.db.api.TableMetadata)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)2 TransactionException (com.scalar.db.exception.transaction.TransactionException)2 DataType (com.scalar.db.io.DataType)2 Key (com.scalar.db.io.Key)2 Value (com.scalar.db.io.Value)2