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());
}
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());
}
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());
}
}
Aggregations