Search in sources :

Example 21 with Delete

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

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method prepareDelete.

static Delete prepareDelete(int id, int type, String table) {
    Key partitionKey = new Key(ACCOUNT_ID, id);
    Key clusteringKey = new Key(ACCOUNT_TYPE, type);
    return new Delete(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key)

Example 22 with Delete

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

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.

@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws TransactionException {
    // Arrange
    populateRecords(TABLE_1);
    Get get = prepareGet(0, 0, TABLE_1);
    Delete delete = prepareDelete(0, 0, TABLE_1);
    GrpcTransaction transaction = manager.start();
    // Act
    Optional<Result> result = transaction.get(get);
    transaction.delete(delete);
    transaction.commit();
    // Assert
    assertThat(result.isPresent()).isTrue();
    GrpcTransaction another = manager.start();
    assertThat(another.get(get).isPresent()).isFalse();
    another.commit();
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 23 with Delete

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

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method prepareDeletes.

private GrpcTransaction prepareDeletes(int one, String table, int another, String anotherTable) throws TransactionException {
    boolean differentTables = !table.equals(anotherTable);
    GrpcTransaction transaction = manager.start();
    List<Get> gets = prepareGets(table);
    List<Get> anotherGets = differentTables ? prepareGets(anotherTable) : gets;
    transaction.get(gets.get(one));
    transaction.get(anotherGets.get(another));
    List<Delete> deletes = prepareDeletes(table);
    List<Delete> anotherDeletes = differentTables ? prepareDeletes(anotherTable) : deletes;
    transaction.delete(deletes.get(one));
    transaction.delete(anotherDeletes.get(another));
    return transaction;
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction)

Example 24 with Delete

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

the class DistributedStorageServiceTest method mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithSingleDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Delete(partitionKey))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Delete(com.scalar.db.api.Delete) Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 25 with Delete

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

the class DistributedStorageServiceTest method mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly.

@Test
public void mutate_IsCalledWithMixedPutAndDelete_StorageShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    MutateRequest request = MutateRequest.newBuilder().addAllMutation(Arrays.asList(ProtoUtils.toMutation(new Put(partitionKey)), ProtoUtils.toMutation(new Delete(partitionKey)))).build();
    @SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
    // Act
    storageService.mutate(request, responseObserver);
    // Assert
    verify(storage).mutate(anyList());
    verify(responseObserver).onNext(any());
    verify(responseObserver).onCompleted();
}
Also used : Delete(com.scalar.db.api.Delete) Empty(com.google.protobuf.Empty) MutateRequest(com.scalar.db.rpc.MutateRequest) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.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