use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithoutClusteringKeyRange_ShouldReturnProperResult.
private void scan_WithoutClusteringKeyRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
List<Value<?>> expected = getExpected(clusteringKeyValues, null, null, null, null, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, null, null, null, null, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, null, null, orderingType, withLimit));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithoutClusteringKeyRange_ShouldReturnProperResult.
@Test
public void scan_WithoutClusteringKeyRange_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType clusteringKeyType : clusteringKeyTypes) {
for (Order clusteringOrder : Order.values()) {
truncateTable(clusteringKeyType, clusteringOrder);
List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
for (OrderingType orderingType : OrderingType.values()) {
for (boolean withLimit : Arrays.asList(false, true)) {
scan_WithoutClusteringKeyRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, orderingType, withLimit);
}
}
}
}
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult.
private void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> endClusteringKey = getMaxValue(CLUSTERING_KEY, clusteringKeyType);
List<Value<?>> expected = getExpected(clusteringKeyValues, null, null, endClusteringKey, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, null, null, endClusteringKey, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, null, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyStartRange_ShouldReturnProperResult.
private void scan_WithClusteringKeyStartRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> startClusteringKeyValue;
if (clusteringKeyType == DataType.BOOLEAN) {
startClusteringKeyValue = clusteringKeyValues.get(0);
} else {
startClusteringKeyValue = clusteringKeyValues.get(4);
}
List<Value<?>> expected = getExpected(clusteringKeyValues, startClusteringKeyValue, startInclusive, null, null, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, startClusteringKeyValue, startInclusive, null, null, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, startInclusive, null, orderingType, withLimit));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method prepareRecords.
private List<Value<?>> prepareRecords(DataType clusteringKeyType, Order clusteringOrder) throws ExecutionException {
RANDOM.setSeed(seed);
List<Value<?>> ret = new ArrayList<>();
List<Put> puts = new ArrayList<>();
if (clusteringKeyType == DataType.BOOLEAN) {
TestUtils.booleanValues(CLUSTERING_KEY).forEach(clusteringKeyValue -> {
ret.add(clusteringKeyValue);
puts.add(preparePut(clusteringKeyType, clusteringOrder, clusteringKeyValue));
});
} else {
Set<Value<?>> valueSet = new HashSet<>();
// Add min and max clustering key values
Arrays.asList(getMinValue(CLUSTERING_KEY, clusteringKeyType), getMaxValue(CLUSTERING_KEY, clusteringKeyType)).forEach(clusteringKeyValue -> {
valueSet.add(clusteringKeyValue);
ret.add(clusteringKeyValue);
puts.add(preparePut(clusteringKeyType, clusteringOrder, clusteringKeyValue));
});
IntStream.range(0, CLUSTERING_KEY_NUM - 2).forEach(i -> {
Value<?> clusteringKeyValue;
while (true) {
clusteringKeyValue = getRandomValue(RANDOM, CLUSTERING_KEY, clusteringKeyType);
// reject duplication
if (!valueSet.contains(clusteringKeyValue)) {
valueSet.add(clusteringKeyValue);
break;
}
}
ret.add(clusteringKeyValue);
puts.add(preparePut(clusteringKeyType, clusteringOrder, clusteringKeyValue));
});
}
try {
List<Put> buffer = new ArrayList<>();
for (Put put : puts) {
buffer.add(put);
if (buffer.size() == 20) {
storage.mutate(buffer);
buffer.clear();
}
}
if (!buffer.isEmpty()) {
storage.mutate(buffer);
}
} catch (ExecutionException e) {
throw new ExecutionException("put data to database failed", e);
}
ret.sort(clusteringOrder == Order.ASC ? com.google.common.collect.Ordering.natural() : com.google.common.collect.Ordering.natural().reverse());
return ret;
}
Aggregations