use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class RangeUnionIteratorTest method testRandomSequences.
@Test
public void testRandomSequences() {
ThreadLocalRandom random = ThreadLocalRandom.current();
long[][] values = new long[random.nextInt(1, 20)][];
int numTests = random.nextInt(10, 20);
for (int tests = 0; tests < numTests; tests++) {
RangeUnionIterator.Builder<Long, Token> builder = RangeUnionIterator.builder();
int totalCount = 0;
for (int i = 0; i < values.length; i++) {
long[] part = new long[random.nextInt(1, 500)];
for (int j = 0; j < part.length; j++) part[j] = random.nextLong();
// all of the parts have to be sorted to mimic SSTable
Arrays.sort(part);
values[i] = part;
builder.add(new LongIterator(part));
totalCount += part.length;
}
long[] totalOrdering = new long[totalCount];
int index = 0;
for (long[] part : values) {
for (long value : part) totalOrdering[index++] = value;
}
Arrays.sort(totalOrdering);
int count = 0;
RangeIterator<Long, Token> tokens = builder.build();
Assert.assertNotNull(tokens);
while (tokens.hasNext()) Assert.assertEquals(totalOrdering[count++], (long) tokens.next().get());
Assert.assertEquals(totalCount, count);
}
}
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);
}
Aggregations