Search in sources :

Example 26 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class StorageWithReservedKeywordIntegrationTestBase method preparePuts.

private List<Put> preparePuts() {
    List<Put> puts = new ArrayList<>();
    IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
        Key partitionKey = new Key(columnName1, i);
        Key clusteringKey = new Key(columnName4, j);
        Put put = new Put(partitionKey, clusteringKey).withValue(columnName2, Integer.toString(i + j)).withValue(columnName3, i + j).withValue(columnName5, j % 2 == 0);
        puts.add(put);
    }));
    return puts;
}
Also used : 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) Result(com.scalar.db.api.Result) DeleteIf(com.scalar.db.api.DeleteIf) ImmutableList(com.google.common.collect.ImmutableList) 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) 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) 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) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key)

Example 27 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly() throws ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Key partitionKey = new Key(columnName1, pKey);
    Key clusteringKey = new Key(columnName4, 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(columnName1)).isEqualTo(Optional.of(new IntValue(columnName1, pKey)));
    assertThat(actual.get().getValue(columnName2)).isEqualTo(Optional.of(new TextValue(columnName2, Integer.toString(pKey + cKey))));
    assertThat(actual.get().getValue(columnName3)).isEqualTo(Optional.of(new IntValue(columnName3, pKey + cKey)));
    assertThat(actual.get().getValue(columnName4)).isEqualTo(Optional.of(new IntValue(columnName4, cKey)));
    assertThat(actual.get().getValue(columnName5)).isEqualTo(Optional.of(new BooleanValue(columnName5, 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 28 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class StorageWithReservedKeywordIntegrationTestBase method put_PutWithReservedKeywordAndIfGivenWhenSuchRecordExists_ShouldUpdateRecord.

@Test
public void put_PutWithReservedKeywordAndIfGivenWhenSuchRecordExists_ShouldUpdateRecord() throws ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Get get = prepareGet(pKey, cKey);
    // Act Assert
    storage.put(puts.get(0));
    puts.get(0).withCondition(new PutIf(new ConditionalExpression(columnName3, new IntValue(pKey + cKey), ConditionalExpression.Operator.EQ)));
    puts.get(0).withValue(columnName3, Integer.MAX_VALUE);
    assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException();
    // Assert
    Optional<Result> actual = storage.get(get);
    assertThat(actual.isPresent()).isTrue();
    Result result = actual.get();
    assertThat(result.getValue(columnName1)).isEqualTo(Optional.of(new IntValue(columnName1, pKey)));
    assertThat(result.getValue(columnName4)).isEqualTo(Optional.of(new IntValue(columnName4, cKey)));
    assertThat(result.getValue(columnName3)).isEqualTo(Optional.of(new IntValue(columnName3, Integer.MAX_VALUE)));
}
Also used : PutIf(com.scalar.db.api.PutIf) Get(com.scalar.db.api.Get) ConditionalExpression(com.scalar.db.api.ConditionalExpression) IntValue(com.scalar.db.io.IntValue) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 29 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class StorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.

@Test
public void delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_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(columnName2, 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(columnName1, 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 30 with Put

use of com.scalar.db.api.Put in project scalardb by scalar-labs.

the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() throws IOException, ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Scan scan = new Scan(new Key(columnName1, pKey));
    // Act
    assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(scan);
    assertThat(results.size()).isEqualTo(3);
    assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey);
    assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 1);
    assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 2);
}
Also used : Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Aggregations

Put (com.scalar.db.api.Put)374 Key (com.scalar.db.io.Key)216 Test (org.junit.jupiter.api.Test)209 Result (com.scalar.db.api.Result)108 Get (com.scalar.db.api.Get)93 Test (org.junit.Test)67 Delete (com.scalar.db.api.Delete)64 IntValue (com.scalar.db.io.IntValue)63 TextValue (com.scalar.db.io.TextValue)48 Scan (com.scalar.db.api.Scan)44 Value (com.scalar.db.io.Value)37 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)35 BooleanValue (com.scalar.db.io.BooleanValue)33 ConditionalExpression (com.scalar.db.api.ConditionalExpression)30 PutIfNotExists (com.scalar.db.api.PutIfNotExists)29 PutIf (com.scalar.db.api.PutIf)28 DoubleValue (com.scalar.db.io.DoubleValue)26 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)19 ExecutionException (com.scalar.db.exception.storage.ExecutionException)17 Mutation (com.scalar.db.api.Mutation)16