Search in sources :

Example 1 with RequestStatsCollector

use of com.hotels.styx.server.RequestStatsCollector in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method updatesRequestsOngoingCountOnChannelReadEvent.

@Test
public void updatesRequestsOngoingCountOnChannelReadEvent() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler pipelineHandler = handlerWithMocks(doNotRespondHandler).responseEnhancer(DO_NOT_MODIFY_RESPONSE).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    pipelineHandler.channelActive(ctx);
    pipelineHandler.channelRead0(ctx, get("/foo").build());
    assertThat(requestOutstandingValue(registry), is(1.0));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with RequestStatsCollector

use of com.hotels.styx.server.RequestStatsCollector in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method decrementsRequestsOngoingOnExceptionCaught.

@Test
public void decrementsRequestsOngoingOnExceptionCaught() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler adapter = handlerWithMocks(doNotRespondHandler).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    adapter.channelActive(ctx);
    LiveHttpRequest request = get("/foo").build();
    adapter.channelRead0(ctx, request);
    assertThat(requestOutstandingValue(registry), is(1.0));
    adapter.exceptionCaught(ctx, new Throwable("Exception"));
    assertThat(requestOutstandingValue(registry), is(0.0));
    adapter.channelInactive(ctx);
    assertThat(requestOutstandingValue(registry), is(0.0));
    verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with RequestStatsCollector

use of com.hotels.styx.server.RequestStatsCollector in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method decrementsRequestsOngoingCountOnChannelInactiveWhenRequestIsOngoing.

@Test
public void decrementsRequestsOngoingCountOnChannelInactiveWhenRequestIsOngoing() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler adapter = handlerWithMocks(doNotRespondHandler).responseEnhancer(DO_NOT_MODIFY_RESPONSE).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    adapter.channelActive(ctx);
    adapter.channelRead0(ctx, get("/foo").build());
    assertThat(requestOutstandingValue(registry), is(1.0));
    adapter.channelInactive(ctx);
    assertThat(requestOutstandingValue(registry), is(0.0));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MeterRegistry (com.hotels.styx.api.MeterRegistry)3 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)3 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)3 RequestStatsCollector (com.hotels.styx.server.RequestStatsCollector)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Test (org.junit.jupiter.api.Test)3 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1