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.31 by jsr166, Sat Nov 21 02:33:20 2009 UTC vs.
Revision 1.39 by jsr166, Tue Mar 15 19:47:07 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 15 | Line 15 | import java.io.*;
15  
16   public class ReentrantLockTest extends JSR166TestCase {
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20      public static Test suite() {
21          return new TestSuite(ReentrantLockTest.class);
# Line 56 | Line 56 | public class ReentrantLockTest extends J
56          public Collection<Thread> getWaitingThreads(Condition c) {
57              return super.getWaitingThreads(c);
58          }
59
60
59      }
60  
61      /**
# Line 270 | Line 268 | public class ReentrantLockTest extends J
268              }});
269  
270          t.start();
271 +        Thread.sleep(SHORT_DELAY_MS);
272          t.interrupt();
273          t.join();
274      }
# Line 283 | Line 282 | public class ReentrantLockTest extends J
282          lock.lock();
283          Thread t = new Thread(new CheckedRunnable() {
284              public void realRun() {
285 <                threadAssertFalse(lock.tryLock());
285 >                assertFalse(lock.tryLock());
286              }});
287  
288          t.start();
# Line 299 | Line 298 | public class ReentrantLockTest extends J
298          lock.lock();
299          Thread t = new Thread(new CheckedRunnable() {
300              public void realRun() throws InterruptedException {
301 <                threadAssertFalse(lock.tryLock(1, MILLISECONDS));
301 >                assertFalse(lock.tryLock(1, MILLISECONDS));
302              }});
303  
304          t.start();
# Line 370 | Line 369 | public class ReentrantLockTest extends J
369          lock.lockInterruptibly();
370          Thread t = new Thread(new InterruptedLockRunnable(lock));
371          t.start();
372 +        Thread.sleep(SHORT_DELAY_MS);
373          t.interrupt();
374          assertTrue(lock.isLocked());
375          assertTrue(lock.isHeldByCurrentThread());
# Line 413 | Line 413 | public class ReentrantLockTest extends J
413      }
414  
415      /**
416 <     *  timed await without a signal times out
416 >     * timed await without a signal times out
417       */
418      public void testAwait_Timeout() throws InterruptedException {
419          final ReentrantLock lock = new ReentrantLock();
# Line 579 | Line 579 | public class ReentrantLockTest extends J
579          Thread t = new Thread(new CheckedRunnable() {
580              public void realRun() throws InterruptedException {
581                  lock.lock();
582 <                threadAssertFalse(lock.hasWaiters(c));
583 <                threadAssertEquals(0, lock.getWaitQueueLength(c));
582 >                assertFalse(lock.hasWaiters(c));
583 >                assertEquals(0, lock.getWaitQueueLength(c));
584                  c.await();
585                  lock.unlock();
586              }});
# Line 610 | Line 610 | public class ReentrantLockTest extends J
610          Thread t1 = new Thread(new CheckedRunnable() {
611              public void realRun() throws InterruptedException {
612                  lock.lock();
613 <                threadAssertFalse(lock.hasWaiters(c));
614 <                threadAssertEquals(0, lock.getWaitQueueLength(c));
613 >                assertFalse(lock.hasWaiters(c));
614 >                assertEquals(0, lock.getWaitQueueLength(c));
615                  c.await();
616                  lock.unlock();
617              }});
# Line 619 | Line 619 | public class ReentrantLockTest extends J
619          Thread t2 = new Thread(new CheckedRunnable() {
620              public void realRun() throws InterruptedException {
621                  lock.lock();
622 <                threadAssertTrue(lock.hasWaiters(c));
623 <                threadAssertEquals(1, lock.getWaitQueueLength(c));
622 >                assertTrue(lock.hasWaiters(c));
623 >                assertEquals(1, lock.getWaitQueueLength(c));
624                  c.await();
625                  lock.unlock();
626              }});
# Line 654 | Line 654 | public class ReentrantLockTest extends J
654          Thread t1 = new Thread(new CheckedRunnable() {
655              public void realRun() throws InterruptedException {
656                  lock.lock();
657 <                threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
657 >                assertTrue(lock.getWaitingThreads(c).isEmpty());
658                  c.await();
659                  lock.unlock();
660              }});
# Line 662 | Line 662 | public class ReentrantLockTest extends J
662          Thread t2 = new Thread(new CheckedRunnable() {
663              public void realRun() throws InterruptedException {
664                  lock.lock();
665 <                threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
665 >                assertFalse(lock.getWaitingThreads(c).isEmpty());
666                  c.await();
667                  lock.unlock();
668              }});
# Line 774 | Line 774 | public class ReentrantLockTest extends J
774          Thread t = new Thread(new CheckedInterruptedRunnable() {
775              public void realRun() throws InterruptedException {
776                  lock.lock();
777 <                c.awaitNanos(1000 * 1000 * 1000); // 1 sec
777 >                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
778              }});
779  
780          t.start();
# Line 845 | Line 845 | public class ReentrantLockTest extends J
845          Thread t1 = new Thread(new CheckedRunnable() {
846              public void realRun() throws InterruptedException {
847                  lock.lock();
848 <                threadAssertEquals(1, lock.getHoldCount());
848 >                assertEquals(1, lock.getHoldCount());
849                  c.await();
850 <                threadAssertEquals(1, lock.getHoldCount());
850 >                assertEquals(1, lock.getHoldCount());
851                  lock.unlock();
852              }});
853  
# Line 855 | Line 855 | public class ReentrantLockTest extends J
855              public void realRun() throws InterruptedException {
856                  lock.lock();
857                  lock.lock();
858 <                threadAssertEquals(2, lock.getHoldCount());
858 >                assertEquals(2, lock.getHoldCount());
859                  c.await();
860 <                threadAssertEquals(2, lock.getHoldCount());
860 >                assertEquals(2, lock.getHoldCount());
861                  lock.unlock();
862                  lock.unlock();
863              }});
# Line 887 | Line 887 | public class ReentrantLockTest extends J
887              new ObjectOutputStream(new BufferedOutputStream(bout));
888          out.writeObject(l);
889          out.close();
890 <        
890 >
891          ByteArrayInputStream bin =
892              new ByteArrayInputStream(bout.toByteArray());
893          ObjectInputStream in =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines