@Test public void inprocessTransportOutboundFlowControl() throws Exception { final Semaphore semaphore = new Semaphore(0); final List<Object> receivedMessages = new ArrayList<>(6); final SettableFuture<ServerCallStreamObserver<Integer>> observerFuture = SettableFuture.create(); ServerServiceDefinition service = ServerServiceDefinition.builder( new ServiceDescriptor("some", STREAMING_METHOD)) .addMethod(STREAMING_METHOD, ServerCalls.asyncBidiStreamingCall( new ServerCalls.BidiStreamingMethod<Integer, Integer>() { @Override public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) { final ServerCallStreamObserver<Integer> serverCallObserver = (ServerCallStreamObserver<Integer>) responseObserver; serverCallObserver.disableAutoInboundFlowControl(); observerFuture.set(serverCallObserver); return new StreamObserver<Integer>() { @Override public void onNext(Integer value) { receivedMessages.add(value); } @Override public void onError(Throwable t) { receivedMessages.add(t); } @Override public void onCompleted() { serverCallObserver.onCompleted(); } }; } })) .build(); long tag = System.nanoTime(); server = InProcessServerBuilder.forName("go-with-the-flow" + tag).directExecutor() .addService(service).build().start(); channel = InProcessChannelBuilder.forName("go-with-the-flow" + tag).directExecutor().build(); final ClientCall<Integer, Integer> clientCall = channel.newCall(STREAMING_METHOD, CallOptions.DEFAULT); final SettableFuture<Void> future = SettableFuture.create(); ClientResponseObserver<Integer, Integer> responseObserver = new ClientResponseObserver<Integer, Integer>() { @Override public void beforeStart(final ClientCallStreamObserver<Integer> requestStream) { requestStream.setOnReadyHandler(new Runnable() { int iteration; @Override public void run() { while (requestStream.isReady()) { requestStream.onNext(iteration); } iteration++; if (iteration == 3) { requestStream.onCompleted(); } semaphore.release(); } }); } @Override public void onNext(Integer value) { } @Override public void onError(Throwable t) { future.setException(t); } @Override public void onCompleted() { future.set(null); } }; ClientCalls.asyncBidiStreamingCall(clientCall, responseObserver); ServerCallStreamObserver<Integer> serverCallObserver = observerFuture.get(5, TimeUnit.SECONDS); serverCallObserver.request(1); assertTrue(semaphore.tryAcquire(5, TimeUnit.SECONDS)); serverCallObserver.request(2); assertTrue(semaphore.tryAcquire(5, TimeUnit.SECONDS)); serverCallObserver.request(3); future.get(5, TimeUnit.SECONDS); assertEquals(Arrays.asList(0, 1, 1, 2, 2, 2), receivedMessages); }
public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall( ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) { return asyncStreamingRequestCall(call, responseObserver, true); }
ClientCalls { public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall( ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) { return asyncStreamingRequestCall(call, responseObserver, true); } }
ClientCalls { public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall( ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) { return asyncStreamingRequestCall(call, responseObserver, true); } private  ClientCalls(); }
ClientCalls { public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall( ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) { return asyncStreamingRequestCall(call, responseObserver, true); } private  ClientCalls(); static void asyncUnaryCall(
      ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver); static void asyncServerStreamingCall(
      ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver); static StreamObserver<ReqT> asyncClientStreamingCall(
      ClientCall<ReqT, RespT> call,
      StreamObserver<RespT> responseObserver); static StreamObserver<ReqT> asyncBidiStreamingCall(
      ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver); static RespT blockingUnaryCall(ClientCall<ReqT, RespT> call, ReqT req); static RespT blockingUnaryCall(
      Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req); static Iterator<RespT> blockingServerStreamingCall(
      ClientCall<ReqT, RespT> call, ReqT req); static Iterator<RespT> blockingServerStreamingCall(
      Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req); static ListenableFuture<RespT> futureUnaryCall(
      ClientCall<ReqT, RespT> call, ReqT req); static Object getArgumentFromRequest(Object request); }
ClientCalls { public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall( ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) { return asyncStreamingRequestCall(call, responseObserver, true); } private  ClientCalls(); static void asyncUnaryCall(
      ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver); static void asyncServerStreamingCall(
      ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver); static StreamObserver<ReqT> asyncClientStreamingCall(
      ClientCall<ReqT, RespT> call,
      StreamObserver<RespT> responseObserver); static StreamObserver<ReqT> asyncBidiStreamingCall(
      ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver); static RespT blockingUnaryCall(ClientCall<ReqT, RespT> call, ReqT req); static RespT blockingUnaryCall(
      Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req); static Iterator<RespT> blockingServerStreamingCall(
      ClientCall<ReqT, RespT> call, ReqT req); static Iterator<RespT> blockingServerStreamingCall(
      Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req); static ListenableFuture<RespT> futureUnaryCall(
      ClientCall<ReqT, RespT> call, ReqT req); static Object getArgumentFromRequest(Object request);  }