Search in sources :

Example 1 with ExpectedResultBuilder

use of com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder 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);
}
Also used : ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ArrayList(java.util.ArrayList) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 2 with ExpectedResultBuilder

use of com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder 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));
}
Also used : ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 3 with ExpectedResultBuilder

use of com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder 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);
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) IntColumn(com.scalar.db.io.IntColumn) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TestUtils.assertResultsAreASubsetOf(com.scalar.db.util.TestUtils.assertResultsAreASubsetOf) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) TestUtils(com.scalar.db.util.TestUtils) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) Key(com.scalar.db.io.Key) Properties(java.util.Properties) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) TestUtils.assertResultsContainsExactlyInAnyOrder(com.scalar.db.util.TestUtils.assertResultsContainsExactlyInAnyOrder) TransactionFactory(com.scalar.db.service.TransactionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Ordering(com.scalar.db.api.Scan.Ordering) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ArrayList(java.util.ArrayList) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 4 with ExpectedResultBuilder

use of com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder 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();
    });
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) IntColumn(com.scalar.db.io.IntColumn) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TestUtils.assertResultsAreASubsetOf(com.scalar.db.util.TestUtils.assertResultsAreASubsetOf) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) TestUtils(com.scalar.db.util.TestUtils) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) Key(com.scalar.db.io.Key) Properties(java.util.Properties) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) TestUtils.assertResultsContainsExactlyInAnyOrder(com.scalar.db.util.TestUtils.assertResultsContainsExactlyInAnyOrder) TransactionFactory(com.scalar.db.service.TransactionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Ordering(com.scalar.db.api.Scan.Ordering) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ArrayList(java.util.ArrayList) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 5 with ExpectedResultBuilder

use of com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder 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));
}
Also used : ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Aggregations

ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)5 ExpectedResultBuilder (com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder)5 Test (org.junit.jupiter.api.Test)5 Key (com.scalar.db.io.Key)3 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 Ordering (com.scalar.db.api.Scan.Ordering)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)2 CommitException (com.scalar.db.exception.transaction.CommitException)2 CrudException (com.scalar.db.exception.transaction.CrudException)2 TransactionException (com.scalar.db.exception.transaction.TransactionException)2 DataType (com.scalar.db.io.DataType)2 IntColumn (com.scalar.db.io.IntColumn)2 IntValue (com.scalar.db.io.IntValue)2 Value (com.scalar.db.io.Value)2 TransactionFactory (com.scalar.db.service.TransactionFactory)2 TestUtils (com.scalar.db.util.TestUtils)2 TestUtils.assertResultsAreASubsetOf (com.scalar.db.util.TestUtils.assertResultsAreASubsetOf)2 TestUtils.assertResultsContainsExactlyInAnyOrder (com.scalar.db.util.TestUtils.assertResultsContainsExactlyInAnyOrder)2 Arrays (java.util.Arrays)2