use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class PerMessageDeflateEncoderTest method testIllegalStateWhenCompressionInProgress.
@Test
public void testIllegalStateWhenCompressionInProgress() {
WebSocketExtensionFilter selectivityCompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame.content().readableBytes() < 100;
}
};
final EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false, selectivityCompressionFilter));
byte[] firstPayload = new byte[200];
random.nextBytes(firstPayload);
byte[] finalPayload = new byte[90];
random.nextBytes(finalPayload);
BinaryWebSocketFrame firstPart = new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(firstPayload));
final ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(finalPayload));
assertTrue(encoderChannel.writeOutbound(firstPart));
BinaryWebSocketFrame outboundFirstPart = encoderChannel.readOutbound();
// first part is compressed
assertEquals(WebSocketExtension.RSV1, outboundFirstPart.rsv());
assertFalse(Arrays.equals(firstPayload, ByteBufUtil.getBytes(outboundFirstPart.content())));
assertTrue(outboundFirstPart.release());
// final part throwing exception
try {
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() throws Throwable {
encoderChannel.writeOutbound(finalPart);
}
});
} finally {
assertTrue(finalPart.release());
assertFalse(encoderChannel.finishAndReleaseAll());
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class SpdyHeaderBlockZlibDecoderTest method testHeaderBlockInvalidDictionary.
@Test
public void testHeaderBlockInvalidDictionary() throws Exception {
final ByteBuf headerBlock = Unpooled.buffer(7);
headerBlock.writeByte(0x78);
headerBlock.writeByte(0x3f);
// Unknown dictionary
headerBlock.writeByte(0x01);
// Unknown dictionary
headerBlock.writeByte(0x02);
// Unknown dictionary
headerBlock.writeByte(0x03);
// Unknown dictionary
headerBlock.writeByte(0x04);
// Non-compressed block
headerBlock.writeByte(0);
assertThrows(SpdyProtocolException.class, new Executable() {
@Override
public void execute() throws Throwable {
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
}
});
headerBlock.release();
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class SpdyHeaderBlockZlibDecoderTest method testHeaderBlockInvalidDeflateBlock.
@Test
public void testHeaderBlockInvalidDeflateBlock() throws Exception {
final ByteBuf headerBlock = Unpooled.buffer(11);
headerBlock.writeBytes(zlibHeader);
// Non-compressed block
headerBlock.writeByte(0);
// little-endian length (0)
headerBlock.writeByte(0x00);
// little-endian length (0)
headerBlock.writeByte(0x00);
// invalid one's compliment
headerBlock.writeByte(0x00);
// invalid one's compliment
headerBlock.writeByte(0x00);
assertThrows(SpdyProtocolException.class, new Executable() {
@Override
public void execute() throws Throwable {
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
}
});
headerBlock.release();
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class AbstractScheduledEventExecutorTest method testScheduleAtFixedRateRunnableNegative.
@Test
public void testScheduleAtFixedRateRunnableNegative() {
final TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
}
});
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class AbstractReferenceCountedTest method testRetainOverflow2.
@Test
public void testRetainOverflow2() {
final AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertEquals(1, referenceCounted.refCnt());
assertThrows(IllegalReferenceCountException.class, new Executable() {
@Override
public void execute() {
referenceCounted.retain(Integer.MAX_VALUE);
}
});
}
Aggregations