use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.
the class PhaserTest method testArrive2.
/**
* arriveAndDeregister does not wait for others to arrive at barrier
*/
public void testArrive2() {
final Phaser phaser = new Phaser();
assertEquals(0, phaser.register());
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 10; i++) {
assertEquals(0, phaser.register());
threads.add(newStartedThread(new CheckedRunnable() {
public void realRun() {
assertEquals(0, phaser.arriveAndDeregister());
}
}));
}
for (Thread thread : threads) awaitTermination(thread);
assertState(phaser, 0, 1, 1);
assertEquals(0, phaser.arrive());
assertState(phaser, 1, 1, 1);
}
use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.
the class PhaserTest method testAwaitAdvance2.
/**
* awaitAdvance with a negative parameter will return without affecting the
* phaser
*/
public void testAwaitAdvance2() {
Phaser phaser = new Phaser();
assertTrue(phaser.awaitAdvance(-1) < 0);
assertState(phaser, 0, 0, 0);
}
use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.
the class PhaserTest method testRegister4.
/**
* register causes the next arrive to not increment the phase
* rather retain the phase number
*/
public void testRegister4() {
Phaser phaser = new Phaser(1);
assertEquals(0, phaser.arrive());
assertEquals(1, phaser.register());
assertEquals(1, phaser.arrive());
assertState(phaser, 1, 2, 1);
}
use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.
the class PhaserTest method testArriveAndAwaitAdvance1.
/**
* arriveAndAwaitAdvance throws IllegalStateException with no
* unarrived parties
*/
public void testArriveAndAwaitAdvance1() {
Phaser phaser = new Phaser();
try {
phaser.arriveAndAwaitAdvance();
shouldThrow();
} catch (IllegalStateException success) {
}
}
use of java8.util.concurrent.Phaser in project streamsupport by stefan-zobel.
the class PhaserTest method testRegister3.
/**
* register() correctly returns the current barrier phase number
* when invoked
*/
public void testRegister3() {
Phaser phaser = new Phaser();
assertEquals(0, phaser.register());
assertEquals(0, phaser.arrive());
assertEquals(1, phaser.register());
assertState(phaser, 1, 2, 2);
}
Aggregations