Search in sources :

Example 81 with Key

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

the class DistributedStorageIntegrationTestBase method get_GetGivenForIndexedColumnMatchingMultipleRecords_ShouldThrowIllegalArgumentException.

@Test
public void get_GetGivenForIndexedColumnMatchingMultipleRecords_ShouldThrowIllegalArgumentException() {
    // Arrange
    populateRecords();
    int c3 = 3;
    Get get = new Get(new Key(COL_NAME3, c3));
    // Act Assert
    assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 82 with Key

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

the class DistributedStorageIntegrationTestBase 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 : 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 83 with Key

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

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

Example 84 with Key

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

the class DistributedStorageIntegrationTestBase method scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectResults.

@Test
public void scannerIterator_IteratorCalledMultipleTimes_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);
    actual.add(scanner.iterator().next());
    actual.add(scanner.iterator().next());
    actual.add(scanner.iterator().next());
    scanner.close();
    // Assert
    assertThat(actual.size()).isEqualTo(3);
    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(0);
    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(1);
    assertThat(actual.get(2).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(actual.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(2).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(actual.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2);
}
Also used : ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 85 with Key

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

the class DistributedStorageIntegrationTestBase method operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException.

@Test
public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    // a wrong namespace
    storage.with("wrong_" + namespace, 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 : Key(com.scalar.db.io.Key) 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