use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase 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.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase 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.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentException.
@Test
public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentException() {
// Arrange
populateRecords();
String c2 = "test";
Scan scan = new Scan(new Key(COL_NAME2, c2));
// Act Assert
assertThatThrownBy(() -> scanAll(scan)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyEveryTime.
@Test
public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyEveryTime() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
// Act
Scan scan = new Scan(new Key(COL_NAME1, pKey));
double t1 = System.currentTimeMillis();
List<Result> actual = scanAll(scan);
double t2 = System.currentTimeMillis();
Scanner scanner = storage.scan(scan);
scanner.close();
double t3 = System.currentTimeMillis();
scanner = storage.scan(scan);
scanner.close();
double t4 = System.currentTimeMillis();
// Assert
assertThat(actual.get(0).getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0)));
System.err.println("first: " + (t2 - t1) + " (ms)");
System.err.println("second: " + (t3 - t2) + " (ms)");
System.err.println("third: " + (t4 - t3) + " (ms)");
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException.
@Test
public void mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
// Act
assertThatCode(() -> storage.mutate(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);
}
Aggregations