use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = null;
List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = new PutIfNotExists();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)).build();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class MergedResultTest method getValues_ResultAndPutGiven_ShouldReturnMergedValues.
@Test
public void getValues_ResultAndPutGiven_ShouldReturnMergedValues() {
// Arrange
Put put = new Put(new Key(ANY_NAME_1, ANY_TEXT_1), new Key(ANY_NAME_2, ANY_TEXT_2)).withValue(ANY_NAME_3, ANY_INT_3);
MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA);
// Act
Map<String, Value<?>> values = mergedResult.getValues();
// Assert
assertThat(values.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
assertThat(values.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
assertThat(values.get(ANY_NAME_3)).isEqualTo(new IntValue(ANY_NAME_3, ANY_INT_3));
assertThat(values.get(ANY_NAME_4)).isEqualTo(new TextValue(ANY_NAME_4, ANY_TEXT_3));
assertThat(values.get(Attribute.ID)).isEqualTo(Attribute.toIdValue(ANY_ID_2));
assertThat(values.get(Attribute.PREPARED_AT)).isEqualTo(Attribute.toPreparedAtValue(ANY_TIME_3));
assertThat(values.get(Attribute.COMMITTED_AT)).isEqualTo(Attribute.toCommittedAtValue(ANY_TIME_4));
assertThat(values.get(Attribute.STATE)).isEqualTo(Attribute.toStateValue(TransactionState.COMMITTED));
assertThat(values.get(Attribute.VERSION)).isEqualTo(Attribute.toVersionValue(ANY_VERSION_2));
assertThat(values.get(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(new IntValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_1));
assertThat(values.get(Attribute.BEFORE_ID)).isEqualTo(Attribute.toBeforeIdValue(ANY_ID_1));
assertThat(values.get(Attribute.BEFORE_PREPARED_AT)).isEqualTo(Attribute.toBeforePreparedAtValue(ANY_TIME_1));
assertThat(values.get(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(Attribute.toBeforeCommittedAtValue(ANY_TIME_2));
assertThat(values.get(Attribute.BEFORE_STATE)).isEqualTo(Attribute.toBeforeStateValue(TransactionState.COMMITTED));
assertThat(values.get(Attribute.BEFORE_VERSION)).isEqualTo(Attribute.toBeforeVersionValue(ANY_VERSION_1));
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class MergedResultTest method getValue_OnlyPutGiven_ShouldReturnMergedValue.
@Test
public void getValue_OnlyPutGiven_ShouldReturnMergedValue() {
// Arrange
Put put = new Put(new Key(ANY_NAME_1, ANY_TEXT_1), new Key(ANY_NAME_2, ANY_TEXT_2)).withValue(ANY_NAME_3, ANY_INT_3);
MergedResult mergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA);
// Act Assert
assertThat(mergedResult.getValue(ANY_NAME_1)).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1)));
assertThat(mergedResult.getValue(ANY_NAME_2)).isEqualTo(Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2)));
assertThat(mergedResult.getValue(ANY_NAME_3)).isEqualTo(Optional.of(new IntValue(ANY_NAME_3, ANY_INT_3)));
assertThat(mergedResult.getValue(ANY_NAME_4)).isEqualTo(Optional.of(new TextValue(ANY_NAME_4, (String) null)));
assertThat(mergedResult.getValue(Attribute.ID)).isEqualTo(Optional.of(Attribute.toIdValue(null)));
assertThat(mergedResult.getValue(Attribute.PREPARED_AT)).isEqualTo(Optional.of(Attribute.toPreparedAtValue(0L)));
assertThat(mergedResult.getValue(Attribute.COMMITTED_AT)).isEqualTo(Optional.of(Attribute.toCommittedAtValue(0L)));
assertThat(mergedResult.getValue(Attribute.STATE)).isEqualTo(Optional.of(new IntValue(Attribute.STATE, 0)));
assertThat(mergedResult.getValue(Attribute.VERSION)).isEqualTo(Optional.of(Attribute.toVersionValue(0)));
assertThat(mergedResult.getValue(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(Optional.of(new IntValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, 0)));
assertThat(mergedResult.getValue(Attribute.BEFORE_ID)).isEqualTo(Optional.of(Attribute.toBeforeIdValue(null)));
assertThat(mergedResult.getValue(Attribute.BEFORE_PREPARED_AT)).isEqualTo(Optional.of(Attribute.toBeforePreparedAtValue(0L)));
assertThat(mergedResult.getValue(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(Optional.of(Attribute.toBeforeCommittedAtValue(0L)));
assertThat(mergedResult.getValue(Attribute.BEFORE_STATE)).isEqualTo(Optional.of(new IntValue(Attribute.BEFORE_STATE, 0)));
assertThat(mergedResult.getValue(Attribute.BEFORE_VERSION)).isEqualTo(Optional.of(Attribute.toBeforeVersionValue(0)));
assertThat(mergedResult.getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4, Attribute.ID, Attribute.PREPARED_AT, Attribute.COMMITTED_AT, Attribute.STATE, Attribute.VERSION, Attribute.BEFORE_PREFIX + ANY_NAME_3, Attribute.BEFORE_PREFIX + ANY_NAME_4, Attribute.BEFORE_ID, Attribute.BEFORE_PREPARED_AT, Attribute.BEFORE_COMMITTED_AT, Attribute.BEFORE_STATE, Attribute.BEFORE_VERSION)));
assertThat(mergedResult.contains(ANY_NAME_1)).isTrue();
assertThat(mergedResult.isNull(ANY_NAME_1)).isFalse();
assertThat(mergedResult.getText(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
assertThat(mergedResult.getAsObject(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
assertThat(mergedResult.contains(ANY_NAME_2)).isTrue();
assertThat(mergedResult.isNull(ANY_NAME_2)).isFalse();
assertThat(mergedResult.getText(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
assertThat(mergedResult.getAsObject(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
assertThat(mergedResult.contains(ANY_NAME_3)).isTrue();
assertThat(mergedResult.isNull(ANY_NAME_3)).isFalse();
assertThat(mergedResult.getInt(ANY_NAME_3)).isEqualTo(ANY_INT_3);
assertThat(mergedResult.getAsObject(ANY_NAME_3)).isEqualTo(ANY_INT_3);
assertThat(mergedResult.contains(ANY_NAME_4)).isTrue();
assertThat(mergedResult.isNull(ANY_NAME_4)).isTrue();
assertThat(mergedResult.getText(ANY_NAME_4)).isNull();
assertThat(mergedResult.getAsObject(ANY_NAME_4)).isNull();
assertThat(mergedResult.contains(Attribute.ID)).isTrue();
assertThat(mergedResult.isNull(Attribute.ID)).isTrue();
assertThat(mergedResult.getText(Attribute.ID)).isNull();
assertThat(mergedResult.getAsObject(Attribute.ID)).isNull();
assertThat(mergedResult.contains(Attribute.PREPARED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.PREPARED_AT)).isTrue();
assertThat(mergedResult.getBigInt(Attribute.PREPARED_AT)).isEqualTo(0L);
assertThat(mergedResult.getAsObject(Attribute.PREPARED_AT)).isNull();
assertThat(mergedResult.contains(Attribute.COMMITTED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.COMMITTED_AT)).isTrue();
assertThat(mergedResult.getBigInt(Attribute.COMMITTED_AT)).isEqualTo(0L);
assertThat(mergedResult.getAsObject(Attribute.COMMITTED_AT)).isNull();
assertThat(mergedResult.contains(Attribute.STATE)).isTrue();
assertThat(mergedResult.isNull(Attribute.STATE)).isTrue();
assertThat(mergedResult.getInt(Attribute.STATE)).isEqualTo(0);
assertThat(mergedResult.getAsObject(Attribute.STATE)).isNull();
assertThat(mergedResult.contains(Attribute.VERSION)).isTrue();
assertThat(mergedResult.isNull(Attribute.VERSION)).isTrue();
assertThat(mergedResult.getInt(Attribute.VERSION)).isEqualTo(0);
assertThat(mergedResult.getAsObject(Attribute.VERSION)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isTrue();
assertThat(mergedResult.getInt(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(0);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isTrue();
assertThat(mergedResult.getText(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isNull();
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_ID)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_ID)).isTrue();
assertThat(mergedResult.getText(Attribute.BEFORE_ID)).isNull();
assertThat(mergedResult.getAsObject(Attribute.BEFORE_ID)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_PREPARED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREPARED_AT)).isTrue();
assertThat(mergedResult.getBigInt(Attribute.BEFORE_PREPARED_AT)).isEqualTo(0L);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREPARED_AT)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_COMMITTED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_COMMITTED_AT)).isTrue();
assertThat(mergedResult.getBigInt(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(0L);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_COMMITTED_AT)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_STATE)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_STATE)).isTrue();
assertThat(mergedResult.getInt(Attribute.BEFORE_STATE)).isEqualTo(0);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_STATE)).isNull();
assertThat(mergedResult.contains(Attribute.BEFORE_VERSION)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_VERSION)).isTrue();
assertThat(mergedResult.getInt(Attribute.BEFORE_VERSION)).isEqualTo(0);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_VERSION)).isNull();
}
use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.
the class ConsensusCommitSpecificIntegrationTestBase 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;
}
Aggregations