@Test public void routeChat_echoResponse() throws Exception { final List<RouteNote> notesDelivered = new ArrayList<>(); RouteGuideImplBase routeChatImpl = new RouteGuideImplBase() { @Override public StreamObserver<RouteNote> routeChat( final StreamObserver<RouteNote> responseObserver) { StreamObserver<RouteNote> requestObserver = new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote value) { notesDelivered.add(value); responseObserver.onNext(value); } @Override public void onError(Throwable t) { responseObserver.onError(t); } @Override public void onCompleted() { responseObserver.onCompleted(); } }; return requestObserver; } }; serviceRegistry.addService(routeChatImpl); client.routeChat().await(1, TimeUnit.SECONDS); String[] messages = {"First message", "Second message", "Third message", "Fourth message"}; for (int i = 0; i < 4; i++) { verify(testHelper).onMessage(notesDelivered.get(i)); assertEquals(messages[i], notesDelivered.get(i).getMessage()); } verify(testHelper, never()).onRpcError(any(Throwable.class)); }
public CountDownLatch routeChat() { info("*** RouteChat"); final CountDownLatch finishLatch = new CountDownLatch(1); StreamObserver<RouteNote> requestObserver = asyncStub.routeChat(new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote note) { info("Got message \"{0}\" at {1}, {2}", note.getMessage(), note.getLocation() .getLatitude(), note.getLocation().getLongitude()); if (testHelper != null) { testHelper.onMessage(note); } } @Override public void onError(Throwable t) { warning("RouteChat Failed: {0}", Status.fromThrowable(t)); if (testHelper != null) { testHelper.onRpcError(t); } finishLatch.countDown(); } @Override public void onCompleted() { info("Finished RouteChat"); finishLatch.countDown(); } }); try { RouteNote[] requests = {newNote("First message", 0, 0), newNote("Second message", 0, 1), newNote("Third message", 1, 0), newNote("Fourth message", 1, 1)}; for (RouteNote request : requests) { info("Sending message \"{0}\" at {1}, {2}", request.getMessage(), request.getLocation() .getLatitude(), request.getLocation().getLongitude()); requestObserver.onNext(request); } } catch (RuntimeException e) { requestObserver.onError(e); throw e; } requestObserver.onCompleted(); return finishLatch; }
RouteGuideClient { public CountDownLatch routeChat() { info("*** RouteChat"); final CountDownLatch finishLatch = new CountDownLatch(1); StreamObserver<RouteNote> requestObserver = asyncStub.routeChat(new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote note) { info("Got message \"{0}\" at {1}, {2}", note.getMessage(), note.getLocation() .getLatitude(), note.getLocation().getLongitude()); if (testHelper != null) { testHelper.onMessage(note); } } @Override public void onError(Throwable t) { warning("RouteChat Failed: {0}", Status.fromThrowable(t)); if (testHelper != null) { testHelper.onRpcError(t); } finishLatch.countDown(); } @Override public void onCompleted() { info("Finished RouteChat"); finishLatch.countDown(); } }); try { RouteNote[] requests = {newNote("First message", 0, 0), newNote("Second message", 0, 1), newNote("Third message", 1, 0), newNote("Fourth message", 1, 1)}; for (RouteNote request : requests) { info("Sending message \"{0}\" at {1}, {2}", request.getMessage(), request.getLocation() .getLatitude(), request.getLocation().getLongitude()); requestObserver.onNext(request); } } catch (RuntimeException e) { requestObserver.onError(e); throw e; } requestObserver.onCompleted(); return finishLatch; } }
RouteGuideClient { public CountDownLatch routeChat() { info("*** RouteChat"); final CountDownLatch finishLatch = new CountDownLatch(1); StreamObserver<RouteNote> requestObserver = asyncStub.routeChat(new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote note) { info("Got message \"{0}\" at {1}, {2}", note.getMessage(), note.getLocation() .getLatitude(), note.getLocation().getLongitude()); if (testHelper != null) { testHelper.onMessage(note); } } @Override public void onError(Throwable t) { warning("RouteChat Failed: {0}", Status.fromThrowable(t)); if (testHelper != null) { testHelper.onRpcError(t); } finishLatch.countDown(); } @Override public void onCompleted() { info("Finished RouteChat"); finishLatch.countDown(); } }); try { RouteNote[] requests = {newNote("First message", 0, 0), newNote("Second message", 0, 1), newNote("Third message", 1, 0), newNote("Fourth message", 1, 1)}; for (RouteNote request : requests) { info("Sending message \"{0}\" at {1}, {2}", request.getMessage(), request.getLocation() .getLatitude(), request.getLocation().getLongitude()); requestObserver.onNext(request); } } catch (RuntimeException e) { requestObserver.onError(e); throw e; } requestObserver.onCompleted(); return finishLatch; } RouteGuideClient(String host, int port);  RouteGuideClient(ManagedChannelBuilder<?> channelBuilder); }
RouteGuideClient { public CountDownLatch routeChat() { info("*** RouteChat"); final CountDownLatch finishLatch = new CountDownLatch(1); StreamObserver<RouteNote> requestObserver = asyncStub.routeChat(new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote note) { info("Got message \"{0}\" at {1}, {2}", note.getMessage(), note.getLocation() .getLatitude(), note.getLocation().getLongitude()); if (testHelper != null) { testHelper.onMessage(note); } } @Override public void onError(Throwable t) { warning("RouteChat Failed: {0}", Status.fromThrowable(t)); if (testHelper != null) { testHelper.onRpcError(t); } finishLatch.countDown(); } @Override public void onCompleted() { info("Finished RouteChat"); finishLatch.countDown(); } }); try { RouteNote[] requests = {newNote("First message", 0, 0), newNote("Second message", 0, 1), newNote("Third message", 1, 0), newNote("Fourth message", 1, 1)}; for (RouteNote request : requests) { info("Sending message \"{0}\" at {1}, {2}", request.getMessage(), request.getLocation() .getLatitude(), request.getLocation().getLongitude()); requestObserver.onNext(request); } } catch (RuntimeException e) { requestObserver.onError(e); throw e; } requestObserver.onCompleted(); return finishLatch; } RouteGuideClient(String host, int port);  RouteGuideClient(ManagedChannelBuilder<?> channelBuilder); void shutdown(); void getFeature(int lat, int lon); void listFeatures(int lowLat, int lowLon, int hiLat, int hiLon); void recordRoute(List<Feature> features, int numPoints); CountDownLatch routeChat(); static void main(String[] args); }
RouteGuideClient { public CountDownLatch routeChat() { info("*** RouteChat"); final CountDownLatch finishLatch = new CountDownLatch(1); StreamObserver<RouteNote> requestObserver = asyncStub.routeChat(new StreamObserver<RouteNote>() { @Override public void onNext(RouteNote note) { info("Got message \"{0}\" at {1}, {2}", note.getMessage(), note.getLocation() .getLatitude(), note.getLocation().getLongitude()); if (testHelper != null) { testHelper.onMessage(note); } } @Override public void onError(Throwable t) { warning("RouteChat Failed: {0}", Status.fromThrowable(t)); if (testHelper != null) { testHelper.onRpcError(t); } finishLatch.countDown(); } @Override public void onCompleted() { info("Finished RouteChat"); finishLatch.countDown(); } }); try { RouteNote[] requests = {newNote("First message", 0, 0), newNote("Second message", 0, 1), newNote("Third message", 1, 0), newNote("Fourth message", 1, 1)}; for (RouteNote request : requests) { info("Sending message \"{0}\" at {1}, {2}", request.getMessage(), request.getLocation() .getLatitude(), request.getLocation().getLongitude()); requestObserver.onNext(request); } } catch (RuntimeException e) { requestObserver.onError(e); throw e; } requestObserver.onCompleted(); return finishLatch; } RouteGuideClient(String host, int port);  RouteGuideClient(ManagedChannelBuilder<?> channelBuilder); void shutdown(); void getFeature(int lat, int lon); void listFeatures(int lowLat, int lowLon, int hiLat, int hiLon); void recordRoute(List<Feature> features, int numPoints); CountDownLatch routeChat(); static void main(String[] args);  }