use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteStreamFailure.
@Test
public void testDeleteStreamFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
when(rangeService.deleteStream(deleteReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<DeleteStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<DeleteStreamResponse> streamObserver = new StreamObserver<DeleteStreamResponse>() {
@Override
public void onNext(DeleteStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.deleteStream(DeleteStreamRequest.newBuilder().setColName(nsName).setName(streamName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(deleteResp, resultHolder.get());
verify(rangeService, times(1)).deleteStream(deleteReq);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateNamespaceSuccess.
//
// Test Namespace API
//
@Test
public void testCreateNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).setColProps(namespaceProps).build();
CreateNamespaceRequest createReq = createCreateNamespaceRequest(nsName, namespaceConf);
when(rangeService.createNamespace(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
AtomicReference<CreateNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateNamespaceResponse> streamObserver = new StreamObserver<CreateNamespaceResponse>() {
@Override
public void onNext(CreateNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createNamespace(CreateNamespaceRequest.newBuilder().setName(nsName).setColConf(namespaceConf).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(createResp == resultHolder.get());
verify(rangeService, times(1)).createNamespace(createReq);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestStorageContainerResponseHandler method testInternalError.
@SuppressWarnings("unchecked")
@Test
public void testInternalError() throws Exception {
StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
AtomicReference<StorageContainerResponse> responseHolder = new AtomicReference<>(null);
CountDownLatch latch = new CountDownLatch(1);
doAnswer((Answer<Void>) invocation -> {
StorageContainerResponse resp = invocation.getArgument(0);
responseHolder.set(resp);
latch.countDown();
return null;
}).when(observer).onNext(any(StorageContainerResponse.class));
StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
StorageException exception = new StorageException("test-exception");
handler.accept(null, exception);
verify(observer, times(1)).onNext(any());
verify(observer, times(1)).onCompleted();
verify(observer, times(0)).onError(any());
latch.await();
assertNotNull(responseHolder.get());
assertEquals(StatusCode.INTERNAL_SERVER_ERROR, responseHolder.get().getCode());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project spring_boot by hryou0922.
the class RouteGuideClientTest method recordRoute.
/**
* Example for testing async client-streaming.
*/
@Test
public void recordRoute() throws Exception {
client.setRandom(noRandomness);
Point point1 = Point.newBuilder().setLatitude(1).setLongitude(1).build();
Point point2 = Point.newBuilder().setLatitude(2).setLongitude(2).build();
Point point3 = Point.newBuilder().setLatitude(3).setLongitude(3).build();
Feature requestFeature1 = Feature.newBuilder().setLocation(point1).build();
Feature requestFeature2 = Feature.newBuilder().setLocation(point2).build();
Feature requestFeature3 = Feature.newBuilder().setLocation(point3).build();
final List<Feature> features = Arrays.asList(requestFeature1, requestFeature2, requestFeature3);
final List<Point> pointsDelivered = new ArrayList<Point>();
final RouteSummary fakeResponse = RouteSummary.newBuilder().setPointCount(7).setFeatureCount(8).setDistance(9).setElapsedTime(10).build();
// implement the fake service
RouteGuideImplBase recordRouteImpl = new RouteGuideImplBase() {
@Override
public StreamObserver<Point> recordRoute(final StreamObserver<RouteSummary> responseObserver) {
StreamObserver<Point> requestObserver = new StreamObserver<Point>() {
@Override
public void onNext(Point value) {
pointsDelivered.add(value);
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
responseObserver.onNext(fakeResponse);
responseObserver.onCompleted();
}
};
return requestObserver;
}
};
serviceRegistry.addService(recordRouteImpl);
// send requestFeature1, requestFeature2, requestFeature3, and then requestFeature1 again
client.recordRoute(features, 4);
assertEquals(Arrays.asList(requestFeature1.getLocation(), requestFeature2.getLocation(), requestFeature3.getLocation(), requestFeature1.getLocation()), pointsDelivered);
verify(testHelper).onMessage(fakeResponse);
verify(testHelper, never()).onRpcError(any(Throwable.class));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project spring_boot by hryou0922.
the class RouteGuideClientTest method listFeatures.
/**
* Example for testing blocking server-streaming.
*/
@Test
public void listFeatures() {
final Feature responseFeature1 = Feature.newBuilder().setName("feature 1").build();
final Feature responseFeature2 = Feature.newBuilder().setName("feature 2").build();
final AtomicReference<Rectangle> rectangleDelivered = new AtomicReference<Rectangle>();
// implement the fake service
RouteGuideImplBase listFeaturesImpl = new RouteGuideImplBase() {
@Override
public void listFeatures(Rectangle rectangle, StreamObserver<Feature> responseObserver) {
rectangleDelivered.set(rectangle);
// send two response messages
responseObserver.onNext(responseFeature1);
responseObserver.onNext(responseFeature2);
// complete the response
responseObserver.onCompleted();
}
};
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());
verify(testHelper).onMessage(responseFeature1);
verify(testHelper).onMessage(responseFeature2);
verify(testHelper, never()).onRpcError(any(Throwable.class));
}
Aggregations