コード例 #1
0
  /** This tests a simple GET request with a key as the value. */
  @Test
  public void shouldDecodeRequestWithSimpleValue() {
    ByteBuf incoming = Unpooled.buffer();
    incoming.writeBytes(GET_REQUEST);
    channel.writeInbound(incoming);

    BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();

    assertThat(request, notNullValue());
    assertThat(request.getHeader(), notNullValue());
    assertThat(request.getKey(), notNullValue());
    assertThat(request.getExtras(), nullValue());

    BinaryMemcacheRequestHeader header = request.getHeader();
    assertThat(header.getKeyLength(), is((short) 3));
    assertThat(header.getExtrasLength(), is((byte) 0));
    assertThat(header.getTotalBodyLength(), is(3));

    request.release();
    assertThat(channel.readInbound(), instanceOf(LastMemcacheContent.class));
  }
コード例 #2
0
  /** This test makes sure that large content is emitted in chunks. */
  @Test
  public void shouldDecodeRequestWithChunkedContent() {
    int smallBatchSize = 2;
    channel = new EmbeddedChannel(new BinaryMemcacheRequestDecoder(smallBatchSize));

    ByteBuf incoming = Unpooled.buffer();
    incoming.writeBytes(SET_REQUEST_WITH_CONTENT);
    channel.writeInbound(incoming);

    BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();

    assertThat(request, notNullValue());
    assertThat(request.getHeader(), notNullValue());
    assertThat(request.getKey(), notNullValue());
    assertThat(request.getExtras(), nullValue());

    BinaryMemcacheRequestHeader header = request.getHeader();
    assertThat(header.getKeyLength(), is((short) 3));
    assertThat(header.getExtrasLength(), is((byte) 0));
    assertThat(header.getTotalBodyLength(), is(11));

    request.release();

    int expectedContentChunks = 4;
    for (int i = 1; i <= expectedContentChunks; i++) {
      MemcacheContent content = (MemcacheContent) channel.readInbound();
      if (i < expectedContentChunks) {
        assertThat(content, instanceOf(MemcacheContent.class));
      } else {
        assertThat(content, instanceOf(LastMemcacheContent.class));
      }
      assertThat(content.content().readableBytes(), is(2));
      content.release();
    }
    assertThat(channel.readInbound(), nullValue());
  }