Search in sources :

Example 6 with StrongTestCounter

use of org.infinispan.counter.util.StrongTestCounter in project infinispan by infinispan.

the class StrongCounterTest method testCompareAndSetMaxAndMinLong.

public void testCompareAndSetMaxAndMinLong(Method method) {
    final String counterName = method.getName();
    StrongTestCounter counter = createCounter(counterManager(0), counterName, 0);
    assertFalse(counter.compareAndSet(-1, Long.MAX_VALUE));
    assertEquals(0, counter.getValue());
    assertTrue(counter.compareAndSet(0, Long.MAX_VALUE));
    assertEquals(Long.MAX_VALUE, counter.getValue());
    counter.reset();
    assertFalse(counter.compareAndSet(-1, Long.MIN_VALUE));
    assertEquals(0, counter.getValue());
    assertTrue(counter.compareAndSet(0, Long.MIN_VALUE));
    assertEquals(Long.MIN_VALUE, counter.getValue());
}
Also used : StrongTestCounter(org.infinispan.counter.util.StrongTestCounter)

Example 7 with StrongTestCounter

use of org.infinispan.counter.util.StrongTestCounter in project infinispan by infinispan.

the class StrongCounterTest method testCompareAndSwapMaxAndMinLong.

public void testCompareAndSwapMaxAndMinLong(Method method) {
    final String counterName = method.getName();
    StrongTestCounter counter = createCounter(counterManager(0), counterName, 0);
    assertEquals(0, counter.compareAndSwap(-1, Long.MAX_VALUE));
    assertEquals(0, counter.getValue());
    assertEquals(0, counter.compareAndSwap(0, Long.MAX_VALUE));
    assertEquals(Long.MAX_VALUE, counter.getValue());
    counter.reset();
    assertEquals(0, counter.compareAndSwap(-1, Long.MIN_VALUE));
    assertEquals(0, counter.getValue());
    assertEquals(0, counter.compareAndSwap(0, Long.MIN_VALUE));
    assertEquals(Long.MIN_VALUE, counter.getValue());
}
Also used : StrongTestCounter(org.infinispan.counter.util.StrongTestCounter)

Example 8 with StrongTestCounter

use of org.infinispan.counter.util.StrongTestCounter in project infinispan by infinispan.

the class StrongCounterTest method testCompareAndSet.

public void testCompareAndSet(Method method) {
    final String counterName = method.getName();
    TestContext context = new TestContext();
    context.printSeed(counterName);
    long expect = context.random.nextLong();
    long value = context.random.nextLong();
    StrongTestCounter counter = createCounter(counterManager(0), counterName, expect);
    for (int i = 0; i < 10; ++i) {
        assertTrue(counter.compareAndSet(expect, value));
        assertEquals(value, counter.getValue());
        expect = value;
        value = context.random.nextLong();
    }
    for (int i = 0; i < 10; ++i) {
        long notExpected = context.random.nextLong();
        while (expect == notExpected) {
            notExpected = context.random.nextLong();
        }
        assertFalse(counter.compareAndSet(notExpected, value));
        assertEquals(expect, counter.getValue());
    }
}
Also used : StrongTestCounter(org.infinispan.counter.util.StrongTestCounter)

Aggregations

StrongTestCounter (org.infinispan.counter.util.StrongTestCounter)8 CounterManager (org.infinispan.counter.api.CounterManager)4 ArrayList (java.util.ArrayList)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 Future (java.util.concurrent.Future)3 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.testng.annotations.Test)1