Search in sources :

Example 6 with Phaser

use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.

the class PhaserTest method testArrive1.

/**
 * arrive() on a registered phaser increments phase.
 */
public void testArrive1() {
    Phaser phaser = new Phaser(1);
    assertState(phaser, 0, 1, 1);
    assertEquals(0, phaser.arrive());
    assertState(phaser, 1, 1, 1);
}
Also used : Phaser(java8.util.concurrent.Phaser)

Example 7 with Phaser

use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.

the class PhaserTest method testBulkRegister3.

/**
 * Registering with a number of parties greater than or equal to 1<<16
 * throws IllegalStateException.
 */
public void testBulkRegister3() {
    assertEquals(0, new Phaser().bulkRegister((1 << 16) - 1));
    try {
        new Phaser().bulkRegister(1 << 16);
        shouldThrow();
    } catch (IllegalStateException success) {
    }
    try {
        new Phaser(2).bulkRegister((1 << 16) - 2);
        shouldThrow();
    } catch (IllegalStateException success) {
    }
}
Also used : Phaser(java8.util.concurrent.Phaser)

Example 8 with Phaser

use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.

the class PhaserTest method testArriveAndDeregister3.

/**
 * arriveAndDeregister arrives at the barrier on a phaser with a parent and
 * when a deregistration occurs and causes the phaser to have zero parties
 * its parent will be deregistered as well
 */
public void testArriveAndDeregister3() {
    Phaser parent = new Phaser();
    Phaser child = new Phaser(parent);
    assertState(child, 0, 0, 0);
    assertState(parent, 0, 0, 0);
    assertEquals(0, child.register());
    assertState(child, 0, 1, 1);
    assertState(parent, 0, 1, 1);
    assertEquals(0, child.arriveAndDeregister());
    assertTerminated(child, 1);
    assertTerminated(parent, 1);
}
Also used : Phaser(java8.util.concurrent.Phaser)

Example 9 with Phaser

use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.

the class PhaserTest method testBulkRegister2.

/**
 * bulkRegister should correctly record the number of unarrived
 * parties with the number of parties being registered
 */
public void testBulkRegister2() {
    Phaser phaser = new Phaser();
    assertEquals(0, phaser.bulkRegister(0));
    assertState(phaser, 0, 0, 0);
    assertEquals(0, phaser.bulkRegister(20));
    assertState(phaser, 0, 20, 20);
}
Also used : Phaser(java8.util.concurrent.Phaser)

Example 10 with Phaser

use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.

the class PhaserTest method testConstructor5.

/**
 * The parent being input into the parameter should equal the original
 * parent when being returned
 */
public void testConstructor5() {
    Phaser parent = new Phaser();
    assertSame(parent, new Phaser(parent, 0).getParent());
    assertNull(new Phaser(null, 0).getParent());
}
Also used : Phaser(java8.util.concurrent.Phaser)

Aggregations

Phaser (java8.util.concurrent.Phaser)51 CountDownLatch (java.util.concurrent.CountDownLatch)9 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 LinkedList (java.util.LinkedList)2 Executors (java.util.concurrent.Executors)2 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.testng.annotations.Test)2 Array (java.lang.reflect.Array)1 ArrayDeque (java.util.ArrayDeque)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1