Search in sources :

Example 86 with Key

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

the class DistributedStorageIntegrationTestBase 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) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 87 with Key

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

the class DistributedStorageIntegrationTestBase method put_PutWithoutValuesGivenTwice_ShouldStoreProperly.

@Test
public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    // Act
    assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
    assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
    // Assert
    Optional<Result> result = storage.get(new Get(partitionKey, clusteringKey));
    assertThat(result).isPresent();
}
Also used : Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 88 with Key

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

the class DistributedStorageIntegrationTestBase method scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentException.

@Test
public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentException() {
    // Arrange
    populateRecords();
    String c2 = "test";
    Scan scan = new Scan(new Key(COL_NAME2, c2));
    // Act Assert
    assertThatThrownBy(() -> scanAll(scan)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 89 with Key

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

the class DistributedStorageIntegrationTestBase 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 : IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 90 with Key

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

the class DistributedStorageIntegrationTestBase method mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException.

@Test
public void mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgumentException() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    // Act
    assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(3), puts.get(6)))).isInstanceOf(IllegalArgumentException.class);
    // Assert
    List<Result> results;
    results = scanAll(new Scan(new Key(COL_NAME1, 0)));
    assertThat(results.size()).isEqualTo(0);
    results = scanAll(new Scan(new Key(COL_NAME1, 3)));
    assertThat(results.size()).isEqualTo(0);
    results = scanAll(new Scan(new Key(COL_NAME1, 6)));
    assertThat(results.size()).isEqualTo(0);
}
Also used : Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Aggregations

Key (com.scalar.db.io.Key)603 Test (org.junit.jupiter.api.Test)391 Put (com.scalar.db.api.Put)211 Scan (com.scalar.db.api.Scan)145 Get (com.scalar.db.api.Get)134 Delete (com.scalar.db.api.Delete)118 Result (com.scalar.db.api.Result)94 Test (org.junit.Test)90 TextValue (com.scalar.db.io.TextValue)88 IntValue (com.scalar.db.io.IntValue)81 BooleanValue (com.scalar.db.io.BooleanValue)51 HashMap (java.util.HashMap)42 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)40 ArrayList (java.util.ArrayList)39 Value (com.scalar.db.io.Value)38 DoubleValue (com.scalar.db.io.DoubleValue)35 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)29 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)27 ByteBuffer (java.nio.ByteBuffer)27