Search in sources :

Example 1 with SignalFxReporterFactory

use of com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method two_arg_constructor_sets_fields_as_expected.

@Test
public void two_arg_constructor_sets_fields_as_expected() {
    // given
    SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class);
    Pair<Pair<SignalFxReporter, MetricMetadata>, Pair<Long, TimeUnit>> wiredUpMocksAndData = wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock);
    MetricMetadata expectedMetricMetadata = wiredUpMocksAndData.getLeft().getRight();
    long expectedReportingInterval = wiredUpMocksAndData.getRight().getLeft();
    TimeUnit expectedReportingTimeUnit = wiredUpMocksAndData.getRight().getRight();
    // when
    SignalFxEndpointMetricsHandler instance = new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock);
    // then
    assertThat(instance.metricMetadata).isSameAs(expectedMetricMetadata);
    assertThat(instance.metricRegistry).isSameAs(metricRegistryMock);
    assertThat(instance.requestTimerBuilder).isInstanceOf(RollingWindowTimerBuilder.class);
    RollingWindowTimerBuilder rwtb = (RollingWindowTimerBuilder) instance.requestTimerBuilder;
    assertThat(rwtb.amount).isEqualTo(expectedReportingInterval);
    assertThat(rwtb.timeUnit).isEqualTo(expectedReportingTimeUnit);
    assertThat(instance.requestTimerDimensionConfigurator).isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR);
}
Also used : MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) SignalFxReporterFactory(com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory) TimeUnit(java.util.concurrent.TimeUnit) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Pair(com.nike.internal.util.Pair) Test(org.junit.Test)

Example 2 with SignalFxReporterFactory

use of com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method two_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null.

@DataProvider(value = { "true   |   false", "false  |   true" }, splitBy = "\\|")
@Test
public void two_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null(boolean amountIsNull, boolean timeUnitIsNull) {
    // given
    SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class);
    wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock);
    if (amountIsNull)
        doReturn(null).when(reporterFactoryMock).getInterval();
    if (timeUnitIsNull)
        doReturn(null).when(reporterFactoryMock).getTimeUnit();
    // when
    Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock));
    // then
    if (amountIsNull) {
        assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency amount cannot be null");
    }
    if (timeUnitIsNull) {
        assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency TimeUnit cannot be null");
    }
}
Also used : SignalFxReporterFactory(com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 3 with SignalFxReporterFactory

use of com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method two_arg_constructor_fails_with_IllegalArgumentException_if_metricRegistry_is_null.

@Test
public void two_arg_constructor_fails_with_IllegalArgumentException_if_metricRegistry_is_null() {
    // given
    SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class);
    wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock);
    // when
    Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterFactoryMock, null));
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("MetricRegistry cannot be null");
}
Also used : SignalFxReporterFactory(com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Aggregations

SignalFxReporterFactory (com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory)3 Test (org.junit.Test)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 Pair (com.nike.internal.util.Pair)1 RollingWindowTimerBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder)1 MetricMetadata (com.signalfx.codahale.reporter.MetricMetadata)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 TimeUnit (java.util.concurrent.TimeUnit)1