Search in sources :

Example 1 with Builder

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);
}
Also used : Builder(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 2 with Builder

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);
}
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 3 with Builder

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

Aggregations

Builder (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder)3 Test (org.junit.Test)3 Histogram (com.codahale.metrics.Histogram)1 DefaultMetricNamingStrategy (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy)1 ServerConfigMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames)1 ServerStatisticsMetricNames (com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames)1 ServerConfig (com.nike.riposte.server.config.ServerConfig)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1