use of org.HdrHistogram.ConcurrentHistogram in project jcog by dumbai.
the class HashedWheelTimerTest method fixedDelaySubsequentFireTest.
private void fixedDelaySubsequentFireTest(int periodMS, int count, boolean fixedDelayOrRate) throws InterruptedException {
int warmup = count / 2;
CountDownLatch latch = new CountDownLatch(count + warmup);
Histogram when = new ConcurrentHistogram(1_000L, /* 1 uS */
1_000_000_000L * 2, /* 2 Sec */
5);
long start = System.nanoTime();
long[] last = { start };
Runnable task = () -> {
long now = System.nanoTime();
if (latch.getCount() < count)
when.recordValue(now - last[0]);
last[0] = now;
latch.countDown();
};
if (fixedDelayOrRate) {
timer.scheduleWithFixedDelay(task, 0, periodMS, TimeUnit.MILLISECONDS);
} else {
timer.scheduleAtFixedRate(task, 0, periodMS, TimeUnit.MILLISECONDS);
}
assertTrue(latch.await(count * periodMS * 3, TimeUnit.MILLISECONDS), () -> latch.getCount() + " should be zero");
assertTrue(1 >= timer.size(), () -> timer.size() + " tasks in wheel");
{
Histogram w = when.copy();
Str.histogramPrint(w, System.out);
// System.out.println("mean=" + Texts.timeStr(w.getMean()));
// System.out.println("max=" + Texts.timeStr(w.getMaxValue()));
long delayNS = TimeUnit.MILLISECONDS.toNanos(periodMS);
double err = Math.abs(delayNS - w.getMean());
assertTrue(err < delayNS / 4.0);
}
}
Aggregations