141 |
|
|
142 |
|
/** |
143 |
|
* "Missing" test found while investigating JDK-8210280. |
144 |
< |
* See discussion on mailing list. |
145 |
< |
* TODO: randomize |
144 |
> |
* ant -Djsr166.tckTestClass=HashMapTest -Djsr166.methodFilter=testBug8210280 -Djsr166.runsPerTest=1000000 tck |
145 |
|
*/ |
146 |
|
public void testBug8210280() { |
147 |
< |
Map m = impl.emptyMap(); |
148 |
< |
for (int i = 0; i < 4; i++) m.put(7 + i * 16, 0); |
149 |
< |
Map more = impl.emptyMap(); |
150 |
< |
for (int i = 0; i < 128; i++) more.put(-i, 42); |
151 |
< |
m.putAll(more); |
152 |
< |
for (int i = 0; i < 4; i++) assertEquals(0, m.get(7 + i * 16)); |
147 |
> |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
148 |
> |
final int size1 = rnd.nextInt(32); |
149 |
> |
final int size2 = rnd.nextInt(128); |
150 |
> |
|
151 |
> |
final Map m1 = impl.emptyMap(); |
152 |
> |
for (int i = 0; i < size1; i++) { |
153 |
> |
int elt = rnd.nextInt(1024 * i, 1024 * (i + 1)); |
154 |
> |
assertNull(m1.put(impl.makeKey(elt), impl.makeValue(elt))); |
155 |
> |
} |
156 |
> |
|
157 |
> |
final Map m2 = impl.emptyMap(); |
158 |
> |
for (int i = 0; i < size2; i++) { |
159 |
> |
int elt = rnd.nextInt(Integer.MIN_VALUE + 1024 * i, |
160 |
> |
Integer.MIN_VALUE + 1024 * (i + 1)); |
161 |
> |
assertNull(m2.put(impl.makeKey(elt), impl.makeValue(-elt))); |
162 |
> |
} |
163 |
> |
|
164 |
> |
final Map m1Copy = impl.emptyMap(); |
165 |
> |
m1Copy.putAll(m1); |
166 |
> |
|
167 |
> |
m1.putAll(m2); |
168 |
> |
|
169 |
> |
for (Object elt : m2.keySet()) |
170 |
> |
assertEquals(m2.get(elt), m1.get(elt)); |
171 |
> |
for (Object elt : m1Copy.keySet()) |
172 |
> |
assertSame(m1Copy.get(elt), m1.get(elt)); |
173 |
> |
assertEquals(size1 + size2, m1.size()); |
174 |
> |
} |
175 |
> |
|
176 |
> |
/** |
177 |
> |
* 8222930: ConcurrentSkipListMap.clone() shares size variable between original and clone |
178 |
> |
*/ |
179 |
> |
public void testClone() { |
180 |
> |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
181 |
> |
final int size = rnd.nextInt(4); |
182 |
> |
final Map map = impl.emptyMap(); |
183 |
> |
for (int i = size; i--> 0; ) |
184 |
> |
map.put(impl.makeKey(i), impl.makeValue(i)); |
185 |
> |
final Map clone = cloneableClone(map); |
186 |
> |
if (clone == null) return; // not cloneable? |
187 |
> |
|
188 |
> |
assertEquals(size, map.size()); |
189 |
> |
assertEquals(size, clone.size()); |
190 |
> |
assertEquals(map.isEmpty(), clone.isEmpty()); |
191 |
> |
|
192 |
> |
clone.put(impl.makeKey(-1), impl.makeValue(-1)); |
193 |
> |
assertEquals(size, map.size()); |
194 |
> |
assertEquals(size + 1, clone.size()); |
195 |
> |
|
196 |
> |
clone.clear(); |
197 |
> |
assertEquals(size, map.size()); |
198 |
> |
assertEquals(0, clone.size()); |
199 |
> |
assertTrue(clone.isEmpty()); |
200 |
|
} |
201 |
|
|
202 |
|
// public void testFailsIntentionallyForDebugging() { |