Search in sources :

Example 6 with Delete

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

the class StorageIntegrationTestBase method delete_DeleteWithIfExistsGivenWhenNoSuchRecord_ShouldThrowNoMutationException.

@Test
public void delete_DeleteWithIfExistsGivenWhenNoSuchRecord_ShouldThrowNoMutationException() {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act Assert
    Delete delete = prepareDelete(pKey, Integer.MAX_VALUE);
    delete.withCondition(new DeleteIfExists());
    assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Test(org.junit.Test)

Example 7 with Delete

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

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

Example 9 with Delete

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

the class StorageIntegrationTestBase method delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeleteProperly.

@Test
public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_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 DeleteIfExists());
    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) Get(com.scalar.db.api.Get) Key(com.scalar.db.io.Key) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 10 with Delete

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

the class PrepareMutationComposerTest method delete_DeleteAndNullResultGiven_ShouldThrowIllegalArgumentException.

@Test
public void delete_DeleteAndNullResultGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    Delete delete = prepareDelete();
    // Act Assert
    assertThatThrownBy(() -> composer.add(delete, null)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Test(org.junit.Test)

Aggregations

Delete (com.scalar.db.api.Delete)174 Key (com.scalar.db.io.Key)112 Test (org.junit.jupiter.api.Test)111 Put (com.scalar.db.api.Put)59 Get (com.scalar.db.api.Get)29 Result (com.scalar.db.api.Result)29 Test (org.junit.Test)25 DeleteIfExists (com.scalar.db.api.DeleteIfExists)24 ConditionalExpression (com.scalar.db.api.ConditionalExpression)16 DeleteIf (com.scalar.db.api.DeleteIf)15 Mutation (com.scalar.db.api.Mutation)14 MutationCondition (com.scalar.db.api.MutationCondition)11 Scan (com.scalar.db.api.Scan)11 PutIfNotExists (com.scalar.db.api.PutIfNotExists)10 TextValue (com.scalar.db.io.TextValue)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)6 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)6 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)6 PartitionKey (com.azure.cosmos.models.PartitionKey)5