Search in sources :

Example 1 with LocalPNCounterStats

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);
}
Also used : PNCounter(com.hazelcast.crdt.pncounter.PNCounter) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) LocalPNCounterStats(com.hazelcast.internal.monitor.LocalPNCounterStats) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 PNCounter (com.hazelcast.crdt.pncounter.PNCounter)1 LocalPNCounterStats (com.hazelcast.internal.monitor.LocalPNCounterStats)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1