Search in sources :

Example 36 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 37 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 38 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 39 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)

Example 40 with ThreadLocalRandom

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

Aggregations

ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)236 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)73 Ignite (org.apache.ignite.Ignite)65 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)53 IgniteCache (org.apache.ignite.IgniteCache)44 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 IgniteException (org.apache.ignite.IgniteException)27 Transaction (org.apache.ignite.transactions.Transaction)26 CacheException (javax.cache.CacheException)24 HashMap (java.util.HashMap)22 Map (java.util.Map)20 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)17 LongAdder (java.util.concurrent.atomic.LongAdder)15 TreeMap (java.util.TreeMap)14 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Callable (java.util.concurrent.Callable)11 CountDownLatch (java.util.concurrent.CountDownLatch)11