Search in sources :

Example 11 with DownstreamRequestFirstChunkInfo

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

the class ProxyRouterEndpointTest method downstreamRequestFirstChunkInfo_throws_IllegalArgumentException_if_constructed_with_null_firstChunk.

public void downstreamRequestFirstChunkInfo_throws_IllegalArgumentException_if_constructed_with_null_firstChunk() {
    // when
    Throwable ex = catchThrowable(() -> new DownstreamRequestFirstChunkInfo("localhost", 8080, true, null));
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("firstChunk cannot be null.");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DownstreamRequestFirstChunkInfo(com.nike.riposte.server.http.ProxyRouterEndpoint.DownstreamRequestFirstChunkInfo)

Example 12 with DownstreamRequestFirstChunkInfo

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

the class SimpleProxyRouterEndpointTest method getDownstreamRequestFirstChunkInfo_returns_exceptionally_completed_future_if_passed_request_with_null_method.

@Test
public void getDownstreamRequestFirstChunkInfo_returns_exceptionally_completed_future_if_passed_request_with_null_method() {
    // given
    SimpleProxyRouterEndpoint instance = new SimpleProxyRouterEndpoint(mock(Matcher.class), "fooHost", 4242, "/barPath", false);
    RequestInfo<?> requestMock = mock(RequestInfo.class);
    doReturn(null).when(requestMock).getMethod();
    // when
    CompletableFuture<DownstreamRequestFirstChunkInfo> result = instance.getDownstreamRequestFirstChunkInfo(requestMock, mock(Executor.class), mock(ChannelHandlerContext.class));
    // then
    assertThat(result).isCompletedExceptionally();
    Throwable ex = catchThrowable(result::get);
    assertThat(ex).isInstanceOf(ExecutionException.class);
    assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class).hasMessage("Received a request with null request.getMethod(). This should never happen.");
}
Also used : Executor(java.util.concurrent.Executor) Matcher(com.nike.riposte.util.Matcher) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DownstreamRequestFirstChunkInfo(com.nike.riposte.server.http.ProxyRouterEndpoint.DownstreamRequestFirstChunkInfo) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 13 with DownstreamRequestFirstChunkInfo

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

the class ProxyRouterEndpointExecutionHandler method getCircuitBreaker.

