--- jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2019/08/15 16:06:13 1.52 +++ jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2019/08/16 02:32:26 1.53 @@ -12,6 +12,7 @@ import static java.util.concurrent.TimeU import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.AbstractQueuedLongSynchronizer; import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; @@ -1263,16 +1264,26 @@ public class AbstractQueuedLongSynchroni public void testInterruptedFailingAcquire() throws Throwable { class PleaseThrow extends RuntimeException {} final PleaseThrow ex = new PleaseThrow(); + final AtomicBoolean thrown = new AtomicBoolean(); // A synchronizer only offering a choice of failure modes class Sync extends AbstractQueuedLongSynchronizer { volatile boolean pleaseThrow; + void maybeThrow() { + if (pleaseThrow) { + // assert: tryAcquire methods can throw at most once + if (! thrown.compareAndSet(false, true)) + throw new AssertionError(); + throw ex; + } + } + @Override protected boolean tryAcquire(long ignored) { - if (pleaseThrow) throw ex; + maybeThrow(); return false; } @Override protected long tryAcquireShared(long ignored) { - if (pleaseThrow) throw ex; + maybeThrow(); return -1; } @Override protected boolean tryRelease(long ignored) { @@ -1356,6 +1367,9 @@ public class AbstractQueuedLongSynchroni } awaitTermination(thread); + if (! acquireInterruptibly) + assertTrue(thrown.get()); + assertNull(s.getFirstQueuedThread()); assertFalse(s.hasQueuedPredecessors()); assertFalse(s.hasQueuedThreads());