use of com.scalar.db.rpc.MutateRequest in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method mutate_GateKeeperReturnsFalse_ShouldThrowUnavailableError.
@Test
public void mutate_GateKeeperReturnsFalse_ShouldThrowUnavailableError() {
// Arrange
Key partitionKey = new Key("col1", 1);
MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
@SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
when(gateKeeper.letIn()).thenReturn(false);
// Act
storageService.mutate(request, responseObserver);
// Assert
verify(responseObserver).onError(exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Code.UNAVAILABLE);
}
use of com.scalar.db.rpc.MutateRequest in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method mutate_IsCalledWithMultiplePuts_StorageShouldBeCalledProperly.
@Test
public void mutate_IsCalledWithMultiplePuts_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 Put(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.rpc.MutateRequest in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method mutate_StorageThrowsNoMutationException_ShouldThrowFailedPreconditionError.
@Test
public void mutate_StorageThrowsNoMutationException_ShouldThrowFailedPreconditionError() throws ExecutionException {
// Arrange
Key partitionKey = new Key("col1", 1);
MutateRequest request = MutateRequest.newBuilder().addMutation(ProtoUtils.toMutation(new Put(partitionKey))).build();
@SuppressWarnings("unchecked") StreamObserver<Empty> responseObserver = mock(StreamObserver.class);
doThrow(NoMutationException.class).when(storage).mutate(anyList());
// Act
storageService.mutate(request, responseObserver);
// Assert
verify(responseObserver).onError(exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Code.FAILED_PRECONDITION);
}
use of com.scalar.db.rpc.MutateRequest in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method mutate_IsCalledWithMultipleDeletes_StorageShouldBeCalledProperly.
@Test
public void mutate_IsCalledWithMultipleDeletes_StorageShouldBeCalledProperly() throws ExecutionException {
// Arrange
Key partitionKey = new Key("col1", 1);
MutateRequest request = MutateRequest.newBuilder().addAllMutation(Arrays.asList(ProtoUtils.toMutation(new Delete(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();
}