ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.72 by jsr166, Thu Aug 15 16:06:13 2019 UTC vs.
Revision 1.73 by jsr166, Fri Aug 16 02:32:26 2019 UTC

# Line 13 | Line 13 | import java.util.ArrayList;
13   import java.util.Arrays;
14   import java.util.Collection;
15   import java.util.HashSet;
16 + import java.util.concurrent.atomic.AtomicBoolean;
17   import java.util.concurrent.locks.AbstractQueuedSynchronizer;
18   import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject;
19  
# Line 1314 | Line 1315 | public class AbstractQueuedSynchronizerT
1315      public void testInterruptedFailingAcquire() throws Throwable {
1316          class PleaseThrow extends RuntimeException {}
1317          final PleaseThrow ex = new PleaseThrow();
1318 +        final AtomicBoolean thrown = new AtomicBoolean();
1319  
1320          // A synchronizer only offering a choice of failure modes
1321          class Sync extends AbstractQueuedSynchronizer {
1322              volatile boolean pleaseThrow;
1323 +            void maybeThrow() {
1324 +                if (pleaseThrow) {
1325 +                    // assert: tryAcquire methods can throw at most once
1326 +                    if (! thrown.compareAndSet(false, true))
1327 +                        throw new AssertionError();
1328 +                    throw ex;
1329 +                }
1330 +            }
1331 +
1332              @Override protected boolean tryAcquire(int ignored) {
1333 <                if (pleaseThrow) throw ex;
1333 >                maybeThrow();
1334                  return false;
1335              }
1336              @Override protected int tryAcquireShared(int ignored) {
1337 <                if (pleaseThrow) throw ex;
1337 >                maybeThrow();
1338                  return -1;
1339              }
1340              @Override protected boolean tryRelease(int ignored) {
# Line 1407 | Line 1418 | public class AbstractQueuedSynchronizerT
1418          }
1419          awaitTermination(thread);
1420  
1421 +        if (! acquireInterruptibly)
1422 +            assertTrue(thrown.get());
1423 +
1424          assertNull(s.getFirstQueuedThread());
1425          assertFalse(s.hasQueuedPredecessors());
1426          assertFalse(s.hasQueuedThreads());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines