Search in sources :

Example 1 with RollingWindowHistogramBuilder

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
    // when
    Histogram histogram = rwhb.newMetric();
    // then
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 2 with RollingWindowHistogramBuilder

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_isInstance_works_as_expected.

@DataProvider(value = { "true   |   true", "false  |   false" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_isInstance_works_as_expected(boolean useHistogram, boolean expectedResult) {
    // given
    Metric metric = (useHistogram) ? mock(Histogram.class) : mock(Gauge.class);
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(42, TimeUnit.DAYS);
    // when
    boolean result = rwhb.isInstance(metric);
    // then
    assertThat(result).isEqualTo(expectedResult);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Metric(com.codahale.metrics.Metric) Gauge(com.codahale.metrics.Gauge) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 3 with RollingWindowHistogramBuilder

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_a_new_histogram_with_each_call.

@Test
public void RollingWindowHistogramBuilder_newMetric_creates_a_new_histogram_with_each_call() {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(42, TimeUnit.DAYS);
    // when
    Histogram firstCallHistogram = rwhb.newMetric();
    Histogram secondCallHistogram = rwhb.newMetric();
    // then
    assertThat(firstCallHistogram).isNotSameAs(secondCallHistogram);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Test(org.junit.Test)

Example 4 with RollingWindowHistogramBuilder

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_constructor_sets_fields_as_expected.

@Test
public void RollingWindowHistogramBuilder_constructor_sets_fields_as_expected() {
    // given
    long amount = 42;
    TimeUnit timeUnit = TimeUnit.DAYS;
    // when
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
    // then
    assertThat(rwhb.amount).isEqualTo(amount);
    assertThat(rwhb.timeUnit).isEqualTo(timeUnit);
}
Also used : RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 5 with RollingWindowHistogramBuilder

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowArrayReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowArrayReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
    // when
    Histogram histogram = rwhb.newMetric();
    // then
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowArrayReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowArrayReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowArrayReservoir(com.codahale.metrics.SlidingTimeWindowArrayReservoir) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

RollingWindowHistogramBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder)5 Test (org.junit.Test)5 Histogram (com.codahale.metrics.Histogram)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 Reservoir (com.codahale.metrics.Reservoir)2 Gauge (com.codahale.metrics.Gauge)1 Metric (com.codahale.metrics.Metric)1 SlidingTimeWindowArrayReservoir (com.codahale.metrics.SlidingTimeWindowArrayReservoir)1 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)1 TimeUnit (java.util.concurrent.TimeUnit)1