use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class JdbcTransactionIntegrationTest method preparePut.
private Put preparePut(int id, int type, String namespace, String table) {
Key partitionKey = new Key(ACCOUNT_ID, id);
Key clusteringKey = new Key(ACCOUNT_TYPE, type);
return new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method preparePut.
private Put preparePut(int id, int type, String namespace, String table) {
Key partitionKey = new Key(ACCOUNT_ID, id);
Key clusteringKey = new Key(ACCOUNT_TYPE, type);
return new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method prepareTransfer.
private ConsensusCommit prepareTransfer(int fromId, String fromNamespace, String fromTable, int toId, String toNamespace, String toTable, int amount) throws CrudException {
boolean differentTables = toNamespace.equals(fromNamespace) || !toTable.equals(fromTable);
ConsensusCommit transaction = manager.start();
List<Get> fromGets = prepareGets(fromNamespace, fromTable);
List<Get> toGets = differentTables ? prepareGets(toNamespace, toTable) : fromGets;
Optional<Result> fromResult = transaction.get(fromGets.get(fromId));
assertThat(fromResult).isPresent();
IntValue fromBalance = new IntValue(BALANCE, getBalance(fromResult.get()) - amount);
Optional<Result> toResult = transaction.get(toGets.get(toId));
assertThat(toResult).isPresent();
IntValue toBalance = new IntValue(BALANCE, getBalance(toResult.get()) + amount);
List<Put> fromPuts = preparePuts(fromNamespace, fromTable);
List<Put> toPuts = differentTables ? preparePuts(toNamespace, toTable) : fromPuts;
fromPuts.get(fromId).withValue(fromBalance);
toPuts.get(toId).withValue(toBalance);
transaction.put(fromPuts.get(fromId));
transaction.put(toPuts.get(toId));
return transaction;
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method populateRecords.
private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
ConsensusCommit transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withValue(BALANCE, INITIAL_BALANCE);
transaction.put(put);
}));
transaction.commit();
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceForPrepareAndCommit.
@Test
public void putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceForPrepareAndCommit() throws CommitException, UnknownTransactionStatusException, ExecutionException, CoordinatorException {
// Arrange
IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE);
List<Put> puts = preparePuts(namespace1, TABLE_1);
puts.get(0).withValue(balance);
// next account
puts.get(NUM_TYPES).withValue(balance);
ConsensusCommit transaction = manager.start();
// Act
transaction.put(puts.get(0));
transaction.put(puts.get(NUM_TYPES));
transaction.commit();
// Assert
// twice for prepare, twice for commit
verify(storage, times(4)).mutate(anyList());
verify(coordinator).putState(any(Coordinator.State.class));
}
Aggregations