Search in sources :

Example 1 with DeleteIfExists

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

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

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

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

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

the class OperationCheckerTest method whenCheckingDeleteOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingDeleteOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, "c3", "val1");
    MutationCondition condition = new DeleteIfExists();
    Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Delete(com.scalar.db.api.Delete) MutationCondition(com.scalar.db.api.MutationCondition) Key(com.scalar.db.io.Key) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteIfExists (com.scalar.db.api.DeleteIfExists)25 Delete (com.scalar.db.api.Delete)22 Test (org.junit.jupiter.api.Test)20 Key (com.scalar.db.io.Key)11 Put (com.scalar.db.api.Put)9 PutIfNotExists (com.scalar.db.api.PutIfNotExists)6 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)5 Test (org.junit.Test)5 MutationCondition (com.scalar.db.api.MutationCondition)4 CosmosException (com.azure.cosmos.CosmosException)3 Result (com.scalar.db.api.Result)3 TextValue (com.scalar.db.io.TextValue)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)3 TransactWriteItemsRequest (software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsRequest)3 ConditionalExpression (com.scalar.db.api.ConditionalExpression)2 DeleteIf (com.scalar.db.api.DeleteIf)2 Scan (com.scalar.db.api.Scan)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)2 TransactionCanceledException (software.amazon.awssdk.services.dynamodb.model.TransactionCanceledException)2