17 |
|
return new TestSuite(CountDownLatchTest.class); |
18 |
|
} |
19 |
|
|
20 |
< |
public void testConstructor(){ |
20 |
> |
/** |
21 |
> |
* |
22 |
> |
*/ |
23 |
> |
public void testConstructor() { |
24 |
|
try { |
25 |
|
new CountDownLatch(-1); |
26 |
< |
fail("should throw IllegalArgumentException"); |
26 |
> |
shouldThrow(); |
27 |
|
} catch(IllegalArgumentException success){} |
28 |
|
} |
29 |
|
|
30 |
< |
public void testGetCount(){ |
30 |
> |
/** |
31 |
> |
* |
32 |
> |
*/ |
33 |
> |
public void testGetCount() { |
34 |
|
final CountDownLatch l = new CountDownLatch(2); |
35 |
|
assertEquals(2, l.getCount()); |
36 |
|
l.countDown(); |
37 |
|
assertEquals(1, l.getCount()); |
38 |
|
} |
39 |
|
|
40 |
< |
public void testAwait(){ |
40 |
> |
/** |
41 |
> |
* |
42 |
> |
*/ |
43 |
> |
public void testAwait() { |
44 |
|
final CountDownLatch l = new CountDownLatch(2); |
45 |
|
|
46 |
< |
Thread t = new Thread(new Runnable(){ |
47 |
< |
public void run(){ |
46 |
> |
Thread t = new Thread(new Runnable() { |
47 |
> |
public void run() { |
48 |
|
try { |
49 |
|
l.await(); |
50 |
|
} catch(InterruptedException e){ |
51 |
< |
threadFail("unexpected exception"); |
51 |
> |
threadUnexpectedException(); |
52 |
|
} |
53 |
|
} |
54 |
|
}); |
62 |
|
assertEquals(l.getCount(), 0); |
63 |
|
t.join(); |
64 |
|
} catch (InterruptedException e){ |
65 |
< |
fail("unexpected exception"); |
65 |
> |
unexpectedException(); |
66 |
|
} |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
< |
public void testTimedAwait(){ |
70 |
> |
/** |
71 |
> |
* |
72 |
> |
*/ |
73 |
> |
public void testTimedAwait() { |
74 |
|
final CountDownLatch l = new CountDownLatch(2); |
75 |
|
|
76 |
< |
Thread t = new Thread(new Runnable(){ |
77 |
< |
public void run(){ |
76 |
> |
Thread t = new Thread(new Runnable() { |
77 |
> |
public void run() { |
78 |
|
try { |
79 |
|
threadAssertTrue(l.await(SMALL_DELAY_MS, TimeUnit.MILLISECONDS)); |
80 |
|
} catch(InterruptedException e){ |
81 |
< |
threadFail("unexpected exception"); |
81 |
> |
threadUnexpectedException(); |
82 |
|
} |
83 |
|
} |
84 |
|
}); |
92 |
|
assertEquals(l.getCount(), 0); |
93 |
|
t.join(); |
94 |
|
} catch (InterruptedException e){ |
95 |
< |
fail("unexpected exception"); |
95 |
> |
unexpectedException(); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
< |
public void testAwait_InterruptedException(){ |
102 |
> |
/** |
103 |
> |
* |
104 |
> |
*/ |
105 |
> |
public void testAwait_InterruptedException() { |
106 |
|
final CountDownLatch l = new CountDownLatch(1); |
107 |
< |
Thread t = new Thread(new Runnable(){ |
108 |
< |
public void run(){ |
107 |
> |
Thread t = new Thread(new Runnable() { |
108 |
> |
public void run() { |
109 |
|
try { |
110 |
|
l.await(); |
111 |
< |
threadFail("should throw"); |
111 |
> |
threadShouldThrow(); |
112 |
|
} catch(InterruptedException success){} |
113 |
|
} |
114 |
|
}); |
118 |
|
t.interrupt(); |
119 |
|
t.join(); |
120 |
|
} catch (InterruptedException e){ |
121 |
< |
fail("unexpected exception"); |
121 |
> |
unexpectedException(); |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
< |
public void testTimedAwait_InterruptedException(){ |
125 |
> |
/** |
126 |
> |
* |
127 |
> |
*/ |
128 |
> |
public void testTimedAwait_InterruptedException() { |
129 |
|
final CountDownLatch l = new CountDownLatch(1); |
130 |
< |
Thread t = new Thread(new Runnable(){ |
131 |
< |
public void run(){ |
130 |
> |
Thread t = new Thread(new Runnable() { |
131 |
> |
public void run() { |
132 |
|
try { |
133 |
|
l.await(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
134 |
< |
threadFail("should throw"); |
134 |
> |
threadShouldThrow(); |
135 |
|
} catch(InterruptedException success){} |
136 |
|
} |
137 |
|
}); |
142 |
|
t.interrupt(); |
143 |
|
t.join(); |
144 |
|
} catch (InterruptedException e){ |
145 |
< |
fail("unexpected exception"); |
145 |
> |
unexpectedException(); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
< |
public void testAwaitTimeout(){ |
149 |
> |
/** |
150 |
> |
* |
151 |
> |
*/ |
152 |
> |
public void testAwaitTimeout() { |
153 |
|
final CountDownLatch l = new CountDownLatch(1); |
154 |
< |
Thread t = new Thread(new Runnable(){ |
155 |
< |
public void run(){ |
154 |
> |
Thread t = new Thread(new Runnable() { |
155 |
> |
public void run() { |
156 |
|
try { |
157 |
|
threadAssertFalse(l.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
158 |
|
} catch(InterruptedException ie){ |
159 |
< |
threadFail("unexpected exception"); |
159 |
> |
threadUnexpectedException(); |
160 |
|
} |
161 |
|
} |
162 |
|
}); |
165 |
|
assertEquals(l.getCount(), 1); |
166 |
|
t.join(); |
167 |
|
} catch (InterruptedException e){ |
168 |
< |
fail("unexpected exception"); |
168 |
> |
unexpectedException(); |
169 |
|
} |
170 |
|
} |
171 |
|
|