Search in sources :

Example 1 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class LongAdderTest method testIntValue.

/**
 * intValue returns current value.
 */
public void testIntValue() {
    LongAdder ai = new LongAdder();
    assertEquals(0, ai.intValue());
    ai.increment();
    assertEquals(1, ai.intValue());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 2 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class LongAdderTest method testConstructor.

/**
 * default constructed initializes to zero
 */
public void testConstructor() {
    LongAdder ai = new LongAdder();
    assertEquals(0, ai.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 3 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class LongAdderTest method testReset.

/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    LongAdder ai = new LongAdder();
    ai.add(2);
    assertEquals(2, ai.sum());
    ai.reset();
    assertEquals(0, ai.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 4 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class LongAdderTest method testDecrementAndSum.

/**
 * decrement decrements and sum returns current value
 */
public void testDecrementAndSum() {
    LongAdder ai = new LongAdder();
    ai.decrement();
    assertEquals(-1, ai.sum());
    ai.decrement();
    assertEquals(-2, ai.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 5 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class LongAdderTest method testSerialization.

/**
 * a deserialized/reserialized adder holds same value
 */
public void testSerialization() throws Exception {
    LongAdder x = new LongAdder();
    LongAdder y = serialClone(x);
    assertNotSame(x, y);
    x.add(-22);
    LongAdder z = serialClone(x);
    assertNotSame(y, z);
    assertEquals(-22, x.sum());
    assertEquals(0, y.sum());
    assertEquals(-22, z.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)50 SplittableRandom (java8.util.SplittableRandom)18 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)18 DoubleConsumer (java8.util.function.DoubleConsumer)3 IntConsumer (java8.util.function.IntConsumer)3 LongConsumer (java8.util.function.LongConsumer)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1