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.42 by jsr166, Fri Sep 29 19:34:37 2017 UTC vs.
Revision 1.48 by jsr166, Tue Aug 13 23:05:18 2019 UTC

# Line 15 | Line 15 | import java.util.HashSet;
15   import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
16   import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject;
17  
18 import junit.framework.AssertionFailedError;
18   import junit.framework.Test;
19   import junit.framework.TestSuite;
20  
# Line 140 | Line 139 | public class AbstractQueuedLongSynchroni
139          long startTime = System.nanoTime();
140          while (!sync.isQueued(t)) {
141              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
142 <                throw new AssertionFailedError("timed out");
142 >                throw new AssertionError("timed out");
143              Thread.yield();
144          }
145          assertTrue(t.isAlive());
# Line 224 | Line 223 | public class AbstractQueuedLongSynchroni
223              assertTrue(c.await(timeoutMillis, MILLISECONDS));
224              break;
225          case awaitNanos:
226 <            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
227 <            long nanosRemaining = c.awaitNanos(nanosTimeout);
226 >            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
227 >            long nanosRemaining = c.awaitNanos(timeoutNanos);
228              assertTrue(nanosRemaining > 0);
229              break;
230          case awaitUntil:
# Line 252 | Line 251 | public class AbstractQueuedLongSynchroni
251                  break;
252              case awaitNanos:
253                  startTime = System.nanoTime();
254 <                long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
255 <                long nanosRemaining = c.awaitNanos(nanosTimeout);
254 >                long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
255 >                long nanosRemaining = c.awaitNanos(timeoutNanos);
256                  assertTrue(nanosRemaining <= 0);
257                  assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
258                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
# Line 1256 | Line 1255 | public class AbstractQueuedLongSynchroni
1255          sync.release();
1256      }
1257  
1258 +    /**
1259 +     * Tests scenario for
1260 +     * JDK-8191937: Lost interrupt in AbstractQueuedSynchronizer when tryAcquire methods throw
1261 +     */
1262 +    public void testInterruptedFailingAcquire() throws InterruptedException {
1263 +        final RuntimeException ex = new RuntimeException();
1264 +
1265 +        // A synchronizer only offering a choice of failure modes
1266 +        class Sync extends AbstractQueuedLongSynchronizer {
1267 +            volatile boolean pleaseThrow;
1268 +            @Override protected boolean tryAcquire(long ignored) {
1269 +                if (pleaseThrow) throw ex;
1270 +                return false;
1271 +            }
1272 +            @Override protected long tryAcquireShared(long ignored) {
1273 +                if (pleaseThrow) throw ex;
1274 +                return -1;
1275 +            }
1276 +            @Override protected boolean tryRelease(long ignored) {
1277 +                return true;
1278 +            }
1279 +            @Override protected boolean tryReleaseShared(long ignored) {
1280 +                return true;
1281 +            }
1282 +        }
1283 +
1284 +        final Sync s = new Sync();
1285 +
1286 +        final Thread thread = newStartedThread(new CheckedRunnable() {
1287 +            public void realRun() {
1288 +                try {
1289 +                    if (randomBoolean())
1290 +                        s.acquire(1);
1291 +                    else
1292 +                        s.acquireShared(1);
1293 +                    shouldThrow();
1294 +                } catch (Throwable t) {
1295 +                    assertSame(ex, t);
1296 +                    assertTrue(Thread.interrupted());
1297 +                }
1298 +            }});
1299 +        waitForThreadToEnterWaitState(thread);
1300 +        assertSame(thread, s.getFirstQueuedThread());
1301 +        assertTrue(s.hasQueuedPredecessors());
1302 +        assertTrue(s.hasQueuedThreads());
1303 +        assertEquals(1, s.getQueueLength());
1304 +
1305 +        s.pleaseThrow = true;
1306 +        thread.interrupt();
1307 +        s.release(1);
1308 +        awaitTermination(thread);
1309 +    }
1310 +
1311   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines