use of com.hazelcast.internal.monitor.LocalPNCounterStats in project hazelcast by hazelcast.
the class AbstractPNCounterBasicIntegrationTest method statistics.
@Test
public void statistics() {
final PNCounter counter1 = getInstance1().getPNCounter("counterWithStats");
final PNCounter counter2 = getInstance2().getPNCounter("counterWithStats");
final int parallelism = 5;
final int loopsPerThread = 100;
final AtomicLong finalValue = new AtomicLong();
final ArrayList<Future> futures = new ArrayList<Future>(parallelism);
for (int i = 0; i < parallelism; i++) {
futures.add(spawn(new Runnable() {
@Override
public void run() {
for (int j = 0; j < loopsPerThread; j++) {
counter1.addAndGet(5);
finalValue.addAndGet(5);
counter2.addAndGet(-2);
finalValue.addAndGet(-2);
}
}
}));
}
FutureUtil.waitForever(futures);
assertCounterValueEventually(finalValue.longValue(), counter1);
assertCounterValueEventually(finalValue.longValue(), counter2);
int increments = 0;
int decrements = 0;
for (HazelcastInstance member : getMembers()) {
final PNCounterService service = getNodeEngineImpl(member).getService(PNCounterService.SERVICE_NAME);
for (LocalPNCounterStats stats : service.getStats().values()) {
increments += stats.getTotalIncrementOperationCount();
decrements += stats.getTotalDecrementOperationCount();
}
}
assertEquals(parallelism * loopsPerThread, increments);
assertEquals(parallelism * loopsPerThread, decrements);
}
Aggregations