mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#1586 - ENH: Add TimedMetric.addSinceNanos() ... as a helper when using start nanos
This commit is contained in:
1 parent
58f6c67d78
commit
0377e3ec5c
7 files changed
+76
-2
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.MetricType;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DTimedMetricMapTest {
|
||||
|
||||
@Test
|
||||
public void addSinceNanos() throws InterruptedException {
|
||||
|
||||
DTimedMetricMap metricMap = new DTimedMetricMap(MetricType.L2, "addSinceNanos");
|
||||
|
||||
long nanos = System.nanoTime();
|
||||
Thread.sleep(10);
|
||||
|
||||
metricMap.addSinceNanos("some", nanos);
|
||||
|
||||
BasicMetricVisitor visitor = new BasicMetricVisitor();
|
||||
metricMap.visit(visitor);
|
||||
|
||||
MetaTimedMetric timedMetric = visitor.getTimedMetrics().get(0);
|
||||
assertThat(timedMetric.getCount()).isEqualTo(1);
|
||||
assertThat(timedMetric.getTotal()).isGreaterThan(10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.meta.MetricType;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DTimedMetricTest {
|
||||
|
||||
@Test
|
||||
public void addSinceNanos() throws InterruptedException {
|
||||
|
||||
DTimedMetric metric = new DTimedMetric(MetricType.L2, "addSinceNanos");
|
||||
|
||||
long start = System.nanoTime();
|
||||
Thread.sleep(10);
|
||||
|
||||
metric.addSinceNanos(start);
|
||||
|
||||
DTimeMetricStats stats = metric.collect(true);
|
||||
assertThat(stats.getCount()).isEqualTo(1);
|
||||
assertThat(stats.getTotal()).isGreaterThan(10);
|
||||
assertThat(stats.getMax()).isEqualTo(stats.getTotal());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user