5 |
|
* Other contributors include John Vint |
6 |
|
*/ |
7 |
|
|
8 |
< |
import junit.framework.*; |
8 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
9 |
> |
|
10 |
|
import java.util.ArrayList; |
11 |
|
import java.util.List; |
11 |
– |
import java.util.concurrent.Phaser; |
12 |
|
import java.util.concurrent.CountDownLatch; |
13 |
+ |
import java.util.concurrent.Phaser; |
14 |
|
import java.util.concurrent.TimeoutException; |
14 |
– |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 |
– |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
16 |
– |
import java.util.concurrent.atomic.AtomicBoolean; |
15 |
|
import java.util.concurrent.atomic.AtomicInteger; |
16 |
|
|
17 |
+ |
import junit.framework.Test; |
18 |
+ |
import junit.framework.TestSuite; |
19 |
+ |
|
20 |
|
public class PhaserTest extends JSR166TestCase { |
21 |
|
|
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run(suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
|
26 |
|
public static Test suite() { |
166 |
|
} |
167 |
|
|
168 |
|
/** |
169 |
< |
* register() correctly returns the current barrier phase number when |
170 |
< |
* invoked |
169 |
> |
* register() correctly returns the current barrier phase number |
170 |
> |
* when invoked |
171 |
|
*/ |
172 |
|
public void testRegister3() { |
173 |
|
Phaser phaser = new Phaser(); |
178 |
|
} |
179 |
|
|
180 |
|
/** |
181 |
< |
* register causes the next arrive to not increment the phase rather retain |
182 |
< |
* the phase number |
181 |
> |
* register causes the next arrive to not increment the phase |
182 |
> |
* rather retain the phase number |
183 |
|
*/ |
184 |
|
public void testRegister4() { |
185 |
|
Phaser phaser = new Phaser(1); |
190 |
|
} |
191 |
|
|
192 |
|
/** |
193 |
+ |
* register on a subphaser that is currently empty succeeds, even |
194 |
+ |
* in the presence of another non-empty subphaser |
195 |
+ |
*/ |
196 |
+ |
public void testRegisterEmptySubPhaser() { |
197 |
+ |
Phaser root = new Phaser(); |
198 |
+ |
Phaser child1 = new Phaser(root, 1); |
199 |
+ |
Phaser child2 = new Phaser(root, 0); |
200 |
+ |
assertEquals(0, child2.register()); |
201 |
+ |
assertState(root, 0, 2, 2); |
202 |
+ |
assertState(child1, 0, 1, 1); |
203 |
+ |
assertState(child2, 0, 1, 1); |
204 |
+ |
assertEquals(0, child2.arriveAndDeregister()); |
205 |
+ |
assertState(root, 0, 1, 1); |
206 |
+ |
assertState(child1, 0, 1, 1); |
207 |
+ |
assertState(child2, 0, 0, 0); |
208 |
+ |
assertEquals(0, child2.register()); |
209 |
+ |
assertEquals(0, child2.arriveAndDeregister()); |
210 |
+ |
assertState(root, 0, 1, 1); |
211 |
+ |
assertState(child1, 0, 1, 1); |
212 |
+ |
assertState(child2, 0, 0, 0); |
213 |
+ |
assertEquals(0, child1.arriveAndDeregister()); |
214 |
+ |
assertTerminated(root, 1); |
215 |
+ |
assertTerminated(child1, 1); |
216 |
+ |
assertTerminated(child2, 1); |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
/** |
220 |
|
* Invoking bulkRegister with a negative parameter throws an |
221 |
|
* IllegalArgumentException |
222 |
|
*/ |
228 |
|
} |
229 |
|
|
230 |
|
/** |
231 |
< |
* bulkRegister should correctly record the number of unarrived parties with |
232 |
< |
* the number of parties being registered |
231 |
> |
* bulkRegister should correctly record the number of unarrived |
232 |
> |
* parties with the number of parties being registered |
233 |
|
*/ |
234 |
|
public void testBulkRegister2() { |
235 |
|
Phaser phaser = new Phaser(); |
338 |
|
* registered or unarrived parties would become negative |
339 |
|
*/ |
340 |
|
public void testArriveAndDeregister1() { |
341 |
+ |
Phaser phaser = new Phaser(); |
342 |
|
try { |
314 |
– |
Phaser phaser = new Phaser(); |
343 |
|
phaser.arriveAndDeregister(); |
344 |
|
shouldThrow(); |
345 |
|
} catch (IllegalStateException success) {} |
629 |
|
count.incrementAndGet(); |
630 |
|
assertEquals(2*k+1, phaser.arrive()); |
631 |
|
assertEquals(2*k+2, phaser.awaitAdvance(2*k+1)); |
632 |
< |
assertEquals(count.get(), 4*(k+1)); |
632 |
> |
assertEquals(4*(k+1), count.get()); |
633 |
|
}}})); |
634 |
|
|
635 |
|
for (Thread thread : threads) |
748 |
|
* unarrived parties |
749 |
|
*/ |
750 |
|
public void testArriveAndAwaitAdvance1() { |
751 |
+ |
Phaser phaser = new Phaser(); |
752 |
|
try { |
724 |
– |
Phaser phaser = new Phaser(); |
753 |
|
phaser.arriveAndAwaitAdvance(); |
754 |
|
shouldThrow(); |
755 |
|
} catch (IllegalStateException success) {} |