use of com.scalar.db.rpc.GetResponse in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method get_GateKeeperReturnsFalse_ShouldThrowUnavailableError.
@Test
public void get_GateKeeperReturnsFalse_ShouldThrowUnavailableError() {
// Arrange
GetRequest request = GetRequest.newBuilder().build();
@SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
when(gateKeeper.letIn()).thenReturn(false);
// Act
storageService.get(request, responseObserver);
// Assert
verify(responseObserver).onError(exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Code.UNAVAILABLE);
}
use of com.scalar.db.rpc.GetResponse in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method get_IsCalledWithProperArguments_StorageShouldBeCalledProperly.
@Test
public void get_IsCalledWithProperArguments_StorageShouldBeCalledProperly() throws ExecutionException {
// Arrange
GetRequest request = GetRequest.newBuilder().build();
@SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
// Act
storageService.get(request, responseObserver);
// Assert
verify(storage).get(any());
verify(responseObserver).onNext(any());
verify(responseObserver).onCompleted();
}
use of com.scalar.db.rpc.GetResponse in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method get_StorageThrowsExecutionException_ShouldThrowInternalError.
@Test
public void get_StorageThrowsExecutionException_ShouldThrowInternalError() throws ExecutionException {
// Arrange
GetRequest request = GetRequest.newBuilder().build();
@SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
when(storage.get(any())).thenThrow(ExecutionException.class);
// Act
storageService.get(request, responseObserver);
// Assert
verify(responseObserver).onError(exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INTERNAL);
}
use of com.scalar.db.rpc.GetResponse in project scalardb by scalar-labs.
the class DistributedStorageServiceTest method get_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError.
@Test
public void get_StorageThrowsIllegalArgumentException_ShouldThrowInvalidArgumentError() throws ExecutionException {
// Arrange
GetRequest request = GetRequest.newBuilder().build();
@SuppressWarnings("unchecked") StreamObserver<GetResponse> responseObserver = mock(StreamObserver.class);
when(storage.get(any())).thenThrow(IllegalArgumentException.class);
// Act
storageService.get(request, responseObserver);
// Assert
verify(responseObserver).onError(exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue().getStatus().getCode()).isEqualTo(Status.Code.INVALID_ARGUMENT);
}
use of com.scalar.db.rpc.GetResponse in project scalardb by scalar-labs.
the class DistributedStorageService method get.
@Override
public void get(GetRequest request, StreamObserver<GetResponse> responseObserver) {
execute(() -> {
TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getGet().getNamespace(), request.getGet().getTable());
if (metadata == null) {
throw new IllegalArgumentException("the specified table is not found");
}
Get get = ProtoUtils.toGet(request.getGet(), metadata);
Optional<Result> result = storage.get(get);
GetResponse.Builder builder = GetResponse.newBuilder();
result.ifPresent(r -> builder.setResult(ProtoUtils.toResult(r)));
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}, responseObserver, "get");
}
Aggregations