use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues.
@Test
public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
// Arrange
Key partitionKey = new Key(COL_NAME1, 1);
for (int i = 0; i < 345; i++) {
Key clusteringKey = new Key(COL_NAME4, i);
storage.put(new Put(partitionKey, clusteringKey));
}
Scan scan = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.ASC));
// Act
List<Result> results = new ArrayList<>();
try (Scanner scanner = storage.scan(scan)) {
Iterator<Result> iterator = scanner.iterator();
for (int i = 0; i < 234; i++) {
results.add(iterator.next());
}
}
// Assert
assertThat(results.size()).isEqualTo(234);
for (int i = 0; i < 234; i++) {
assertThat(results.get(i).getPartitionKey().isPresent()).isTrue();
assertThat(results.get(i).getClusteringKey().isPresent()).isTrue();
assertThat(results.get(i).getPartitionKey().get().get().get(0).getAsInt()).isEqualTo(1);
assertThat(results.get(i).getClusteringKey().get().get().get(0).getAsInt()).isEqualTo(i);
}
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_IncorrectPutGiven_ShouldThrowIllegalArgumentException.
@Test
public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() {
// Arrange
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(COL_NAME1, pKey);
Put put = new Put(partitionKey).withValue(COL_NAME4, cKey);
// Act Assert
assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults.
@Test
public void scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults() throws IOException, ExecutionException {
// Arrange
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));
// Act
List<Result> actual = scanAll(scan);
// Assert
assertThat(actual.size()).isEqualTo(3);
assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 2)));
assertThat(actual.get(1).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 1)));
assertThat(actual.get(2).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0)));
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_PutWithoutValuesGivenTwice_ShouldStoreProperly.
@Test
public void put_PutWithoutValuesGivenTwice_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();
assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
// Assert
Optional<Result> result = storage.get(new Get(partitionKey, clusteringKey));
assertThat(result).isPresent();
}
use of com.scalar.db.api.Put in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_MultiplePutGiven_ShouldStoreProperly.
@Test
public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionException, IOException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Scan scan = new Scan(new Key(COL_NAME1, pKey));
// Act
assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(3);
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_NAME4).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey);
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_NAME4).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 1);
assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 2);
}
Aggregations