test/java/util/concurrent/Phaser/Basic.java

Print this page

        

*** 46,55 **** --- 46,57 ---- import java.util.concurrent.atomic.AtomicInteger; import static java.util.concurrent.TimeUnit.*; public class Basic { + private static final int TIMEOUT = 100; + private static void checkTerminated(final Phaser phaser) { check(phaser.isTerminated()); int unarriverParties = phaser.getUnarrivedParties(); int registeredParties = phaser.getRegisteredParties(); int phase = phaser.getPhase();
*** 94,104 **** expectNextPhase = true; } int phase = atTheStartingGate.getPhase(); equal(phase, atTheStartingGate.arrive()); int awaitPhase = atTheStartingGate.awaitAdvanceInterruptibly ! (phase, 10, SECONDS); if (expectNextPhase) check(awaitPhase == (phase + 1)); pass(); } catch (Throwable t) { unexpected(t); --- 96,106 ---- expectNextPhase = true; } int phase = atTheStartingGate.getPhase(); equal(phase, atTheStartingGate.arrive()); int awaitPhase = atTheStartingGate.awaitAdvanceInterruptibly ! (phase, 30, SECONDS); if (expectNextPhase) check(awaitPhase == (phase + 1)); pass(); } catch (Throwable t) { unexpected(t);
*** 186,196 **** case 1: case 5: return awaiter(phaser); case 2: case 6: case 7: return awaiter(phaser, -1, SECONDS); default: ! return awaiter(phaser, 10, SECONDS); }} public void remove() {throw new UnsupportedOperationException();}}; } // Returns an infinite lazy list of all possible awaiter only combinations. private static Iterator<Awaiter> awaiterIterator(final Phaser phaser) { --- 188,198 ---- case 1: case 5: return awaiter(phaser); case 2: case 6: case 7: return awaiter(phaser, -1, SECONDS); default: ! return awaiter(phaser, 30, SECONDS); }} public void remove() {throw new UnsupportedOperationException();}}; } // Returns an infinite lazy list of all possible awaiter only combinations. private static Iterator<Awaiter> awaiterIterator(final Phaser phaser) {
*** 202,212 **** case 1: case 4: case 7: return awaiter(phaser); case 2: case 5: return awaiter(phaser, -1, SECONDS); default: ! return awaiter(phaser, 10, SECONDS); }} public void remove() {throw new UnsupportedOperationException();}}; } private static void realMain(String[] args) throws Throwable { --- 204,214 ---- case 1: case 4: case 7: return awaiter(phaser); case 2: case 5: return awaiter(phaser, -1, SECONDS); default: ! return awaiter(phaser, 30, SECONDS); }} public void remove() {throw new UnsupportedOperationException();}}; } private static void realMain(String[] args) throws Throwable {
*** 249,262 **** Phaser phaser = new Phaser(3); Iterator<Arriver> arrivers = arriverIterator(phaser); int phase = phaser.getPhase(); for (int i = 0; i < 4; i++) { check(phaser.getPhase() == phase); ! Awaiter a1 = awaiter(phaser, 10, SECONDS); a1.start(); Arriver a2 = arrivers.next(); a2.start(); toTheStartingGate(); a1.interrupt(); a1.join(); phaser.arriveAndAwaitAdvance(); a2.join(); checkResult(a1, InterruptedException.class); checkResult(a2, null); --- 251,269 ---- Phaser phaser = new Phaser(3); Iterator<Arriver> arrivers = arriverIterator(phaser); int phase = phaser.getPhase(); for (int i = 0; i < 4; i++) { check(phaser.getPhase() == phase); ! Awaiter a1 = awaiter(phaser, 30, SECONDS); a1.start(); Arriver a2 = arrivers.next(); a2.start(); toTheStartingGate(); + int count = 0; + while (a1.result() == null && count < 20) { + Thread.sleep(TIMEOUT); a1.interrupt(); + count++; + } a1.join(); phaser.arriveAndAwaitAdvance(); a2.join(); checkResult(a1, InterruptedException.class); checkResult(a2, null);