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.70 by jsr166, Thu Aug 15 14:56:32 2019 UTC vs.
Revision 1.71 by jsr166, Thu Aug 15 16:01:30 2019 UTC

# Line 1312 | Line 1312 | public class AbstractQueuedSynchronizerT
1312       * ant -Djsr166.tckTestClass=AbstractQueuedSynchronizerTest -Djsr166.methodFilter=testInterruptedFailingAcquire -Djsr166.runsPerTest=10000 tck
1313       */
1314      public void testInterruptedFailingAcquire() throws Throwable {
1315 <        final RuntimeException ex = new RuntimeException();
1315 >        class PleaseThrow extends RuntimeException {}
1316 >        final PleaseThrow ex = new PleaseThrow();
1317  
1318          // A synchronizer only offering a choice of failure modes
1319          class Sync extends AbstractQueuedSynchronizer {
# Line 1334 | Line 1335 | public class AbstractQueuedSynchronizerT
1335          }
1336  
1337          final Sync s = new Sync();
1338 <        final Action[] uninterruptibleAcquireMethods = {
1338 >        final boolean acquireInterruptibly = randomBoolean();
1339 >        final Action[] uninterruptibleAcquireActions = {
1340              () -> s.acquire(1),
1341              () -> s.acquireShared(1),
1340            // TODO: test interruptible acquire methods
1342          };
1343 <        final Action[] releaseMethods = {
1343 >        final long nanosTimeout = MILLISECONDS.toNanos(2 * LONG_DELAY_MS);
1344 >        final Action[] interruptibleAcquireActions = {
1345 >            () -> s.acquireInterruptibly(1),
1346 >            () -> s.acquireSharedInterruptibly(1),
1347 >            () -> s.tryAcquireNanos(1, nanosTimeout),
1348 >            () -> s.tryAcquireSharedNanos(1, nanosTimeout),
1349 >        };
1350 >        final Action[] releaseActions = {
1351              () -> s.release(1),
1352              () -> s.releaseShared(1),
1353          };
1354 <        final Action acquireMethod
1355 <            = chooseRandomly(uninterruptibleAcquireMethods);
1356 <        final Action releaseMethod
1357 <            = chooseRandomly(releaseMethods);
1354 >        final Action acquireAction = acquireInterruptibly
1355 >            ? chooseRandomly(interruptibleAcquireActions)
1356 >            : chooseRandomly(uninterruptibleAcquireActions);
1357 >        final Action releaseAction
1358 >            = chooseRandomly(releaseActions);
1359  
1360          // From os_posix.cpp:
1361          //
# Line 1359 | Line 1368 | public class AbstractQueuedSynchronizerT
1368          // is allowed and not harmful, and the possibility is so rare that
1369          // it is not worth the added complexity to add yet another lock.
1370          final Thread thread = newStartedThread(new CheckedRunnable() {
1371 <            public void realRun() {
1371 >            public void realRun() throws Throwable {
1372                  try {
1373 <                    acquireMethod.run();
1373 >                    acquireAction.run();
1374                      shouldThrow();
1375 <                } catch (Throwable t) {
1376 <                    assertSame(ex, t);
1375 >                } catch (InterruptedException possible) {
1376 >                    assertTrue(acquireInterruptibly);
1377 >                    assertFalse(Thread.interrupted());
1378 >                } catch (PleaseThrow possible) {
1379                      awaitInterrupted();
1380                  }
1381              }});
# Line 1388 | Line 1399 | public class AbstractQueuedSynchronizerT
1399          // release and interrupt, in random order
1400          if (randomBoolean()) {
1401              thread.interrupt();
1402 <            releaseMethod.run();
1402 >            releaseAction.run();
1403          } else {
1404 <            releaseMethod.run();
1404 >            releaseAction.run();
1405              thread.interrupt();
1406          }
1407          awaitTermination(thread);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines