Java Code Examples for org.eclipse.microprofile.metrics.Timer#time()

The following examples show how to use org.eclipse.microprofile.metrics.Timer#time() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(4)
public void timesCallableInstances() throws Exception {
    Timer timer = registry.timer("testCallable");
    final String value = timer.time(() -> "one");

    Assert.assertEquals(timer.getCount(), 1);

    Assert.assertEquals(value, "one");
}
 
Example 2
Source File: TimerTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(5)
public void timesRunnableInstances() throws Exception {
    Timer timer = registry.timer("testRunnable");
    final AtomicBoolean called = new AtomicBoolean();
    timer.time(() -> called.set(true));

    Assert.assertEquals(timer.getCount(), 1);

    Assert.assertEquals(called.get(), true);
}
 
Example 3
Source File: MetricAppBean.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
public void timeMe() {

        Timer timer = metrics.timer("metricTest.test1.timer");

        Timer.Context context = timer.time();
        try {
            Thread.sleep((long) (Math.random() * 1000));
        }
        catch (InterruptedException e) {
        } finally {
            context.stop();
        }

    }