use of com.scalar.db.api.Result 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.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResults.
@Test
public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResults() throws ExecutionException, IOException {
// Arrange
populateRecords();
int pKey = 0;
// Act
Scan scan = new Scan(new Key(COL_NAME1, pKey));
List<Result> actual = new ArrayList<>();
Scanner scanner = storage.scan(scan);
scanner.forEach(actual::add);
scanner.close();
// Assert
assertThat(actual.size()).isEqualTo(3);
assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1);
assertThat(actual.get(2).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(2).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2);
}
use of com.scalar.db.api.Result 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.Result 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();
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_SinglePutGiven_ShouldStoreProperly.
@Test
public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Key partitionKey = new Key(COL_NAME1, pKey);
Key clusteringKey = new Key(COL_NAME4, cKey);
Get get = new Get(partitionKey, clusteringKey);
// Act
storage.mutate(Collections.singletonList(puts.get(pKey * 2 + cKey)));
// Assert
Optional<Result> actual = storage.get(get);
assertThat(actual.isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
assertThat(actual.get().getValue(COL_NAME2)).isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey))));
assertThat(actual.get().getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey)));
assertThat(actual.get().getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey)));
assertThat(actual.get().getValue(COL_NAME5)).isEqualTo(Optional.of(new BooleanValue(COL_NAME5, cKey % 2 == 0)));
}
Aggregations