Search in sources :

Example 36 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackDecoderTest method testDecodeULE128IntOverflow1.

@Test
public void testDecodeULE128IntOverflow1() throws Http2Exception {
    byte[] input = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x07 };
    final ByteBuf in = Unpooled.wrappedBuffer(input);
    final int readerIndex = in.readerIndex();
    try {
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                decodeULE128(in, 1);
            }
        });
    } finally {
        assertEquals(readerIndex, in.readerIndex());
        in.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 37 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class DefaultHttp2ConnectionDecoderTest method dataReadForUnknownStreamShouldApplyFlowControl.

@Test
public void dataReadForUnknownStreamShouldApplyFlowControl() throws Exception {
    when(connection.stream(STREAM_ID)).thenReturn(null);
    final ByteBuf data = dummyData();
    final int padding = 10;
    int processedBytes = data.readableBytes() + padding;
    try {
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                decode().onDataRead(ctx, STREAM_ID, data, padding, true);
            }
        });
        verify(localFlow).receiveFlowControlledFrame(eq((Http2Stream) null), eq(data), eq(padding), eq(true));
        verify(localFlow).consumeBytes(eq((Http2Stream) null), eq(processedBytes));
        verify(localFlow).frameWriter(any(Http2FrameWriter.class));
        verifyNoMoreInteractions(localFlow);
        // Verify that the event was absorbed and not propagated to the observer.
        verify(listener, never()).onDataRead(eq(ctx), anyInt(), any(ByteBuf.class), anyInt(), anyBoolean());
    } finally {
        data.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 38 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class DefaultHttp2ConnectionDecoderTest method dataReadForStreamInInvalidStateShouldThrow.

@Test
public void dataReadForStreamInInvalidStateShouldThrow() throws Exception {
    // Throw an exception when checking stream state.
    when(stream.state()).thenReturn(Http2Stream.State.CLOSED);
    final ByteBuf data = dummyData();
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            decode().onDataRead(ctx, STREAM_ID, data, 10, true);
        }
    });
    data.release();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 39 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class DefaultHttp2FrameReaderTest method failedWhenDataFrameNotAssociateWithStream.

@Test
public void failedWhenDataFrameNotAssociateWithStream() throws Http2Exception {
    final ByteBuf input = Unpooled.buffer();
    ByteBuf payload = Unpooled.buffer();
    try {
        payload.writeByte(1);
        writeFrameHeader(input, payload.readableBytes(), DATA, new Http2Flags().endOfStream(true), 0);
        input.writeBytes(payload);
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                frameReader.readFrame(ctx, input, listener);
            }
        });
    } finally {
        payload.release();
        input.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 40 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class DefaultHttp2FrameReaderTest method failedWhenSettingsFrameOnNonZeroStream.

@Test
public void failedWhenSettingsFrameOnNonZeroStream() throws Http2Exception {
    final ByteBuf input = Unpooled.buffer();
    try {
        writeFrameHeader(input, 6, SETTINGS, new Http2Flags(), 1);
        input.writeShort(SETTINGS_MAX_HEADER_LIST_SIZE);
        input.writeInt(1024);
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                frameReader.readFrame(ctx, input, listener);
            }
        });
    } finally {
        input.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) 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