protected Optional<CircuitBreaker<HttpResponse>> getCircuitBreaker(DownstreamRequestFirstChunkInfo downstreamReqFirstChunkInfo, ChannelHandlerContext ctx) {
    if (downstreamReqFirstChunkInfo == null || downstreamReqFirstChunkInfo.disableCircuitBreaker)
        return Optional.empty();
    // custom one is not specified.
    if (downstreamReqFirstChunkInfo.customCircuitBreaker.isPresent())
        return downstreamReqFirstChunkInfo.customCircuitBreaker;
    // No custom circuit breaker. Use the default for the given request's host.
    EventLoop nettyEventLoop = ctx.channel().eventLoop();
    CircuitBreaker<Integer> defaultStatusCodeCircuitBreaker = getDefaultHttpStatusCodeCircuitBreakerForKey(downstreamReqFirstChunkInfo.host, Optional.ofNullable(nettyEventLoop), Optional.ofNullable(nettyEventLoop));
    return Optional.of(new CircuitBreakerDelegate<>(defaultStatusCodeCircuitBreaker, httpResponse -> (httpResponse == null ? null : httpResponse.status().code())));
}
Also used : Span(com.nike.wingtips.Span) LoggerFactory(org.slf4j.LoggerFactory) ResponseInfo(com.nike.riposte.server.http.ResponseInfo) HttpObject(io.netty.handler.codec.http.HttpObject) ProxyRouterEndpoint(com.nike.riposte.server.http.ProxyRouterEndpoint) Map(java.util.Map) HttpRequest(io.netty.handler.codec.http.HttpRequest) CompletionException(java.util.concurrent.CompletionException) EventLoop(io.netty.channel.EventLoop) DownstreamRequestFirstChunkInfo(com.nike.riposte.server.http.ProxyRouterEndpoint.DownstreamRequestFirstChunkInfo) BaseInboundHandlerWithTracingAndMdcSupport(com.nike.riposte.server.handler.base.BaseInboundHandlerWithTracingAndMdcSupport) Endpoint(com.nike.riposte.server.http.Endpoint) HttpUtils(com.nike.riposte.util.HttpUtils) StreamingChannel(com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient.StreamingChannel) ChannelAttributes(com.nike.riposte.server.channelpipeline.ChannelAttributes) CircuitBreaker(com.nike.fastbreak.CircuitBreaker) RiposteInternalRequestInfo(com.nike.riposte.server.http.impl.RiposteInternalRequestInfo) Optional(java.util.Optional) HttpResponse(io.netty.handler.codec.http.HttpResponse) StreamingCallback(com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient.StreamingCallback) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) EventExecutor(io.netty.util.concurrent.EventExecutor) RequestInfo(com.nike.riposte.server.http.RequestInfo) CircuitBreakerDelegate(com.nike.fastbreak.CircuitBreakerDelegate) ManualModeTask(com.nike.fastbreak.CircuitBreaker.ManualModeTask) CompletableFuture(java.util.concurrent.CompletableFuture) StreamingAsyncHttpClient(com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Deque(java.util.Deque) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) AsyncNettyHelper(com.nike.riposte.util.AsyncNettyHelper) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpContent(io.netty.handler.codec.http.HttpContent) Attribute(io.netty.util.Attribute) OutboundMessageSendHeadersChunkFromResponseInfo(com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) AsyncNettyHelper.executeOnlyIfChannelIsActive(com.nike.riposte.util.AsyncNettyHelper.executeOnlyIfChannelIsActive) CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(com.nike.fastbreak.CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey) AsyncNettyHelper.functionWithTracingAndMdc(com.nike.riposte.util.AsyncNettyHelper.functionWithTracingAndMdc) ChannelFuture(io.netty.channel.ChannelFuture) ExecutionException(java.util.concurrent.ExecutionException) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) WrapperException(com.nike.backstopper.exception.WrapperException) OutboundMessageSendContentChunk(com.nike.riposte.server.channelpipeline.message.OutboundMessageSendContentChunk) DistributedTracingConfig(com.nike.riposte.server.config.distributedtracing.DistributedTracingConfig) AsyncNettyHelper.runnableWithTracingAndMdc(com.nike.riposte.util.AsyncNettyHelper.runnableWithTracingAndMdc) LastOutboundMessageSendLastContentChunk(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendLastContentChunk) Pair(com.nike.internal.util.Pair) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) EventLoop(io.netty.channel.EventLoop)

Aggregations

DownstreamRequestFirstChunkInfo (com.nike.riposte.server.http.ProxyRouterEndpoint.DownstreamRequestFirstChunkInfo)13 Test (org.junit.Test)8 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)5 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 WrapperException (com.nike.backstopper.exception.WrapperException)2 CircuitBreaker (com.nike.fastbreak.CircuitBreaker)2 ManualModeTask (com.nike.fastbreak.CircuitBreaker.ManualModeTask)2 CircuitBreakerDelegate (com.nike.fastbreak.CircuitBreakerDelegate)2 CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey (com.nike.fastbreak.CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey)2 Pair (com.nike.internal.util.Pair)2 StreamingAsyncHttpClient (com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient)2 StreamingCallback (com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient.StreamingCallback)2 StreamingChannel (com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient.StreamingChannel)2 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 LastOutboundMessageSendLastContentChunk (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendLastContentChunk)2 OutboundMessageSendContentChunk (com.nike.riposte.server.channelpipeline.message.OutboundMessageSendContentChunk)2 OutboundMessageSendHeadersChunkFromResponseInfo (com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo)2 DistributedTracingConfig (com.nike.riposte.server.config.distributedtracing.DistributedTracingConfig)2