Search in sources :

Example 36 with RequestInfo

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

the class RequestInfoImplTest method setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null.

@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
    assertThat(requestInfo.getRawContentBytes(), nullValue());
    // when
    requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {
    });
    // then
    assertThat(requestInfo.getContent(), nullValue());
}
Also used : RequestInfo(com.nike.riposte.server.http.RequestInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 37 with RequestInfo

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

the class NonblockingEndpointExecutionHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    proxyRouterStateAttrMock = mock(Attribute.class);
    requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    endpointMock = mock(StandardEndpoint.class);
    longRunningTaskExecutorMock = mock(Executor.class);
    responseFuture = new CompletableFuture<>();
    stateWorkChainFutureSpy = spy(CompletableFuture.completedFuture(null));
    eventLoopMock = mock(EventLoop.class);
    eventExecutorMock = mock(EventExecutor.class);
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(false).when(stateMock).isRequestHandled();
    doReturn(proxyRouterStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(proxyRouterStateMock).when(proxyRouterStateAttrMock).get();
    doReturn(endpointMock).when(stateMock).getEndpointForExecution();
    doReturn(requestInfo).when(stateMock).getRequestInfo();
    doReturn(responseFuture).when(endpointMock).execute(any(RequestInfo.class), any(Executor.class), any(ChannelHandlerContext.class));
    doReturn(eventLoopMock).when(channelMock).eventLoop();
    doReturn(eventExecutorMock).when(ctxMock).executor();
    doReturn(true).when(eventExecutorMock).inEventLoop();
    doReturn(true).when(channelMock).isActive();
    doAnswer(invocation -> {
        CompletableFuture actualFutureForAttaching = (CompletableFuture) invocation.callRealMethod();
        futureThatWillBeAttachedToSpy = spy(actualFutureForAttaching);
        return futureThatWillBeAttachedToSpy;
    }).when(stateWorkChainFutureSpy).thenCompose(any(Function.class));
    doReturn(stateWorkChainFutureSpy).when(stateMock).getPreEndpointExecutionWorkChain();
    handlerSpy = spy(new NonblockingEndpointExecutionHandler(longRunningTaskExecutorMock, defaultCompletableFutureTimeoutMillis));
}
Also used : Attribute(io.netty.util.Attribute) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Channel(io.netty.channel.Channel) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RequestInfo(com.nike.riposte.server.http.RequestInfo) Function(java.util.function.Function) CompletableFuture(java.util.concurrent.CompletableFuture) EventExecutor(io.netty.util.concurrent.EventExecutor) Executor(java.util.concurrent.Executor) EventLoop(io.netty.channel.EventLoop) EventExecutor(io.netty.util.concurrent.EventExecutor) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Before(org.junit.Before)

Example 38 with RequestInfo

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

the class RiposteApiExceptionHandlerTest method maybeHandleErrorExplosionThrowsUnexpectedMajorErrorHandlingError.

// Note the difference between UnexpectedMajor**Exception**HandlingError and UnexpectedMajor**Error**HandlingError. I know, I know, confusing and annoying. Adapters can be like that.
@Test(expected = UnexpectedMajorErrorHandlingError.class)
public void maybeHandleErrorExplosionThrowsUnexpectedMajorErrorHandlingError() throws UnexpectedMajorExceptionHandlingError, UnexpectedMajorErrorHandlingError {
    UnexpectedMajorExceptionHandlingError innerExplosion = new UnexpectedMajorExceptionHandlingError("intentional kaboom", new Exception());
    doThrow(innerExplosion).when(adapterSpy).maybeHandleException(any(Throwable.class), any(RequestInfoForLogging.class));
    RequestInfo requestInfoMock = mock(RequestInfo.class);
    adapterSpy.maybeHandleError(new Exception(), requestInfoMock);
}
Also used : UnexpectedMajorExceptionHandlingError(com.nike.backstopper.handler.UnexpectedMajorExceptionHandlingError) RequestInfoForLogging(com.nike.backstopper.handler.RequestInfoForLogging) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 39 with RequestInfo

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

the class RiposteApiExceptionHandlerTest method maybeHandleErrorFromNettyInterfaceReturnsNullIfBackstopperMaybeHandleExceptionReturnsNull.

@Test
public void maybeHandleErrorFromNettyInterfaceReturnsNullIfBackstopperMaybeHandleExceptionReturnsNull() throws UnexpectedMajorExceptionHandlingError, UnexpectedMajorErrorHandlingError {
    doReturn(null).when(adapterSpy).maybeHandleException(any(Throwable.class), any(RequestInfoForLogging.class));
    RequestInfo requestInfoMock = mock(RequestInfo.class);
    assertThat(adapterSpy.maybeHandleError(new Exception(), requestInfoMock), nullValue());
}
Also used : RequestInfoForLogging(com.nike.backstopper.handler.RequestInfoForLogging) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Aggregations

RequestInfo (com.nike.riposte.server.http.RequestInfo)39 Test (org.junit.Test)30 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)13 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)10 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)6 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 Pair (com.nike.internal.util.Pair)5 RequestInfoForLogging (com.nike.backstopper.handler.RequestInfoForLogging)4 Endpoint (com.nike.riposte.server.http.Endpoint)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 Optional (java.util.Optional)4 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)3 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 BaseInboundHandlerWithTracingAndMdcSupport (com.nike.riposte.server.handler.base.BaseInboundHandlerWithTracingAndMdcSupport)2 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)2