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

Comparing jsr166/src/test/tck/ReentrantLockTest.java (file contents):
Revision 1.40 by dl, Fri May 6 11:22:07 2011 UTC vs.
Revision 1.41 by jsr166, Sat May 7 02:51:33 2011 UTC

# Line 262 | Line 262 | public class ReentrantLockTest extends J
262      public void testInterruptedException2() throws InterruptedException {
263          final ReentrantLock lock = new ReentrantLock();
264          lock.lock();
265 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
265 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
266              public void realRun() throws InterruptedException {
267                  lock.tryLock(MEDIUM_DELAY_MS,MILLISECONDS);
268              }});
269  
270        t.start();
270          delay(SHORT_DELAY_MS);
271          t.interrupt();
272          t.join();
# Line 280 | Line 279 | public class ReentrantLockTest extends J
279      public void testTryLockWhenLocked() throws InterruptedException {
280          final ReentrantLock lock = new ReentrantLock();
281          lock.lock();
282 <        Thread t = new Thread(new CheckedRunnable() {
282 >        Thread t = newStartedThread(new CheckedRunnable() {
283              public void realRun() {
284                  assertFalse(lock.tryLock());
285              }});
286  
288        t.start();
287          t.join();
288          lock.unlock();
289      }
# Line 296 | Line 294 | public class ReentrantLockTest extends J
294      public void testTryLock_Timeout() throws InterruptedException {
295          final ReentrantLock lock = new ReentrantLock();
296          lock.lock();
297 <        Thread t = new Thread(new CheckedRunnable() {
297 >        Thread t = newStartedThread(new CheckedRunnable() {
298              public void realRun() throws InterruptedException {
299                  assertFalse(lock.tryLock(1, MILLISECONDS));
300              }});
301  
304        t.start();
302          t.join();
303          lock.unlock();
304      }
# Line 331 | Line 328 | public class ReentrantLockTest extends J
328          assertTrue(lock.isLocked());
329          lock.unlock();
330          assertFalse(lock.isLocked());
331 <        Thread t = new Thread(new CheckedRunnable() {
331 >        Thread t = newStartedThread(new CheckedRunnable() {
332              public void realRun() throws InterruptedException {
333                  lock.lock();
334                  delay(SMALL_DELAY_MS);
335                  lock.unlock();
336              }});
337  
341        t.start();
338          delay(SHORT_DELAY_MS);
339          assertTrue(lock.isLocked());
340          t.join();
# Line 352 | Line 348 | public class ReentrantLockTest extends J
348      public void testLockInterruptibly1() throws InterruptedException {
349          final ReentrantLock lock = new ReentrantLock();
350          lock.lock();
351 <        Thread t = new Thread(new InterruptedLockRunnable(lock));
356 <        t.start();
351 >        Thread t = newStartedThread(new InterruptedLockRunnable(lock));
352          delay(SHORT_DELAY_MS);
353          t.interrupt();
354          delay(SHORT_DELAY_MS);
# Line 367 | Line 362 | public class ReentrantLockTest extends J
362      public void testLockInterruptibly2() throws InterruptedException {
363          final ReentrantLock lock = new ReentrantLock();
364          lock.lockInterruptibly();
365 <        Thread t = new Thread(new InterruptedLockRunnable(lock));
371 <        t.start();
365 >        Thread t = newStartedThread(new InterruptedLockRunnable(lock));
366          delay(SHORT_DELAY_MS);
367          t.interrupt();
368          assertTrue(lock.isLocked());
# Line 441 | Line 435 | public class ReentrantLockTest extends J
435      public void testAwait() throws InterruptedException {
436          final ReentrantLock lock = new ReentrantLock();
437          final Condition c = lock.newCondition();
438 <        Thread t = new Thread(new CheckedRunnable() {
438 >        Thread t = newStartedThread(new CheckedRunnable() {
439              public void realRun() throws InterruptedException {
440                  lock.lock();
441                  c.await();
442                  lock.unlock();
443              }});
444  
451        t.start();
445          delay(SHORT_DELAY_MS);
446          lock.lock();
447          c.signal();
# Line 576 | Line 569 | public class ReentrantLockTest extends J
569      public void testHasWaiters() throws InterruptedException {
570          final ReentrantLock lock = new ReentrantLock();
571          final Condition c = lock.newCondition();
572 <        Thread t = new Thread(new CheckedRunnable() {
572 >        Thread t = newStartedThread(new CheckedRunnable() {
573              public void realRun() throws InterruptedException {
574                  lock.lock();
575                  assertFalse(lock.hasWaiters(c));
# Line 585 | Line 578 | public class ReentrantLockTest extends J
578                  lock.unlock();
579              }});
580  
588        t.start();
581          delay(SHORT_DELAY_MS);
582          lock.lock();
583          assertTrue(lock.hasWaiters(c));
# Line 607 | Line 599 | public class ReentrantLockTest extends J
599      public void testGetWaitQueueLength() throws InterruptedException {
600          final ReentrantLock lock = new ReentrantLock();
601          final Condition c = lock.newCondition();
602 <        Thread t1 = new Thread(new CheckedRunnable() {
602 >        Thread t1 = newStartedThread(new CheckedRunnable() {
603              public void realRun() throws InterruptedException {
604                  lock.lock();
605                  assertFalse(lock.hasWaiters(c));
# Line 616 | Line 608 | public class ReentrantLockTest extends J
608                  lock.unlock();
609              }});
610  
611 <        Thread t2 = new Thread(new CheckedRunnable() {
611 >        delay(SHORT_DELAY_MS);
612 >
613 >        Thread t2 = newStartedThread(new CheckedRunnable() {
614              public void realRun() throws InterruptedException {
615                  lock.lock();
616                  assertTrue(lock.hasWaiters(c));
# Line 625 | Line 619 | public class ReentrantLockTest extends J
619                  lock.unlock();
620              }});
621  
628        t1.start();
629        delay(SHORT_DELAY_MS);
630        t2.start();
622          delay(SHORT_DELAY_MS);
623          lock.lock();
624          assertTrue(lock.hasWaiters(c));
# Line 752 | Line 743 | public class ReentrantLockTest extends J
743      public void testAwait_Interrupt() throws InterruptedException {
744          final ReentrantLock lock = new ReentrantLock();
745          final Condition c = lock.newCondition();
746 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
746 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
747              public void realRun() throws InterruptedException {
748                  lock.lock();
749                  c.await();
750              }});
751  
761        t.start();
752          delay(SHORT_DELAY_MS);
753          t.interrupt();
754          t.join(SHORT_DELAY_MS);
# Line 771 | Line 761 | public class ReentrantLockTest extends J
761      public void testAwaitNanos_Interrupt() throws InterruptedException {
762          final ReentrantLock lock = new ReentrantLock();
763          final Condition c = lock.newCondition();
764 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
764 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
765              public void realRun() throws InterruptedException {
766                  lock.lock();
767                  c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
768              }});
769  
780        t.start();
770          delay(SHORT_DELAY_MS);
771          t.interrupt();
772          t.join(SHORT_DELAY_MS);
# Line 790 | Line 779 | public class ReentrantLockTest extends J
779      public void testAwaitUntil_Interrupt() throws InterruptedException {
780          final ReentrantLock lock = new ReentrantLock();
781          final Condition c = lock.newCondition();
782 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
782 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
783              public void realRun() throws InterruptedException {
784                  lock.lock();
785                  java.util.Date d = new java.util.Date();
786                  c.awaitUntil(new java.util.Date(d.getTime() + 10000));
787              }});
788  
800        t.start();
789          delay(SHORT_DELAY_MS);
790          t.interrupt();
791          t.join(SHORT_DELAY_MS);
# Line 810 | Line 798 | public class ReentrantLockTest extends J
798      public void testSignalAll() throws InterruptedException {
799          final ReentrantLock lock = new ReentrantLock();
800          final Condition c = lock.newCondition();
801 <        Thread t1 = new Thread(new CheckedRunnable() {
801 >        Thread t1 = newStartedThread(new CheckedRunnable() {
802              public void realRun() throws InterruptedException {
803                  lock.lock();
804                  c.await();
805                  lock.unlock();
806              }});
807  
808 <        Thread t2 = new Thread(new CheckedRunnable() {
808 >        Thread t2 = newStartedThread(new CheckedRunnable() {
809              public void realRun() throws InterruptedException {
810                  lock.lock();
811                  c.await();
812                  lock.unlock();
813              }});
814  
827        t1.start();
828        t2.start();
815          delay(SHORT_DELAY_MS);
816          lock.lock();
817          c.signalAll();
# Line 842 | Line 828 | public class ReentrantLockTest extends J
828      public void testAwaitLockCount() throws InterruptedException {
829          final ReentrantLock lock = new ReentrantLock();
830          final Condition c = lock.newCondition();
831 <        Thread t1 = new Thread(new CheckedRunnable() {
831 >        Thread t1 = newStartedThread(new CheckedRunnable() {
832              public void realRun() throws InterruptedException {
833                  lock.lock();
834                  assertEquals(1, lock.getHoldCount());
# Line 851 | Line 837 | public class ReentrantLockTest extends J
837                  lock.unlock();
838              }});
839  
840 <        Thread t2 = new Thread(new CheckedRunnable() {
840 >        Thread t2 = newStartedThread(new CheckedRunnable() {
841              public void realRun() throws InterruptedException {
842                  lock.lock();
843                  lock.lock();
# Line 862 | Line 848 | public class ReentrantLockTest extends J
848                  lock.unlock();
849              }});
850  
865        t1.start();
866        t2.start();
851          delay(SHORT_DELAY_MS);
852          lock.lock();
853          c.signalAll();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines