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(columns, 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 StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRange_ShouldReturnProperResult.
@Test
public void scan_WithClusteringKeyEndRange_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType clusteringKeyType : clusteringKeyTypes) {
for (Order clusteringOrder : Order.values()) {
truncateTable(clusteringKeyType, clusteringOrder);
List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
for (boolean endInclusive : Arrays.asList(true, false)) {
for (OrderingType orderingType : OrderingType.values()) {
for (boolean withLimit : Arrays.asList(false, true)) {
scan_WithClusteringKeyEndRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, endInclusive, orderingType, withLimit);
}
}
}
}
}
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSinglePartitionKeyIntegrationTestBase method getAndDelete_ShouldBehaveCorrectly.
@Test
public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException {
for (DataType partitionKeyType : partitionKeyTypes) {
truncateTable(partitionKeyType);
List<Value<?>> partitionKeyValues = prepareRecords(partitionKeyType);
String description = description(partitionKeyType);
// for get
for (Value<?> partitionKeyValue : partitionKeyValues) {
// Arrange
Get get = prepareGet(partitionKeyType, partitionKeyValue);
// Act
Optional<Result> result = storage.get(get);
// Assert
Assertions.assertThat(result).describedAs(description).isPresent();
Assertions.assertThat(result.get().getValue(PARTITION_KEY).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKeyValue);
Assertions.assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(COL_NAME).get().getAsInt()).describedAs(description).isEqualTo(1);
}
// for delete
for (Value<?> partitionKeyValue : partitionKeyValues) {
// Arrange
Delete delete = prepareDelete(partitionKeyType, partitionKeyValue);
// Act
storage.delete(delete);
// Assert
Optional<Result> result = storage.get(prepareGet(partitionKeyType, partitionKeyValue));
Assertions.assertThat(result).describedAs(description).isNotPresent();
}
}
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSinglePartitionKeyIntegrationTestBase method prepareRecords.
private List<Value<?>> prepareRecords(DataType partitionKeyType) throws ExecutionException {
RANDOM.setSeed(seed);
List<Value<?>> ret = new ArrayList<>();
List<Put> puts = new ArrayList<>();
if (partitionKeyType == DataType.BOOLEAN) {
TestUtils.booleanValues(PARTITION_KEY).forEach(partitionKeyValue -> {
ret.add(partitionKeyValue);
puts.add(preparePut(partitionKeyType, partitionKeyValue));
});
} else {
Set<Value<?>> valueSet = new HashSet<>();
// Add min and max partition key values
Arrays.asList(getMinValue(PARTITION_KEY, partitionKeyType), getMaxValue(PARTITION_KEY, partitionKeyType)).forEach(partitionKeyValue -> {
valueSet.add(partitionKeyValue);
ret.add(partitionKeyValue);
puts.add(preparePut(partitionKeyType, partitionKeyValue));
});
IntStream.range(0, PARTITION_KEY_NUM - 2).forEach(i -> {
Value<?> partitionKeyValue;
while (true) {
partitionKeyValue = getRandomValue(RANDOM, PARTITION_KEY, partitionKeyType);
// reject duplication
if (!valueSet.contains(partitionKeyValue)) {
valueSet.add(partitionKeyValue);
break;
}
}
ret.add(partitionKeyValue);
puts.add(preparePut(partitionKeyType, partitionKeyValue));
});
}
try {
for (Put put : puts) {
storage.put(put);
}
} catch (ExecutionException e) {
throw new ExecutionException("put data to database failed", e);
}
return ret;
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageMultiplePartitionKeyIntegrationTestBase 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