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

# Line 1261 | Line 1261 | public class AbstractQueuedLongSynchroni
1261       * ant -Djsr166.tckTestClass=AbstractQueuedLongSynchronizerTest -Djsr166.methodFilter=testInterruptedFailingAcquire -Djsr166.runsPerTest=10000 tck
1262       */
1263      public void testInterruptedFailingAcquire() throws Throwable {
1264 <        final RuntimeException ex = new RuntimeException();
1264 >        class PleaseThrow extends RuntimeException {}
1265 >        final PleaseThrow ex = new PleaseThrow();
1266  
1267          // A synchronizer only offering a choice of failure modes
1268          class Sync extends AbstractQueuedLongSynchronizer {
# Line 1283 | Line 1284 | public class AbstractQueuedLongSynchroni
1284          }
1285  
1286          final Sync s = new Sync();
1287 <        final Action[] uninterruptibleAcquireMethods = {
1287 >        final boolean acquireInterruptibly = randomBoolean();
1288 >        final Action[] uninterruptibleAcquireActions = {
1289              () -> s.acquire(1),
1290              () -> s.acquireShared(1),
1289            // TODO: test interruptible acquire methods
1291          };
1292 <        final Action[] releaseMethods = {
1292 >        final long nanosTimeout = MILLISECONDS.toNanos(2 * LONG_DELAY_MS);
1293 >        final Action[] interruptibleAcquireActions = {
1294 >            () -> s.acquireInterruptibly(1),
1295 >            () -> s.acquireSharedInterruptibly(1),
1296 >            () -> s.tryAcquireNanos(1, nanosTimeout),
1297 >            () -> s.tryAcquireSharedNanos(1, nanosTimeout),
1298 >        };
1299 >        final Action[] releaseActions = {
1300              () -> s.release(1),
1301              () -> s.releaseShared(1),
1302          };
1303 <        final Action acquireMethod
1304 <            = chooseRandomly(uninterruptibleAcquireMethods);
1305 <        final Action releaseMethod
1306 <            = chooseRandomly(releaseMethods);
1303 >        final Action acquireAction = acquireInterruptibly
1304 >            ? chooseRandomly(interruptibleAcquireActions)
1305 >            : chooseRandomly(uninterruptibleAcquireActions);
1306 >        final Action releaseAction
1307 >            = chooseRandomly(releaseActions);
1308  
1309          // From os_posix.cpp:
1310          //
# Line 1308 | Line 1317 | public class AbstractQueuedLongSynchroni
1317          // is allowed and not harmful, and the possibility is so rare that
1318          // it is not worth the added complexity to add yet another lock.
1319          final Thread thread = newStartedThread(new CheckedRunnable() {
1320 <            public void realRun() {
1320 >            public void realRun() throws Throwable {
1321                  try {
1322 <                    acquireMethod.run();
1322 >                    acquireAction.run();
1323                      shouldThrow();
1324 <                } catch (Throwable t) {
1325 <                    assertSame(ex, t);
1324 >                } catch (InterruptedException possible) {
1325 >                    assertTrue(acquireInterruptibly);
1326 >                    assertFalse(Thread.interrupted());
1327 >                } catch (PleaseThrow possible) {
1328                      awaitInterrupted();
1329                  }
1330              }});
# Line 1337 | Line 1348 | public class AbstractQueuedLongSynchroni
1348          // release and interrupt, in random order
1349          if (randomBoolean()) {
1350              thread.interrupt();
1351 <            releaseMethod.run();
1351 >            releaseAction.run();
1352          } else {
1353 <            releaseMethod.run();
1353 >            releaseAction.run();
1354              thread.interrupt();
1355          }
1356          awaitTermination(thread);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines