Ejemplo n.º 1
0
  @Test
  public void testReplacement() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new BloatedLineDecoder());

    // "AB" should be forwarded to LineDecoder by BloatedLineDecoder.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'A', 'B'}));
    assertNull(ch.readInbound());

    // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'C', '\n'}));
    assertEquals(
        releaseLater(Unpooled.wrappedBuffer(new byte[] {'A', 'B', 'C'})),
        releaseLater(ch.readInbound()));

    ch.finish();
    assertNull(ch.readInbound());
  }
Ejemplo n.º 2
0
  @Test
  public void testSingleDecode() throws Exception {
    LineDecoder decoder = new LineDecoder();
    decoder.setSingleDecode(true);
    EmbeddedChannel ch = new EmbeddedChannel(decoder);

    // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'C', '\n', 'B', '\n'}));
    assertEquals(
        releaseLater(Unpooled.wrappedBuffer(new byte[] {'C'})), releaseLater(ch.readInbound()));
    assertNull("Must be null as it must only decode one frame", ch.readInbound());

    ch.read();
    ch.finish();
    assertEquals(
        releaseLater(Unpooled.wrappedBuffer(new byte[] {'B'})), releaseLater(ch.readInbound()));
    assertNull(ch.readInbound());
  }
Ejemplo n.º 3
0
  @Test
  public void testLineProtocol() {
    EmbeddedChannel ch = new EmbeddedChannel(new LineDecoder());

    // Ordinary input
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'A'}));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'B'}));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'C'}));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'\n'}));
    assertEquals(Unpooled.wrappedBuffer(new byte[] {'A', 'B', 'C'}), ch.readInbound());

    // Truncated input
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] {'A'}));
    assertNull(ch.readInbound());

    ch.finish();
    assertNull(ch.readInbound());
  }