Search in sources :

Example 1 with DefaultMetricNamingStrategy

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

Example 2 with DefaultMetricNamingStrategy

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);
}
Also used : DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) MetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.MetricNamingStrategy) DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) Test(org.junit.Test)

Example 3 with DefaultMetricNamingStrategy

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);
}
Also used : DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy)

Example 4 with DefaultMetricNamingStrategy

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);
}
Also used : DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) Matchers.anyString(org.mockito.Matchers.anyString) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 5 with DefaultMetricNamingStrategy

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);
}
Also used : DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) MetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.MetricNamingStrategy) DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) Test(org.junit.Test)

Aggregations

DefaultMetricNamingStrategy (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy)7 Test (org.junit.Test)5 MetricNamingStrategy (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.MetricNamingStrategy)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Histogram (com.codahale.metrics.Histogram)1 Builder (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder)1 ServerConfigMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames)1 ServerStatisticsMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames)1