use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class MergedResultTest method getValues_ResultAndPutWithNullValueGiven_ShouldReturnMergedValues.
@Test
public void getValues_ResultAndPutWithNullValueGiven_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).withTextValue(ANY_NAME_4, null);
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, (String) null));
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.TextValue in project scalardb by scalar-labs.
the class MergedResultTest method getValue_ResultAndPutWithNullValueGiven_ShouldReturnMergedValue.
@Test
public void getValue_ResultAndPutWithNullValueGiven_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).withTextValue(ANY_NAME_4, null);
MergedResult mergedResult = new MergedResult(Optional.of(result), 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(ANY_ID_2)));
assertThat(mergedResult.getValue(Attribute.PREPARED_AT)).isEqualTo(Optional.of(Attribute.toPreparedAtValue(ANY_TIME_3)));
assertThat(mergedResult.getValue(Attribute.COMMITTED_AT)).isEqualTo(Optional.of(Attribute.toCommittedAtValue(ANY_TIME_4)));
assertThat(mergedResult.getValue(Attribute.STATE)).isEqualTo(Optional.of(Attribute.toStateValue(TransactionState.COMMITTED)));
assertThat(mergedResult.getValue(Attribute.VERSION)).isEqualTo(Optional.of(Attribute.toVersionValue(ANY_VERSION_2)));
assertThat(mergedResult.getValue(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(Optional.of(new IntValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_1)));
assertThat(mergedResult.getValue(Attribute.BEFORE_ID)).isEqualTo(Optional.of(Attribute.toBeforeIdValue(ANY_ID_1)));
assertThat(mergedResult.getValue(Attribute.BEFORE_PREPARED_AT)).isEqualTo(Optional.of(Attribute.toBeforePreparedAtValue(ANY_TIME_1)));
assertThat(mergedResult.getValue(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(Optional.of(Attribute.toBeforeCommittedAtValue(ANY_TIME_2)));
assertThat(mergedResult.getValue(Attribute.BEFORE_STATE)).isEqualTo(Optional.of(Attribute.toBeforeStateValue(TransactionState.COMMITTED)));
assertThat(mergedResult.getValue(Attribute.BEFORE_VERSION)).isEqualTo(Optional.of(Attribute.toBeforeVersionValue(ANY_VERSION_1)));
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)).isFalse();
assertThat(mergedResult.getText(Attribute.ID)).isEqualTo(ANY_ID_2);
assertThat(mergedResult.getAsObject(Attribute.ID)).isEqualTo(ANY_ID_2);
assertThat(mergedResult.contains(Attribute.PREPARED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.PREPARED_AT)).isFalse();
assertThat(mergedResult.getBigInt(Attribute.PREPARED_AT)).isEqualTo(ANY_TIME_3);
assertThat(mergedResult.getAsObject(Attribute.PREPARED_AT)).isEqualTo(ANY_TIME_3);
assertThat(mergedResult.contains(Attribute.COMMITTED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.COMMITTED_AT)).isFalse();
assertThat(mergedResult.getBigInt(Attribute.COMMITTED_AT)).isEqualTo(ANY_TIME_4);
assertThat(mergedResult.getAsObject(Attribute.COMMITTED_AT)).isEqualTo(ANY_TIME_4);
assertThat(mergedResult.contains(Attribute.STATE)).isTrue();
assertThat(mergedResult.isNull(Attribute.STATE)).isFalse();
assertThat(mergedResult.getInt(Attribute.STATE)).isEqualTo(TransactionState.COMMITTED.get());
assertThat(mergedResult.getAsObject(Attribute.STATE)).isEqualTo(TransactionState.COMMITTED.get());
assertThat(mergedResult.contains(Attribute.VERSION)).isTrue();
assertThat(mergedResult.isNull(Attribute.VERSION)).isFalse();
assertThat(mergedResult.getInt(Attribute.VERSION)).isEqualTo(ANY_VERSION_2);
assertThat(mergedResult.getAsObject(Attribute.VERSION)).isEqualTo(ANY_VERSION_2);
assertThat(mergedResult.contains(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isFalse();
assertThat(mergedResult.getInt(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(ANY_INT_1);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREFIX + ANY_NAME_3)).isEqualTo(ANY_INT_1);
assertThat(mergedResult.contains(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isFalse();
assertThat(mergedResult.getText(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isEqualTo(ANY_TEXT_4);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREFIX + ANY_NAME_4)).isEqualTo(ANY_TEXT_4);
assertThat(mergedResult.contains(Attribute.BEFORE_ID)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_ID)).isFalse();
assertThat(mergedResult.getText(Attribute.BEFORE_ID)).isEqualTo(ANY_ID_1);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_ID)).isEqualTo(ANY_ID_1);
assertThat(mergedResult.contains(Attribute.BEFORE_PREPARED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_PREPARED_AT)).isFalse();
assertThat(mergedResult.getBigInt(Attribute.BEFORE_PREPARED_AT)).isEqualTo(ANY_TIME_1);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_PREPARED_AT)).isEqualTo(ANY_TIME_1);
assertThat(mergedResult.contains(Attribute.BEFORE_COMMITTED_AT)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_COMMITTED_AT)).isFalse();
assertThat(mergedResult.getBigInt(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(ANY_TIME_2);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_COMMITTED_AT)).isEqualTo(ANY_TIME_2);
assertThat(mergedResult.contains(Attribute.BEFORE_STATE)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_STATE)).isFalse();
assertThat(mergedResult.getInt(Attribute.BEFORE_STATE)).isEqualTo(TransactionState.COMMITTED.get());
assertThat(mergedResult.getAsObject(Attribute.BEFORE_STATE)).isEqualTo(TransactionState.COMMITTED.get());
assertThat(mergedResult.contains(Attribute.BEFORE_VERSION)).isTrue();
assertThat(mergedResult.isNull(Attribute.BEFORE_VERSION)).isFalse();
assertThat(mergedResult.getInt(Attribute.BEFORE_VERSION)).isEqualTo(ANY_VERSION_1);
assertThat(mergedResult.getAsObject(Attribute.BEFORE_VERSION)).isEqualTo(ANY_VERSION_1);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method setConsistency_DeleteOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial.
@Test
public void setConsistency_DeleteOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ))).withConsistency(Consistency.EVENTUAL);
// Act
handler.setConsistency(bound, del);
// Assert
verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM);
verify(bound).setSerialConsistencyLevel(ConsistencyLevel.SERIAL);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class UpdateStatementHandlerTest method bind_PutOperationWithIfGiven_ShouldBindProperly.
@Test
public void bind_PutOperationWithIfGiven_ShouldBindProperly() {
// Arrange
configureBehavior(null);
put = preparePutWithClusteringKey();
put.withCondition(new PutIf(new ConditionalExpression(ANY_NAME_4, new IntValue(ANY_INT_2), Operator.EQ), new ConditionalExpression(ANY_NAME_5, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.bind(prepared, put);
// Assert
verify(bound).setInt(0, ANY_INT_1);
verify(bound).setString(1, ANY_TEXT_1);
verify(bound).setString(2, ANY_TEXT_2);
verify(bound).setInt(3, ANY_INT_2);
verify(bound).setString(4, ANY_TEXT_3);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithInvalidDeleteIfCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithInvalidDeleteIfCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new DeleteIf(new ConditionalExpression(COL1, new TextValue("1"), ConditionalExpression.Operator.EQ));
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
Aggregations