25 |
|
return new TestSuite(PhaserTest.class); |
26 |
|
} |
27 |
|
|
28 |
+ |
private static final int maxParties = 65535; |
29 |
+ |
|
30 |
|
/** Checks state of phaser. */ |
31 |
|
protected void assertState(Phaser phaser, |
32 |
|
int phase, int parties, int unarrived) { |
54 |
|
* Empty constructor builds a new Phaser with no parent, no registered |
55 |
|
* parties and initial phase number of 0 |
56 |
|
*/ |
57 |
< |
public void testConstructor1() { |
57 |
> |
public void testConstructorDefaultValues() { |
58 |
|
Phaser phaser = new Phaser(); |
59 |
|
assertNull(phaser.getParent()); |
60 |
+ |
assertEquals(0, phaser.getRegisteredParties()); |
61 |
|
assertEquals(0, phaser.getArrivedParties()); |
62 |
+ |
assertEquals(0, phaser.getUnarrivedParties()); |
63 |
|
assertEquals(0, phaser.getPhase()); |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* A negative party number for the constructor throws illegal argument |
68 |
< |
* exception |
67 |
> |
* Constructing with a negative number of parties throws |
68 |
> |
* IllegalArgumentException |
69 |
|
*/ |
70 |
< |
public void testConstructor2() { |
70 |
> |
public void testConstructorNegativeParties() { |
71 |
|
try { |
72 |
|
new Phaser(-1); |
73 |
|
shouldThrow(); |
75 |
|
} |
76 |
|
|
77 |
|
/** |
78 |
< |
* The parent being input into the constructor should equal the original |
79 |
< |
* parent when being returned |
78 |
> |
* Constructing with a negative number of parties throws |
79 |
> |
* IllegalArgumentException |
80 |
|
*/ |
81 |
< |
public void testConstructor3() { |
82 |
< |
Phaser parent = new Phaser(); |
83 |
< |
assertEquals(parent, new Phaser(parent).getParent()); |
81 |
> |
public void testConstructorNegativeParties2() { |
82 |
> |
try { |
83 |
> |
new Phaser(new Phaser(), -1); |
84 |
> |
shouldThrow(); |
85 |
> |
} catch (IllegalArgumentException success) {} |
86 |
|
} |
87 |
|
|
88 |
|
/** |
89 |
< |
* A negative party number for the constructor throws illegal argument |
90 |
< |
* exception |
89 |
> |
* Constructing with a number of parties > 65535 throws |
90 |
> |
* IllegalArgumentException |
91 |
|
*/ |
92 |
< |
public void testConstructor4() { |
92 |
> |
public void testConstructorPartiesExceedsLimit() { |
93 |
> |
new Phaser(maxParties); |
94 |
|
try { |
95 |
< |
new Phaser(new Phaser(), -1); |
95 |
> |
new Phaser(maxParties + 1); |
96 |
> |
shouldThrow(); |
97 |
> |
} catch (IllegalArgumentException success) {} |
98 |
> |
|
99 |
> |
new Phaser(new Phaser(), maxParties); |
100 |
> |
try { |
101 |
> |
new Phaser(new Phaser(), maxParties + 1); |
102 |
|
shouldThrow(); |
103 |
|
} catch (IllegalArgumentException success) {} |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
+ |
* The parent provided to the constructor should be returned from |
108 |
+ |
* a later call to getParent |
109 |
+ |
*/ |
110 |
+ |
public void testConstructor3() { |
111 |
+ |
Phaser parent = new Phaser(); |
112 |
+ |
assertSame(parent, new Phaser(parent).getParent()); |
113 |
+ |
assertNull(new Phaser(null).getParent()); |
114 |
+ |
} |
115 |
+ |
|
116 |
+ |
/** |
117 |
|
* The parent being input into the parameter should equal the original |
118 |
|
* parent when being returned |
119 |
|
*/ |
120 |
|
public void testConstructor5() { |
121 |
|
Phaser parent = new Phaser(); |
122 |
< |
assertEquals(parent, new Phaser(parent, 0).getParent()); |
122 |
> |
assertSame(parent, new Phaser(parent, 0).getParent()); |
123 |
> |
assertNull(new Phaser(null, 0).getParent()); |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
< |
* register() will increment the number of unarrived parties by one and not |
128 |
< |
* affect its arrived parties |
127 |
> |
* register() will increment the number of unarrived parties by |
128 |
> |
* one and not affect its arrived parties |
129 |
|
*/ |
130 |
|
public void testRegister1() { |
131 |
|
Phaser phaser = new Phaser(); |
139 |
|
*/ |
140 |
|
public void testRegister2() { |
141 |
|
Phaser phaser = new Phaser(0); |
118 |
– |
int maxParties = (1 << 16) - 1; |
142 |
|
assertState(phaser, 0, 0, 0); |
143 |
|
assertEquals(0, phaser.bulkRegister(maxParties - 10)); |
144 |
|
assertState(phaser, 0, maxParties - 10, maxParties - 10); |
151 |
|
phaser.register(); |
152 |
|
shouldThrow(); |
153 |
|
} catch (IllegalStateException success) {} |
154 |
+ |
|
155 |
+ |
try { |
156 |
+ |
phaser.bulkRegister(Integer.MAX_VALUE); |
157 |
+ |
shouldThrow(); |
158 |
+ |
} catch (IllegalStateException success) {} |
159 |
|
} |
160 |
|
|
161 |
|
/** |