Search in sources :

Example 16 with Result

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

the class StorageIntegrationTestBase method delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly.

@Test
public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() throws ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    Key partitionKey = new Key(COL_NAME1, pKey);
    Key clusteringKey = new Key(COL_NAME4, cKey);
    // Act
    Delete delete = prepareDelete(pKey, cKey);
    delete.withCondition(new DeleteIf(new ConditionalExpression(COL_NAME2, new TextValue(Integer.toString(pKey)), ConditionalExpression.Operator.EQ)));
    assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
    // Assert
    Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
    assertThat(actual.isPresent()).isFalse();
}
Also used : Delete(com.scalar.db.api.Delete) TextValue(com.scalar.db.io.TextValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) DeleteIf(com.scalar.db.api.DeleteIf) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 17 with Result

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

the class StorageIntegrationTestBase method mutate_SingleDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly.

@Test
public void mutate_SingleDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() throws ExecutionException, IOException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    // Act
    Key partitionKey = new Key(COL_NAME1, pKey);
    Key clusteringKey = new Key(COL_NAME4, cKey);
    Delete delete = new Delete(partitionKey, clusteringKey);
    assertThatCode(() -> storage.mutate(Collections.singletonList(delete))).doesNotThrowAnyException();
    // Assert
    List<Result> actual = scanAll(new Scan(partitionKey));
    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(cKey + 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(cKey + 2);
}
Also used : Delete(com.scalar.db.api.Delete) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 18 with Result

use of com.scalar.db.api.Result 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 19 with Result

use of com.scalar.db.api.Result 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 20 with Result

use of com.scalar.db.api.Result 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)

Aggregations

Result (com.scalar.db.api.Result)324 Test (org.junit.Test)158 Get (com.scalar.db.api.Get)132 Scan (com.scalar.db.api.Scan)106 Put (com.scalar.db.api.Put)101 Key (com.scalar.db.io.Key)85 Test (org.junit.jupiter.api.Test)83 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)39 IntValue (com.scalar.db.io.IntValue)36 GrpcTwoPhaseCommitTransaction (com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction)32 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)29 Delete (com.scalar.db.api.Delete)28 TextValue (com.scalar.db.io.TextValue)24 Value (com.scalar.db.io.Value)19 BigIntValue (com.scalar.db.io.BigIntValue)16 Scanner (com.scalar.db.api.Scanner)15 ArrayList (java.util.ArrayList)14 BooleanValue (com.scalar.db.io.BooleanValue)11 ConditionalExpression (com.scalar.db.api.ConditionalExpression)10 ScanAll (com.scalar.db.api.ScanAll)9