Search in sources :

Example 1 with PNCounter

use of com.hazelcast.crdt.pncounter.PNCounter in project hazelcast by hazelcast.

the class AbstractPNCounterBasicIntegrationTest method testSimpleReplication.

@Test
public void testSimpleReplication() {
    final PNCounter counter1 = getInstance1().getPNCounter("counter");
    final PNCounter counter2 = getInstance2().getPNCounter("counter");
    assertEquals(5, counter1.addAndGet(5));
    assertCounterValueEventually(5, counter1);
    assertCounterValueEventually(5, counter2);
}
Also used : PNCounter(com.hazelcast.crdt.pncounter.PNCounter) Test(org.junit.Test)

Example 2 with PNCounter

use of com.hazelcast.crdt.pncounter.PNCounter 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)

Example 3 with PNCounter

use of com.hazelcast.crdt.pncounter.PNCounter in project hazelcast by hazelcast.

the class AbstractPNCounterNoDataMemberTest method noDataMemberExceptionIsThrown.

@Test(expected = NoDataMemberInClusterException.class)
public void noDataMemberExceptionIsThrown() {
    final PNCounter driver = getCounter();
    mutate(driver);
}
Also used : PNCounter(com.hazelcast.crdt.pncounter.PNCounter) Test(org.junit.Test)

Example 4 with PNCounter

use of com.hazelcast.crdt.pncounter.PNCounter in project hazelcast by hazelcast.

the class PNCounterSplitBrainTest method getCounter.

private PNCounter getCounter(HazelcastInstance instance) {
    final PNCounter pnCounter = instance.getPNCounter(counterName);
    ((PNCounterProxy) pnCounter).setOperationTryCount(1);
    pnCounter.reset();
    return pnCounter;
}
Also used : PNCounter(com.hazelcast.crdt.pncounter.PNCounter)

Example 5 with PNCounter

use of com.hazelcast.crdt.pncounter.PNCounter in project hazelcast by hazelcast.

the class PNCounterStatisticsSplitBrainTest method getCounter.

private PNCounter getCounter(HazelcastInstance instance) {
    final PNCounter pnCounter = instance.getPNCounter(counterName);
    ((PNCounterProxy) pnCounter).setOperationTryCount(1);
    pnCounter.reset();
    return pnCounter;
}
Also used : PNCounter(com.hazelcast.crdt.pncounter.PNCounter)

Aggregations

PNCounter (com.hazelcast.crdt.pncounter.PNCounter)11 Test (org.junit.Test)7 Address (com.hazelcast.cluster.Address)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 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