95 |
|
*/ |
96 |
|
public void testBug8186171() { |
97 |
|
if (!impl.supportsSetValue()) return; |
98 |
+ |
if (!atLeastJava10()) return; // jdk9 is abandoned |
99 |
|
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
100 |
|
final boolean permitsNullValues = impl.permitsNullValues(); |
101 |
|
final Object v1 = (permitsNullValues && rnd.nextBoolean()) |
103 |
|
final Object v2 = (permitsNullValues && rnd.nextBoolean() && v1 != null) |
104 |
|
? null : impl.makeValue(2); |
105 |
|
|
106 |
< |
/** If true, always lands in first bucket in hash tables. */ |
106 |
> |
// If true, always lands in first bucket in hash tables. |
107 |
|
final boolean poorHash = rnd.nextBoolean(); |
108 |
|
class Key implements Comparable<Key> { |
109 |
|
final int i; |
140 |
|
assertEquals(1, m.size()); |
141 |
|
} |
142 |
|
|
143 |
+ |
/** |
144 |
+ |
* "Missing" test found while investigating JDK-8210280. |
145 |
+ |
* ant -Djsr166.tckTestClass=HashMapTest -Djsr166.methodFilter=testBug8210280 -Djsr166.runsPerTest=1000000 tck |
146 |
+ |
*/ |
147 |
+ |
public void testBug8210280() { |
148 |
+ |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
149 |
+ |
final int size1 = rnd.nextInt(32); |
150 |
+ |
final int size2 = rnd.nextInt(128); |
151 |
+ |
|
152 |
+ |
final Map m1 = impl.emptyMap(); |
153 |
+ |
for (int i = 0; i < size1; i++) { |
154 |
+ |
int elt = rnd.nextInt(1024 * i, 1024 * (i + 1)); |
155 |
+ |
assertNull(m1.put(impl.makeKey(elt), impl.makeValue(elt))); |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
final Map m2 = impl.emptyMap(); |
159 |
+ |
for (int i = 0; i < size2; i++) { |
160 |
+ |
int elt = rnd.nextInt(Integer.MIN_VALUE + 1024 * i, |
161 |
+ |
Integer.MIN_VALUE + 1024 * (i + 1)); |
162 |
+ |
assertNull(m2.put(impl.makeKey(elt), impl.makeValue(-elt))); |
163 |
+ |
} |
164 |
+ |
|
165 |
+ |
final Map m1Copy = impl.emptyMap(); |
166 |
+ |
m1Copy.putAll(m1); |
167 |
+ |
|
168 |
+ |
m1.putAll(m2); |
169 |
+ |
|
170 |
+ |
for (Object elt : m2.keySet()) |
171 |
+ |
assertEquals(m2.get(elt), m1.get(elt)); |
172 |
+ |
for (Object elt : m1Copy.keySet()) |
173 |
+ |
assertSame(m1Copy.get(elt), m1.get(elt)); |
174 |
+ |
assertEquals(size1 + size2, m1.size()); |
175 |
+ |
} |
176 |
+ |
|
177 |
+ |
/** |
178 |
+ |
* 8222930: ConcurrentSkipListMap.clone() shares size variable between original and clone |
179 |
+ |
*/ |
180 |
+ |
public void testClone() { |
181 |
+ |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
182 |
+ |
final int size = rnd.nextInt(4); |
183 |
+ |
final Map map = impl.emptyMap(); |
184 |
+ |
for (int i = 0; i < size; i++) |
185 |
+ |
map.put(impl.makeKey(i), impl.makeValue(i)); |
186 |
+ |
final Map clone = cloneableClone(map); |
187 |
+ |
if (clone == null) return; // not cloneable? |
188 |
+ |
|
189 |
+ |
assertEquals(size, map.size()); |
190 |
+ |
assertEquals(size, clone.size()); |
191 |
+ |
assertEquals(map.isEmpty(), clone.isEmpty()); |
192 |
+ |
|
193 |
+ |
clone.put(impl.makeKey(-1), impl.makeValue(-1)); |
194 |
+ |
assertEquals(size, map.size()); |
195 |
+ |
assertEquals(size + 1, clone.size()); |
196 |
+ |
|
197 |
+ |
clone.clear(); |
198 |
+ |
assertEquals(size, map.size()); |
199 |
+ |
assertEquals(0, clone.size()); |
200 |
+ |
assertTrue(clone.isEmpty()); |
201 |
+ |
} |
202 |
+ |
|
203 |
|
// public void testFailsIntentionallyForDebugging() { |
204 |
|
// fail(impl.klazz().getSimpleName()); |
205 |
|
// } |