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

Comparing jsr166/src/test/tck/ConcurrentHashMap8Test.java (file contents):
Revision 1.3 by dl, Fri Mar 22 14:11:32 2013 UTC vs.
Revision 1.33 by jsr166, Sun Nov 6 22:42:10 2016 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
8 < import java.util.*;
9 < import java.util.function.*;
10 < import java.util.concurrent.atomic.LongAdder;
7 > import static java.util.Spliterator.CONCURRENT;
8 > import static java.util.Spliterator.DISTINCT;
9 > import static java.util.Spliterator.NONNULL;
10 >
11 > import java.util.AbstractMap;
12 > import java.util.Arrays;
13 > import java.util.Collection;
14 > import java.util.Iterator;
15 > import java.util.Map;
16 > import java.util.NoSuchElementException;
17 > import java.util.Set;
18 > import java.util.Spliterator;
19 > import java.util.concurrent.ExecutorService;
20 > import java.util.concurrent.Executors;
21   import java.util.concurrent.ConcurrentHashMap;
22 + import java.util.concurrent.atomic.LongAdder;
23 + import java.util.function.BiFunction;
24 +
25 + import junit.framework.Test;
26 + import junit.framework.TestSuite;
27  
28   public class ConcurrentHashMap8Test extends JSR166TestCase {
29      public static void main(String[] args) {
30 <        junit.textui.TestRunner.run(suite());
30 >        main(suite(), args);
31      }
32      public static Test suite() {
33          return new TestSuite(ConcurrentHashMap8Test.class);
# Line 48 | Line 63 | public class ConcurrentHashMap8Test exte
63       */
64      public void testComputeIfAbsent() {
65          ConcurrentHashMap map = map5();
66 <        map.computeIfAbsent(six, (x) -> "Z");
66 >        map.computeIfAbsent(six, x -> "Z");
67          assertTrue(map.containsKey(six));
68      }
69  
70      /**
71 <     * computeIfAbsent does not replace  if the key is already present
71 >     * computeIfAbsent does not replace if the key is already present
72       */
73      public void testComputeIfAbsent2() {
74          ConcurrentHashMap map = map5();
75 <        assertEquals("A", map.computeIfAbsent(one, (x) -> "Z"));
75 >        assertEquals("A", map.computeIfAbsent(one, x -> "Z"));
76      }
77  
78      /**
# Line 65 | Line 80 | public class ConcurrentHashMap8Test exte
80       */
81      public void testComputeIfAbsent3() {
82          ConcurrentHashMap map = map5();
83 <        map.computeIfAbsent(six, (x) -> null);
83 >        map.computeIfAbsent(six, x -> null);
84          assertFalse(map.containsKey(six));
85      }
86 <    
86 >
87      /**
88 <     * computeIfPresent does not replace  if the key is already present
88 >     * computeIfPresent does not replace if the key is already present
89       */
90      public void testComputeIfPresent() {
91          ConcurrentHashMap map = map5();
# Line 87 | Line 102 | public class ConcurrentHashMap8Test exte
102      }
103  
104      /**
105 <     * compute does not replace  if the function returns null
105 >     * compute does not replace if the function returns null
106       */
107      public void testCompute() {
108          ConcurrentHashMap map = map5();
# Line 149 | Line 164 | public class ConcurrentHashMap8Test exte
164          Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
165          assertTrue(a.isEmpty());
166          for (int i = 0; i < n; i++)
167 <            a.add(i);
168 <        assertFalse(a.isEmpty());
167 >            assertTrue(a.add(i));
168 >        assertEquals(n == 0, a.isEmpty());
169          assertEquals(n, a.size());
170          return a;
171      }
# Line 159 | Line 174 | public class ConcurrentHashMap8Test exte
174          Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
175          assertTrue(a.isEmpty());
176          for (int i = 0; i < elements.length; i++)
177 <            a.add(elements[i]);
177 >            assertTrue(a.add(elements[i]));
178          assertFalse(a.isEmpty());
179          assertEquals(elements.length, a.size());
180          return a;
181      }
182  
183      /**
184 +     * replaceAll replaces all matching values.
185 +     */
186 +    public void testReplaceAll() {
187 +        ConcurrentHashMap<Integer, String> map = map5();
188 +        map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; });
189 +        assertEquals("A", map.get(one));
190 +        assertEquals("B", map.get(two));
191 +        assertEquals("C", map.get(three));
192 +        assertEquals("Z", map.get(four));
193 +        assertEquals("Z", map.get(five));
194 +    }
195 +
196 +    /**
197       * Default-constructed set is empty
198       */
199      public void testNewKeySet() {
# Line 174 | Line 202 | public class ConcurrentHashMap8Test exte
202      }
203  
204      /**
205 +     * keySet.add adds the key with the established value to the map;
206 +     * remove removes it.
207 +     */
208 +    public void testKeySetAddRemove() {
209 +        ConcurrentHashMap map = map5();
210 +        Set set1 = map.keySet();
211 +        Set set2 = map.keySet(true);
212 +        set2.add(six);
213 +        assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
214 +        assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
215 +        assertEquals(set2.size(), map.size());
216 +        assertEquals(set1.size(), map.size());
217 +        assertTrue((Boolean)map.get(six));
218 +        assertTrue(set1.contains(six));
219 +        assertTrue(set2.contains(six));
220 +        set2.remove(six);
221 +        assertNull(map.get(six));
222 +        assertFalse(set1.contains(six));
223 +        assertFalse(set2.contains(six));
224 +    }
225 +
226 +    /**
227       * keySet.addAll adds each element from the given collection
228       */
229      public void testAddAll() {
230          Set full = populatedSet(3);
231 <        Vector v = new Vector();
232 <        v.add(three);
233 <        v.add(four);
184 <        v.add(five);
185 <        full.addAll(v);
231 >        assertTrue(full.addAll(Arrays.asList(three, four, five)));
232 >        assertEquals(6, full.size());
233 >        assertFalse(full.addAll(Arrays.asList(three, four, five)));
234          assertEquals(6, full.size());
235      }
236  
# Line 192 | Line 240 | public class ConcurrentHashMap8Test exte
240       */
241      public void testAddAll2() {
242          Set full = populatedSet(3);
243 <        Vector v = new Vector();
244 <        v.add(three);
245 <        v.add(four);
246 <        v.add(one); // will not add this element
199 <        full.addAll(v);
243 >        // "one" is duplicate and will not be added
244 >        assertTrue(full.addAll(Arrays.asList(three, four, one)));
245 >        assertEquals(5, full.size());
246 >        assertFalse(full.addAll(Arrays.asList(three, four, one)));
247          assertEquals(5, full.size());
248      }
249  
# Line 205 | Line 252 | public class ConcurrentHashMap8Test exte
252       */
253      public void testAdd2() {
254          Set full = populatedSet(3);
255 <        full.add(one);
255 >        assertFalse(full.add(one));
256          assertEquals(3, full.size());
257      }
258  
# Line 214 | Line 261 | public class ConcurrentHashMap8Test exte
261       */
262      public void testAdd3() {
263          Set full = populatedSet(3);
264 <        full.add(three);
264 >        assertTrue(full.add(three));
265          assertTrue(full.contains(three));
266 +        assertFalse(full.add(three));
267 +        assertTrue(full.contains(three));
268 +    }
269 +
270 +    /**
271 +     * keySet.add throws UnsupportedOperationException if no default
272 +     * mapped value
273 +     */
274 +    public void testAdd4() {
275 +        Set full = map5().keySet();
276 +        try {
277 +            full.add(three);
278 +            shouldThrow();
279 +        } catch (UnsupportedOperationException success) {}
280 +    }
281 +
282 +    /**
283 +     * keySet.add throws NullPointerException if the specified key is
284 +     * null
285 +     */
286 +    public void testAdd5() {
287 +        Set full = populatedSet(3);
288 +        try {
289 +            full.add(null);
290 +            shouldThrow();
291 +        } catch (NullPointerException success) {}
292 +    }
293 +
294 +    /**
295 +     * KeySetView.getMappedValue returns the map's mapped value
296 +     */
297 +    public void testGetMappedValue() {
298 +        ConcurrentHashMap map = map5();
299 +        assertNull(map.keySet().getMappedValue());
300 +        try {
301 +            map.keySet(null);
302 +            shouldThrow();
303 +        } catch (NullPointerException success) {}
304 +        ConcurrentHashMap.KeySetView set = map.keySet(one);
305 +        assertFalse(set.add(one));
306 +        assertTrue(set.add(six));
307 +        assertTrue(set.add(seven));
308 +        assertTrue(set.getMappedValue() == one);
309 +        assertTrue(map.get(one) != one);
310 +        assertTrue(map.get(six) == one);
311 +        assertTrue(map.get(seven) == one);
312 +    }
313 +
314 +    void checkSpliteratorCharacteristics(Spliterator<?> sp,
315 +                                         int requiredCharacteristics) {
316 +        assertEquals(requiredCharacteristics,
317 +                     requiredCharacteristics & sp.characteristics());
318 +    }
319 +
320 +    /**
321 +     * KeySetView.spliterator returns spliterator over the elements in this set
322 +     */
323 +    public void testKeySetSpliterator() {
324 +        LongAdder adder = new LongAdder();
325 +        ConcurrentHashMap map = map5();
326 +        Set set = map.keySet();
327 +        Spliterator<Integer> sp = set.spliterator();
328 +        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
329 +        assertEquals(sp.estimateSize(), map.size());
330 +        Spliterator<Integer> sp2 = sp.trySplit();
331 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
332 +        long v = adder.sumThenReset();
333 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
334 +        long v2 = adder.sum();
335 +        assertEquals(v + v2, 15);
336      }
337  
338      /**
# Line 258 | Line 375 | public class ConcurrentHashMap8Test exte
375       * KeySet.containsAll returns true for collections with subset of elements
376       */
377      public void testContainsAll() {
378 <        Set full = populatedSet(3);
379 <        Vector v = new Vector();
380 <        v.add(one);
381 <        v.add(two);
382 <        assertTrue(full.containsAll(v));
383 <        v.add(six);
267 <        assertFalse(full.containsAll(v));
378 >        Collection full = populatedSet(3);
379 >        assertTrue(full.containsAll(Arrays.asList()));
380 >        assertTrue(full.containsAll(Arrays.asList(one)));
381 >        assertTrue(full.containsAll(Arrays.asList(one, two)));
382 >        assertFalse(full.containsAll(Arrays.asList(one, two, six)));
383 >        assertFalse(full.containsAll(Arrays.asList(six)));
384      }
385  
386      /**
387       * KeySet.isEmpty is true when empty, else false
388       */
389      public void testIsEmpty() {
390 <        Set empty = ConcurrentHashMap.newKeySet();
391 <        Set full = populatedSet(3);
276 <        assertTrue(empty.isEmpty());
277 <        assertFalse(full.isEmpty());
390 >        assertTrue(populatedSet(0).isEmpty());
391 >        assertFalse(populatedSet(3).isEmpty());
392      }
393  
394      /**
# Line 293 | Line 407 | public class ConcurrentHashMap8Test exte
407          Integer[] elements = new Integer[size];
408          for (int i = 0; i < size; i++)
409              elements[i] = i;
410 <        Collections.shuffle(Arrays.asList(elements));
410 >        shuffle(elements);
411          Collection<Integer> full = populatedSet(elements);
412  
413          Iterator it = full.iterator();
# Line 301 | Line 415 | public class ConcurrentHashMap8Test exte
415              assertTrue(it.hasNext());
416              it.next();
417          }
418 <        assertFalse(it.hasNext());
419 <        try {
420 <            it.next();
421 <            shouldThrow();
422 <        } catch (NoSuchElementException success) {}
418 >        assertIteratorExhausted(it);
419 >    }
420 >
421 >    /**
422 >     * iterator of empty collections has no elements
423 >     */
424 >    public void testEmptyIterator() {
425 >        assertIteratorExhausted(ConcurrentHashMap.newKeySet().iterator());
426 >        assertIteratorExhausted(new ConcurrentHashMap().entrySet().iterator());
427 >        assertIteratorExhausted(new ConcurrentHashMap().values().iterator());
428 >        assertIteratorExhausted(new ConcurrentHashMap().keySet().iterator());
429      }
430  
431      /**
# Line 339 | Line 459 | public class ConcurrentHashMap8Test exte
459       */
460      public void testRemoveAll() {
461          Set full = populatedSet(3);
462 <        Vector v = new Vector();
463 <        v.add(one);
464 <        v.add(two);
345 <        full.removeAll(v);
462 >        assertTrue(full.removeAll(Arrays.asList(one, two)));
463 >        assertEquals(1, full.size());
464 >        assertFalse(full.removeAll(Arrays.asList(one, two)));
465          assertEquals(1, full.size());
466      }
467  
# Line 378 | Line 497 | public class ConcurrentHashMap8Test exte
497          Integer[] elements = new Integer[size];
498          for (int i = 0; i < size; i++)
499              elements[i] = i;
500 <        Collections.shuffle(Arrays.asList(elements));
500 >        shuffle(elements);
501          Collection<Integer> full = populatedSet(elements);
502 <        
502 >
503          assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray())));
504          assertTrue(full.containsAll(Arrays.asList(full.toArray())));
505          assertSame(Object[].class, full.toArray().getClass());
# Line 398 | Line 517 | public class ConcurrentHashMap8Test exte
517          a = new Integer[0];
518          assertSame(a, empty.toArray(a));
519  
520 <        a = new Integer[size/2];
520 >        a = new Integer[size / 2];
521          Arrays.fill(a, 42);
522          assertSame(a, empty.toArray(a));
523          assertNull(a[0]);
# Line 408 | Line 527 | public class ConcurrentHashMap8Test exte
527          Integer[] elements = new Integer[size];
528          for (int i = 0; i < size; i++)
529              elements[i] = i;
530 <        Collections.shuffle(Arrays.asList(elements));
530 >        shuffle(elements);
531          Collection<Integer> full = populatedSet(elements);
532  
533          Arrays.fill(a, 42);
# Line 431 | Line 550 | public class ConcurrentHashMap8Test exte
550          Set x = populatedSet(size);
551          Set y = serialClone(x);
552  
553 <        assertTrue(x != y);
553 >        assertNotSame(x, y);
554          assertEquals(x.size(), y.size());
436        assertEquals(x.toString(), y.toString());
437        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
555          assertEquals(x, y);
556          assertEquals(y, x);
557      }
558  
442
559      static final int SIZE = 10000;
560      static ConcurrentHashMap<Long, Long> longMap;
561 <    
561 >
562      static ConcurrentHashMap<Long, Long> longMap() {
563          if (longMap == null) {
564              longMap = new ConcurrentHashMap<Long, Long>(SIZE);
# Line 456 | Line 572 | public class ConcurrentHashMap8Test exte
572      static class AddKeys implements BiFunction<Map.Entry<Long,Long>, Map.Entry<Long,Long>, Map.Entry<Long,Long>> {
573          public Map.Entry<Long,Long> apply(Map.Entry<Long,Long> x, Map.Entry<Long,Long> y) {
574              return new AbstractMap.SimpleEntry<Long,Long>
575 <             (Long.valueOf(x.getKey().longValue() + y.getKey().longValue()),
575 >             (Long.valueOf(x.getKey().longValue() + y.getKey().longValue()),
576                Long.valueOf(1L));
577          }
578      }
# Line 467 | Line 583 | public class ConcurrentHashMap8Test exte
583      public void testForEachKeySequentially() {
584          LongAdder adder = new LongAdder();
585          ConcurrentHashMap<Long, Long> m = longMap();
586 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
586 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
587          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
588      }
589  
# Line 477 | Line 593 | public class ConcurrentHashMap8Test exte
593      public void testForEachValueSequentially() {
594          LongAdder adder = new LongAdder();
595          ConcurrentHashMap<Long, Long> m = longMap();
596 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
596 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
597          assertEquals(adder.sum(), SIZE * (SIZE - 1));
598      }
599  
# Line 487 | Line 603 | public class ConcurrentHashMap8Test exte
603      public void testForEachSequentially() {
604          LongAdder adder = new LongAdder();
605          ConcurrentHashMap<Long, Long> m = longMap();
606 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
606 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
607          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
608      }
609  
# Line 497 | Line 613 | public class ConcurrentHashMap8Test exte
613      public void testForEachEntrySequentially() {
614          LongAdder adder = new LongAdder();
615          ConcurrentHashMap<Long, Long> m = longMap();
616 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
616 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
617          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
618      }
619  
# Line 507 | Line 623 | public class ConcurrentHashMap8Test exte
623      public void testForEachKeyInParallel() {
624          LongAdder adder = new LongAdder();
625          ConcurrentHashMap<Long, Long> m = longMap();
626 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
626 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
627          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
628      }
629  
# Line 517 | Line 633 | public class ConcurrentHashMap8Test exte
633      public void testForEachValueInParallel() {
634          LongAdder adder = new LongAdder();
635          ConcurrentHashMap<Long, Long> m = longMap();
636 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
636 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
637          assertEquals(adder.sum(), SIZE * (SIZE - 1));
638      }
639  
# Line 527 | Line 643 | public class ConcurrentHashMap8Test exte
643      public void testForEachInParallel() {
644          LongAdder adder = new LongAdder();
645          ConcurrentHashMap<Long, Long> m = longMap();
646 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
646 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
647          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
648      }
649  
# Line 537 | Line 653 | public class ConcurrentHashMap8Test exte
653      public void testForEachEntryInParallel() {
654          LongAdder adder = new LongAdder();
655          ConcurrentHashMap<Long, Long> m = longMap();
656 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
656 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
657          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
658      }
659  
# Line 548 | Line 664 | public class ConcurrentHashMap8Test exte
664      public void testMappedForEachKeySequentially() {
665          LongAdder adder = new LongAdder();
666          ConcurrentHashMap<Long, Long> m = longMap();
667 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
667 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
668                                   (Long x) -> adder.add(x.longValue()));
669          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
670      }
# Line 560 | Line 676 | public class ConcurrentHashMap8Test exte
676      public void testMappedForEachValueSequentially() {
677          LongAdder adder = new LongAdder();
678          ConcurrentHashMap<Long, Long> m = longMap();
679 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
679 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
680                                     (Long x) -> adder.add(x.longValue()));
681          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
682      }
# Line 572 | Line 688 | public class ConcurrentHashMap8Test exte
688      public void testMappedForEachSequentially() {
689          LongAdder adder = new LongAdder();
690          ConcurrentHashMap<Long, Long> m = longMap();
691 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
691 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
692                                (Long x) -> adder.add(x.longValue()));
693          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
694      }
# Line 584 | Line 700 | public class ConcurrentHashMap8Test exte
700      public void testMappedForEachEntrySequentially() {
701          LongAdder adder = new LongAdder();
702          ConcurrentHashMap<Long, Long> m = longMap();
703 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
703 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
704                                     (Long x) -> adder.add(x.longValue()));
705          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
706      }
# Line 596 | Line 712 | public class ConcurrentHashMap8Test exte
712      public void testMappedForEachKeyInParallel() {
713          LongAdder adder = new LongAdder();
714          ConcurrentHashMap<Long, Long> m = longMap();
715 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
715 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
716                                 (Long x) -> adder.add(x.longValue()));
717          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
718      }
# Line 608 | Line 724 | public class ConcurrentHashMap8Test exte
724      public void testMappedForEachValueInParallel() {
725          LongAdder adder = new LongAdder();
726          ConcurrentHashMap<Long, Long> m = longMap();
727 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
727 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
728                                   (Long x) -> adder.add(x.longValue()));
729          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
730      }
# Line 620 | Line 736 | public class ConcurrentHashMap8Test exte
736      public void testMappedForEachInParallel() {
737          LongAdder adder = new LongAdder();
738          ConcurrentHashMap<Long, Long> m = longMap();
739 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
739 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
740                              (Long x) -> adder.add(x.longValue()));
741          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
742      }
# Line 632 | Line 748 | public class ConcurrentHashMap8Test exte
748      public void testMappedForEachEntryInParallel() {
749          LongAdder adder = new LongAdder();
750          ConcurrentHashMap<Long, Long> m = longMap();
751 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
751 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
752                                   (Long x) -> adder.add(x.longValue()));
753          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
754      }
755  
640
756      /**
757       * reduceKeysSequentially accumulates across all keys,
758       */
759      public void testReduceKeysSequentially() {
760          ConcurrentHashMap<Long, Long> m = longMap();
761          Long r;
762 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
762 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
763          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
764      }
765  
# Line 654 | Line 769 | public class ConcurrentHashMap8Test exte
769      public void testReduceValuesSequentially() {
770          ConcurrentHashMap<Long, Long> m = longMap();
771          Long r;
772 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
772 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
773          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
774      }
775  
661
776      /**
777       * reduceEntriesSequentially accumulates across all entries
778       */
779      public void testReduceEntriesSequentially() {
780          ConcurrentHashMap<Long, Long> m = longMap();
781          Map.Entry<Long,Long> r;
782 <        r = m.reduceEntriesSequentially(new AddKeys());
782 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
783          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
784      }
785  
# Line 675 | Line 789 | public class ConcurrentHashMap8Test exte
789      public void testReduceKeysInParallel() {
790          ConcurrentHashMap<Long, Long> m = longMap();
791          Long r;
792 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
792 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
793          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
794      }
795  
# Line 685 | Line 799 | public class ConcurrentHashMap8Test exte
799      public void testReduceValuesInParallel() {
800          ConcurrentHashMap<Long, Long> m = longMap();
801          Long r;
802 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
802 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
803          assertEquals((long)r, (long)SIZE * (SIZE - 1));
804      }
805  
# Line 695 | Line 809 | public class ConcurrentHashMap8Test exte
809      public void testReduceEntriesInParallel() {
810          ConcurrentHashMap<Long, Long> m = longMap();
811          Map.Entry<Long,Long> r;
812 <        r = m.reduceEntriesInParallel(new AddKeys());
812 >        r = m.reduceEntries(1L, new AddKeys());
813          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
814      }
815  
816 <    /*
816 >    /**
817       * Mapped reduceKeysSequentially accumulates mapped keys
818       */
819      public void testMapReduceKeysSequentially() {
820          ConcurrentHashMap<Long, Long> m = longMap();
821 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
821 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
822                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
823          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
824      }
825  
826 <    /*
826 >    /**
827       * Mapped reduceValuesSequentially accumulates mapped values
828       */
829      public void testMapReduceValuesSequentially() {
830          ConcurrentHashMap<Long, Long> m = longMap();
831 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
831 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
832                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
833          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
834      }
# Line 724 | Line 838 | public class ConcurrentHashMap8Test exte
838       */
839      public void testMappedReduceSequentially() {
840          ConcurrentHashMap<Long, Long> m = longMap();
841 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
841 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
842                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
843 <        
843 >
844          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
845      }
846  
847 <    /*
847 >    /**
848       * Mapped reduceKeysInParallel, accumulates mapped keys
849       */
850      public void testMapReduceKeysInParallel() {
851          ConcurrentHashMap<Long, Long> m = longMap();
852 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
852 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
853                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
854          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
855      }
856  
857 <    /*
857 >    /**
858       * Mapped reduceValuesInParallel accumulates mapped values
859       */
860      public void testMapReduceValuesInParallel() {
861          ConcurrentHashMap<Long, Long> m = longMap();
862 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
862 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
863                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
864          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
865      }
# Line 756 | Line 870 | public class ConcurrentHashMap8Test exte
870      public void testMappedReduceInParallel() {
871          ConcurrentHashMap<Long, Long> m = longMap();
872          Long r;
873 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
873 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
874                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
875          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
876      }
877  
878 <
765 <    /*
878 >    /**
879       * reduceKeysToLongSequentially accumulates mapped keys
880       */
881      public void testReduceKeysToLongSequentially() {
882          ConcurrentHashMap<Long, Long> m = longMap();
883 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
883 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
884          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
885      }
886  
887 <    /*
887 >    /**
888       * reduceKeysToIntSequentially accumulates mapped keys
889       */
890      public void testReduceKeysToIntSequentially() {
891          ConcurrentHashMap<Long, Long> m = longMap();
892 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
893 <        assertEquals(ir, (int)SIZE * (SIZE - 1) / 2);
892 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
893 >        assertEquals(ir, SIZE * (SIZE - 1) / 2);
894      }
895  
896 <    /*
896 >    /**
897       * reduceKeysToDoubleSequentially accumulates mapped keys
898       */
899      public void testReduceKeysToDoubleSequentially() {
900          ConcurrentHashMap<Long, Long> m = longMap();
901 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
901 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
902          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
903      }
904  
905 <    /*
905 >    /**
906       * reduceValuesToLongSequentially accumulates mapped values
907       */
908      public void testReduceValuesToLongSequentially() {
909          ConcurrentHashMap<Long, Long> m = longMap();
910 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
910 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
911          assertEquals(lr, (long)SIZE * (SIZE - 1));
912      }
913  
914 <    /*
914 >    /**
915       * reduceValuesToIntSequentially accumulates mapped values
916       */
917      public void testReduceValuesToIntSequentially() {
918          ConcurrentHashMap<Long, Long> m = longMap();
919 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
920 <        assertEquals(ir, (int)SIZE * (SIZE - 1));
919 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
920 >        assertEquals(ir, SIZE * (SIZE - 1));
921      }
922  
923 <    /*
923 >    /**
924       * reduceValuesToDoubleSequentially accumulates mapped values
925       */
926      public void testReduceValuesToDoubleSequentially() {
927          ConcurrentHashMap<Long, Long> m = longMap();
928 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
928 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
929          assertEquals(dr, (double)SIZE * (SIZE - 1));
930      }
931  
932 <    /*
932 >    /**
933       * reduceKeysToLongInParallel accumulates mapped keys
934       */
935      public void testReduceKeysToLongInParallel() {
936          ConcurrentHashMap<Long, Long> m = longMap();
937 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
937 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
938          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
939      }
940  
941 <    /*
941 >    /**
942       * reduceKeysToIntInParallel accumulates mapped keys
943       */
944      public void testReduceKeysToIntInParallel() {
945          ConcurrentHashMap<Long, Long> m = longMap();
946 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
947 <        assertEquals(ir, (int)SIZE * (SIZE - 1) / 2);
946 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
947 >        assertEquals(ir, SIZE * (SIZE - 1) / 2);
948      }
949  
950 <    /*
950 >    /**
951       * reduceKeysToDoubleInParallel accumulates mapped values
952       */
953      public void testReduceKeysToDoubleInParallel() {
954          ConcurrentHashMap<Long, Long> m = longMap();
955 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
955 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
956          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
957      }
958  
959 <    /*
959 >    /**
960       * reduceValuesToLongInParallel accumulates mapped values
961       */
962      public void testReduceValuesToLongInParallel() {
963          ConcurrentHashMap<Long, Long> m = longMap();
964 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
964 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
965          assertEquals(lr, (long)SIZE * (SIZE - 1));
966      }
967  
968 <    /*
968 >    /**
969       * reduceValuesToIntInParallel accumulates mapped values
970       */
971      public void testReduceValuesToIntInParallel() {
972          ConcurrentHashMap<Long, Long> m = longMap();
973 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
974 <        assertEquals(ir, (int)SIZE * (SIZE - 1));
973 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
974 >        assertEquals(ir, SIZE * (SIZE - 1));
975      }
976  
977 <    /*
977 >    /**
978       * reduceValuesToDoubleInParallel accumulates mapped values
979       */
980      public void testReduceValuesToDoubleInParallel() {
981          ConcurrentHashMap<Long, Long> m = longMap();
982 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
982 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
983          assertEquals(dr, (double)SIZE * (SIZE - 1));
984      }
985  
# Line 877 | Line 990 | public class ConcurrentHashMap8Test exte
990      public void testSearchKeysSequentially() {
991          ConcurrentHashMap<Long, Long> m = longMap();
992          Long r;
993 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
993 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
994          assertEquals((long)r, (long)(SIZE/2));
995 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L? x : null);
995 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
996          assertNull(r);
997      }
998  
# Line 890 | Line 1003 | public class ConcurrentHashMap8Test exte
1003      public void testSearchValuesSequentially() {
1004          ConcurrentHashMap<Long, Long> m = longMap();
1005          Long r;
1006 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1006 >        r = m.searchValues(Long.MAX_VALUE,
1007 >            (Long x) -> (x.longValue() == (long)(SIZE/2)) ? x : null);
1008          assertEquals((long)r, (long)(SIZE/2));
1009 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L? x : null);
1009 >        r = m.searchValues(Long.MAX_VALUE,
1010 >            (Long x) -> (x.longValue() < 0L) ? x : null);
1011          assertNull(r);
1012      }
1013  
# Line 903 | Line 1018 | public class ConcurrentHashMap8Test exte
1018      public void testSearchSequentially() {
1019          ConcurrentHashMap<Long, Long> m = longMap();
1020          Long r;
1021 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null);
1021 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1022          assertEquals((long)r, (long)(SIZE/2));
1023 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L? x : null);
1023 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1024          assertNull(r);
1025      }
1026  
# Line 916 | Line 1031 | public class ConcurrentHashMap8Test exte
1031      public void testSearchEntriesSequentially() {
1032          ConcurrentHashMap<Long, Long> m = longMap();
1033          Long r;
1034 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null);
1034 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1035          assertEquals((long)r, (long)(SIZE/2));
1036 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null);
1036 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1037          assertNull(r);
1038      }
1039  
# Line 929 | Line 1044 | public class ConcurrentHashMap8Test exte
1044      public void testSearchKeysInParallel() {
1045          ConcurrentHashMap<Long, Long> m = longMap();
1046          Long r;
1047 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1047 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1048          assertEquals((long)r, (long)(SIZE/2));
1049 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L? x : null);
1049 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1050          assertNull(r);
1051      }
1052  
# Line 942 | Line 1057 | public class ConcurrentHashMap8Test exte
1057      public void testSearchValuesInParallel() {
1058          ConcurrentHashMap<Long, Long> m = longMap();
1059          Long r;
1060 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1060 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1061          assertEquals((long)r, (long)(SIZE/2));
1062 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L? x : null);
1062 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1063          assertNull(r);
1064      }
1065  
# Line 955 | Line 1070 | public class ConcurrentHashMap8Test exte
1070      public void testSearchInParallel() {
1071          ConcurrentHashMap<Long, Long> m = longMap();
1072          Long r;
1073 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null);
1073 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1074          assertEquals((long)r, (long)(SIZE/2));
1075 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L? x : null);
1075 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1076          assertNull(r);
1077      }
1078  
# Line 968 | Line 1083 | public class ConcurrentHashMap8Test exte
1083      public void testSearchEntriesInParallel() {
1084          ConcurrentHashMap<Long, Long> m = longMap();
1085          Long r;
1086 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null);
1086 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1087          assertEquals((long)r, (long)(SIZE/2));
1088 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null);
1088 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1089          assertNull(r);
1090      }
1091  
1092      /**
1093 <     * Invoking task versions of bulk methods has same effect as
1094 <     * parallel methods
1095 <     */
1096 <    public void testForkJoinTasks() {
1097 <        LongAdder adder = new LongAdder();
1098 <        ConcurrentHashMap<Long, Long> m = longMap();
1099 <        ConcurrentHashMap.ForkJoinTasks.forEachKey
1100 <            (m, (Long x) -> adder.add(x.longValue())).invoke();
1101 <        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
1102 <        adder.reset();
1103 <        ConcurrentHashMap.ForkJoinTasks.forEachValue
1104 <            (m, (Long x) -> adder.add(x.longValue())).invoke();
1105 <        assertEquals(adder.sum(), SIZE * (SIZE - 1));
1106 <        adder.reset();
1107 <        ConcurrentHashMap.ForkJoinTasks.forEach
1108 <            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
1109 <        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1110 <        adder.reset();
1111 <        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1112 <            (m,
1113 <             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
1114 <        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1115 <        adder.reset();
1116 <        ConcurrentHashMap.ForkJoinTasks.forEachKey
1002 <            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1003 <             (Long x) -> adder.add(x.longValue())).invoke();
1004 <        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
1005 <        adder.reset();
1006 <        ConcurrentHashMap.ForkJoinTasks.forEachValue
1007 <            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1008 <             (Long x) -> adder.add(x.longValue())).invoke();
1009 <        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
1010 <        adder.reset();
1011 <        ConcurrentHashMap.ForkJoinTasks.forEach
1012 <            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1013 <             (Long x) -> adder.add(x.longValue())).invoke();
1014 <        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1015 <        adder.reset();
1016 <        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1017 <            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1018 <             (Long x) -> adder.add(x.longValue())).invoke();
1019 <        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1020 <        adder.reset();
1093 >     * Tests performance of computeIfAbsent when the element is present.
1094 >     * See JDK-8161372
1095 >     * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testcomputeIfAbsent_performance -Djsr166.expensiveTests=true tck
1096 >     */
1097 >    public void testcomputeIfAbsent_performance() {
1098 >        final int mapSize = 20;
1099 >        final int iterations = expensiveTests ? (1 << 23) : mapSize * 2;
1100 >        final int threads = expensiveTests ? 10 : 2;
1101 >        final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
1102 >        for (int i = 0; i < mapSize; i++)
1103 >            map.put(i, i);
1104 >        final ExecutorService pool = Executors.newFixedThreadPool(2);
1105 >        try (PoolCleaner cleaner = cleaner(pool)) {
1106 >            Runnable r = new CheckedRunnable() {
1107 >                public void realRun() {
1108 >                    int result = 0;
1109 >                    for (int i = 0; i < iterations; i++)
1110 >                        result += map.computeIfAbsent(i % mapSize, k -> k + k);
1111 >                    if (result == -42) throw new Error();
1112 >                }};
1113 >            for (int i = 0; i < threads; i++)
1114 >                pool.execute(r);
1115 >        }
1116 >    }
1117  
1022        Long r; long lr; int ir; double dr;
1023        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1024            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1025        assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
1026        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1027            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1028        assertEquals((long)r, (long)SIZE * (SIZE - 1));
1029        r = ConcurrentHashMap.ForkJoinTasks.reduce
1030            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1031             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1032        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1033        r = ConcurrentHashMap.ForkJoinTasks.reduceEntries
1034            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1035             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1036        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1037        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1038            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1039             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1040        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
1041        lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong
1042            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1043        assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
1044        ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt
1045            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1046        assertEquals(ir, (int)SIZE * (SIZE - 1) / 2);
1047        dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble
1048            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1049        assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
1050        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1051            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1052             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1053        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
1054        lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong
1055            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1056        assertEquals(lr, (long)SIZE * (SIZE - 1));
1057        ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt
1058            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1059        assertEquals(ir, (int)SIZE * (SIZE - 1));
1060        dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble
1061            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1062        assertEquals(dr, (double)SIZE * (SIZE - 1));
1063        r = ConcurrentHashMap.ForkJoinTasks.searchKeys
1064            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1065        assertEquals((long)r, (long)(SIZE/2));
1066        r = ConcurrentHashMap.ForkJoinTasks.searchValues
1067            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1068        assertEquals((long)r, (long)(SIZE/2));
1069        r = ConcurrentHashMap.ForkJoinTasks.search
1070            (m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1071        assertEquals((long)r, (long)(SIZE/2));
1072        r = ConcurrentHashMap.ForkJoinTasks.searchEntries
1073            (m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke();
1074        assertEquals((long)r, (long)(SIZE/2));
1075    }            
1118   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines