@Test public void unaryFutureCallSuccess() throws Exception { final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<ClientCall.Listener<String>>(); final AtomicReference<Integer> message = new AtomicReference<Integer>(); final AtomicReference<Boolean> halfClosed = new AtomicReference<Boolean>(); NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() { @Override public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) { listener.set(responseListener); } @Override public void sendMessage(Integer msg) { message.set(msg); } @Override public void halfClose() { halfClosed.set(true); } }; Integer req = 2; ListenableFuture<String> future = ClientCalls.futureUnaryCall(call, req); assertEquals(req, message.get()); assertTrue(halfClosed.get()); listener.get().onMessage("bar"); listener.get().onClose(Status.OK, new Metadata()); assertEquals("bar", future.get()); }
public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall( ClientCall<ReqT, RespT> call, ReqT req) { GrpcFuture<RespT> responseFuture = new GrpcFuture<RespT>(call); asyncUnaryRequestCall(call, req, new UnaryStreamToFuture<RespT>(responseFuture), false); return responseFuture; }
ClientCalls { public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall( ClientCall<ReqT, RespT> call, ReqT req) { GrpcFuture<RespT> responseFuture = new GrpcFuture<RespT>(call); asyncUnaryRequestCall(call, req, new UnaryStreamToFuture<RespT>(responseFuture), false); return responseFuture; } }
ClientCalls { public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall( ClientCall<ReqT, RespT> call, ReqT req) { GrpcFuture<RespT> responseFuture = new GrpcFuture<RespT>(call); asyncUnaryRequestCall(call, req, new UnaryStreamToFuture<RespT>(responseFuture), false); return responseFuture; } private  ClientCalls(); }
ClientCalls { public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall( ClientCall<ReqT, RespT> call, ReqT req) { GrpcFuture<RespT> responseFuture = new GrpcFuture<RespT>(call); asyncUnaryRequestCall(call, req, new UnaryStreamToFuture<RespT>(responseFuture), false); return responseFuture; } 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> ListenableFuture<RespT> futureUnaryCall( ClientCall<ReqT, RespT> call, ReqT req) { GrpcFuture<RespT> responseFuture = new GrpcFuture<RespT>(call); asyncUnaryRequestCall(call, req, new UnaryStreamToFuture<RespT>(responseFuture), false); return responseFuture; } 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);  }