Search in sources :

Example 1 with LastOutboundMessage

use of com.nike.riposte.server.channelpipeline.message.LastOutboundMessage in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method finalizeChannelPipeline_does_not_add_idle_channel_timeout_handler_to_pipeline_if_workerChannelIdleTimeoutMillis_is_not_greater_than_0_or_idle_timeout_handler_already_exists.

@DataProvider(value = { "0      |   false", "-42    |   false", "42     |   true" }, splitBy = "\\|")
@Test
public void finalizeChannelPipeline_does_not_add_idle_channel_timeout_handler_to_pipeline_if_workerChannelIdleTimeoutMillis_is_not_greater_than_0_or_idle_timeout_handler_already_exists(long timeoutVal, boolean idleTimeoutHandlerAlreadyExists) throws JsonProcessingException {
    // given
    Whitebox.setInternalState(handler, "workerChannelIdleTimeoutMillis", timeoutVal);
    LastOutboundMessage msg = mock(LastOutboundMessage.class);
    if (idleTimeoutHandlerAlreadyExists)
        doReturn(mock(ChannelHandler.class)).when(pipelineMock).get(IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
    // when
    handler.finalizeChannelPipeline(ctxMock, msg, state, null);
    // then
    verify(pipelineMock, never()).addFirst(anyString(), anyObject());
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 2 with LastOutboundMessage

use of com.nike.riposte.server.channelpipeline.message.LastOutboundMessage in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method finalizeChannelPipeline_should_add_idle_channel_timeout_handler_first_in_pipeline_if_workerChannelIdleTimeoutMillis_is_greater_than_0.

@Test
public void finalizeChannelPipeline_should_add_idle_channel_timeout_handler_first_in_pipeline_if_workerChannelIdleTimeoutMillis_is_greater_than_0() throws JsonProcessingException {
    // given
    LastOutboundMessage msg = mock(LastOutboundMessage.class);
    // when
    handler.finalizeChannelPipeline(ctxMock, msg, state, null);
    // then
    ArgumentCaptor<ChannelHandler> idleHandlerArgCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(pipelineMock).addFirst(eq(IDLE_CHANNEL_TIMEOUT_HANDLER_NAME), idleHandlerArgCaptor.capture());
    ChannelHandler handlerRegistered = idleHandlerArgCaptor.getValue();
    assertThat(handlerRegistered, instanceOf(IdleChannelTimeoutHandler.class));
    IdleChannelTimeoutHandler idleHandler = (IdleChannelTimeoutHandler) handlerRegistered;
    long idleValue = (long) Whitebox.getInternalState(idleHandler, "idleTimeoutMillis");
    assertThat(idleValue, is(workerChannelIdleTimeoutMillis));
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 3 with LastOutboundMessage

use of com.nike.riposte.server.channelpipeline.message.LastOutboundMessage in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method doChannelRead_gets_state_from_getStateAndCreateIfNeeded_method_and_then_calls_finalizeChannelPipeline_and_then_returns_DO_NOT_FIRE_CONTINUE_EVENT_if_msg_is_LastOutboundMessage.

@Test
public void doChannelRead_gets_state_from_getStateAndCreateIfNeeded_method_and_then_calls_finalizeChannelPipeline_and_then_returns_DO_NOT_FIRE_CONTINUE_EVENT_if_msg_is_LastOutboundMessage() throws Exception {
    // given
    ChannelPipelineFinalizerHandler handlerSpy = spy(handler);
    LastOutboundMessage msg = mock(LastOutboundMessage.class);
    state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class));
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).finalizeChannelPipeline(eq(ctxMock), eq(msg), eq(state), any(Throwable.class));
    assertThat(result, is(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT));
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) ChannelFuture(io.netty.channel.ChannelFuture) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 4 with LastOutboundMessage

use of com.nike.riposte.server.channelpipeline.message.LastOutboundMessage in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandler method doChannelRead.

@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof LastOutboundMessage) {
        Exception ex = new Exception("Manually created exception to be used for diagnostic stack trace");
        HttpProcessingState state = getStateAndCreateIfNeeded(ctx, ex);
        finalizeChannelPipeline(ctx, msg, state, ex);
    }
    return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT;
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with LastOutboundMessage

use of com.nike.riposte.server.channelpipeline.message.LastOutboundMessage in project riposte by Nike-Inc.

the class DTraceEndHandlerTest method doChannelRead_calls_endDtrace_and_returns_CONTINUE_if_msg_is_LastOutboundMessage.

@Test
public void doChannelRead_calls_endDtrace_and_returns_CONTINUE_if_msg_is_LastOutboundMessage() throws Exception {
    // given
    LastOutboundMessage msg = mock(LastOutboundMessage.class);
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).endDtrace(ctxMock);
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Aggregations

LastOutboundMessage (com.nike.riposte.server.channelpipeline.message.LastOutboundMessage)5 Test (org.junit.Test)4 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1