use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testIntsCount.
/**
* A parallel sized stream of ints generates the given number of values
*/
public void testIntsCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.ints(size).parallel().forEach(new IntConsumer() {
@Override
public void accept(int x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).forEach(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).parallel().forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).parallel().forEach(new IntConsumer() {
@Override
public void accept(int x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testDoublesCount.
/**
* A parallel sized stream of doubles generates the given number of values
*/
public void testDoublesCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.doubles(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
Aggregations