Fix buffer leaks in BinaryMemcacheEncoderTest
This commit is contained in:
parent
a8bc720977
commit
acf7dbf811
@ -22,6 +22,7 @@ import io.netty.handler.codec.EncoderException;
|
||||
import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
|
||||
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -43,6 +44,11 @@ public class BinaryMemcacheEncoderTest {
|
||||
channel = new EmbeddedChannel(new BinaryMemcacheRequestEncoder());
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
channel.finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeDefaultHeader() {
|
||||
BinaryMemcacheRequestHeader header = new DefaultBinaryMemcacheRequestHeader();
|
||||
@ -55,6 +61,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
||||
assertThat(written.readByte(), is((byte) 0x80));
|
||||
assertThat(written.readByte(), is((byte) 0x00));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,6 +78,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
||||
assertThat(written.readByte(), is((byte) 0xAA));
|
||||
assertThat(written.readByte(), is(BinaryMemcacheOpcodes.GET));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,6 +97,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
|
||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,6 +115,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
|
||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo(key));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -132,22 +142,23 @@ public class BinaryMemcacheEncoderTest {
|
||||
written = (ByteBuf) channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(content1.content().readableBytes()));
|
||||
assertThat(
|
||||
written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is("Netty")
|
||||
written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is("Netty")
|
||||
);
|
||||
written.release();
|
||||
|
||||
written = (ByteBuf) channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(content2.content().readableBytes()));
|
||||
assertThat(
|
||||
written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is(" Rocks!")
|
||||
written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is(" Rocks!")
|
||||
);
|
||||
written.release();
|
||||
}
|
||||
|
||||
@Test(expected = EncoderException.class)
|
||||
public void shouldFailWithoutLastContent() {
|
||||
channel.writeOutbound(new DefaultMemcacheContent(Unpooled.EMPTY_BUFFER));
|
||||
channel.writeOutbound(
|
||||
new DefaultBinaryMemcacheRequest(new DefaultBinaryMemcacheRequestHeader()));
|
||||
channel.writeOutbound(new DefaultBinaryMemcacheRequest(new DefaultBinaryMemcacheRequestHeader()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user