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