Search in sources :

Example 91 with IntValue

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

the class StorageIntegrationTestBase method put_PutWithNullValue_ShouldPutProperly.

@Test
public void put_PutWithNullValue_ShouldPutProperly() throws ExecutionException {
    // Arrange
    Put put = preparePuts().get(0);
    storage.put(put);
    put.withNullValue(COL_NAME2);
    // Act
    storage.put(put);
    // Assert
    Optional<Result> actual = storage.get(prepareGet(0, 0));
    assertThat(actual.isPresent()).isTrue();
    Result result = actual.get();
    assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, 0)));
    assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0)));
    assertThat(result.getValue(COL_NAME2)).isEqualTo(Optional.of(new TextValue(COL_NAME2, (String) null)));
    assertThat(result.getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, 0)));
    assertThat(result.getValue(COL_NAME5)).isEqualTo(Optional.of(new BooleanValue(COL_NAME5, true)));
    assertThat(result.getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5)));
    assertThat(result.contains(COL_NAME1)).isTrue();
    assertThat(result.isNull(COL_NAME1)).isFalse();
    assertThat(result.getInt(COL_NAME1)).isEqualTo(0);
    assertThat(result.getAsObject(COL_NAME1)).isEqualTo(0);
    assertThat(result.contains(COL_NAME4)).isTrue();
    assertThat(result.isNull(COL_NAME4)).isFalse();
    assertThat(result.getInt(COL_NAME4)).isEqualTo(0);
    assertThat(result.getAsObject(COL_NAME4)).isEqualTo(0);
    assertThat(result.contains(COL_NAME2)).isTrue();
    assertThat(result.isNull(COL_NAME2)).isTrue();
    assertThat(result.getText(COL_NAME2)).isNull();
    assertThat(result.getAsObject(COL_NAME2)).isNull();
    assertThat(result.contains(COL_NAME3)).isTrue();
    assertThat(result.isNull(COL_NAME3)).isFalse();
    assertThat(result.getInt(COL_NAME3)).isEqualTo(0);
    assertThat(result.getAsObject(COL_NAME3)).isEqualTo(0);
    assertThat(result.contains(COL_NAME5)).isTrue();
    assertThat(result.isNull(COL_NAME5)).isFalse();
    assertThat(result.getBoolean(COL_NAME5)).isEqualTo(true);
    assertThat(result.getAsObject(COL_NAME5)).isEqualTo(true);
}
Also used : TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 92 with IntValue

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

the class StorageIntegrationTestBase method put_SinglePutGiven_ShouldStoreProperly.

@Test
public void put_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.put(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 93 with IntValue

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

the class StorageIntegrationTestBase method scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults.

@Test
public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() 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.ASC));
    // 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, 0)));
    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, 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 94 with IntValue

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

the class StorageIntegrationTestBase method scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyEveryTime.

@Test
public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyEveryTime() throws IOException, ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act
    Scan scan = new Scan(new Key(COL_NAME1, pKey));
    double t1 = System.currentTimeMillis();
    List<Result> actual = scanAll(scan);
    double t2 = System.currentTimeMillis();
    Scanner scanner = storage.scan(scan);
    scanner.close();
    double t3 = System.currentTimeMillis();
    scanner = storage.scan(scan);
    scanner.close();
    double t4 = System.currentTimeMillis();
    // Assert
    assertThat(actual.get(0).getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
    assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0)));
    System.err.println("first: " + (t2 - t1) + " (ms)");
    System.err.println("second: " + (t3 - t2) + " (ms)");
    System.err.println("third: " + (t4 - t3) + " (ms)");
}
Also used : Scanner(com.scalar.db.api.Scanner) Scan(com.scalar.db.api.Scan) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 95 with IntValue

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

the class StorageIntegrationTestBase method get_GetGivenForIndexedColumn_ShouldGet.

@Test
public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException {
    // Arrange
    // (0,0)
    storage.put(preparePuts().get(0));
    int c3 = 0;
    Get get = new Get(new Key(COL_NAME3, c3));
    // Act
    Optional<Result> actual = storage.get(get);
    // Assert
    assertThat(actual.isPresent()).isTrue();
    assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, 0)));
    assertThat(actual.get().getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0)));
}
Also used : Get(com.scalar.db.api.Get) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) 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