ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/MapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/MapTest.java (file contents):
Revision 1.2 by jsr166, Mon Jan 8 03:56:32 2018 UTC vs.
Revision 1.5 by jsr166, Wed Apr 24 17:29:50 2019 UTC

# Line 139 | Line 139 | public class MapTest extends JSR166TestC
139          assertEquals(1, m.size());
140      }
141  
142 +    /**
143 +     * "Missing" test found while investigating JDK-8210280.
144 +     * ant -Djsr166.tckTestClass=HashMapTest -Djsr166.methodFilter=testBug8210280 -Djsr166.runsPerTest=1000000 tck
145 +     */
146 +    public void testBug8210280() {
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() {
203   //         fail(impl.klazz().getSimpleName());
204   //     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines