use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class ZlibTest method testMaxAllocation.
@Test
public void testMaxAllocation() throws Exception {
int maxAllocation = 1024;
ZlibDecoder decoder = createDecoder(ZlibWrapper.ZLIB, maxAllocation);
final EmbeddedChannel chDecoder = new EmbeddedChannel(decoder);
TestByteBufAllocator alloc = new TestByteBufAllocator(chDecoder.alloc());
chDecoder.config().setAllocator(alloc);
DecompressionException e = assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() throws Throwable {
chDecoder.writeInbound(Unpooled.wrappedBuffer(deflate(BYTES_LARGE)));
}
});
assertTrue(e.getMessage().startsWith("Decompression buffer has reached maximum size"));
assertEquals(maxAllocation, alloc.getMaxAllocation());
assertTrue(decoder.isClosed());
assertFalse(chDecoder.finish());
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class SnappyTest method testDecodeWithOverlyLongPreamble.
@Test
public void testDecodeWithOverlyLongPreamble() {
final ByteBuf in = Unpooled.wrappedBuffer(new byte[] { // preamble length
-0x80, // preamble length
-0x80, // preamble length
-0x80, // preamble length
-0x80, // preamble length
0x7f, // literal tag + length
0x04 << 2, // "netty"
0x6e, // "netty"
0x65, // "netty"
0x74, // "netty"
0x74, // "netty"
0x79 });
final ByteBuf out = Unpooled.buffer(10);
try {
assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() {
snappy.decode(in, out);
}
});
} finally {
in.release();
out.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class SnappyTest method testDecodeCopyWithOffsetBeforeChunk.
@Test
public void testDecodeCopyWithOffsetBeforeChunk() {
final ByteBuf in = Unpooled.wrappedBuffer(new byte[] { // preamble length
0x0a, // literal tag + length
0x04 << 2, // "netty"
0x6e, // "netty"
0x65, // "netty"
0x74, // "netty"
0x74, // "netty"
0x79, // copy with 1-byte offset + length
0x05 << 2 | 0x01, // INVALID offset (greater than chunk size)
0x0b });
final ByteBuf out = Unpooled.buffer(10);
try {
assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() {
snappy.decode(in, out);
}
});
} finally {
in.release();
out.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class Lz4FrameDecoderTest method testDecompressedAndCompressedLengthMismatch.
@Test
public void testDecompressedAndCompressedLengthMismatch() {
final byte[] data = Arrays.copyOf(DATA, DATA.length);
data[13] = 0x01;
final ByteBuf in = Unpooled.wrappedBuffer(data);
assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() {
channel.writeInbound(in);
}
}, "mismatch");
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class Lz4FrameEncoderTest method testAllocateOnHeapBufferOverflowsOutputSize.
/**
* This test might be a invasive in terms of knowing what happens inside
* {@link Lz4FrameEncoder#allocateBuffer(ChannelHandlerContext, ByteBuf, boolean)}, but this is safest way
* of testing the overflow conditions as allocating the huge buffers fails in many CI environments.
*/
@Test
public void testAllocateOnHeapBufferOverflowsOutputSize() {
final int maxEncodeSize = Integer.MAX_VALUE;
final Lz4FrameEncoder encoder = newEncoder(Lz4Constants.DEFAULT_BLOCK_SIZE, maxEncodeSize);
when(buffer.readableBytes()).thenReturn(maxEncodeSize);
buffer.writerIndex(maxEncodeSize);
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() {
encoder.allocateBuffer(ctx, buffer, false);
}
});
}
Aggregations