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.");
}
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.");
}
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())));
}
Aggregations