Search in sources :

Example 1 with IntValue

use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.

the class StorageIntegrationTestBase method scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults.

@Test
public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() throws IOException, ExecutionException {
    // setup
    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)).withLimit(1);
    // exercise
    List<Result> actual = scanAll(scan);
    // verify
    assertThat(actual.size()).isEqualTo(1);
    assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 2)));
}
Also used : Ordering(com.scalar.db.api.Scan.Ordering) Scan(com.scalar.db.api.Scan) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 2 with IntValue

use of com.scalar.db.io.IntValue 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)));
}
Also used : TextValue(com.scalar.db.io.TextValue) Get(com.scalar.db.api.Get) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 3 with IntValue

use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.

the class StorageIntegrationTestBase method put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException.

@Test
public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException() throws IOException, ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException();
    puts.get(0).withCondition(new PutIfNotExists());
    puts.get(1).withCondition(new PutIfNotExists());
    puts.get(2).withCondition(new PutIfNotExists());
    Scan scan = new Scan(new Key(COL_NAME1, pKey));
    // Act
    assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).isInstanceOf(NoMutationException.class);
    // Assert
    List<Result> results = scanAll(scan);
    assertThat(results.size()).isEqualTo(1);
    assertThat(results.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, pKey + cKey)));
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) Scan(com.scalar.db.api.Scan) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 4 with IntValue

use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.

the class StorageIntegrationTestBase 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)));
}
Also used : Ordering(com.scalar.db.api.Scan.Ordering) Scan(com.scalar.db.api.Scan) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 5 with IntValue

use of com.scalar.db.io.IntValue in project scalardb by scalar-labs.

the class StorageIntegrationTestBase method get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues.

@Test
public void get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    // Act
    Get get = prepareGet(pKey, cKey);
    get.withProjection(COL_NAME1).withProjection(COL_NAME2).withProjection(COL_NAME3);
    Optional<Result> actual = storage.get(get);
    // Assert
    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)));
    // since it's clustering key
    assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME5).isPresent()).isFalse();
}
Also used : TextValue(com.scalar.db.io.TextValue) Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Aggregations

IntValue (com.scalar.db.io.IntValue)108 Test (org.junit.jupiter.api.Test)65 TextValue (com.scalar.db.io.TextValue)63 Key (com.scalar.db.io.Key)62 Put (com.scalar.db.api.Put)55 BooleanValue (com.scalar.db.io.BooleanValue)48 DoubleValue (com.scalar.db.io.DoubleValue)38 Result (com.scalar.db.api.Result)35 Test (org.junit.Test)33 Get (com.scalar.db.api.Get)29 Value (com.scalar.db.io.Value)26 BigIntValue (com.scalar.db.io.BigIntValue)23 BlobValue (com.scalar.db.io.BlobValue)20 FloatValue (com.scalar.db.io.FloatValue)19 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)15 ConditionalExpression (com.scalar.db.api.ConditionalExpression)13 MutationCondition (com.scalar.db.api.MutationCondition)12 PutIf (com.scalar.db.api.PutIf)8 TransactionState (com.scalar.db.api.TransactionState)8 DeleteIf (com.scalar.db.api.DeleteIf)6