use of com.scalar.db.util.TestUtils.ExpectedResult in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase method scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues.
@Test
public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
// Arrange
for (int i = 0; i < 345; i++) {
Key partitionKey = new Key(COL_NAME1, i % 4);
Key clusteringKey = new Key(COL_NAME4, i);
storage.put(new Put(partitionKey, clusteringKey).withBlobValue(COL_NAME6, new byte[5000]));
}
Scan scan = new ScanAll();
// Act
List<Result> results = scanAll(scan);
// Assert
List<ExpectedResult> expectedResults = new ArrayList<>();
for (int i = 0; i < 345; i++) {
Key partitionKey = new Key(COL_NAME1, i % 4);
Key clusteringKey = new Key(COL_NAME4, i);
expectedResults.add(new ExpectedResultBuilder().partitionKey(partitionKey).clusteringKey(clusteringKey).nonKeyColumns(Arrays.asList(TextColumn.ofNull(COL_NAME2), IntColumn.ofNull(COL_NAME3), BooleanColumn.ofNull(COL_NAME5), BlobColumn.of(COL_NAME6, new byte[5000]))).build());
}
assertResultsContainsExactlyInAnyOrder(results, expectedResults);
}
use of com.scalar.db.util.TestUtils.ExpectedResult in project scalardb by scalar-labs.
the class DistributedTransactionIntegrationTestBase method scan_ScanAllWithProjectionsGivenOnNonPrimaryKeyColumnsForCommittedRecord_ShouldReturnOnlyProjectedColumns.
@Test
public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKeyColumnsForCommittedRecord_ShouldReturnOnlyProjectedColumns() throws TransactionException {
// Arrange
populateSingleRecord();
DistributedTransaction transaction = manager.start();
ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(BALANCE, SOME_COLUMN));
// Act
List<Result> results = transaction.scan(scanAll);
transaction.commit();
// Assert
ExpectedResult expectedResult = new ExpectedResultBuilder().nonKeyColumns(ImmutableList.of(IntColumn.of(BALANCE, INITIAL_BALANCE), IntColumn.ofNull(SOME_COLUMN))).build();
assertResultsContainsExactlyInAnyOrder(results, Collections.singletonList(expectedResult));
}
use of com.scalar.db.util.TestUtils.ExpectedResult in project scalardb by scalar-labs.
the class DistributedTransactionIntegrationTestBase method scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues.
@Test
public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws TransactionException {
// Arrange
populateRecords();
DistributedTransaction transaction = manager.start();
ScanAll scanAll = prepareScanAll().withProjection(ACCOUNT_TYPE).withProjection(BALANCE);
// Act
List<Result> results = transaction.scan(scanAll);
transaction.commit();
// Assert
List<ExpectedResult> expectedResults = new ArrayList<>();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
ExpectedResultBuilder erBuilder = new ExpectedResultBuilder().clusteringKey(Key.ofInt(ACCOUNT_TYPE, j)).nonKeyColumns(ImmutableList.of(IntColumn.of(BALANCE, INITIAL_BALANCE)));
expectedResults.add(erBuilder.build());
}));
assertResultsContainsExactlyInAnyOrder(results, expectedResults);
}
use of com.scalar.db.util.TestUtils.ExpectedResult in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionIntegrationTestBase method scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues.
@Test
public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws TransactionException {
// Arrange
populateRecords();
TwoPhaseCommitTransaction transaction = manager.start();
ScanAll scanAll = prepareScanAll().withProjection(ACCOUNT_TYPE).withProjection(BALANCE);
// Act
List<Result> results = transaction.scan(scanAll);
transaction.prepare();
transaction.validate();
transaction.commit();
// Assert
List<ExpectedResult> expectedResults = new ArrayList<>();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
ExpectedResultBuilder erBuilder = new ExpectedResultBuilder().clusteringKey(Key.ofInt(ACCOUNT_TYPE, j)).nonKeyColumns(ImmutableList.of(IntColumn.of(BALANCE, INITIAL_BALANCE)));
expectedResults.add(erBuilder.build());
}));
assertResultsContainsExactlyInAnyOrder(results, expectedResults);
results.forEach(result -> {
assertThat(result.contains(ACCOUNT_ID)).isFalse();
assertThat(result.contains(SOME_COLUMN)).isFalse();
});
}
use of com.scalar.db.util.TestUtils.ExpectedResult in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionIntegrationTestBase method scan_ScanAllWithProjectionsGivenOnNonPrimaryKeyColumnsForCommittedRecord_ShouldReturnOnlyProjectedColumns.
@Test
public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKeyColumnsForCommittedRecord_ShouldReturnOnlyProjectedColumns() throws TransactionException {
// Arrange
populateSingleRecord();
TwoPhaseCommitTransaction transaction = manager.start();
ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(BALANCE, SOME_COLUMN));
// Act
List<Result> results = transaction.scan(scanAll);
transaction.prepare();
transaction.validate();
transaction.commit();
// Assert
ExpectedResult expectedResult = new ExpectedResultBuilder().nonKeyColumns(ImmutableList.of(IntColumn.of(BALANCE, INITIAL_BALANCE), IntColumn.ofNull(SOME_COLUMN))).build();
assertResultsContainsExactlyInAnyOrder(results, Collections.singletonList(expectedResult));
}
Aggregations