use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly.
@Test
public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() throws IOException, ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Scan scan = new Scan(new Key(columnName1, pKey));
// Act
assertThatCode(() -> storage.put(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(columnName1).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey);
assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 1);
assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 2);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues.
@Test
public void scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
// Act
Scan scan = new Scan(new Key(columnName1, pKey)).withProjection(columnName1).withProjection(columnName2).withProjection(columnName3);
List<Result> actual = scanAll(scan);
// Assert
assertThat(actual.size()).isEqualTo(3);
assertThat(actual.get(0).getValue(columnName1).isPresent()).isTrue();
assertThat(actual.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(actual.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(1).getValue(columnName1).isPresent()).isTrue();
assertThat(actual.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(1).getValue(columnName4).isPresent()).isTrue();
assertThat(actual.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1);
assertThat(actual.get(2).getValue(columnName1).isPresent()).isTrue();
assertThat(actual.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(2).getValue(columnName4).isPresent()).isTrue();
assertThat(actual.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(2);
actual.forEach(a -> {
assertThat(a.getValue(columnName1).isPresent()).isTrue();
assertThat(a.getValue(columnName2).isPresent()).isTrue();
assertThat(a.getValue(columnName3).isPresent()).isTrue();
// since it's clustering key
assertThat(a.getValue(columnName4).isPresent()).isTrue();
assertThat(a.getValue(columnName5).isPresent()).isFalse();
});
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method scan_DeleteCalledBefore_ShouldReturnEmpty.
@Test
public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws CommitException, UnknownTransactionStatusException, CrudException {
// Arrange
ConsensusCommit transaction = manager.start();
transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
transaction.commit();
// Act
ConsensusCommit transaction1 = manager.start();
Scan scan = prepareScan(0, 0, 0, namespace1, TABLE_1);
List<Result> resultBefore = transaction1.scan(scan);
transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1));
List<Result> resultAfter = transaction1.scan(scan);
assertThatCode(transaction1::commit).doesNotThrowAnyException();
// Assert
assertThat(resultBefore.size()).isEqualTo(1);
assertThat(resultAfter.size()).isEqualTo(0);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction.
@Test
public void scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction() throws ExecutionException, CoordinatorException, CrudException {
Scan scan = prepareScan(0, 0, 0, namespace1, TABLE_1);
selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction(scan);
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitIntegrationTest method scan_DeleteGivenBefore_ShouldScan.
@Test
public void scan_DeleteGivenBefore_ShouldScan() throws TransactionException {
// Arrange
TwoPhaseConsensusCommit transaction = manager.start();
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction.put(preparePut(0, 1, TABLE_1).withValue(BALANCE, 1));
transaction.prepare();
transaction.commit();
// Act
TwoPhaseConsensusCommit transaction1 = manager.start();
transaction1.delete(prepareDelete(0, 0, TABLE_1));
Scan scan = prepareScan(0, 0, 1, TABLE_1);
List<Result> results = transaction1.scan(scan);
assertThatCode(() -> {
transaction1.prepare();
transaction1.commit();
}).doesNotThrowAnyException();
// Assert
assertThat(results.size()).isEqualTo(1);
}
Aggregations