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

Comparing jsr166/src/test/tck/CountDownLatchTest.java (file contents):
Revision 1.13 by jsr166, Sat Nov 21 05:05:38 2009 UTC vs.
Revision 1.19 by jsr166, Fri May 27 19:40:19 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 13 | Line 13 | import static java.util.concurrent.TimeU
13  
14   public class CountDownLatchTest extends JSR166TestCase {
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run (suite());
16 >        junit.textui.TestRunner.run(suite());
17      }
18      public static Test suite() {
19          return new TestSuite(CountDownLatchTest.class);
# Line 59 | Line 59 | public class CountDownLatchTest extends
59  
60          Thread t = new Thread(new CheckedRunnable() {
61              public void realRun() throws InterruptedException {
62 <                threadAssertTrue(l.getCount() > 0);
62 >                assertTrue(l.getCount() > 0);
63                  l.await();
64 <                threadAssertTrue(l.getCount() == 0);
64 >                assertEquals(0, l.getCount());
65              }});
66  
67          t.start();
68          assertEquals(l.getCount(), 2);
69 <        Thread.sleep(SHORT_DELAY_MS);
69 >        delay(SHORT_DELAY_MS);
70          l.countDown();
71          assertEquals(l.getCount(), 1);
72          l.countDown();
# Line 74 | Line 74 | public class CountDownLatchTest extends
74          t.join();
75      }
76  
77
77      /**
78       * timed await returns after countDown to zero
79       */
# Line 83 | Line 82 | public class CountDownLatchTest extends
82  
83          Thread t = new Thread(new CheckedRunnable() {
84              public void realRun() throws InterruptedException {
85 <                threadAssertTrue(l.getCount() > 0);
86 <                threadAssertTrue(l.await(SMALL_DELAY_MS, MILLISECONDS));
85 >                assertTrue(l.getCount() > 0);
86 >                assertTrue(l.await(SMALL_DELAY_MS, MILLISECONDS));
87              }});
88  
89          t.start();
90          assertEquals(l.getCount(), 2);
91 <        Thread.sleep(SHORT_DELAY_MS);
91 >        delay(SHORT_DELAY_MS);
92          l.countDown();
93          assertEquals(l.getCount(), 1);
94          l.countDown();
# Line 104 | Line 103 | public class CountDownLatchTest extends
103          final CountDownLatch l = new CountDownLatch(1);
104          Thread t = new Thread(new CheckedInterruptedRunnable() {
105              public void realRun() throws InterruptedException {
106 <                threadAssertTrue(l.getCount() > 0);
106 >                assertTrue(l.getCount() > 0);
107                  l.await();
108              }});
109  
# Line 121 | Line 120 | public class CountDownLatchTest extends
120          final CountDownLatch l = new CountDownLatch(1);
121          Thread t = new Thread(new CheckedInterruptedRunnable() {
122              public void realRun() throws InterruptedException {
123 <                threadAssertTrue(l.getCount() > 0);
123 >                assertTrue(l.getCount() > 0);
124                  l.await(MEDIUM_DELAY_MS, MILLISECONDS);
125              }});
126  
127          t.start();
128 <        Thread.sleep(SHORT_DELAY_MS);
128 >        delay(SHORT_DELAY_MS);
129          assertEquals(l.getCount(), 1);
130          t.interrupt();
131          t.join();
# Line 139 | Line 138 | public class CountDownLatchTest extends
138          final CountDownLatch l = new CountDownLatch(1);
139          Thread t = new Thread(new CheckedRunnable() {
140              public void realRun() throws InterruptedException {
141 <                threadAssertTrue(l.getCount() > 0);
142 <                threadAssertFalse(l.await(SHORT_DELAY_MS, MILLISECONDS));
143 <                threadAssertTrue(l.getCount() > 0);
141 >                assertTrue(l.getCount() > 0);
142 >                assertFalse(l.await(SHORT_DELAY_MS, MILLISECONDS));
143 >                assertTrue(l.getCount() > 0);
144              }});
145  
146          t.start();
# Line 154 | Line 153 | public class CountDownLatchTest extends
153       */
154      public void testToString() {
155          CountDownLatch s = new CountDownLatch(2);
156 <        String us = s.toString();
158 <        assertTrue(us.indexOf("Count = 2") >= 0);
156 >        assertTrue(s.toString().contains("Count = 2"));
157          s.countDown();
158 <        String s1 = s.toString();
161 <        assertTrue(s1.indexOf("Count = 1") >= 0);
158 >        assertTrue(s.toString().contains("Count = 1"));
159          s.countDown();
160 <        String s2 = s.toString();
164 <        assertTrue(s2.indexOf("Count = 0") >= 0);
160 >        assertTrue(s.toString().contains("Count = 0"));
161      }
162  
163   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines