Search in sources :

Example 6 with State

use of com.scalar.db.transaction.consensuscommit.Coordinator.State in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitIntegrationTest method populatePreparedRecordAndCoordinatorStateRecord.

private void populatePreparedRecordAndCoordinatorStateRecord(String table, TransactionState recordState, long preparedAt, TransactionState coordinatorState) throws ExecutionException, CoordinatorException {
    Key partitionKey = new Key(new IntValue(ACCOUNT_ID, 0));
    Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, 0));
    Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(table).withValue(new IntValue(BALANCE, INITIAL_BALANCE)).withValue(Attribute.toIdValue(ANY_ID_2)).withValue(Attribute.toStateValue(recordState)).withValue(Attribute.toVersionValue(2)).withValue(Attribute.toPreparedAtValue(preparedAt)).withValue(Attribute.toBeforeIdValue(ANY_ID_1)).withValue(Attribute.toBeforeStateValue(TransactionState.COMMITTED)).withValue(Attribute.toBeforeVersionValue(1)).withValue(Attribute.toBeforePreparedAtValue(1)).withValue(Attribute.toBeforeCommittedAtValue(1));
    storage.put(put);
    if (coordinatorState == null) {
        return;
    }
    State state = new State(ANY_ID_2, coordinatorState);
    coordinator.putState(state);
}
Also used : State(com.scalar.db.transaction.consensuscommit.Coordinator.State) TransactionState(com.scalar.db.api.TransactionState) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Aggregations

TransactionState (com.scalar.db.api.TransactionState)6 State (com.scalar.db.transaction.consensuscommit.Coordinator.State)6 Test (org.junit.jupiter.api.Test)3 Put (com.scalar.db.api.Put)2 Result (com.scalar.db.api.Result)2 IntValue (com.scalar.db.io.IntValue)2 Key (com.scalar.db.io.Key)2 Test (org.junit.Test)1