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.8 by jsr166, Thu Apr 11 20:03:44 2013 UTC vs.
Revision 1.23 by jsr166, Fri Feb 27 19:47:57 2015 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.Collections;
15 > import java.util.Iterator;
16 > import java.util.Map;
17 > import java.util.NoSuchElementException;
18 > import java.util.Set;
19 > import java.util.Spliterator;
20   import java.util.concurrent.ConcurrentHashMap;
21 + import java.util.concurrent.atomic.LongAdder;
22 + import java.util.function.BiFunction;
23 +
24 + import junit.framework.Test;
25 + import junit.framework.TestSuite;
26  
27   public class ConcurrentHashMap8Test extends JSR166TestCase {
28      public static void main(String[] args) {
# Line 53 | Line 67 | public class ConcurrentHashMap8Test exte
67      }
68  
69      /**
70 <     * computeIfAbsent does not replace  if the key is already present
70 >     * computeIfAbsent does not replace if the key is already present
71       */
72      public void testComputeIfAbsent2() {
73          ConcurrentHashMap map = map5();
# Line 70 | Line 84 | public class ConcurrentHashMap8Test exte
84      }
85  
86      /**
87 <     * computeIfPresent does not replace  if the key is already present
87 >     * computeIfPresent does not replace if the key is already present
88       */
89      public void testComputeIfPresent() {
90          ConcurrentHashMap map = map5();
# Line 87 | Line 101 | public class ConcurrentHashMap8Test exte
101      }
102  
103      /**
104 <     * compute does not replace  if the function returns null
104 >     * compute does not replace if the function returns null
105       */
106      public void testCompute() {
107          ConcurrentHashMap map = map5();
# Line 150 | Line 164 | public class ConcurrentHashMap8Test exte
164          assertTrue(a.isEmpty());
165          for (int i = 0; i < n; i++)
166              a.add(i);
167 <        assertFalse(a.isEmpty());
167 >        assertEquals(n == 0, a.isEmpty());
168          assertEquals(n, a.size());
169          return a;
170      }
# Line 166 | Line 180 | public class ConcurrentHashMap8Test exte
180      }
181  
182      /**
183 +     * replaceAll replaces all matching values.
184 +     */
185 +    public void testReplaceAll() {
186 +        ConcurrentHashMap<Integer, String> map = map5();
187 +        map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; });
188 +        assertEquals("A", map.get(one));
189 +        assertEquals("B", map.get(two));
190 +        assertEquals("C", map.get(three));
191 +        assertEquals("Z", map.get(four));
192 +        assertEquals("Z", map.get(five));
193 +    }
194 +
195 +    /**
196       * Default-constructed set is empty
197       */
198      public void testNewKeySet() {
# Line 174 | Line 201 | public class ConcurrentHashMap8Test exte
201      }
202  
203      /**
204 +     * keySet.add adds the key with the established value to the map;
205 +     * remove removes it.
206 +     */
207 +    public void testKeySetAddRemove() {
208 +        ConcurrentHashMap map = map5();
209 +        Set set1 = map.keySet();
210 +        Set set2 = map.keySet(true);
211 +        set2.add(six);
212 +        assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
213 +        assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
214 +        assertEquals(set2.size(), map.size());
215 +        assertEquals(set1.size(), map.size());
216 +        assertTrue((Boolean)map.get(six));
217 +        assertTrue(set1.contains(six));
218 +        assertTrue(set2.contains(six));
219 +        set2.remove(six);
220 +        assertNull(map.get(six));
221 +        assertFalse(set1.contains(six));
222 +        assertFalse(set2.contains(six));
223 +    }
224 +
225 +    /**
226       * keySet.addAll adds each element from the given collection
227       */
228      public void testAddAll() {
229          Set full = populatedSet(3);
230 <        Vector v = new Vector();
231 <        v.add(three);
232 <        v.add(four);
184 <        v.add(five);
185 <        full.addAll(v);
230 >        assertTrue(full.addAll(Arrays.asList(three, four, five)));
231 >        assertEquals(6, full.size());
232 >        assertFalse(full.addAll(Arrays.asList(three, four, five)));
233          assertEquals(6, full.size());
234      }
235  
# Line 192 | Line 239 | public class ConcurrentHashMap8Test exte
239       */
240      public void testAddAll2() {
241          Set full = populatedSet(3);
242 <        Vector v = new Vector();
243 <        v.add(three);
244 <        v.add(four);
245 <        v.add(one); // will not add this element
199 <        full.addAll(v);
242 >        // "one" is duplicate and will not be added
243 >        assertTrue(full.addAll(Arrays.asList(three, four, one)));
244 >        assertEquals(5, full.size());
245 >        assertFalse(full.addAll(Arrays.asList(three, four, one)));
246          assertEquals(5, full.size());
247      }
248  
# Line 219 | Line 265 | public class ConcurrentHashMap8Test exte
265      }
266  
267      /**
268 +     * keySet.add throws UnsupportedOperationException if no default
269 +     * mapped value
270 +     */
271 +    public void testAdd4() {
272 +        Set full = map5().keySet();
273 +        try {
274 +            full.add(three);
275 +            shouldThrow();
276 +        } catch (UnsupportedOperationException e){}
277 +    }
278 +
279 +    /**
280 +     * keySet.add throws NullPointerException if the specified key is
281 +     * null
282 +     */
283 +    public void testAdd5() {
284 +        Set full = populatedSet(3);
285 +        try {
286 +            full.add(null);
287 +            shouldThrow();
288 +        } catch (NullPointerException e){}
289 +    }
290 +
291 +    /**
292 +     * KeySetView.getMappedValue returns the map's mapped value
293 +     */
294 +    public void testGetMappedValue() {
295 +        ConcurrentHashMap map = map5();
296 +        assertNull(map.keySet().getMappedValue());
297 +        try {
298 +            map.keySet(null);
299 +            shouldThrow();
300 +        } catch (NullPointerException e) {}
301 +        ConcurrentHashMap.KeySetView set = map.keySet(one);
302 +        set.add(one);
303 +        set.add(six);
304 +        set.add(seven);
305 +        assertTrue(set.getMappedValue() == one);
306 +        assertTrue(map.get(one) != one);
307 +        assertTrue(map.get(six) == one);
308 +        assertTrue(map.get(seven) == one);
309 +    }
310 +
311 +    void checkSpliteratorCharacteristics(Spliterator<?> sp,
312 +                                         int requiredCharacteristics) {
313 +        assertEquals(requiredCharacteristics,
314 +                     requiredCharacteristics & sp.characteristics());
315 +    }
316 +
317 +    /**
318 +     * KeySetView.spliterator returns spliterator over the elements in this set
319 +     */
320 +    public void testKeySetSpliterator() {
321 +        LongAdder adder = new LongAdder();
322 +        ConcurrentHashMap map = map5();
323 +        Set set = map.keySet();
324 +        Spliterator<Integer> sp = set.spliterator();
325 +        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
326 +        assertEquals(sp.estimateSize(), map.size());
327 +        Spliterator<Integer> sp2 = sp.trySplit();
328 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
329 +        long v = adder.sumThenReset();
330 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
331 +        long v2 = adder.sum();
332 +        assertEquals(v + v2, 15);
333 +    }
334 +
335 +    /**
336       * keyset.clear removes all elements from the set
337       */
338      public void testClear() {
# Line 258 | Line 372 | public class ConcurrentHashMap8Test exte
372       * KeySet.containsAll returns true for collections with subset of elements
373       */
374      public void testContainsAll() {
375 <        Set full = populatedSet(3);
376 <        Vector v = new Vector();
377 <        v.add(one);
378 <        v.add(two);
379 <        assertTrue(full.containsAll(v));
380 <        v.add(six);
267 <        assertFalse(full.containsAll(v));
375 >        Collection full = populatedSet(3);
376 >        assertTrue(full.containsAll(Arrays.asList()));
377 >        assertTrue(full.containsAll(Arrays.asList(one)));
378 >        assertTrue(full.containsAll(Arrays.asList(one, two)));
379 >        assertFalse(full.containsAll(Arrays.asList(one, two, six)));
380 >        assertFalse(full.containsAll(Arrays.asList(six)));
381      }
382  
383      /**
384       * KeySet.isEmpty is true when empty, else false
385       */
386      public void testIsEmpty() {
387 <        Set empty = ConcurrentHashMap.newKeySet();
388 <        Set full = populatedSet(3);
276 <        assertTrue(empty.isEmpty());
277 <        assertFalse(full.isEmpty());
387 >        assertTrue(populatedSet(0).isEmpty());
388 >        assertFalse(populatedSet(3).isEmpty());
389      }
390  
391      /**
# Line 301 | Line 412 | public class ConcurrentHashMap8Test exte
412              assertTrue(it.hasNext());
413              it.next();
414          }
415 <        assertFalse(it.hasNext());
416 <        try {
417 <            it.next();
418 <            shouldThrow();
419 <        } catch (NoSuchElementException success) {}
415 >        assertIteratorExhausted(it);
416 >    }
417 >
418 >    /**
419 >     * iterator of empty collections has no elements
420 >     */
421 >    public void testEmptyIterator() {
422 >        assertIteratorExhausted(ConcurrentHashMap.newKeySet().iterator());
423 >        assertIteratorExhausted(new ConcurrentHashMap().entrySet().iterator());
424 >        assertIteratorExhausted(new ConcurrentHashMap().values().iterator());
425 >        assertIteratorExhausted(new ConcurrentHashMap().keySet().iterator());
426      }
427  
428      /**
# Line 339 | Line 456 | public class ConcurrentHashMap8Test exte
456       */
457      public void testRemoveAll() {
458          Set full = populatedSet(3);
459 <        Vector v = new Vector();
460 <        v.add(one);
461 <        v.add(two);
345 <        full.removeAll(v);
459 >        assertTrue(full.removeAll(Arrays.asList(one, two)));
460 >        assertEquals(1, full.size());
461 >        assertFalse(full.removeAll(Arrays.asList(one, two)));
462          assertEquals(1, full.size());
463      }
464  
# Line 431 | Line 547 | public class ConcurrentHashMap8Test exte
547          Set x = populatedSet(size);
548          Set y = serialClone(x);
549  
550 <        assertTrue(x != y);
550 >        assertNotSame(x, y);
551          assertEquals(x.size(), y.size());
436        assertEquals(x.toString(), y.toString());
437        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
552          assertEquals(x, y);
553          assertEquals(y, x);
554      }
555  
442
556      static final int SIZE = 10000;
557      static ConcurrentHashMap<Long, Long> longMap;
558  
# Line 467 | Line 580 | public class ConcurrentHashMap8Test exte
580      public void testForEachKeySequentially() {
581          LongAdder adder = new LongAdder();
582          ConcurrentHashMap<Long, Long> m = longMap();
583 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
583 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
584          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
585      }
586  
# Line 477 | Line 590 | public class ConcurrentHashMap8Test exte
590      public void testForEachValueSequentially() {
591          LongAdder adder = new LongAdder();
592          ConcurrentHashMap<Long, Long> m = longMap();
593 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
593 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
594          assertEquals(adder.sum(), SIZE * (SIZE - 1));
595      }
596  
# Line 487 | Line 600 | public class ConcurrentHashMap8Test exte
600      public void testForEachSequentially() {
601          LongAdder adder = new LongAdder();
602          ConcurrentHashMap<Long, Long> m = longMap();
603 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
603 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
604          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
605      }
606  
# Line 497 | Line 610 | public class ConcurrentHashMap8Test exte
610      public void testForEachEntrySequentially() {
611          LongAdder adder = new LongAdder();
612          ConcurrentHashMap<Long, Long> m = longMap();
613 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
613 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
614          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
615      }
616  
# Line 507 | Line 620 | public class ConcurrentHashMap8Test exte
620      public void testForEachKeyInParallel() {
621          LongAdder adder = new LongAdder();
622          ConcurrentHashMap<Long, Long> m = longMap();
623 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
623 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
624          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
625      }
626  
# Line 517 | Line 630 | public class ConcurrentHashMap8Test exte
630      public void testForEachValueInParallel() {
631          LongAdder adder = new LongAdder();
632          ConcurrentHashMap<Long, Long> m = longMap();
633 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
633 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
634          assertEquals(adder.sum(), SIZE * (SIZE - 1));
635      }
636  
# Line 527 | Line 640 | public class ConcurrentHashMap8Test exte
640      public void testForEachInParallel() {
641          LongAdder adder = new LongAdder();
642          ConcurrentHashMap<Long, Long> m = longMap();
643 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
643 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
644          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
645      }
646  
# Line 537 | Line 650 | public class ConcurrentHashMap8Test exte
650      public void testForEachEntryInParallel() {
651          LongAdder adder = new LongAdder();
652          ConcurrentHashMap<Long, Long> m = longMap();
653 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
653 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
654          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
655      }
656  
# Line 548 | Line 661 | public class ConcurrentHashMap8Test exte
661      public void testMappedForEachKeySequentially() {
662          LongAdder adder = new LongAdder();
663          ConcurrentHashMap<Long, Long> m = longMap();
664 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
664 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
665                                   (Long x) -> adder.add(x.longValue()));
666          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
667      }
# Line 560 | Line 673 | public class ConcurrentHashMap8Test exte
673      public void testMappedForEachValueSequentially() {
674          LongAdder adder = new LongAdder();
675          ConcurrentHashMap<Long, Long> m = longMap();
676 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
676 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
677                                     (Long x) -> adder.add(x.longValue()));
678          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
679      }
# Line 572 | Line 685 | public class ConcurrentHashMap8Test exte
685      public void testMappedForEachSequentially() {
686          LongAdder adder = new LongAdder();
687          ConcurrentHashMap<Long, Long> m = longMap();
688 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
688 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
689                                (Long x) -> adder.add(x.longValue()));
690          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
691      }
# Line 584 | Line 697 | public class ConcurrentHashMap8Test exte
697      public void testMappedForEachEntrySequentially() {
698          LongAdder adder = new LongAdder();
699          ConcurrentHashMap<Long, Long> m = longMap();
700 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
700 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
701                                     (Long x) -> adder.add(x.longValue()));
702          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
703      }
# Line 596 | Line 709 | public class ConcurrentHashMap8Test exte
709      public void testMappedForEachKeyInParallel() {
710          LongAdder adder = new LongAdder();
711          ConcurrentHashMap<Long, Long> m = longMap();
712 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
712 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
713                                 (Long x) -> adder.add(x.longValue()));
714          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
715      }
# Line 608 | Line 721 | public class ConcurrentHashMap8Test exte
721      public void testMappedForEachValueInParallel() {
722          LongAdder adder = new LongAdder();
723          ConcurrentHashMap<Long, Long> m = longMap();
724 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
724 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
725                                   (Long x) -> adder.add(x.longValue()));
726          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
727      }
# Line 620 | Line 733 | public class ConcurrentHashMap8Test exte
733      public void testMappedForEachInParallel() {
734          LongAdder adder = new LongAdder();
735          ConcurrentHashMap<Long, Long> m = longMap();
736 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
736 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
737                              (Long x) -> adder.add(x.longValue()));
738          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
739      }
# Line 632 | Line 745 | public class ConcurrentHashMap8Test exte
745      public void testMappedForEachEntryInParallel() {
746          LongAdder adder = new LongAdder();
747          ConcurrentHashMap<Long, Long> m = longMap();
748 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
748 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
749                                   (Long x) -> adder.add(x.longValue()));
750          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
751      }
752  
640
753      /**
754       * reduceKeysSequentially accumulates across all keys,
755       */
756      public void testReduceKeysSequentially() {
757          ConcurrentHashMap<Long, Long> m = longMap();
758          Long r;
759 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
759 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
760          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
761      }
762  
# Line 654 | Line 766 | public class ConcurrentHashMap8Test exte
766      public void testReduceValuesSequentially() {
767          ConcurrentHashMap<Long, Long> m = longMap();
768          Long r;
769 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
769 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
770          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
771      }
772  
661
773      /**
774       * reduceEntriesSequentially accumulates across all entries
775       */
776      public void testReduceEntriesSequentially() {
777          ConcurrentHashMap<Long, Long> m = longMap();
778          Map.Entry<Long,Long> r;
779 <        r = m.reduceEntriesSequentially(new AddKeys());
779 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
780          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
781      }
782  
# Line 675 | Line 786 | public class ConcurrentHashMap8Test exte
786      public void testReduceKeysInParallel() {
787          ConcurrentHashMap<Long, Long> m = longMap();
788          Long r;
789 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
789 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
790          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
791      }
792  
# Line 685 | Line 796 | public class ConcurrentHashMap8Test exte
796      public void testReduceValuesInParallel() {
797          ConcurrentHashMap<Long, Long> m = longMap();
798          Long r;
799 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
799 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
800          assertEquals((long)r, (long)SIZE * (SIZE - 1));
801      }
802  
# Line 695 | Line 806 | public class ConcurrentHashMap8Test exte
806      public void testReduceEntriesInParallel() {
807          ConcurrentHashMap<Long, Long> m = longMap();
808          Map.Entry<Long,Long> r;
809 <        r = m.reduceEntriesInParallel(new AddKeys());
809 >        r = m.reduceEntries(1L, new AddKeys());
810          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
811      }
812  
# Line 704 | Line 815 | public class ConcurrentHashMap8Test exte
815       */
816      public void testMapReduceKeysSequentially() {
817          ConcurrentHashMap<Long, Long> m = longMap();
818 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
818 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
819                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
820          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
821      }
# Line 714 | Line 825 | public class ConcurrentHashMap8Test exte
825       */
826      public void testMapReduceValuesSequentially() {
827          ConcurrentHashMap<Long, Long> m = longMap();
828 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
828 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
829                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
830          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
831      }
# Line 724 | Line 835 | public class ConcurrentHashMap8Test exte
835       */
836      public void testMappedReduceSequentially() {
837          ConcurrentHashMap<Long, Long> m = longMap();
838 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
838 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
839                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
840  
841          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 735 | Line 846 | public class ConcurrentHashMap8Test exte
846       */
847      public void testMapReduceKeysInParallel() {
848          ConcurrentHashMap<Long, Long> m = longMap();
849 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
849 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
850                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
851          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
852      }
# Line 745 | Line 856 | public class ConcurrentHashMap8Test exte
856       */
857      public void testMapReduceValuesInParallel() {
858          ConcurrentHashMap<Long, Long> m = longMap();
859 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
859 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
860                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
861          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
862      }
# Line 756 | Line 867 | public class ConcurrentHashMap8Test exte
867      public void testMappedReduceInParallel() {
868          ConcurrentHashMap<Long, Long> m = longMap();
869          Long r;
870 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
870 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
871                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
872          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
873      }
874  
764
875      /**
876       * reduceKeysToLongSequentially accumulates mapped keys
877       */
878      public void testReduceKeysToLongSequentially() {
879          ConcurrentHashMap<Long, Long> m = longMap();
880 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
880 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
881          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
882      }
883  
# Line 776 | Line 886 | public class ConcurrentHashMap8Test exte
886       */
887      public void testReduceKeysToIntSequentially() {
888          ConcurrentHashMap<Long, Long> m = longMap();
889 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
889 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
890          assertEquals(ir, SIZE * (SIZE - 1) / 2);
891      }
892  
# Line 785 | Line 895 | public class ConcurrentHashMap8Test exte
895       */
896      public void testReduceKeysToDoubleSequentially() {
897          ConcurrentHashMap<Long, Long> m = longMap();
898 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
898 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
899          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
900      }
901  
# Line 794 | Line 904 | public class ConcurrentHashMap8Test exte
904       */
905      public void testReduceValuesToLongSequentially() {
906          ConcurrentHashMap<Long, Long> m = longMap();
907 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
907 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
908          assertEquals(lr, (long)SIZE * (SIZE - 1));
909      }
910  
# Line 803 | Line 913 | public class ConcurrentHashMap8Test exte
913       */
914      public void testReduceValuesToIntSequentially() {
915          ConcurrentHashMap<Long, Long> m = longMap();
916 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
916 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
917          assertEquals(ir, SIZE * (SIZE - 1));
918      }
919  
# Line 812 | Line 922 | public class ConcurrentHashMap8Test exte
922       */
923      public void testReduceValuesToDoubleSequentially() {
924          ConcurrentHashMap<Long, Long> m = longMap();
925 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
925 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
926          assertEquals(dr, (double)SIZE * (SIZE - 1));
927      }
928  
# Line 821 | Line 931 | public class ConcurrentHashMap8Test exte
931       */
932      public void testReduceKeysToLongInParallel() {
933          ConcurrentHashMap<Long, Long> m = longMap();
934 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
934 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
935          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
936      }
937  
# Line 830 | Line 940 | public class ConcurrentHashMap8Test exte
940       */
941      public void testReduceKeysToIntInParallel() {
942          ConcurrentHashMap<Long, Long> m = longMap();
943 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
943 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
944          assertEquals(ir, SIZE * (SIZE - 1) / 2);
945      }
946  
# Line 839 | Line 949 | public class ConcurrentHashMap8Test exte
949       */
950      public void testReduceKeysToDoubleInParallel() {
951          ConcurrentHashMap<Long, Long> m = longMap();
952 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
952 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
953          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
954      }
955  
# Line 848 | Line 958 | public class ConcurrentHashMap8Test exte
958       */
959      public void testReduceValuesToLongInParallel() {
960          ConcurrentHashMap<Long, Long> m = longMap();
961 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
961 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
962          assertEquals(lr, (long)SIZE * (SIZE - 1));
963      }
964  
# Line 857 | Line 967 | public class ConcurrentHashMap8Test exte
967       */
968      public void testReduceValuesToIntInParallel() {
969          ConcurrentHashMap<Long, Long> m = longMap();
970 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
970 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
971          assertEquals(ir, SIZE * (SIZE - 1));
972      }
973  
# Line 866 | Line 976 | public class ConcurrentHashMap8Test exte
976       */
977      public void testReduceValuesToDoubleInParallel() {
978          ConcurrentHashMap<Long, Long> m = longMap();
979 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
979 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
980          assertEquals(dr, (double)SIZE * (SIZE - 1));
981      }
982  
# Line 877 | Line 987 | public class ConcurrentHashMap8Test exte
987      public void testSearchKeysSequentially() {
988          ConcurrentHashMap<Long, Long> m = longMap();
989          Long r;
990 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
990 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
991          assertEquals((long)r, (long)(SIZE/2));
992 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
992 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
993          assertNull(r);
994      }
995  
# Line 890 | Line 1000 | public class ConcurrentHashMap8Test exte
1000      public void testSearchValuesSequentially() {
1001          ConcurrentHashMap<Long, Long> m = longMap();
1002          Long r;
1003 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1003 >        r = m.searchValues(Long.MAX_VALUE,
1004 >            (Long x) -> (x.longValue() == (long)(SIZE/2)) ? x : null);
1005          assertEquals((long)r, (long)(SIZE/2));
1006 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
1006 >        r = m.searchValues(Long.MAX_VALUE,
1007 >            (Long x) -> (x.longValue() < 0L) ? x : null);
1008          assertNull(r);
1009      }
1010  
# Line 903 | Line 1015 | public class ConcurrentHashMap8Test exte
1015      public void testSearchSequentially() {
1016          ConcurrentHashMap<Long, Long> m = longMap();
1017          Long r;
1018 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1018 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1019          assertEquals((long)r, (long)(SIZE/2));
1020 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1020 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1021          assertNull(r);
1022      }
1023  
# Line 916 | Line 1028 | public class ConcurrentHashMap8Test exte
1028      public void testSearchEntriesSequentially() {
1029          ConcurrentHashMap<Long, Long> m = longMap();
1030          Long r;
1031 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1031 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1032          assertEquals((long)r, (long)(SIZE/2));
1033 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1033 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1034          assertNull(r);
1035      }
1036  
# Line 929 | Line 1041 | public class ConcurrentHashMap8Test exte
1041      public void testSearchKeysInParallel() {
1042          ConcurrentHashMap<Long, Long> m = longMap();
1043          Long r;
1044 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1044 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1045          assertEquals((long)r, (long)(SIZE/2));
1046 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1046 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1047          assertNull(r);
1048      }
1049  
# Line 942 | Line 1054 | public class ConcurrentHashMap8Test exte
1054      public void testSearchValuesInParallel() {
1055          ConcurrentHashMap<Long, Long> m = longMap();
1056          Long r;
1057 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1057 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1058          assertEquals((long)r, (long)(SIZE/2));
1059 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1059 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1060          assertNull(r);
1061      }
1062  
# Line 955 | Line 1067 | public class ConcurrentHashMap8Test exte
1067      public void testSearchInParallel() {
1068          ConcurrentHashMap<Long, Long> m = longMap();
1069          Long r;
1070 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1070 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1071          assertEquals((long)r, (long)(SIZE/2));
1072 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1072 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1073          assertNull(r);
1074      }
1075  
# Line 968 | Line 1080 | public class ConcurrentHashMap8Test exte
1080      public void testSearchEntriesInParallel() {
1081          ConcurrentHashMap<Long, Long> m = longMap();
1082          Long r;
1083 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1083 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1084          assertEquals((long)r, (long)(SIZE/2));
1085 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1085 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1086          assertNull(r);
1087      }
1088  
977    /**
978     * Invoking task versions of bulk methods has same effect as
979     * parallel methods
980     */
981    public void testForkJoinTasks() {
982        LongAdder adder = new LongAdder();
983        ConcurrentHashMap<Long, Long> m = longMap();
984        ConcurrentHashMap.ForkJoinTasks.forEachKey
985            (m, (Long x) -> adder.add(x.longValue())).invoke();
986        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
987        adder.reset();
988        ConcurrentHashMap.ForkJoinTasks.forEachValue
989            (m, (Long x) -> adder.add(x.longValue())).invoke();
990        assertEquals(adder.sum(), SIZE * (SIZE - 1));
991        adder.reset();
992        ConcurrentHashMap.ForkJoinTasks.forEach
993            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
994        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
995        adder.reset();
996        ConcurrentHashMap.ForkJoinTasks.forEachEntry
997            (m,
998             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
999        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1000        adder.reset();
1001        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();
1021
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, 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, 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    }
1089   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines