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

Comparing jsr166/src/test/tck/StampedLockTest.java (file contents):
Revision 1.4 by dl, Wed Mar 20 16:51:11 2013 UTC vs.
Revision 1.9 by jsr166, Wed Dec 31 16:44:02 2014 UTC

# Line 6 | Line 6
6   */
7  
8   import junit.framework.*;
9 import java.util.concurrent.atomic.AtomicBoolean;
9   import java.util.concurrent.locks.Lock;
10   import java.util.concurrent.locks.StampedLock;
11   import java.util.concurrent.CountDownLatch;
# Line 270 | Line 269 | public class StampedLockTest extends JSR
269              assertTrue((s = lock.writeLock()) != 0L);
270              assertTrue(lock.validate(s));
271              assertFalse(lock.validate(lock.tryWriteLock()));
272 <            assertFalse(lock.validate(lock.tryWriteLock(100L, MILLISECONDS)));
272 >            assertFalse(lock.validate(lock.tryWriteLock(10L, MILLISECONDS)));
273              assertFalse(lock.validate(lock.tryReadLock()));
274 <            assertFalse(lock.validate(lock.tryReadLock(100L, MILLISECONDS)));
274 >            assertFalse(lock.validate(lock.tryReadLock(10L, MILLISECONDS)));
275              assertFalse(lock.validate(lock.tryOptimisticRead()));
276              lock.unlockWrite(s);
277          } catch (InterruptedException ie) {
# Line 292 | Line 291 | public class StampedLockTest extends JSR
291                  running.countDown();
292                  lock.writeLockInterruptibly();
293              }});
294 <        try {
295 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
294 >        try {
295 >            running.await();
296 >            waitForThreadToEnterWaitState(t, 100);
297              t.interrupt();
298              awaitTermination(t);
299              releaseWriteLock(lock, s);
# Line 314 | Line 314 | public class StampedLockTest extends JSR
314                  running.countDown();
315                  lock.tryWriteLock(2 * LONG_DELAY_MS, MILLISECONDS);
316              }});
317 <        try {
318 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
317 >        try {
318 >            running.await();
319 >            waitForThreadToEnterWaitState(t, 100);
320              t.interrupt();
321              awaitTermination(t);
322              releaseWriteLock(lock, s);
# Line 336 | Line 337 | public class StampedLockTest extends JSR
337                  running.countDown();
338                  lock.readLockInterruptibly();
339              }});
340 <        try {
341 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
340 >        try {
341 >            running.await();
342 >            waitForThreadToEnterWaitState(t, 100);
343              t.interrupt();
344              awaitTermination(t);
345              releaseWriteLock(lock, s);
# Line 358 | Line 360 | public class StampedLockTest extends JSR
360                  running.countDown();
361                  lock.tryReadLock(2 * LONG_DELAY_MS, MILLISECONDS);
362              }});
363 <        try {
364 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
363 >        try {
364 >            running.await();
365 >            waitForThreadToEnterWaitState(t, 100);
366              t.interrupt();
367              awaitTermination(t);
368              releaseWriteLock(lock, s);
# Line 448 | Line 451 | public class StampedLockTest extends JSR
451                  long s = lock.writeLock();
452                  lock.unlockWrite(s);
453              }});
454 <        try {
455 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
454 >        try {
455 >            running.await();
456 >            waitForThreadToEnterWaitState(t, 100);
457              assertFalse(lock.isWriteLocked());
458              lock.unlockRead(rs);
459              awaitTermination(t);
# Line 571 | Line 575 | public class StampedLockTest extends JSR
575                  assertEquals(rs, 0L);
576                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
577              }});
578 <        
578 >
579          awaitTermination(t);
580          assertTrue(lock.isWriteLocked());
581          lock.unlockWrite(s);
# Line 595 | Line 599 | public class StampedLockTest extends JSR
599                  lock.writeLockInterruptibly();
600              }});
601  
602 <        try {
603 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
602 >        try {
603 >            running.await();
604 >            waitForThreadToEnterWaitState(t, 100);
605              t.interrupt();
606              assertTrue(lock.isWriteLocked());
607              awaitTermination(t);
# Line 626 | Line 631 | public class StampedLockTest extends JSR
631                  running.countDown();
632                  lock.readLockInterruptibly();
633              }});
634 <        try {
635 <            running.await(); Thread.sleep(SHORT_DELAY_MS);
634 >        try {
635 >            running.await();
636 >            waitForThreadToEnterWaitState(t, 100);
637              t.interrupt();
638              awaitTermination(t);
639              releaseWriteLock(lock, s);
# Line 650 | Line 656 | public class StampedLockTest extends JSR
656          clone.unlockWrite(s);
657          assertFalse(clone.isWriteLocked());
658      }
659 +
660      /**
661       * toString indicates current lock state
662       */
# Line 735 | Line 742 | public class StampedLockTest extends JSR
742                      running.countDown();
743                      lock.writeLockInterruptibly();
744                  }});
745 <        try {
745 >        try {
746              running.await();
747              assertFalse(lock.validate(p));
748              assertFalse((p = lock.tryOptimisticRead()) != 0L);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines