12 |
|
import java.util.concurrent.CountDownLatch; |
13 |
|
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 |
|
public class PhaserTest extends JSR166TestCase { |
163 |
|
} |
164 |
|
|
165 |
|
/** |
166 |
< |
* register() correctly returns the current barrier phase number when |
167 |
< |
* invoked |
166 |
> |
* register() correctly returns the current barrier phase number |
167 |
> |
* when invoked |
168 |
|
*/ |
169 |
|
public void testRegister3() { |
170 |
|
Phaser phaser = new Phaser(); |
175 |
|
} |
176 |
|
|
177 |
|
/** |
178 |
< |
* register causes the next arrive to not increment the phase rather retain |
179 |
< |
* the phase number |
178 |
> |
* register causes the next arrive to not increment the phase |
179 |
> |
* rather retain the phase number |
180 |
|
*/ |
181 |
|
public void testRegister4() { |
182 |
|
Phaser phaser = new Phaser(1); |
187 |
|
} |
188 |
|
|
189 |
|
/** |
190 |
+ |
* register on a subphaser that is currently empty succeeds, even |
191 |
+ |
* in the presence of another non-empty subphaser |
192 |
+ |
*/ |
193 |
+ |
public void testRegisterEmptySubPhaser() { |
194 |
+ |
Phaser root = new Phaser(); |
195 |
+ |
Phaser child1 = new Phaser(root, 1); |
196 |
+ |
Phaser child2 = new Phaser(root, 0); |
197 |
+ |
assertEquals(0, child2.register()); |
198 |
+ |
assertState(root, 0, 2, 2); |
199 |
+ |
assertState(child1, 0, 1, 1); |
200 |
+ |
assertState(child2, 0, 1, 1); |
201 |
+ |
assertEquals(0, child2.arriveAndDeregister()); |
202 |
+ |
assertState(root, 0, 1, 1); |
203 |
+ |
assertState(child1, 0, 1, 1); |
204 |
+ |
assertState(child2, 0, 0, 0); |
205 |
+ |
assertEquals(0, child2.register()); |
206 |
+ |
assertEquals(0, child2.arriveAndDeregister()); |
207 |
+ |
assertState(root, 0, 1, 1); |
208 |
+ |
assertState(child1, 0, 1, 1); |
209 |
+ |
assertState(child2, 0, 0, 0); |
210 |
+ |
assertEquals(0, child1.arriveAndDeregister()); |
211 |
+ |
assertTerminated(root, 1); |
212 |
+ |
assertTerminated(child1, 1); |
213 |
+ |
assertTerminated(child2, 1); |
214 |
+ |
} |
215 |
+ |
|
216 |
+ |
/** |
217 |
|
* Invoking bulkRegister with a negative parameter throws an |
218 |
|
* IllegalArgumentException |
219 |
|
*/ |
225 |
|
} |
226 |
|
|
227 |
|
/** |
228 |
< |
* bulkRegister should correctly record the number of unarrived parties with |
229 |
< |
* the number of parties being registered |
228 |
> |
* bulkRegister should correctly record the number of unarrived |
229 |
> |
* parties with the number of parties being registered |
230 |
|
*/ |
231 |
|
public void testBulkRegister2() { |
232 |
|
Phaser phaser = new Phaser(); |
626 |
|
count.incrementAndGet(); |
627 |
|
assertEquals(2*k+1, phaser.arrive()); |
628 |
|
assertEquals(2*k+2, phaser.awaitAdvance(2*k+1)); |
629 |
< |
assertEquals(count.get(), 4*(k+1)); |
629 |
> |
assertEquals(4*(k+1), count.get()); |
630 |
|
}}})); |
631 |
|
|
632 |
|
for (Thread thread : threads) |