/** * Get or create a new timer. * * @param name * @return */ public Timer getTimer(String name) { return factory.getTimer(base, name); }
/** * Get or create a new timer. * * @param name * @return */ public Timer getTimer(String name) { return factory.getTimer(base, name); }
/** Start timing the processing of a document */ public void startDocumentProcess() { finishDocumentProcess(); // Check we've finished the timing of the previous document documentTimerContext = MetricsFactory.getInstance().getTimer(pipelineName, DOCUMENT_TIMER).time(); }
/** Start timing the processing of a document */ public void startDocumentProcess() { finishDocumentProcess(); // Check we've finished the timing of the previous document documentTimerContext = MetricsFactory.getInstance().getTimer(pipelineName, DOCUMENT_TIMER).time(); }
@Test public void testGetTimer() { Timer a = metrics.getTimer(MetricsFactoryTest.class, "a"); assertNotNull(a); assertSame(a, metrics.getTimer(MetricsFactoryTest.class, "a")); assertNotEquals(a, metrics.getTimer(MetricsFactoryTest.class, "b")); Timer b = metrics.getTimer(MetricsFactoryTest.class.getCanonicalName(), "b"); assertNotNull(b); assertSame(b, metrics.getTimer(MetricsFactoryTest.class.getCanonicalName(), "b")); assertNotEquals(b, metrics.getTimer(MetricsFactoryTest.class.getCanonicalName(), "c")); }
@Test public void testGetTimer() { metrics.getTimer("timer"); verify(factory).getTimer(anyString(), eq("timer")); }
@Test public void testRemove() { metrics.getCounter(MetricsFactoryTest.class, "removeC"); metrics.getTimer(MetricsFactoryTest.class, "removeT"); metrics.getHistogram(MetricsFactoryTest.class, "removeH"); metrics.getMeter(MetricsFactoryTest.class, "removeM"); assertFalse(metrics.getRegistry().getMetrics().isEmpty()); metrics.removeAll(); assertTrue(metrics.getRegistry().getMetrics().isEmpty()); }
@Test public void test() throws Exception { PipelineMetrics pm = MetricsFactory.getInstance().getPipelineMetrics(PIPELINE_NAME); assertEquals(PIPELINE_NAME, pm.getPipelineName()); pm.startDocumentProcess(); Thread.sleep(10); pm.finishDocumentProcess(); Timer t = MetricsFactory.getInstance().getTimer(PIPELINE_NAME, "documentProcessingTime"); assertEquals(1, t.getCount()); assertTrue(t.getMeanRate() > 0); assertEquals(pm, MetricsFactory.getInstance().getPipelineMetrics(PIPELINE_NAME)); } }
@Test public void testDoesntCrash() { MetricsFactory factory = MetricsFactory.getInstance(); factory.getRegistry().addListener(new LoggingMetricListener()); assertNotNull(factory.getCounter(LoggingMetricListenerTest.class, "a")); assertNotNull(factory.getHistogram(LoggingMetricListenerTest.class, "b")); assertNotNull(factory.getMeter(LoggingMetricListenerTest.class, "c")); assertNotNull(factory.getTimer(LoggingMetricListenerTest.class, "d")); factory.removeAll(); }