use of org.apache.commons.math3.stat.descriptive.SynchronizedSummaryStatistics in project xian by happyyangyuan.
the class TestDistributedAtomicLong method testSimulation.
@Test
public void testSimulation() throws Exception {
final int threadQty = 20;
final int executionQty = 50;
final AtomicInteger optimisticTries = new AtomicInteger();
final AtomicInteger promotedLockTries = new AtomicInteger();
final AtomicInteger failures = new AtomicInteger();
final AtomicInteger errors = new AtomicInteger();
final SummaryStatistics timingStats = new SynchronizedSummaryStatistics();
List<Future<Void>> procs = Lists.newArrayList();
ExecutorService executorService = Executors.newFixedThreadPool(threadQty);
for (int i = 0; i < threadQty; ++i) {
Callable<Void> proc = new Callable<Void>() {
@Override
public Void call() throws Exception {
doSimulation(executionQty, timingStats, optimisticTries, promotedLockTries, failures, errors);
return null;
}
};
procs.add(executorService.submit(proc));
}
for (Future<Void> f : procs) {
f.get();
}
System.out.println("OptimisticTries: " + optimisticTries.get());
System.out.println("PromotedLockTries: " + promotedLockTries.get());
System.out.println("Failures: " + failures.get());
System.out.println("Errors: " + errors.get());
System.out.println();
System.out.println("Avg time: " + timingStats.getMean());
System.out.println("Max time: " + timingStats.getMax());
System.out.println("Min time: " + timingStats.getMin());
System.out.println("Qty: " + timingStats.getN());
Assert.assertEquals(errors.get(), 0);
Assert.assertTrue(optimisticTries.get() > 0);
Assert.assertTrue(promotedLockTries.get() > 0);
}
Aggregations