Search in sources :

Example 91 with Executable

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

Example 92 with Executable

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

Example 93 with Executable

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

Example 94 with Executable

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

Example 95 with Executable

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);
        }
    });
}
Also used : 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