use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy 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.DefaultMetricNamingStrategy in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method metricNamingStrategy_defaultNoPrefixImpl_method_works_as_expected.
@Test
public void metricNamingStrategy_defaultNoPrefixImpl_method_works_as_expected() {
// when
MetricNamingStrategy result = MetricNamingStrategy.defaultNoPrefixImpl();
// then
assertThat(result).isInstanceOf(DefaultMetricNamingStrategy.class);
DefaultMetricNamingStrategy defStrat = (DefaultMetricNamingStrategy) result;
assertThat(defStrat.prefix).isEqualTo(null);
assertThat(defStrat.wordDelimiter).isEqualTo(DEFAULT_WORD_DELIMITER);
}
use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method assertNamingStrategyIsDefault.
private void assertNamingStrategyIsDefault(MetricNamingStrategy namingStrategy, String expectedPrefix, String expectedWordDelimiter) {
assertThat(namingStrategy).isInstanceOf(DefaultMetricNamingStrategy.class);
DefaultMetricNamingStrategy defNamingStrategy = (DefaultMetricNamingStrategy) namingStrategy;
assertThat(defNamingStrategy.prefix).isEqualTo(expectedPrefix);
assertThat(defNamingStrategy.wordDelimiter).isEqualTo(expectedWordDelimiter);
}
use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method defaultMetricNamingStrategy_works_as_expected.
@DataProvider(value = { // Underscore word delimiters on the next two
"null | _ | foo_bar | single", "somePrefix | _ | somePrefix.foo_bar | somePrefix.single", // Word delimiter on the next line is a dash '-', not an underscore '_'
"null | - | foo-bar | single", "other.Prefix | weirddelimiter | other.Prefix.fooweirddelimiterbar | other.Prefix.single", " | | foobar | single", "null | null | foobar | single", "yetMorePrefix | null | yetMorePrefix.foobar | yetMorePrefix.single" }, splitBy = "\\|")
@Test
public void defaultMetricNamingStrategy_works_as_expected(String prefix, String wordDelimiter, String expectedFooBarName, String expectedSingleName) {
// given
DefaultMetricNamingStrategy<FooMetricName> strat = new DefaultMetricNamingStrategy<>(prefix, wordDelimiter);
// when
String actualFooBarName = strat.nameFor(FooMetricName.FOO_BAR);
String actualSingleName = strat.nameFor(FooMetricName.SINGLE);
// then
assertThat(actualFooBarName).isEqualTo(expectedFooBarName);
assertThat(actualSingleName).isEqualTo(expectedSingleName);
}
use of com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method metricNamingStrategy_defaultImpl_no_args_method_works_as_expected.
@Test
public void metricNamingStrategy_defaultImpl_no_args_method_works_as_expected() {
// when
MetricNamingStrategy result = MetricNamingStrategy.defaultImpl();
// then
assertThat(result).isInstanceOf(DefaultMetricNamingStrategy.class);
DefaultMetricNamingStrategy defStrat = (DefaultMetricNamingStrategy) result;
assertThat(defStrat.prefix).isEqualTo(DEFAULT_PREFIX);
assertThat(defStrat.wordDelimiter).isEqualTo(DEFAULT_WORD_DELIMITER);
}
Aggregations