Search in sources :

Example 86 with Executable

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();
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 87 with Executable

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();
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 88 with Executable

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();
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 89 with Executable

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());
    }
}
Also used : ContinuationWebSocketFrame(io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame) WebSocketExtensionFilter(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) ContinuationWebSocketFrame(io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 90 with Executable

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());
    }
}
Also used : TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Aggregations

Executable (org.junit.jupiter.api.function.Executable)476 Test (org.junit.jupiter.api.Test)434 lombok.val (lombok.val)112 ByteBuf (io.netty.buffer.ByteBuf)83 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)36 CucumberException (io.cucumber.core.exception.CucumberException)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)15 Feature (io.cucumber.core.gherkin.Feature)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 StepDefinition (io.cucumber.core.backend.StepDefinition)14 Step (io.cucumber.core.gherkin.Step)14 Argument (io.cucumber.core.stepexpression.Argument)14 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 LocalChannel (io.netty.channel.local.LocalChannel)12 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)11 SSLEngine (javax.net.ssl.SSLEngine)11 Bootstrap (io.netty.bootstrap.Bootstrap)10