Free up all buffers after the tests
This commit is contained in:
parent
cbf269e9b9
commit
5447fe1e59
@ -15,15 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.compression;
|
package io.netty.handler.codec.compression;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
|
||||||
import io.netty.util.CharsetUtil;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class JZlibTest extends ZlibTest {
|
public class JZlibTest extends ZlibTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -35,61 +26,4 @@ public class JZlibTest extends ZlibTest {
|
|||||||
protected ZlibDecoder createDecoder(ZlibWrapper wrapper) {
|
protected ZlibDecoder createDecoder(ZlibWrapper wrapper) {
|
||||||
return new JZlibDecoder(wrapper);
|
return new JZlibDecoder(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testZLIB_OR_NONE() throws Exception {
|
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(new JZlibEncoder(ZlibWrapper.NONE));
|
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
|
||||||
assertTrue(chEncoder.finish());
|
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
|
||||||
|
|
||||||
EmbeddedChannel chDecoderZlibOrNone = new EmbeddedChannel(new JZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
|
|
||||||
|
|
||||||
chDecoderZlibOrNone.writeInbound(deflatedData);
|
|
||||||
assertTrue(chDecoderZlibOrNone.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderZlibOrNone.readInbound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testZLIB_OR_NONE2() throws Exception {
|
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(new JZlibEncoder(ZlibWrapper.ZLIB));
|
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
|
||||||
assertTrue(chEncoder.finish());
|
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
|
||||||
|
|
||||||
EmbeddedChannel chDecoderZlibOrNone = new EmbeddedChannel(new JZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
|
|
||||||
|
|
||||||
chDecoderZlibOrNone.writeInbound(deflatedData);
|
|
||||||
assertTrue(chDecoderZlibOrNone.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderZlibOrNone.readInbound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testZLIB_OR_NONE3() throws Exception {
|
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(new JZlibEncoder(ZlibWrapper.GZIP));
|
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
|
||||||
assertTrue(chEncoder.finish());
|
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
|
||||||
|
|
||||||
EmbeddedChannel chDecoderZlibOrNone = new EmbeddedChannel(new JZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
|
|
||||||
|
|
||||||
chDecoderZlibOrNone.writeInbound(deflatedData);
|
|
||||||
assertTrue(chDecoderZlibOrNone.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderZlibOrNone.readInbound());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,21 @@ public class JdkZlibTest extends ZlibTest {
|
|||||||
return new JdkZlibDecoder(wrapper);
|
return new JdkZlibDecoder(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testZLIB_OR_NONE() throws Exception {
|
public void testZLIB_OR_NONE() throws Exception {
|
||||||
new JdkZlibDecoder(ZlibWrapper.ZLIB_OR_NONE);
|
new JdkZlibDecoder(ZlibWrapper.ZLIB_OR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testZLIB_OR_NONE2() throws Exception {
|
||||||
|
new JdkZlibDecoder(ZlibWrapper.ZLIB_OR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testZLIB_OR_NONE3() throws Exception {
|
||||||
|
new JdkZlibDecoder(ZlibWrapper.ZLIB_OR_NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public abstract class ZlibTest {
|
public abstract class ZlibTest {
|
||||||
@ -41,64 +42,68 @@ public abstract class ZlibTest {
|
|||||||
EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
|
EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
|
||||||
chDecoderGZip.writeInbound(deflatedData.copy());
|
chDecoderGZip.writeInbound(deflatedData.copy());
|
||||||
assertTrue(chDecoderGZip.finish());
|
assertTrue(chDecoderGZip.finish());
|
||||||
assertEquals(chDecoderGZip.readInbound(), data);
|
ByteBuf buf = (ByteBuf) chDecoderGZip.readInbound();
|
||||||
|
assertEquals(buf, data);
|
||||||
|
assertNull(chDecoderGZip.readInbound());
|
||||||
|
data.release();
|
||||||
|
deflatedData.release();
|
||||||
|
buf.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testCompress(ZlibWrapper encoderWrapper, ZlibWrapper decoderWrapper) throws Exception {
|
||||||
|
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
||||||
|
EmbeddedChannel chEncoder = new EmbeddedChannel(createEncoder(encoderWrapper));
|
||||||
|
|
||||||
|
chEncoder.writeOutbound(data.copy());
|
||||||
|
assertTrue(chEncoder.finish());
|
||||||
|
|
||||||
|
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(decoderWrapper));
|
||||||
|
for (;;) {
|
||||||
|
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
||||||
|
if (deflatedData == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
chDecoderZlib.writeInbound(deflatedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(chDecoderZlib.finish());
|
||||||
|
|
||||||
|
ByteBuf buf = (ByteBuf) chDecoderZlib.readInbound();
|
||||||
|
assertEquals(data, buf);
|
||||||
|
assertNull(chDecoderZlib.readInbound());
|
||||||
|
|
||||||
|
data.release();
|
||||||
|
buf.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZLIB() throws Exception {
|
public void testZLIB() throws Exception {
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
testCompress(ZlibWrapper.ZLIB, ZlibWrapper.ZLIB);
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(createEncoder(ZlibWrapper.ZLIB));
|
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
|
||||||
assertTrue(chEncoder.finish());
|
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
|
||||||
|
|
||||||
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(ZlibWrapper.ZLIB));
|
|
||||||
|
|
||||||
chDecoderZlib.writeInbound(deflatedData.copy());
|
|
||||||
assertTrue(chDecoderZlib.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderZlib.readInbound());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNONE() throws Exception {
|
public void testNONE() throws Exception {
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
testCompress(ZlibWrapper.NONE, ZlibWrapper.NONE);
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(createEncoder(ZlibWrapper.NONE));
|
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
|
||||||
assertTrue(chEncoder.finish());
|
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
|
||||||
|
|
||||||
EmbeddedChannel chDecoderZlibNone = new EmbeddedChannel(createDecoder(ZlibWrapper.NONE));
|
|
||||||
|
|
||||||
chDecoderZlibNone.writeInbound(deflatedData.copy());
|
|
||||||
assertTrue(chDecoderZlibNone.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderZlibNone.readInbound());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGZIP() throws Exception {
|
public void testGZIP() throws Exception {
|
||||||
ByteBuf data = Unpooled.copiedBuffer("test", CharsetUtil.UTF_8);
|
testCompress(ZlibWrapper.GZIP, ZlibWrapper.GZIP);
|
||||||
|
}
|
||||||
|
|
||||||
EmbeddedChannel chEncoder = new EmbeddedChannel(createEncoder(ZlibWrapper.GZIP));
|
@Test
|
||||||
|
public void testZLIB_OR_NONE() throws Exception {
|
||||||
|
testCompress(ZlibWrapper.NONE, ZlibWrapper.ZLIB_OR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
chEncoder.writeOutbound(data.copy());
|
@Test
|
||||||
assertTrue(chEncoder.finish());
|
public void testZLIB_OR_NONE2() throws Exception {
|
||||||
|
testCompress(ZlibWrapper.ZLIB, ZlibWrapper.ZLIB_OR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
@Test
|
||||||
|
public void testZLIB_OR_NONE3() throws Exception {
|
||||||
EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
|
testCompress(ZlibWrapper.GZIP, ZlibWrapper.ZLIB_OR_NONE);
|
||||||
|
|
||||||
chDecoderGZip.writeInbound(deflatedData.copy());
|
|
||||||
assertTrue(chDecoderGZip.finish());
|
|
||||||
|
|
||||||
assertEquals(data, chDecoderGZip.readInbound());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] gzip(String message) throws IOException {
|
private static byte[] gzip(String message) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user