use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult.
@Test
public void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType clusteringKeyType : clusteringKeyTypes) {
for (Order clusteringOrder : Order.values()) {
truncateTable(clusteringKeyType, clusteringOrder);
List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
for (boolean startInclusive : Arrays.asList(true, false)) {
for (OrderingType orderingType : OrderingType.values()) {
for (boolean withLimit : Arrays.asList(false, true)) {
scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, startInclusive, orderingType, withLimit);
}
}
}
}
}
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.
@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
// Arrange
ResultImpl result = new ResultImpl(values, TABLE_METADATA);
// Act
Map<String, Value<?>> actual = result.getValues();
// Assert
assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
assertThat(actual.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, true));
assertThat(actual.get(ANY_COLUMN_NAME_7)).isEqualTo(new BlobValue(ANY_COLUMN_NAME_7, "bytes".getBytes(StandardCharsets.UTF_8)));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class ResultImplTest method getValues_TryToModifyReturned_ShouldThrowException.
@Test
public void getValues_TryToModifyReturned_ShouldThrowException() {
// Arrange
ResultImpl result = new ResultImpl(values, TABLE_METADATA);
Map<String, Value<?>> values = result.getValues();
// Act Assert
assertThatThrownBy(() -> values.put("new", new TextValue(ANY_NAME_1, ANY_TEXT_1))).isInstanceOf(UnsupportedOperationException.class);
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class DistributedStorageMultipleClusteringKeyScanIntegrationTestBase method prepareRecords.
private List<ClusteringKey> prepareRecords(DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder) throws ExecutionException {
RANDOM.setSeed(seed);
List<ClusteringKey> ret = new ArrayList<>();
List<Put> puts = new ArrayList<>();
if (firstClusteringKeyType == DataType.BOOLEAN) {
TestUtils.booleanValues(FIRST_CLUSTERING_KEY).forEach(firstClusteringKeyValue -> prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret));
} else {
Set<Value<?>> valueSet = new HashSet<>();
// Add min and max first clustering key values
Arrays.asList(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType), getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)).forEach(firstClusteringKeyValue -> {
valueSet.add(firstClusteringKeyValue);
prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
});
IntStream.range(0, FIRST_CLUSTERING_KEY_NUM - 2).forEach(i -> {
Value<?> firstClusteringKeyValue;
while (true) {
firstClusteringKeyValue = getFirstClusteringKeyValue(firstClusteringKeyType);
// reject duplication
if (!valueSet.contains(firstClusteringKeyValue)) {
valueSet.add(firstClusteringKeyValue);
break;
}
}
prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
});
}
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(getClusteringKeyComparator(firstClusteringOrder, secondClusteringOrder));
return ret;
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class DistributedStorageMultiplePartitionKeyIntegrationTestBase method prepareRecords.
private List<PartitionKey> prepareRecords(DataType firstPartitionKeyType, DataType secondPartitionKeyType) throws ExecutionException {
RANDOM.setSeed(seed);
List<Put> puts = new ArrayList<>();
List<PartitionKey> ret = new ArrayList<>();
if (firstPartitionKeyType == DataType.BOOLEAN) {
TestUtils.booleanValues(FIRST_PARTITION_KEY).forEach(firstPartitionKeyValue -> prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret));
} else {
Set<Value<?>> valueSet = new HashSet<>();
// Add min and max partition key values
Arrays.asList(getMinValue(FIRST_PARTITION_KEY, firstPartitionKeyType), getMaxValue(FIRST_PARTITION_KEY, firstPartitionKeyType)).forEach(firstPartitionKeyValue -> {
valueSet.add(firstPartitionKeyValue);
prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret);
});
IntStream.range(0, FIRST_PARTITION_KEY_NUM - 2).forEach(i -> {
Value<?> firstPartitionKeyValue;
while (true) {
firstPartitionKeyValue = getRandomValue(RANDOM, FIRST_PARTITION_KEY, firstPartitionKeyType);
// reject duplication
if (!valueSet.contains(firstPartitionKeyValue)) {
valueSet.add(firstPartitionKeyValue);
break;
}
}
prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret);
});
}
try {
for (Put put : puts) {
storage.put(put);
}
} catch (ExecutionException e) {
throw new ExecutionException("put data to database failed", e);
}
return ret;
}
Aggregations