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