use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_PutWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException.
@Test
public void put_PutWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException() throws ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Get get = prepareGet(pKey, cKey);
// Act Assert
storage.put(puts.get(0));
puts.get(0).withCondition(new PutIf(new ConditionalExpression(COL_NAME3, new IntValue(pKey + cKey + 1), ConditionalExpression.Operator.EQ)));
puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE);
assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class);
// Assert
Optional<Result> actual = storage.get(get);
assertThat(actual.isPresent()).isTrue();
Result result = actual.get();
assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey)));
assertThat(result.getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey)));
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method assertResults.
private void assertResults(List<Result> results, Value<?> secondaryIndexValue) {
assertThat(results.size()).isEqualTo(DATA_NUM);
Set<Integer> partitionKeySet = new HashSet<>();
for (int i = 0; i < DATA_NUM; i++) {
partitionKeySet.add(i);
}
for (Result result : results) {
assertThat(result.getValue(PARTITION_KEY).isPresent()).isTrue();
partitionKeySet.remove(result.getValue(PARTITION_KEY).get().getAsInt());
assertThat(result.getValue(INDEX_COL_NAME).isPresent()).isTrue();
assertThat(result.getValue(INDEX_COL_NAME).get()).isEqualTo(secondaryIndexValue);
assertThat(result.getValue(COL_NAME).isPresent()).isTrue();
assertThat(result.getValue(COL_NAME).get().getAsInt()).isEqualTo(1);
}
assertThat(partitionKeySet).isEmpty();
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method scan_WithMaxSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithMaxSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
// Arrange
Value<?> secondaryIndexValue = getMaxValue(INDEX_COL_NAME, secondaryIndexType);
prepareRecords(secondaryIndexType, secondaryIndexValue);
Scan scan = new Scan(new Key(secondaryIndexValue)).forNamespace(namespace).forTable(getTableName(secondaryIndexType));
// Act
List<Result> results = scanAll(scan);
// Assert
assertResults(results, secondaryIndexValue);
}
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method scan_WithRandomSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithRandomSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
RANDOM.setSeed(seed);
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
for (int i = 0; i < ATTEMPT_COUNT; i++) {
// Arrange
Value<?> secondaryIndexValue = getRandomValue(RANDOM, INDEX_COL_NAME, secondaryIndexType);
prepareRecords(secondaryIndexType, secondaryIndexValue);
Scan scan = new Scan(new Key(secondaryIndexValue)).forNamespace(namespace).forTable(getTableName(secondaryIndexType));
// Act
List<Result> results = scanAll(scan);
// Assert
assertResults(results, secondaryIndexValue);
}
}
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method scan_WithMinSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithMinSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
// Arrange
Value<?> secondaryIndexValue = getMinValue(INDEX_COL_NAME, secondaryIndexType);
prepareRecords(secondaryIndexType, secondaryIndexValue);
Scan scan = new Scan(new Key(secondaryIndexValue)).forNamespace(namespace).forTable(getTableName(secondaryIndexType));
// Act
List<Result> results = scanAll(scan);
// Assert
assertResults(results, secondaryIndexValue);
}
}
Aggregations