@Test public void metricMethodsWithDefaultNamingConvention() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(metricNames()))); } }
@Test public void callGaugeAfterSetterCall() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey(GAUGE_NAME)); @SuppressWarnings("unchecked") Gauge<Long> gauge = registry.getGauges().get(GAUGE_NAME); // Call the setter method and assert the gauge is up-to-date long value = Math.round(Math.random() * Long.MAX_VALUE); instance.setSingleGauge(value); assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(value))); } }
@Test public void callStaticGaugeAfterSetterCall() { long value = Math.round(Math.random() * Long.MAX_VALUE); // Call the setter static method and assert the gauge is up-to-date GaugeStaticMethodWithRegistryFromString.setSingleGauge(value); assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey(GAUGE_NAME)); @SuppressWarnings("unchecked") Gauge<Long> gauge = registry.getGauges().get(GAUGE_NAME); assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(value))); } }
@Test public void gaugeCalledWithDefaultValue() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey(GAUGE_NAME)); @SuppressWarnings("unchecked") Gauge<Long> gauge = registry.getGauges().get(GAUGE_NAME); // Make sure that the gauge has the expected value assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(0L))); }
@Test public void exceptionMeteredMethodsNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that all the meters haven't been called yet assertThat("Meter counts are incorrect", registry.getMeters().values(), everyItem(Matchers.<Meter>hasProperty("count", equalTo(0L)))); }
@Test public void overloadedTimedMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that all the timers haven't been called yet assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(0L)))); }
@Test public void gaugesCalledWithDefaultValues() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauges are not registered correctly", registry.getGauges().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that the gauges have the expected values assertThat("Gauge values are incorrect", registry.getGauges().values(), everyItem(Matchers.<Gauge>hasProperty("value", equalTo(0L)))); }
@Test public void timedMethodsNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that all the timers haven't been called yet assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(0L)))); }
@Test public void timedMethodsNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that all the timers haven't been called yet assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(0L)))); }
@Test public void metricsMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(absoluteMetricNames()))); // Make sure that the metrics haven't been called yet assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName("exception")).getCount(), is(equalTo(0L))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName("meter")).getCount(), is(equalTo(0L))); assertThat("Timer count is incorrect", registry.getTimers().get(absoluteMetricName("timer")).getCount(), is(equalTo(0L))); }
@Test public void timedMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Make sure that the timer hasn't been called yet assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(0L))); }
@Test public void meteredMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Meter is not registered correctly", registry.getMeters(), hasKey(METER_NAME)); Meter meter = registry.getMeters().get(METER_NAME); // Make sure that the meter hasn't been called yet assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(0L))); }
@Test public void timedMethodNotCalledYet() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Make sure that the timer hasn't been called yet assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(0L))); }
@Test public void callOverloadedTimedMethodOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Call the timed methods and assert they've all been timed once instance.overloadedTimedMethod(); instance.overloadedTimedMethod("string"); instance.overloadedTimedMethod(new Object()); instance.overloadedTimedMethod(Arrays.asList("string1", "string2")); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }
@Test public void callMeteredMethodOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Meter is not registered correctly", registry.getMeters(), hasKey(METER_NAME)); Meter meter = registry.getMeters().get(METER_NAME); // Call the metered method and assert it's been marked instance.singleMeteredMethod(); assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(1L))); } }
@Test public void callTimedMethodOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Call the timed method and assert it's been timed instance.singleTimedMethod(); assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(1L))); } }
@Test public void callTimedMethodOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Call the timed method and assert it's been timed instance.absoluteTimedMethod(); assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(1L))); } }
@Test public void callMeteredStaticMethodOnce() { // Call the metered method and assert it's been marked MeteredStaticMethodWithRegistryFromString.singleMeteredStaticMethod(); assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timer is not registered correctly", registry.getMeters(), hasKey(METER_NAME)); Meter meter = registry.getMeters().get(METER_NAME); assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(1L))); } }
@Test public void callTimedStaticMethodsOnce() { // Call the timed methods and assert they've all been timed once TimedStaticMethodWithVisibilityModifiers.publicTimedStaticMethod(); TimedStaticMethodWithVisibilityModifiers.protectedTimedStaticMethod(); TimedStaticMethodWithVisibilityModifiers.packagePrivateTimedStaticMethod(); staticMethod("privateTimedStaticMethod").in(TimedStaticMethodWithVisibilityModifiers.class).invoke(); assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }
@Test public void callTimedMethodsOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Call the timed methods and assert they've all been timed once instance.publicTimedMethod(); instance.protectedTimedMethod(); instance.packagePrivateTimedMethod(); method("privateTimedMethod").in(instance).invoke(); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }