Search in sources :

Example 16 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_allows_endpoints_to_override_max_request_size_setting_higher.

@Test
public void doChannelRead_allows_endpoints_to_override_max_request_size_setting_higher() {
    // given
    maxRequestSizeInBytes = 10;
    handler = new RequestInfoSetterHandler(maxRequestSizeInBytes);
    doReturn(100).when(endpointMock).maxRequestSizeInBytesOverride();
    doReturn(99).when(requestInfo).addContentChunk(any());
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
    // then
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
    verify(httpContentMock).release();
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 17 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_override_uses_global_configured_max_request_size_when_necessary_no_error.

@DataProvider(value = { "true   |   false", "false  |   true" }, splitBy = "\\|")
@Test
public void doChannelRead_override_uses_global_configured_max_request_size_when_necessary_no_error(boolean endpointIsNull, boolean endpointReturnsNullOverride) {
    // given
    if (endpointIsNull)
        doReturn(null).when(stateMock).getEndpointForExecution();
    if (endpointReturnsNullOverride)
        doReturn(null).when(endpointMock).maxRequestSizeInBytesOverride();
    maxRequestSizeInBytes = 10;
    handler = new RequestInfoSetterHandler(maxRequestSizeInBytes);
    doReturn(5).when(requestInfo).addContentChunk(any());
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
    // then
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
    verify(httpContentMock).release();
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 18 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_uses_existing_RequestInfo_on_state_if_available_and_does_not_recreate_it.

@Test
public void doChannelRead_uses_existing_RequestInfo_on_state_if_available_and_does_not_recreate_it() {
    // given
    HttpRequest msgMock = mock(HttpRequest.class);
    String uri = "/some/url";
    HttpHeaders headers = new DefaultHttpHeaders();
    doReturn(uri).when(msgMock).uri();
    doReturn(headers).when(msgMock).headers();
    doReturn(HttpVersion.HTTP_1_1).when(msgMock).protocolVersion();
    doReturn(requestInfo).when(stateMock).getRequestInfo();
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msgMock);
    // then
    verify(stateMock, never()).setRequestInfo(any(RequestInfo.class));
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 19 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_does_not_throw_exception_when_exceeding_global_max_size_when_request_validation_is_turned_off.

@Test
public void doChannelRead_does_not_throw_exception_when_exceeding_global_max_size_when_request_validation_is_turned_off() {
    // given
    maxRequestSizeInBytes = 10;
    handler = new RequestInfoSetterHandler(maxRequestSizeInBytes);
    doReturn(0).when(endpointMock).maxRequestSizeInBytesOverride();
    doReturn(100).when(requestInfo).addContentChunk(any());
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
    // then
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
    verify(httpContentMock).release();
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 20 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent_or_channel_is_inactive.

@DataProvider(value = { "true   |   false   |   false", "false  |   true    |   false", "true   |   true    |   false", "false  |   false   |   true" }, splitBy = "\\|")
@Test
public void doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent_or_channel_is_inactive(boolean stateIsNull, boolean responseAlreadySent, boolean channelIsInactive) {
    // given
    if (stateIsNull) {
        doReturn(null).when(stateAttrMock).get();
    }
    if (responseAlreadySent) {
        doReturn(true).when(stateMock).isResponseSendingLastChunkSent();
    }
    if (channelIsInactive) {
        doReturn(false).when(channelMock).isActive();
    }
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
    // then
    verify(httpContentMock).release();
    assertThat(result).isEqualTo(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)92 Test (org.junit.Test)90 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)26 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)11 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 RequestInfo (com.nike.riposte.server.http.RequestInfo)7 Span (com.nike.wingtips.Span)6 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)5 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)5 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)5 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 Pair (com.nike.internal.util.Pair)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 ChannelFuture (io.netty.channel.ChannelFuture)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 InvalidRipostePipelineException (com.nike.riposte.server.error.exception.InvalidRipostePipelineException)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3