Search in sources :

Example 21 with Key

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

the class StorageIntegrationTestBase method operation_NoTargetGiven_ShouldThrowIllegalArgumentException.

@Test
public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    storage.with(null, TABLE);
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    Get get = new Get(partitionKey, clusteringKey);
    // Act Assert
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 22 with Key

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

the class StorageIntegrationTestBase method scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults.

@Test
public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() throws ExecutionException, IOException {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act
    Scan scan = new Scan(new Key(COL_NAME1, pKey));
    List<Result> actual = new ArrayList<>();
    Scanner scanner = storage.scan(scan);
    Optional<Result> result = scanner.one();
    scanner.forEach(actual::add);
    scanner.close();
    // Assert
    assertThat(result.isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(result.get().getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(0);
    assertThat(actual.size()).isEqualTo(2);
    assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1);
    assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2);
}
Also used : Scanner(com.scalar.db.api.Scanner) ArrayList(java.util.ArrayList) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 23 with Key

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

the class StorageIntegrationTestBase method operation_WrongTableGiven_ShouldThrowIllegalArgumentException.

@Test
public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    // a wrong table
    storage.with(namespace, "wrong_" + TABLE);
    Key partitionKey = new Key(COL_NAME1, 0);
    Key clusteringKey = new Key(COL_NAME4, 0);
    Get get = new Get(partitionKey, clusteringKey);
    // Act Assert
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 24 with Key

use of com.scalar.db.io.Key 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 25 with Key

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

the class StorageIntegrationTestBase 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 : Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) Test(org.junit.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