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

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

# Line 12 | Line 12 | import static java.util.concurrent.TimeU
12   import java.util.Arrays;
13   import java.util.Collection;
14   import java.util.HashSet;
15 + import java.util.concurrent.atomic.AtomicBoolean;
16   import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
17   import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject;
18  
# Line 1263 | Line 1264 | public class AbstractQueuedLongSynchroni
1264      public void testInterruptedFailingAcquire() throws Throwable {
1265          class PleaseThrow extends RuntimeException {}
1266          final PleaseThrow ex = new PleaseThrow();
1267 +        final AtomicBoolean thrown = new AtomicBoolean();
1268  
1269          // A synchronizer only offering a choice of failure modes
1270          class Sync extends AbstractQueuedLongSynchronizer {
1271              volatile boolean pleaseThrow;
1272 +            void maybeThrow() {
1273 +                if (pleaseThrow) {
1274 +                    // assert: tryAcquire methods can throw at most once
1275 +                    if (! thrown.compareAndSet(false, true))
1276 +                        throw new AssertionError();
1277 +                    throw ex;
1278 +                }
1279 +            }
1280 +
1281              @Override protected boolean tryAcquire(long ignored) {
1282 <                if (pleaseThrow) throw ex;
1282 >                maybeThrow();
1283                  return false;
1284              }
1285              @Override protected long tryAcquireShared(long ignored) {
1286 <                if (pleaseThrow) throw ex;
1286 >                maybeThrow();
1287                  return -1;
1288              }
1289              @Override protected boolean tryRelease(long ignored) {
# Line 1356 | Line 1367 | public class AbstractQueuedLongSynchroni
1367          }
1368          awaitTermination(thread);
1369  
1370 +        if (! acquireInterruptibly)
1371 +            assertTrue(thrown.get());
1372 +
1373          assertNull(s.getFirstQueuedThread());
1374          assertFalse(s.hasQueuedPredecessors());
1375          assertFalse(s.hasQueuedThreads());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines