Search in sources :

Example 1 with SignalFxReporter

use of com.signalfx.codahale.reporter.SignalFxReporter in project riposte by Nike-Inc.

the class SignalFxReporterFactoryTest method getReporter_passes_properly_configured_builder_to_reporterConfigurator_and_builds_the_result_of_reporterConfigurator.

@Test
public void getReporter_passes_properly_configured_builder_to_reporterConfigurator_and_builds_the_result_of_reporterConfigurator() {
    // when
    SignalFxReporter result = factory.getReporter(metricRegistryMock);
    // then
    // Make sure the configurator function received a properly configured builder.
    ArgumentCaptor<Builder> origBuilderArgCaptor = ArgumentCaptor.forClass(Builder.class);
    verify(configuratorMock).apply(origBuilderArgCaptor.capture());
    Builder origBuilder = origBuilderArgCaptor.getValue();
    assertThat(getInternalState(origBuilder, "registry")).isSameAs(metricRegistryMock);
    assertThat(((AuthToken) getInternalState(origBuilder, "authToken")).getAuthToken()).isEqualTo(apiKey);
    // Make sure the thing returned by the configurator was used to build the final reporter.
    assertThat(((Map<String, DimensionInclusion>) getInternalState(result, "defaultDimensions")).get(customDimKey).getValue()).isEqualTo(customDimValue);
}
Also used : DimensionInclusion(com.signalfx.codahale.reporter.DimensionInclusion) SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) Builder(com.signalfx.codahale.reporter.SignalFxReporter.Builder) AuthToken(com.signalfx.metrics.auth.AuthToken) Test(org.junit.Test)

Example 2 with SignalFxReporter

use of com.signalfx.codahale.reporter.SignalFxReporter in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method three_arg_constructor_fails_with_IllegalArgumentException_if_reportingFrequency_is_null.

@Test
public void three_arg_constructor_fails_with_IllegalArgumentException_if_reportingFrequency_is_null() {
    // given
    SignalFxReporter reporterMock = mock(SignalFxReporter.class);
    wireUpReporterForConstructor(reporterMock);
    // when
    Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterMock, null, metricRegistryMock));
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency cannot be null");
}
Also used : SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 3 with SignalFxReporter

use of com.signalfx.codahale.reporter.SignalFxReporter in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null.

@DataProvider(value = { "true   |   false", "false  |   true" }, splitBy = "\\|")
@Test
public void three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null(boolean amountIsNull, boolean timeUnitIsNull) {
    // given
    SignalFxReporter reporterMock = mock(SignalFxReporter.class);
    wireUpReporterForConstructor(reporterMock);
    Long amount = (amountIsNull) ? null : 42L;
    TimeUnit timeUnit = (timeUnitIsNull) ? null : TimeUnit.DAYS;
    // when
    Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterMock, Pair.of(amount, timeUnit), 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 : SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TimeUnit(java.util.concurrent.TimeUnit) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 4 with SignalFxReporter

use of com.signalfx.codahale.reporter.SignalFxReporter in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method wireUpReporterFactoryMockForConstructor.

private Pair<Pair<SignalFxReporter, MetricMetadata>, Pair<Long, TimeUnit>> wireUpReporterFactoryMockForConstructor(SignalFxReporterFactory factoryMock, MetricRegistry expectedMetricRegistry) {
    SignalFxReporter reporterMock = mock(SignalFxReporter.class);
    doReturn(reporterMock).when(factoryMock).getReporter(expectedMetricRegistry);
    MetricMetadata metricMetadataMock = wireUpReporterForConstructor(reporterMock);
    long reportingInterval = 42;
    TimeUnit reportingTimeUnit = TimeUnit.DAYS;
    doReturn(reportingInterval).when(factoryMock).getInterval();
    doReturn(reportingTimeUnit).when(factoryMock).getTimeUnit();
    return Pair.of(Pair.of(reporterMock, metricMetadataMock), Pair.of(reportingInterval, reportingTimeUnit));
}
Also used : MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) TimeUnit(java.util.concurrent.TimeUnit)

Example 5 with SignalFxReporter

use of com.signalfx.codahale.reporter.SignalFxReporter in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method three_arg_constructor_sets_fields_as_expected.

@Test
public void three_arg_constructor_sets_fields_as_expected() {
    // given
    SignalFxReporter reporterMock = mock(SignalFxReporter.class);
    MetricMetadata expectedMetricMetadata = wireUpReporterForConstructor(reporterMock);
    Pair<Long, TimeUnit> reportingFrequency = Pair.of(42L, TimeUnit.DAYS);
    // when
    SignalFxEndpointMetricsHandler instance = new SignalFxEndpointMetricsHandler(reporterMock, reportingFrequency, 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(reportingFrequency.getLeft());
    assertThat(rwtb.timeUnit).isEqualTo(reportingFrequency.getRight());
    assertThat(instance.requestTimerDimensionConfigurator).isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR);
}
Also used : MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TimeUnit(java.util.concurrent.TimeUnit) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Test(org.junit.Test)

Aggregations

SignalFxReporter (com.signalfx.codahale.reporter.SignalFxReporter)7 Test (org.junit.Test)6 TimeUnit (java.util.concurrent.TimeUnit)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 MetricMetadata (com.signalfx.codahale.reporter.MetricMetadata)2 Builder (com.signalfx.codahale.reporter.SignalFxReporter.Builder)2 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 RollingWindowTimerBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder)1 DimensionInclusion (com.signalfx.codahale.reporter.DimensionInclusion)1 AuthToken (com.signalfx.metrics.auth.AuthToken)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1