@Test public void streamSucceeded() { ArgumentCaptor<BidirectionalStream.Callback> callbackCaptor = ArgumentCaptor.forClass(BidirectionalStream.Callback.class); verify(factory) .newBidirectionalStreamBuilder( isA(String.class), callbackCaptor.capture(), isA(Executor.class)); BidirectionalStream.Callback callback = callbackCaptor.getValue(); callback.onStreamReady(cronetStream); verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class)); CronetWritableBufferAllocator allocator = new CronetWritableBufferAllocator(); String request = new String("request"); WritableBuffer writableBuffer = allocator.allocate(request.length()); writableBuffer.write(request.getBytes(Charset.forName("UTF-8")), 0, request.length()); clientStream.abstractClientStreamSink().writeFrame(writableBuffer, false, true, 1); ArgumentCaptor<ByteBuffer> bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class); verify(cronetStream, times(1)).write(bufferCaptor.capture(), isA(Boolean.class)); ByteBuffer buffer = bufferCaptor.getValue(); buffer.position(request.length()); verify(cronetStream, times(1)).flush(); clientStream.request(2); UrlResponseInfo info = new UrlResponseInfoImpl( new ArrayList<String>(), 200, "", responseHeader("200"), false, "", ""); callback.onResponseHeadersReceived(cronetStream, info); verify(cronetStream, times(1)).read(isA(ByteBuffer.class)); callback.onReadCompleted( cronetStream, info, (ByteBuffer) createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))), false); verify(clientListener, times(1)).messagesAvailable(isA(MessageProducer.class)); verify(cronetStream, times(2)).read(isA(ByteBuffer.class)); callback.onWriteCompleted(cronetStream, null, buffer, false); clientStream.abstractClientStreamSink().writeFrame(null, true, true, 1); verify(cronetStream, times(2)).write(isA(ByteBuffer.class), isA(Boolean.class)); verify(cronetStream, times(2)).flush(); ((CronetClientStream.BidirectionalStreamCallback) callback).processTrailers(trailers(0)); callback.onSucceeded(cronetStream, info); ArgumentCaptor<Metadata> trailerCaptor = ArgumentCaptor.forClass(Metadata.class); ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class); verify(clientListener) .closed(statusCaptor.capture(), isA(RpcProgress.class), trailerCaptor.capture()); Metadata trailers = trailerCaptor.getValue(); Status status = statusCaptor.getValue(); assertEquals( "test-trailer-value", trailers.get(Metadata.Key.of("test-trailer-key", Metadata.ASCII_STRING_MARSHALLER))); assertEquals( "application/grpc", trailers.get(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER))); assertTrue(status.isOk()); }
@Override protected Sink abstractClientStreamSink() { return sink; }
CronetClientStream extends AbstractClientStream { @Override protected Sink abstractClientStreamSink() { return sink; } }
CronetClientStream extends AbstractClientStream { @Override protected Sink abstractClientStreamSink() { return sink; } CronetClientStream(
      final String url,
      @Nullable String userAgent,
      Executor executor,
      final Metadata headers,
      CronetClientTransport transport,
      Runnable startCallback,
      Object lock,
      int maxMessageSize,
      boolean alwaysUsePut,
      MethodDescriptor<?, ?> method,
      StatsTraceContext statsTraceCtx,
      CallOptions callOptions,
      TransportTracer transportTracer); }
CronetClientStream extends AbstractClientStream { @Override protected Sink abstractClientStreamSink() { return sink; } CronetClientStream(
      final String url,
      @Nullable String userAgent,
      Executor executor,
      final Metadata headers,
      CronetClientTransport transport,
      Runnable startCallback,
      Object lock,
      int maxMessageSize,
      boolean alwaysUsePut,
      MethodDescriptor<?, ?> method,
      StatsTraceContext statsTraceCtx,
      CallOptions callOptions,
      TransportTracer transportTracer); @Override void setAuthority(String authority); @Override Attributes getAttributes(); }
CronetClientStream extends AbstractClientStream { @Override protected Sink abstractClientStreamSink() { return sink; } CronetClientStream(
      final String url,
      @Nullable String userAgent,
      Executor executor,
      final Metadata headers,
      CronetClientTransport transport,
      Runnable startCallback,
      Object lock,
      int maxMessageSize,
      boolean alwaysUsePut,
      MethodDescriptor<?, ?> method,
      StatsTraceContext statsTraceCtx,
      CallOptions callOptions,
      TransportTracer transportTracer); @Override void setAuthority(String authority); @Override Attributes getAttributes();  }