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.3 by dl, Sat Sep 20 18:20:07 2003 UTC vs.
Revision 1.4 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 18 | Line 18 | public class CountDownLatchTest extends
18      }
19  
20      /**
21 <     *
21 >     * negative constructor argument throws IAE
22       */
23      public void testConstructor() {
24          try {
# Line 28 | Line 28 | public class CountDownLatchTest extends
28      }
29  
30      /**
31 <     *
31 >     * getCount returns initial count and decreases after countDown
32       */
33      public void testGetCount() {
34          final CountDownLatch l = new CountDownLatch(2);
# Line 38 | Line 38 | public class CountDownLatchTest extends
38      }
39  
40      /**
41 <     *
41 >     * countDown has no effect when count is zero
42 >     */
43 >    public void testcountDown() {
44 >        final CountDownLatch l = new CountDownLatch(1);
45 >        assertEquals(1, l.getCount());
46 >        l.countDown();
47 >        assertEquals(0, l.getCount());
48 >        l.countDown();
49 >        assertEquals(0, l.getCount());
50 >    }
51 >
52 >    /**
53 >     * await returns after countDown to zero, but not before
54       */
55      public void testAwait() {
56          final CountDownLatch l = new CountDownLatch(2);
# Line 46 | Line 58 | public class CountDownLatchTest extends
58          Thread t = new Thread(new Runnable() {
59                  public void run() {
60                      try {
61 +                        threadAssertTrue(l.getCount() > 0);
62                          l.await();
63 +                        threadAssertTrue(l.getCount() == 0);
64                      } catch(InterruptedException e){
65                          threadUnexpectedException();
66                      }
# Line 68 | Line 82 | public class CountDownLatchTest extends
82      
83  
84      /**
85 <     *
85 >     * timed await returns after countDown to zero
86       */
87      public void testTimedAwait() {
88          final CountDownLatch l = new CountDownLatch(2);
# Line 76 | Line 90 | public class CountDownLatchTest extends
90          Thread t = new Thread(new Runnable() {
91                  public void run() {
92                      try {
93 +                        threadAssertTrue(l.getCount() > 0);
94                          threadAssertTrue(l.await(SMALL_DELAY_MS, TimeUnit.MILLISECONDS));
95                      } catch(InterruptedException e){
96                          threadUnexpectedException();
# Line 96 | Line 111 | public class CountDownLatchTest extends
111          }
112      }
113      
99
100
101
114      /**
115 <     *
115 >     * await throws IE ig interrupted before counted down
116       */
117      public void testAwait_InterruptedException() {
118          final CountDownLatch l = new CountDownLatch(1);
119          Thread t = new Thread(new Runnable() {
120                  public void run() {
121                      try {
122 +                        threadAssertTrue(l.getCount() > 0);
123                          l.await();
124                          threadShouldThrow();
125                      } catch(InterruptedException success){}
# Line 123 | Line 136 | public class CountDownLatchTest extends
136      }
137  
138      /**
139 <     *
139 >     * timed await throws IE ig interrupted before counted down
140       */
141      public void testTimedAwait_InterruptedException() {
142          final CountDownLatch l = new CountDownLatch(1);
143          Thread t = new Thread(new Runnable() {
144                  public void run() {
145                      try {
146 +                        threadAssertTrue(l.getCount() > 0);
147                          l.await(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
148                          threadShouldThrow();                        
149                      } catch(InterruptedException success){}
# Line 147 | Line 161 | public class CountDownLatchTest extends
161      }
162  
163      /**
164 <     *
164 >     * timed await times out if not counted down before timeout
165       */
166      public void testAwaitTimeout() {
167          final CountDownLatch l = new CountDownLatch(1);
168          Thread t = new Thread(new Runnable() {
169                  public void run() {
170                      try {
171 +                        threadAssertTrue(l.getCount() > 0);
172                          threadAssertFalse(l.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
173 +                        threadAssertTrue(l.getCount() > 0);
174                      } catch(InterruptedException ie){
175                          threadUnexpectedException();
176                      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines