use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class ReadOnlyDirectByteBufferBufTest method testGetBytesByteBuffer.
@Test
public void testGetBytesByteBuffer() {
byte[] bytes = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
// Ensure destination buffer is bigger then what is in the ByteBuf.
final ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
final ByteBuf buffer = buffer(((ByteBuffer) allocate(bytes.length).put(bytes).flip()).asReadOnlyBuffer());
try {
assertThrows(IndexOutOfBoundsException.class, new Executable() {
@Override
public void execute() {
buffer.getBytes(buffer.readerIndex(), nioBuffer);
}
});
} finally {
buffer.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class ReadOnlyDirectByteBufferBufTest method testSetBytesViaBuffer.
@Test
public void testSetBytesViaBuffer() {
final ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
final ByteBuf copy = Unpooled.copyInt(1);
try {
assertThrows(ReadOnlyBufferException.class, new Executable() {
@Override
public void execute() {
buf.setBytes(0, copy);
}
});
} finally {
buf.release();
copy.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class FixedCompositeByteBufTest method testSetBytesWithByteBuf.
@Test
public void testSetBytesWithByteBuf() {
final ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
final ByteBuf src = wrappedBuffer(new byte[4]);
try {
assertThrows(ReadOnlyBufferException.class, new Executable() {
@Override
public void execute() {
buf.setBytes(0, src);
}
});
} finally {
buf.release();
src.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class PerMessageDeflateDecoderTest method testIllegalStateWhenDecompressionInProgress.
@Test
public void testIllegalStateWhenDecompressionInProgress() {
WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame.content().readableBytes() < 100;
}
};
EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
final EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false, selectivityDecompressionFilter));
byte[] firstPayload = new byte[200];
random.nextBytes(firstPayload);
byte[] finalPayload = new byte[50];
random.nextBytes(finalPayload);
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(firstPayload)));
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(finalPayload)));
ByteBuf compressedFirstPayload = encoderChannel.readOutbound();
ByteBuf compressedFinalPayload = encoderChannel.readOutbound();
assertTrue(encoderChannel.finishAndReleaseAll());
BinaryWebSocketFrame firstPart = new BinaryWebSocketFrame(false, WebSocketExtension.RSV1, compressedFirstPayload);
final ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, WebSocketExtension.RSV1, compressedFinalPayload);
assertTrue(decoderChannel.writeInbound(firstPart));
BinaryWebSocketFrame outboundFirstPart = decoderChannel.readInbound();
// first part is decompressed
assertEquals(0, outboundFirstPart.rsv());
assertArrayEquals(firstPayload, ByteBufUtil.getBytes(outboundFirstPart.content()));
assertTrue(outboundFirstPart.release());
// final part throwing exception
try {
assertThrows(DecoderException.class, new Executable() {
@Override
public void execute() {
decoderChannel.writeInbound(finalPart);
}
});
} finally {
assertTrue(finalPart.release());
assertFalse(encoderChannel.finishAndReleaseAll());
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class PerMessageDeflateEncoderTest method testCodecExceptionForNotFinEmptyFrame.
@Test
public void testCodecExceptionForNotFinEmptyFrame() {
final EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));
final TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, "");
try {
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() {
encoderChannel.writeOutbound(emptyNotFinFrame);
}
});
} finally {
// EmptyByteBuf buffer
assertFalse(emptyNotFinFrame.release());
assertFalse(encoderChannel.finish());
}
}
Aggregations