Exemplo n.º 1
0
  @Test
  public void setStream_flush() {
    stream.start(listener);
    stream.flush();
    stream.setStream(realStream);

    verify(realStream).flush();
  }
Exemplo n.º 2
0
  @Test
  public void setStream_halfClose() {
    stream.start(listener);
    stream.halfClose();
    stream.setStream(realStream);

    verify(realStream).halfClose();
  }
Exemplo n.º 3
0
  @Test
  public void setStream_flowControl() {
    stream.start(listener);
    stream.request(1);
    stream.request(2);

    stream.setStream(realStream);

    verify(realStream).request(3);
  }
Exemplo n.º 4
0
  @Test
  public void setStream_cantCreateTwice() {
    stream.start(listener);
    // The first call will be a success
    stream.setStream(realStream);

    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Stream already created");

    stream.setStream(realStream);
  }
Exemplo n.º 5
0
  @Test
  public void setStream_sendsAllMessages() {
    stream.start(listener);
    stream.setCompressor(Codec.Identity.NONE);
    stream.setDecompressor(Codec.Identity.NONE);

    stream.setMessageCompression(true);
    InputStream message = new ByteArrayInputStream(new byte[] {'a'});
    stream.writeMessage(message);
    stream.setMessageCompression(false);
    stream.writeMessage(message);

    stream.setStream(realStream);

    verify(realStream).setCompressor(Codec.Identity.NONE);
    verify(realStream).setDecompressor(Codec.Identity.NONE);

    // Verify that the order was correct, even though they should be interleaved with the
    // writeMessage calls
    verify(realStream).setMessageCompression(true);
    verify(realStream, times(2)).setMessageCompression(false);

    verify(realStream, times(2)).writeMessage(message);
    verify(realStream).start(listener);
  }
Exemplo n.º 6
0
 @Test
 public void streamCancelled() {
   stream.start(listener);
   stream.cancel(Status.CANCELLED);
   verify(listener).closed(eq(Status.CANCELLED), isA(Metadata.class));
 }