Search in sources :

Example 1 with ServerStatisticsMetricNames

use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method code_coverage_hoops.

@Test
public void code_coverage_hoops() {
    // jump!
    // Account for the logger.isDebugEnabled() branches.
    Logger loggerMock = mock(Logger.class);
    doReturn(false).when(loggerMock).isDebugEnabled();
    Whitebox.setInternalState(listener, "logger", loggerMock);
    listener.onEvent(ServerMetricsEvent.REQUEST_RECEIVED, null);
    listener.onEvent(ServerMetricsEvent.RESPONSE_SENT, state);
    listener.onEvent(ServerMetricsEvent.RESPONSE_WRITE_FAILED, state);
    // Exercise enums
    for (ServerStatisticsMetricNames enumValue : ServerStatisticsMetricNames.values()) {
        assertThat(ServerStatisticsMetricNames.valueOf(enumValue.name())).isEqualTo(enumValue);
    }
    for (ServerConfigMetricNames enumValue : ServerConfigMetricNames.values()) {
        assertThat(ServerConfigMetricNames.valueOf(enumValue.name())).isEqualTo(enumValue);
    }
}
Also used : ServerConfigMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames) ServerStatisticsMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 2 with ServerStatisticsMetricNames

use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method builder_works_as_expected_for_specified_fields.

@DataProvider(value = { "true   |   true", "true   |   false", "false  |   true", "false  |   false" }, splitBy = "\\|")
@Test
public void builder_works_as_expected_for_specified_fields(boolean overrideCodahaleMetricsCollector, boolean includeServerConfigMetrics) {
    // given
    setupMetricRegistryAndCodahaleMetricsCollector();
    CodahaleMetricsCollector alternateCmcMock = mock(CodahaleMetricsCollector.class);
    doReturn(metricRegistryMock).when(alternateCmcMock).getMetricRegistry();
    MetricNamingStrategy<ServerStatisticsMetricNames> statsNamingStrat = new DefaultMetricNamingStrategy<>();
    MetricNamingStrategy<ServerConfigMetricNames> configNamingStrat = new DefaultMetricNamingStrategy<>();
    Supplier<Histogram> histogramSupplier = () -> mock(Histogram.class);
    Builder builder = CodahaleMetricsListener.newBuilder(cmcMock);
    if (overrideCodahaleMetricsCollector)
        builder = builder.withMetricsCollector(alternateCmcMock);
    builder = builder.withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).withServerConfigMetricNamingStrategy(configNamingStrat).withServerStatsMetricNamingStrategy(statsNamingStrat).withRequestAndResponseSizeHistogramSupplier(histogramSupplier);
    // when
    CodahaleMetricsListener result = builder.build();
    // then
    if (overrideCodahaleMetricsCollector)
        assertThat(result.metricsCollector).isSameAs(alternateCmcMock);
    else
        assertThat(result.metricsCollector).isSameAs(cmcMock);
    assertThat(result.endpointMetricsHandler).isSameAs(endpointMetricsHandlerMock);
    assertThat(result.includeServerConfigMetrics).isEqualTo(includeServerConfigMetrics);
    assertThat(result.serverConfigMetricNamingStrategy).isSameAs(configNamingStrat);
    assertThat(result.serverStatsMetricNamingStrategy).isSameAs(statsNamingStrat);
    assertThat(result.requestAndResponseSizeHistogramSupplier).isSameAs(histogramSupplier);
}
Also used : Histogram(com.codahale.metrics.Histogram) DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) ServerConfigMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames) ServerStatisticsMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames) Builder(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

ServerConfigMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames)2 ServerStatisticsMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames)2 Test (org.junit.Test)2 Histogram (com.codahale.metrics.Histogram)1 Builder (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder)1 DefaultMetricNamingStrategy (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 Logger (org.slf4j.Logger)1