use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project bookkeeper by apache.
the class TestGrpcTableService method testRangeActiveRangesException.
@Test
public void testRangeActiveRangesException() throws Exception {
RangeStore rangeService = mock(RangeStore.class);
GrpcTableService grpcService = new GrpcTableService(rangeService);
StorageContainerRequest request = StorageContainerRequest.newBuilder().setKvRangeReq(RangeRequest.newBuilder().setKey(TEST_KEY).setHeader(ROUTING_HEADER)).build();
when(rangeService.range(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
grpcService.range(request, responseObserver);
responseObserver.verifyException(Status.NOT_FOUND);
verify(rangeService, times(1)).range(request);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project bookkeeper by apache.
the class TestGrpcTableService method testPutException.
@Test
public void testPutException() throws Exception {
RangeStore rangeService = mock(RangeStore.class);
GrpcTableService grpcService = new GrpcTableService(rangeService);
StorageContainerRequest request = StorageContainerRequest.newBuilder().setKvPutReq(PutRequest.newBuilder().setKey(TEST_KEY).setValue(TEST_VAL).setHeader(ROUTING_HEADER)).build();
when(rangeService.put(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
grpcService.put(request, responseObserver);
responseObserver.verifyException(Status.NOT_FOUND);
verify(rangeService, times(1)).put(request);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project bookkeeper by apache.
the class TestStorageContainerResponseHandler method testStatusRuntimeException.
@SuppressWarnings("unchecked")
@Test
public void testStatusRuntimeException() {
StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
StatusRuntimeException exception = new StatusRuntimeException(Status.NOT_FOUND);
handler.accept(null, exception);
verify(observer, times(0)).onNext(any());
verify(observer, times(0)).onCompleted();
verify(observer, times(1)).onError(exception);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project spring_boot by hryou0922.
the class RouteGuideClientTest method listFeatures_error.
/**
* Example for testing blocking server-streaming.
*/
@Test
public void listFeatures_error() {
final Feature responseFeature1 = Feature.newBuilder().setName("feature 1").build();
final AtomicReference<Rectangle> rectangleDelivered = new AtomicReference<Rectangle>();
final StatusRuntimeException fakeError = new StatusRuntimeException(Status.INVALID_ARGUMENT);
// implement the fake service
RouteGuideImplBase listFeaturesImpl = new RouteGuideImplBase() {
@Override
public void listFeatures(Rectangle rectangle, StreamObserver<Feature> responseObserver) {
rectangleDelivered.set(rectangle);
// send one response message
responseObserver.onNext(responseFeature1);
// let the rpc fail
responseObserver.onError(fakeError);
}
};
serviceRegistry.addService(listFeaturesImpl);
client.listFeatures(1, 2, 3, 4);
assertEquals(Rectangle.newBuilder().setLo(Point.newBuilder().setLatitude(1).setLongitude(2).build()).setHi(Point.newBuilder().setLatitude(3).setLongitude(4).build()).build(), rectangleDelivered.get());
ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(testHelper).onMessage(responseFeature1);
verify(testHelper).onRpcError(errorCaptor.capture());
assertEquals(fakeError.getStatus(), Status.fromThrowable(errorCaptor.getValue()));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project spring_boot by hryou0922.
the class RouteGuideClientTest method getFeature_error.
/**
* Example for testing blocking unary call.
*/
@Test
public void getFeature_error() {
Point requestPoint = Point.newBuilder().setLatitude(-1).setLongitude(-1).build();
final AtomicReference<Point> pointDelivered = new AtomicReference<Point>();
final StatusRuntimeException fakeError = new StatusRuntimeException(Status.DATA_LOSS);
// implement the fake service
RouteGuideImplBase getFeatureImpl = new RouteGuideImplBase() {
@Override
public void getFeature(Point point, StreamObserver<Feature> responseObserver) {
pointDelivered.set(point);
responseObserver.onError(fakeError);
}
};
serviceRegistry.addService(getFeatureImpl);
client.getFeature(-1, -1);
assertEquals(requestPoint, pointDelivered.get());
ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(testHelper).onRpcError(errorCaptor.capture());
assertEquals(fakeError.getStatus(), Status.fromThrowable(errorCaptor.getValue()));
}
Aggregations