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);
}
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) {
}
}
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);
}
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);
}
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());
}
Aggregations