/** * Send requests and iterate over server responses. * * <p>This returns a live stream that must either be fully consumed or cancelled. Example usage: * * <pre>{@code * BidiStream<String, String> stream = bidiStreamingCallable.call() * for (String s : stream) { * if ("needle".equals(s)) { * // Cancelling the stream will cause `hasNext()` to return false on the next iteration, * // naturally breaking the loop. * stream.cancel(); * } * stream.send(s); * } * }</pre> */ public BidiStream<RequestT, ResponseT> call() { return call((ApiCallContext) null); }
/** * Send requests and iterate over server responses. * * <p>This returns a live stream that must either be fully consumed or cancelled. Example usage: * * <pre>{@code * BidiStream<String, String> stream = bidiStreamingCallable.call() * for (String s : stream) { * if ("needle".equals(s)) { * // Cancelling the stream will cause `hasNext()` to return false on the next iteration, * // naturally breaking the loop. * stream.cancel(); * } * stream.send(s); * } * }</pre> */ public BidiStream<RequestT, ResponseT> call() { return call((ApiCallContext) null); }
call(bidiObserver, null);
call(bidiObserver, null);
@Test public void bidiStreaming_BidiStreamObserver() throws InterruptedException { BidiStreamingStashCallable<Integer, Integer> callIntList = new BidiStreamingStashCallable<>(Arrays.asList(0, 1, 2)); BidiStreamingCallable<Integer, Integer> callable = FakeCallableFactory.createBidiStreamingCallable( callIntList, StreamingCallSettings.<Integer, Integer>newBuilder().build(), clientContext); AccumulatingBidiObserver observer = new AccumulatingBidiObserver(Arrays.asList(3, 4, 5)); callable.call(observer); assertThat(observer.getResponses()).containsExactly(0, 1, 2).inOrder(); assertThat(callIntList.getActualRequests()).containsExactly(3, 4, 5).inOrder(); }