@Test @InSequence(3) public void removeTest() { metrics.remove("nameTest"); Assert.assertFalse(metrics.getNames().contains("nameTest")); }
@Test @InSequence(4) public void removeTimerFromRegistry() { assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Remove the timer from metrics registry registry.remove(TIMER_NAME); try { // Call the timed method and assert an exception is thrown bean.timedMethod(); } catch (RuntimeException cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No timer with name [" + TIMER_NAME + "] found in registry [" + registry + "]"))); // Make sure that the timer hasn't been called assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); } }
@Test @InSequence(3) public void removeMeterFromRegistry() { assertThat("Meter is not registered correctly", registry.getMeters(), hasKey(METER_NAME)); Meter meter = registry.getMeters().get(METER_NAME); // Remove the meter from metrics registry registry.remove(METER_NAME); try { // Call the metered method and assert an exception is thrown bean.meteredMethod(); } catch (RuntimeException cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No meter with name [" + METER_NAME + "] found in registry [" + registry + "]"))); // Make sure that the meter hasn't been marked assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(METER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); } }
@Test @InSequence(3) public void removeTimerFromRegistry() { // Get a contextual instance of the bean TimedMethodBean1 bean = instance.get(); assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME)); Timer timer = registry.getTimers().get(TIMER_NAME); // Remove the timer from metrics registry registry.remove(TIMER_NAME); try { // Call the timed method and assert an exception is thrown bean.timedMethod(); } catch (RuntimeException cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No timer with name [" + TIMER_NAME + "] found in registry [" + registry + "]"))); // Make sure that the timer hasn't been called assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); } }
@Test @InSequence(4) public void removeCounterFromRegistry() { assertThat("Counter is not registered correctly", registry.getCounters(), hasKey(COUNTER_NAME)); Counter counter = registry.getCounters().get(COUNTER_NAME); // Remove the counter from metrics registry registry.remove(COUNTER_NAME); try { // Call the counted method and assert an exception is thrown bean.countedMethod(new Callable<Long>() { @Override public Long call() throws Exception { return null; } }); } catch (Exception cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No counter with name [" + COUNTER_NAME + "] found in registry [" + registry + "]"))); // Make sure that the counter hasn't been called assertThat("Counter count is incorrect", counter.getCount(), is(equalTo(COUNTER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); } }
@Test @InSequence(4) public void removeMonotonicCounterFromRegistry() { assertThat("Counter is not registered correctly", registry.getCounters(), hasKey(COUNTER_NAME)); Counter counter = registry.getCounters().get(COUNTER_NAME); // Remove the counter from metrics registry registry.remove(COUNTER_NAME); try { // Call the counted method and assert an exception is thrown bean.monotonicCountedMethod(new Callable<Long>() { @Override public Long call() throws Exception { return null; } }); } catch (Exception cause) { assertThat(cause, is(Matchers.<Exception>instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No counter with name [" + COUNTER_NAME + "] found in registry [" + registry + "]"))); // Make sure that the counter hasn't been called assertThat("Counter count is incorrect", counter.getCount(), is(equalTo(COUNTER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); } }