use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
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;
}
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
public void testBadStreamBounds() {
ThreadLocalRandom r = ThreadLocalRandom.current();
executeAndCatchIAE(() -> r.ints(2, 1));
executeAndCatchIAE(() -> r.ints(10, 42, 42));
executeAndCatchIAE(() -> r.longs(-1L, -1L));
executeAndCatchIAE(() -> r.longs(10, 1L, -2L));
testDoubleBadOriginBound((o, b) -> r.doubles(10, o, b));
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testNextDoubleBadBound.
/**
* nextDouble(bound) throws IllegalArgumentException
*/
public void testNextDoubleBadBound() {
ThreadLocalRandom r = ThreadLocalRandom.current();
executeAndCatchIAE(() -> r.nextDouble(0.0));
executeAndCatchIAE(() -> r.nextDouble(-0.0));
executeAndCatchIAE(() -> r.nextDouble(+0.0));
executeAndCatchIAE(() -> r.nextDouble(-1.0));
executeAndCatchIAE(() -> r.nextDouble(Double.NaN));
executeAndCatchIAE(() -> r.nextDouble(Double.NEGATIVE_INFINITY));
// Returns Double.MAX_VALUE
// executeAndCatchIAE(() -> r.nextDouble(Double.POSITIVE_INFINITY));
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testUnsizedLongsCount.
/**
* A parallel unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.longs().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
Aggregations