use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method putAndCommit_SinglePartitionMutationsGiven_ShouldAccessStorageOnceForPrepareAndCommit.
@Test
public void putAndCommit_SinglePartitionMutationsGiven_ShouldAccessStorageOnceForPrepareAndCommit() 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);
puts.get(1).withValue(balance);
ConsensusCommit transaction = manager.start();
// Act
transaction.put(puts.get(0));
transaction.put(puts.get(1));
transaction.commit();
// Assert
// one for prepare, one for commit
verify(storage, times(2)).mutate(anyList());
verify(coordinator).putState(any(Coordinator.State.class));
}
use of com.scalar.db.io.IntValue 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.io.IntValue 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));
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class JdbcTransactionIntegrationTest method prepareTransfer.
private JdbcTransaction prepareTransfer(int fromId, int toId, int amount) throws TransactionException {
JdbcTransaction transaction = manager.start();
List<Get> gets = prepareGets(NAMESPACE, TABLE);
Optional<Result> fromResult = transaction.get(gets.get(fromId));
assertThat(fromResult.isPresent()).isTrue();
IntValue fromBalance = new IntValue(BALANCE, getBalance(fromResult.get()) - amount);
Optional<Result> toResult = transaction.get(gets.get(toId));
assertThat(toResult.isPresent()).isTrue();
IntValue toBalance = new IntValue(BALANCE, getBalance(toResult.get()) + amount);
List<Put> puts = preparePuts(NAMESPACE, TABLE);
puts.get(fromId).withValue(fromBalance);
puts.get(toId).withValue(toBalance);
transaction.put(puts.get(fromId));
transaction.put(puts.get(toId));
return transaction;
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class ValueBinderTest method visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull.
@Test
public void visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull() {
// Arrange
IntValue value1 = new IntValue(ANY_NAME, ANY_INT);
BlobValue value2 = new BlobValue(ANY_NAME, (byte[]) null);
TextValue value3 = new TextValue(ANY_NAME, (String) null);
IntValue value4 = new IntValue(ANY_NAME, ANY_INT);
ValueBinder binder = new ValueBinder(bound);
// Act
value1.accept(binder);
value2.accept(binder);
value3.accept(binder);
value4.accept(binder);
// Assert
verify(bound).setInt(0, ANY_INT);
verify(bound, never()).setBytes(anyInt(), any(ByteBuffer.class));
verify(bound, never()).setString(anyInt(), anyString());
verify(bound).setInt(3, ANY_INT);
}
Aggregations