@Test public void write() { 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(); CronetWritableBufferAllocator allocator = new CronetWritableBufferAllocator(); String[] requests = new String[5]; WritableBuffer[] buffers = new WritableBuffer[5]; for (int i = 0; i < 5; ++i) { requests[i] = new String("request" + String.valueOf(i)); buffers[i] = allocator.allocate(requests[i].length()); buffers[i].write(requests[i].getBytes(Charset.forName("UTF-8")), 0, requests[i].length()); clientStream.abstractClientStreamSink().writeFrame(buffers[i], false, i == 2 || i == 4, 1); } verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class)); callback.onStreamReady(cronetStream); verify(cronetStream, times(5)).write(isA(ByteBuffer.class), eq(false)); ByteBuffer fakeBuffer = ByteBuffer.allocateDirect(8); fakeBuffer.position(8); verify(cronetStream, times(2)).flush(); callback.onWriteCompleted(cronetStream, null, fakeBuffer, false); callback.onWriteCompleted(cronetStream, null, fakeBuffer, false); callback.onWriteCompleted(cronetStream, null, fakeBuffer, false); callback.onWriteCompleted(cronetStream, null, fakeBuffer, false); callback.onWriteCompleted(cronetStream, null, fakeBuffer, false); verify(cronetStream, times(5)).write(isA(ByteBuffer.class), eq(false)); clientStream.abstractClientStreamSink().writeFrame(null, true, true, 1); verify(cronetStream, times(1)).write(isA(ByteBuffer.class), eq(true)); verify(cronetStream, times(3)).flush(); }
@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();  }