use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method an_IllegalArgumentException_is_thrown_if_builder_is_built_with_null_CodahaleMetricsCollector.
@Test
public void an_IllegalArgumentException_is_thrown_if_builder_is_built_with_null_CodahaleMetricsCollector() {
// given
Builder builder = CodahaleMetricsListener.newBuilder(null);
// when
Throwable ex = catchThrowable(() -> builder.build());
// then
assertThat(ex).isInstanceOf(IllegalArgumentException.class);
}
use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder 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);
}
use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method builder_works_as_expected_for_default_unspecified_fields.
@Test
public void builder_works_as_expected_for_default_unspecified_fields() {
// given
setupMetricRegistryAndCodahaleMetricsCollector();
Builder builder = CodahaleMetricsListener.newBuilder(cmcMock);
// when
CodahaleMetricsListener result = builder.build();
// then
assertThat(result.metricsCollector).isSameAs(cmcMock);
assertThat(result.endpointMetricsHandler).isNotNull().isInstanceOf(EndpointMetricsHandlerDefaultImpl.class);
assertThat(result.includeServerConfigMetrics).isFalse();
assertNamingStrategyIsDefault(result.serverStatsMetricNamingStrategy, DEFAULT_PREFIX, DEFAULT_WORD_DELIMITER);
assertNamingStrategyIsDefault(result.serverConfigMetricNamingStrategy, ServerConfig.class.getSimpleName(), DEFAULT_WORD_DELIMITER);
assertThat(result.requestAndResponseSizeHistogramSupplier).isSameAs(DEFAULT_REQUEST_AND_RESPONSE_SIZE_HISTOGRAM_SUPPLIER);
assertThat(registeredGauges).isEmpty();
}
Aggregations