@Test public void shouldHandleClientCallForStreamReturningCompletionStage() throws Exception { ClientStreamingMethodHandlerSupplier supplier = new ClientStreamingMethodHandlerSupplier(); AnnotatedMethod method = getMethod("streamCompletionStage", Stream.class); Service service = mock(Service.class); MethodHandler<Long, String> handler = supplier.get("foo", method, () -> service); assertThat(handler, is(notNullValue())); Stream<String> stream = Stream.of("A", "B", "C"); StreamObserver<String> response = mock(StreamObserver.class); MethodHandler.ClientStreaming client = mock(MethodHandler.ClientStreaming.class); when(client.clientStreaming(anyString(), any(StreamObserver.class))).thenReturn(response); Object result = handler.clientStreaming(new Object[]{stream}, client); assertThat(result, is(instanceOf(CompletionStage.class))); ArgumentCaptor<StreamObserver> captor = ArgumentCaptor.forClass(StreamObserver.class); verify(client).clientStreaming(eq("foo"), captor.capture()); StreamObserver observer = captor.getValue(); observer.onNext("bar"); observer.onCompleted(); CompletionStage<Object> stage = (CompletionStage<Object>) result; CompletableFuture<Object> future = stage.toCompletableFuture(); assertThat(future.isDone(), is(true)); assertThat(future.get(), is("bar")); }
@Override @SuppressWarnings("unchecked") public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a client streaming method: " + method); } CallType type = determineCallType(method); MethodHandler handler; switch (type) { case clientStreaming: handler = new ClientStreaming<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case clientStreamingIterable: handler = new ClientStreamingIterable(methodName, method, instance); break; case clientStreamingStream: handler = new ClientStreamingStream(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported client streaming method signature: " + method); } return handler; }
ClientStreamingMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override @SuppressWarnings("unchecked") public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a client streaming method: " + method); } CallType type = determineCallType(method); MethodHandler handler; switch (type) { case clientStreaming: handler = new ClientStreaming<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case clientStreamingIterable: handler = new ClientStreamingIterable(methodName, method, instance); break; case clientStreamingStream: handler = new ClientStreamingStream(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported client streaming method signature: " + method); } return handler; } }
ClientStreamingMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override @SuppressWarnings("unchecked") public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a client streaming method: " + method); } CallType type = determineCallType(method); MethodHandler handler; switch (type) { case clientStreaming: handler = new ClientStreaming<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case clientStreamingIterable: handler = new ClientStreamingIterable(methodName, method, instance); break; case clientStreamingStream: handler = new ClientStreamingStream(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported client streaming method signature: " + method); } return handler; } ClientStreamingMethodHandlerSupplier(); }
ClientStreamingMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override @SuppressWarnings("unchecked") public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a client streaming method: " + method); } CallType type = determineCallType(method); MethodHandler handler; switch (type) { case clientStreaming: handler = new ClientStreaming<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case clientStreamingIterable: handler = new ClientStreamingIterable(methodName, method, instance); break; case clientStreamingStream: handler = new ClientStreamingStream(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported client streaming method signature: " + method); } return handler; } ClientStreamingMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override @SuppressWarnings("unchecked") MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance); }
ClientStreamingMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override @SuppressWarnings("unchecked") public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a client streaming method: " + method); } CallType type = determineCallType(method); MethodHandler handler; switch (type) { case clientStreaming: handler = new ClientStreaming<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case clientStreamingIterable: handler = new ClientStreamingIterable(methodName, method, instance); break; case clientStreamingStream: handler = new ClientStreamingStream(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported client streaming method signature: " + method); } return handler; } ClientStreamingMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override @SuppressWarnings("unchecked") MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance);  }