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.11 by jsr166, Fri Feb 27 21:43:18 2015 UTC vs.
Revision 1.15 by jsr166, Tue Jun 7 00:03:27 2016 UTC

# Line 16 | Line 16 | import junit.framework.TestSuite;
16  
17   public class StampedLockTest extends JSR166TestCase {
18      public static void main(String[] args) {
19 <        junit.textui.TestRunner.run(suite());
19 >        main(suite(), args);
20      }
21      public static Test suite() {
22          return new TestSuite(StampedLockTest.class);
# Line 166 | Line 166 | public class StampedLockTest extends JSR
166       */
167      public void testWriteUnlock_IMSE2() {
168          StampedLock lock = new StampedLock();
169 +        long s = lock.writeLock();
170 +        lock.unlockWrite(s);
171          try {
170            long s = lock.writeLock();
171            lock.unlockWrite(s);
172              lock.unlockWrite(s);
173              shouldThrow();
174          } catch (IllegalMonitorStateException success) {}
# Line 179 | Line 179 | public class StampedLockTest extends JSR
179       */
180      public void testWriteUnlock_IMSE3() {
181          StampedLock lock = new StampedLock();
182 +        long s = lock.readLock();
183          try {
183            long s = lock.readLock();
184              lock.unlockWrite(s);
185              shouldThrow();
186          } catch (IllegalMonitorStateException success) {}
# Line 191 | Line 191 | public class StampedLockTest extends JSR
191       */
192      public void testReadUnlock_IMSE() {
193          StampedLock lock = new StampedLock();
194 +        long s = lock.readLock();
195 +        lock.unlockRead(s);
196          try {
195            long s = lock.readLock();
196            lock.unlockRead(s);
197              lock.unlockRead(s);
198              shouldThrow();
199          } catch (IllegalMonitorStateException success) {}
# Line 215 | Line 215 | public class StampedLockTest extends JSR
215       */
216      public void testReadUnlock_IMSE3() {
217          StampedLock lock = new StampedLock();
218 +        long s = lock.writeLock();
219          try {
219            long s = lock.writeLock();
220              lock.unlockRead(s);
221              shouldThrow();
222          } catch (IllegalMonitorStateException success) {}
# Line 285 | Line 285 | public class StampedLockTest extends JSR
285                  running.countDown();
286                  lock.writeLockInterruptibly();
287              }});
288 <        
288 >
289          running.await();
290          waitForThreadToEnterWaitState(t, 100);
291          t.interrupt();
# Line 305 | Line 305 | public class StampedLockTest extends JSR
305                  running.countDown();
306                  lock.tryWriteLock(2 * LONG_DELAY_MS, MILLISECONDS);
307              }});
308 <        
308 >
309          running.await();
310          waitForThreadToEnterWaitState(t, 100);
311          t.interrupt();
# Line 326 | Line 326 | public class StampedLockTest extends JSR
326                  running.countDown();
327                  lock.readLockInterruptibly();
328              }});
329 <        
329 >
330          running.await();
331          waitForThreadToEnterWaitState(t, 100);
332          t.interrupt();
# Line 346 | Line 346 | public class StampedLockTest extends JSR
346                  running.countDown();
347                  lock.tryReadLock(2 * LONG_DELAY_MS, MILLISECONDS);
348              }});
349 <        
349 >
350          running.await();
351          waitForThreadToEnterWaitState(t, 100);
352          t.interrupt();
# Line 378 | Line 378 | public class StampedLockTest extends JSR
378                  long ws = lock.tryWriteLock();
379                  assertTrue(ws == 0L);
380              }});
381 <        
381 >
382          awaitTermination(t);
383          releaseWriteLock(lock, s);
384      }
# Line 394 | Line 394 | public class StampedLockTest extends JSR
394                  long rs = lock.tryReadLock();
395                  assertEquals(rs, 0L);
396              }});
397 <        
397 >
398          awaitTermination(t);
399          releaseWriteLock(lock, s);
400      }
# Line 416 | Line 416 | public class StampedLockTest extends JSR
416                  long s4 = lock.readLock();
417                  lock.unlockRead(s4);
418              }});
419 <        
419 >
420          awaitTermination(t);
421          lock.unlockRead(s);
422      }
# Line 434 | Line 434 | public class StampedLockTest extends JSR
434                  long s = lock.writeLock();
435                  lock.unlockWrite(s);
436              }});
437 <        
437 >
438          running.await();
439          waitForThreadToEnterWaitState(t, 100);
440          assertFalse(lock.isWriteLocked());
# Line 454 | Line 454 | public class StampedLockTest extends JSR
454                  long rs = lock.readLock();
455                  lock.unlockRead(rs);
456              }});
457 <        
457 >
458          awaitTermination(t1);
459  
460          Thread t2 = newStartedThread(new CheckedRunnable() {
# Line 462 | Line 462 | public class StampedLockTest extends JSR
462                  long ws = lock.writeLock();
463                  lock.unlockWrite(ws);
464              }});
465 <        
465 >
466          assertFalse(lock.isWriteLocked());
467          lock.unlockRead(s);
468          awaitTermination(t2);
# Line 599 | Line 599 | public class StampedLockTest extends JSR
599                  running.countDown();
600                  lock.readLockInterruptibly();
601              }});
602 <        
602 >
603          running.await();
604          waitForThreadToEnterWaitState(t, 100);
605          t.interrupt();
# Line 704 | Line 704 | public class StampedLockTest extends JSR
704                  running.countDown();
705                  lock.writeLockInterruptibly();
706              }});
707 <        
707 >
708          running.await();
709          assertFalse(lock.validate(p));
710          assertFalse((p = lock.tryOptimisticRead()) != 0L);
# Line 876 | Line 876 | public class StampedLockTest extends JSR
876          assertTrue(lock.tryLock());
877      }
878  
879 +    /**
880 +     * Lock.newCondition throws UnsupportedOperationException
881 +     */
882 +    public void testLockViewsDoNotSupportConditions() {
883 +        StampedLock sl = new StampedLock();
884 +        assertThrows(UnsupportedOperationException.class,
885 +                     () -> sl.asWriteLock().newCondition(),
886 +                     () -> sl.asReadLock().newCondition(),
887 +                     () -> sl.asReadWriteLock().writeLock().newCondition(),
888 +                     () -> sl.asReadWriteLock().readLock().newCondition());
889 +    }
890 +
891   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines