Search in sources :

Example 31 with Executable

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

the class DefaultHttp2ConnectionDecoderTest method multipleHeadersContentLength.

private void multipleHeadersContentLength(boolean same) throws Exception {
    final int padding = 10;
    when(connection.isServer()).thenReturn(true);
    final Http2Headers headers = new DefaultHttp2Headers();
    if (same) {
        headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
        headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
    } else {
        headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
        headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 1);
    }
    if (same) {
        decode().onHeadersRead(ctx, STREAM_ID, headers, padding, true);
        verify(listener, times(1)).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class), anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean());
        assertEquals(1, headers.getAll(HttpHeaderNames.CONTENT_LENGTH).size());
    } else {
        assertThrows(Http2Exception.StreamException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                decode().onHeadersRead(ctx, STREAM_ID, headers, padding, true);
            }
        });
        // Verify that the event was absorbed and not propagated to the observer.
        verify(listener, never()).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class), anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean());
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable)

Example 32 with Executable

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

the class DefaultHttp2ConnectionDecoderTest method errorDuringDeliveryShouldReturnCorrectNumberOfBytes.

@Test
public void errorDuringDeliveryShouldReturnCorrectNumberOfBytes() throws Exception {
    final ByteBuf data = dummyData();
    final int padding = 10;
    final AtomicInteger unprocessed = new AtomicInteger(data.readableBytes() + padding);
    doAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock in) throws Throwable {
            return unprocessed.get();
        }
    }).when(localFlow).unconsumedBytes(eq(stream));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock in) throws Throwable {
            int delta = (Integer) in.getArguments()[1];
            int newValue = unprocessed.addAndGet(-delta);
            if (newValue < 0) {
                throw new RuntimeException("Returned too many bytes");
            }
            return null;
        }
    }).when(localFlow).consumeBytes(eq(stream), anyInt());
    // When the listener callback is called, process a few bytes and then throw.
    doAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock in) throws Throwable {
            localFlow.consumeBytes(stream, 4);
            throw new RuntimeException("Fake Exception");
        }
    }).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true));
    try {
        assertThrows(RuntimeException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                decode().onDataRead(ctx, STREAM_ID, data, padding, true);
            }
        });
        verify(localFlow).receiveFlowControlledFrame(eq(stream), eq(data), eq(padding), eq(true));
        verify(listener).onDataRead(eq(ctx), eq(STREAM_ID), eq(data), eq(padding), eq(true));
        assertEquals(0, localFlow.unconsumedBytes(stream));
    } finally {
        data.release();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 33 with Executable

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

the class DefaultHttp2ConnectionTest method reserveWithPushDisallowedShouldThrow.

@Test
public void reserveWithPushDisallowedShouldThrow() throws Http2Exception {
    final Http2Stream stream = server.remote().createStream(3, true);
    server.remote().allowPushTo(false);
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            server.local().reservePushStream(2, stream);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 34 with Executable

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

the class DefaultHttp2ConnectionTest method serverCreatePushShouldFailOnRemoteEndpointWhenMaxAllowedStreamsExceeded.

@Test
public void serverCreatePushShouldFailOnRemoteEndpointWhenMaxAllowedStreamsExceeded() throws Http2Exception {
    server = new DefaultHttp2Connection(true, 0);
    server.remote().maxActiveStreams(1);
    final Http2Stream requestStream = server.remote().createStream(3, false);
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            server.remote().reservePushStream(2, requestStream);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 35 with Executable

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

the class DefaultHttp2HeadersEncoderTest method headersExceedMaxSetSizeShouldFail.

@Test
public void headersExceedMaxSetSizeShouldFail() throws Http2Exception {
    final Http2Headers headers = headers();
    encoder.maxHeaderListSize(2);
    assertThrows(StreamException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            encoder.encodeHeaders(3, /* randomly chosen */
            headers, Unpooled.buffer());
        }
    });
}
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