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);
}
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();
}
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;
}
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();
}
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();
}
Aggregations