Search in sources :

Example 31 with ThreadLocalRandom

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);
    }
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Token(org.apache.cassandra.index.sasi.disk.Token) Test(org.junit.Test)

Example 32 with ThreadLocalRandom

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;
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 33 with ThreadLocalRandom

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));
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 34 with ThreadLocalRandom

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));
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 35 with ThreadLocalRandom

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);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Aggregations

ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)186 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 Ignite (org.apache.ignite.Ignite)47 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)45 IgniteCache (org.apache.ignite.IgniteCache)33 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)26 IgniteException (org.apache.ignite.IgniteException)26 Transaction (org.apache.ignite.transactions.Transaction)24 CacheException (javax.cache.CacheException)21 HashMap (java.util.HashMap)16 Map (java.util.Map)15 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 TreeMap (java.util.TreeMap)11 Callable (java.util.concurrent.Callable)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 LongAdder (java.util.concurrent.atomic.LongAdder)9 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)9