use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase 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.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults.
@Test
public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() throws IOException, ExecutionException {
// setup
List<Put> puts = preparePuts();
storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
Scan scan = new Scan(new Key(COL_NAME1, 0)).withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)).withLimit(1);
// exercise
List<Result> actual = scanAll(scan);
// verify
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 2)));
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly.
@Test
public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() throws ExecutionException, IOException {
// Arrange
populateRecords();
List<Put> puts = preparePuts();
puts.get(1).withValue(COL_NAME3, Integer.MAX_VALUE);
puts.get(2).withValue(COL_NAME3, Integer.MIN_VALUE);
int pKey = 0;
int cKey = 0;
Delete delete = prepareDelete(pKey, cKey);
Scan scan = new Scan(new Key(COL_NAME1, pKey));
// Act
assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(COL_NAME3).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MAX_VALUE);
assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(COL_NAME3).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MIN_VALUE);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException.
@Test
public void put_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
// Act
assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(3), puts.get(6)))).isInstanceOf(IllegalArgumentException.class);
// Assert
List<Result> results;
results = scanAll(new Scan(new Key(COL_NAME1, 0)));
assertThat(results.size()).isEqualTo(0);
results = scanAll(new Scan(new Key(COL_NAME1, 3)));
assertThat(results.size()).isEqualTo(0);
results = scanAll(new Scan(new Key(COL_NAME1, 6)));
assertThat(results.size()).isEqualTo(0);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_PutWithoutValuesGiven_ShouldStoreProperly.
@Test
public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionException {
// Arrange
Key partitionKey = new Key(COL_NAME1, 0);
Key clusteringKey = new Key(COL_NAME4, 0);
// Act
assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
// Assert
Optional<Result> result = storage.get(new Get(partitionKey, clusteringKey));
assertThat(result).isPresent();
}
Aggregations