Search in sources :

Example 26 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class ConsumerWithTracingAndMdcSupportTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    consumerMock = mock(Consumer.class);
    inObj = new Object();
    throwExceptionDuringCall = false;
    currentSpanStackWhenConsumerWasCalled = new ArrayList<>();
    currentMdcInfoWhenConsumerWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenConsumerWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenConsumerWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(consumerMock).accept(inObj);
    resetTracingAndMdc();
}
Also used : Consumer(java.util.function.Consumer) Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Before(org.junit.Before)

Example 27 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class BiFunctionWithTracingAndMdcSupportTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    biFunctionMock = mock(BiFunction.class);
    inObj1 = new Object();
    inObj2 = new Object();
    outObj = new Object();
    throwExceptionDuringCall = false;
    currentSpanStackWhenFunctionWasCalled = new ArrayList<>();
    currentMdcInfoWhenFunctionWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenFunctionWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenFunctionWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return outObj;
    }).when(biFunctionMock).apply(inObj1, inObj2);
    resetTracingAndMdc();
}
Also used : Attribute(io.netty.util.Attribute) BiFunction(java.util.function.BiFunction) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Before(org.junit.Before)

Example 28 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method beforeMethod.

@Before
public void beforeMethod() {
    setupMetricRegistryAndCodahaleMetricsCollector();
    endpointMetricsHandlerMock = mock(EndpointMetricsHandler.class);
    mockHistogramSupplier = () -> mock(Histogram.class);
    listener = new CodahaleMetricsListener(cmcMock, endpointMetricsHandlerMock, true, null, null, mockHistogramSupplier);
    serverConfig = new ServerConfig() {

        private final List<Endpoint<?>> endpoints = Arrays.asList(new DummyEndpoint(Matcher.match("/foo")), new DummyEndpoint(Matcher.match("/bar", HttpMethod.POST, HttpMethod.PUT)), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiFoo", "/multiBar"))), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiBaz", "/multiBat"), HttpMethod.PATCH, HttpMethod.OPTIONS)));

        @Override
        public Collection<Endpoint<?>> appEndpoints() {
            return endpoints;
        }

        @Override
        public int numBossThreads() {
            return 3;
        }

        @Override
        public int numWorkerThreads() {
            return 42;
        }

        @Override
        public int maxRequestSizeInBytes() {
            return 42434445;
        }
    };
    listener.initEndpointAndServerConfigMetrics(serverConfig);
    requestInfoMock = mock(RequestInfo.class);
    responseInfoMock = mock(ResponseInfo.class);
    state = new HttpProcessingState();
    state.setRequestInfo(requestInfoMock);
    state.setResponseInfo(responseInfoMock);
    requestStartTime = Instant.now().minus(42, ChronoUnit.MILLIS);
    state.setRequestStartTime(requestStartTime);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) ServerConfig(com.nike.riposte.server.config.ServerConfig) Histogram(com.codahale.metrics.Histogram) Endpoint(com.nike.riposte.server.http.Endpoint) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Collection(java.util.Collection) RequestInfo(com.nike.riposte.server.http.RequestInfo) Before(org.junit.Before)

Example 29 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class EndpointMetricsHandlerDefaultImplTest method beforeMethod.

@Before
public void beforeMethod() {
    instance = spy(new EndpointMetricsHandlerDefaultImpl());
    serverConfig = new ServerConfig() {

        private final List<Endpoint<?>> endpoints = Arrays.asList(new DummyEndpoint(Matcher.match("/foo")), new DummyEndpoint(Matcher.match("/bar", HttpMethod.POST, HttpMethod.PUT)), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiFoo", "/multiBar"))), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiBaz", "/multiBat"), HttpMethod.PATCH, HttpMethod.OPTIONS)));

        @Override
        public Collection<Endpoint<?>> appEndpoints() {
            return endpoints;
        }

        @Override
        public int numBossThreads() {
            return 3;
        }

        @Override
        public int numWorkerThreads() {
            return 42;
        }

        @Override
        public int maxRequestSizeInBytes() {
            return 42434445;
        }
    };
    setupMetricRegistryMock();
    requestInfoMock = mock(RequestInfo.class);
    responseInfoMock = mock(ResponseInfo.class);
    state = new HttpProcessingState();
    state.setRequestInfo(requestInfoMock);
    state.setResponseInfo(responseInfoMock);
    state.setRequestStartTime(Instant.now());
    instance.setupEndpointsMetrics(serverConfig, metricRegistryMock);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) ServerConfig(com.nike.riposte.server.config.ServerConfig) Endpoint(com.nike.riposte.server.http.Endpoint) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Collection(java.util.Collection) RequestInfo(com.nike.riposte.server.http.RequestInfo) Before(org.junit.Before)

Example 30 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class RunnableWithTracingAndMdcSupportTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    runnableMock = mock(Runnable.class);
    throwExceptionDuringCall = false;
    currentSpanStackWhenRunnableWasCalled = new ArrayList<>();
    currentMdcInfoWhenRunnableWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenRunnableWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenRunnableWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(runnableMock).run();
    resetTracingAndMdc();
}
Also used : Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Before(org.junit.Before)

Aggregations

HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)54 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)22 Before (org.junit.Before)20 Channel (io.netty.channel.Channel)19 Attribute (io.netty.util.Attribute)19 RequestInfo (com.nike.riposte.server.http.RequestInfo)14 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)11 Test (org.junit.Test)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)8 Endpoint (com.nike.riposte.server.http.Endpoint)6 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)6 Span (com.nike.wingtips.Span)5 ChannelFuture (io.netty.channel.ChannelFuture)5 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)5 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)4 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)4 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4