Search in sources :

Example 11 with Key

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

the class StorageIntegrationTestBase method delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.

@Test
public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    List<Delete> deletes = prepareDeletes();
    storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
    deletes.get(0).withCondition(new DeleteIfExists());
    deletes.get(1).withCondition(new DeleteIf(new ConditionalExpression(COL_NAME2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
    // Act
    assertThatCode(() -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(new Key(COL_NAME1, 0)));
    assertThat(results.size()).isEqualTo(0);
}
Also used : Delete(com.scalar.db.api.Delete) TextValue(com.scalar.db.io.TextValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) DeleteIfExists(com.scalar.db.api.DeleteIfExists) DeleteIf(com.scalar.db.api.DeleteIf) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 12 with Key

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

the class StorageIntegrationTestBase method scan_ScanLargeData_ShouldRetrieveExpectedValues.

@Test
public void scan_ScanLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
    // Arrange
    Key partitionKey = new Key(COL_NAME1, 1);
    for (int i = 0; i < 345; i++) {
        Key clusteringKey = new Key(COL_NAME4, i);
        storage.put(new Put(partitionKey, clusteringKey));
    }
    Scan scan = new Scan(partitionKey);
    // Act
    List<Result> results = scanAll(scan);
    // Assert
    assertThat(results.size()).isEqualTo(345);
    for (int i = 0; i < 345; i++) {
        assertThat(results.get(i).getValue(COL_NAME1).isPresent()).isTrue();
        assertThat(results.get(i).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1);
        assertThat(results.get(i).getValue(COL_NAME4).isPresent()).isTrue();
        assertThat(results.get(i).getValue(COL_NAME4).get().getAsInt()).isEqualTo(i);
    }
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 13 with Key

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

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

the class StorageIntegrationTestBase method prepareDeletes.

private List<Delete> prepareDeletes() {
    List<Delete> deletes = new ArrayList<>();
    IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
        Key partitionKey = new Key(COL_NAME1, i);
        Key clusteringKey = new Key(COL_NAME4, j);
        Delete delete = new Delete(partitionKey, clusteringKey);
        deletes.add(delete);
    }));
    return deletes;
}
Also used : Delete(com.scalar.db.api.Delete) IntStream(java.util.stream.IntStream) PutIfNotExists(com.scalar.db.api.PutIfNotExists) DatabaseConfig(com.scalar.db.config.DatabaseConfig) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TextValue(com.scalar.db.io.TextValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) DeleteIfExists(com.scalar.db.api.DeleteIfExists) StorageFactory(com.scalar.db.service.StorageFactory) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) TableMetadata(com.scalar.db.api.TableMetadata) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Result(com.scalar.db.api.Result) DeleteIf(com.scalar.db.api.DeleteIf) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Order(com.scalar.db.api.Scan.Ordering.Order) Map(java.util.Map) DataType(com.scalar.db.io.DataType) Before(org.junit.Before) Scanner(com.scalar.db.api.Scanner) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) NoMutationException(com.scalar.db.exception.storage.NoMutationException) ConditionalExpression(com.scalar.db.api.ConditionalExpression) IOException(java.io.IOException) Test(org.junit.Test) Put(com.scalar.db.api.Put) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) PutIfExists(com.scalar.db.api.PutIfExists) DistributedStorage(com.scalar.db.api.DistributedStorage) PutIf(com.scalar.db.api.PutIf) List(java.util.List) Ordering(com.scalar.db.api.Scan.Ordering) Scan(com.scalar.db.api.Scan) Optional(java.util.Optional) BooleanValue(com.scalar.db.io.BooleanValue) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key)

Example 15 with Key

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

the class StorageIntegrationTestBase method prepareDelete.

private Delete prepareDelete(int pKey, int cKey) {
    Key partitionKey = new Key(COL_NAME1, pKey);
    Key clusteringKey = new Key(COL_NAME4, cKey);
    return new Delete(partitionKey, clusteringKey);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key)

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