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.61 by jsr166, Tue Nov 28 18:06:55 2017 UTC vs.
Revision 1.68 by jsr166, Tue Aug 13 23:05:18 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.ThreadLocalRandom;
16   import java.util.concurrent.locks.AbstractQueuedSynchronizer;
17   import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject;
18  
20 import junit.framework.AssertionFailedError;
19   import junit.framework.Test;
20   import junit.framework.TestSuite;
21  
# Line 145 | Line 143 | public class AbstractQueuedSynchronizerT
143          long startTime = System.nanoTime();
144          while (!sync.isQueued(t)) {
145              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
146 <                throw new AssertionFailedError("timed out");
146 >                throw new AssertionError("timed out");
147              Thread.yield();
148          }
149          assertTrue(t.isAlive());
# Line 229 | Line 227 | public class AbstractQueuedSynchronizerT
227              assertTrue(c.await(timeoutMillis, MILLISECONDS));
228              break;
229          case awaitNanos:
230 <            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
231 <            long nanosRemaining = c.awaitNanos(nanosTimeout);
230 >            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
231 >            long nanosRemaining = c.awaitNanos(timeoutNanos);
232              assertTrue(nanosRemaining > 0);
233              break;
234          case awaitUntil:
# Line 257 | Line 255 | public class AbstractQueuedSynchronizerT
255                  break;
256              case awaitNanos:
257                  startTime = System.nanoTime();
258 <                long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
259 <                long nanosRemaining = c.awaitNanos(nanosTimeout);
258 >                long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
259 >                long nanosRemaining = c.awaitNanos(timeoutNanos);
260                  assertTrue(nanosRemaining <= 0);
261                  assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
262                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
# Line 1262 | Line 1260 | public class AbstractQueuedSynchronizerT
1260      }
1261  
1262      /**
1265     * Disabled demo test for (unfixed as of 2017-11)
1263       * JDK-8191483: AbstractQueuedSynchronizer cancel/cancel race
1264       * ant -Djsr166.tckTestClass=AbstractQueuedSynchronizerTest -Djsr166.methodFilter=testCancelCancelRace -Djsr166.runsPerTest=100 tck
1265       */
1266 <    public void DISABLED_testCancelCancelRace() throws InterruptedException {
1266 >    public void testCancelCancelRace() throws InterruptedException {
1267          class Sync extends AbstractQueuedSynchronizer {
1268              protected boolean tryAcquire(int acquires) {
1269                  return !hasQueuedPredecessors() && compareAndSetState(0, 1);
# Line 1285 | Line 1282 | public class AbstractQueuedSynchronizerT
1282              try {
1283                  s.acquireInterruptibly(1);
1284                  shouldThrow();
1285 <            } catch (InterruptedException expected) {}
1285 >            } catch (InterruptedException success) {}
1286          };
1287          for (int i = 0; i < 2; i++) {
1288              Thread thread = new Thread(failedAcquire);
# Line 1318 | Line 1315 | public class AbstractQueuedSynchronizerT
1315  
1316          // A synchronizer only offering a choice of failure modes
1317          class Sync extends AbstractQueuedSynchronizer {
1318 <            boolean pleaseThrow;
1318 >            volatile boolean pleaseThrow;
1319              @Override protected boolean tryAcquire(int ignored) {
1320                  if (pleaseThrow) throw ex;
1321                  return false;
# Line 1340 | Line 1337 | public class AbstractQueuedSynchronizerT
1337          final Thread thread = newStartedThread(new CheckedRunnable() {
1338              public void realRun() {
1339                  try {
1340 <                    if (ThreadLocalRandom.current().nextBoolean())
1340 >                    if (randomBoolean())
1341                          s.acquire(1);
1342                      else
1343                          s.acquireShared(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines