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