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.6 by dl, Thu Apr 11 19:15:20 2013 UTC vs.
Revision 1.17 by dl, Sun Dec 1 12:19:59 2013 UTC

# Line 6 | Line 6
6  
7   import junit.framework.*;
8   import java.util.*;
9 + import static java.util.Spliterator.*;
10   import java.util.function.*;
11   import java.util.concurrent.atomic.LongAdder;
12   import java.util.concurrent.ConcurrentHashMap;
13 + import java.util.concurrent.ConcurrentHashMap.KeySetView;
14  
15   public class ConcurrentHashMap8Test extends JSR166TestCase {
16      public static void main(String[] args) {
# Line 34 | Line 36 | public class ConcurrentHashMap8Test exte
36          return map;
37      }
38  
37    // classes for testing Comparable fallbacks
38    static class BI implements Comparable<BI> {
39        private final int value;
40        BI(int value) { this.value = value; }
41        public int compareTo(BI other) {
42            return Integer.compare(value, other.value);
43        }
44        public boolean equals(Object x) {
45            return (x instanceof BI) && ((BI)x).value == value;
46        }
47        public int hashCode() { return 42; }
48    }
49    static class CI extends BI { CI(int value) { super(value); } }
50    static class DI extends BI { DI(int value) { super(value); } }
51
52    static class BS implements Comparable<BS> {
53        private final String value;
54        BS(String value) { this.value = value; }
55        public int compareTo(BS other) {
56            return value.compareTo(other.value);
57        }
58        public boolean equals(Object x) {
59            return (x instanceof BS) && value.equals(((BS)x).value);
60        }
61        public int hashCode() { return 42; }
62    }
63
64    static class LexicographicList<E extends Comparable<E>> extends ArrayList<E>
65        implements Comparable<LexicographicList<E>> {
66        LexicographicList(Collection<E> c) { super(c); }
67        LexicographicList(E e) { super(Collections.singleton(e)); }
68        public int compareTo(LexicographicList<E> other) {
69            int common = Math.min(size(), other.size());
70            int r = 0;
71            for (int i = 0; i < common; i++) {
72                if ((r = get(i).compareTo(other.get(i))) != 0)
73                    break;
74            }
75            if (r == 0)
76                r = Integer.compare(size(), other.size());
77            return r;
78        }
79        private static final long serialVersionUID = 0;
80    }
81
82    /**
83     * Inserted elements that are subclasses of the same Comparable
84     * class are found.
85     */
86    public void testComparableFamily() {
87        ConcurrentHashMap<BI, Boolean> m = new ConcurrentHashMap<>();
88        for (int i = 0; i < 1000; i++) {
89            assertTrue(m.put(new CI(i), true) == null);
90        }
91        for (int i = 0; i < 1000; i++) {
92            assertTrue(m.containsKey(new CI(i)));
93            assertTrue(m.containsKey(new DI(i)));
94        }
95    }
96
97    /**
98     * Elements of classes with erased generic type parameters based
99     * on Comparable can be inserted and found.
100     */
101    public void testGenericComparable() {
102        ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>();
103        for (int i = 0; i < 1000; i++) {
104            BI bi = new BI(i);
105            BS bs = new BS(String.valueOf(i));
106            LexicographicList<BI> bis = new LexicographicList<BI>(bi);
107            LexicographicList<BS> bss = new LexicographicList<BS>(bs);
108            assertTrue(m.putIfAbsent(bis, true) == null);
109            assertTrue(m.containsKey(bis));
110            if (m.putIfAbsent(bss, true) == null)
111                assertTrue(m.containsKey(bss));
112            assertTrue(m.containsKey(bis));
113        }
114        for (int i = 0; i < 1000; i++) {
115            assertTrue(m.containsKey(new ArrayList(Collections.singleton(new BI(i)))));
116        }
117    }
118
119    /**
120     * Elements of non-comparable classes equal to those of classes
121     * with erased generic type parameters based on Comparable can be
122     * inserted and found.
123     */
124    public void testGenericComparable2() {
125        ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>();
126        for (int i = 0; i < 1000; i++) {
127            m.put(new ArrayList(Collections.singleton(new BI(i))), true);
128        }
129
130        for (int i = 0; i < 1000; i++) {
131            LexicographicList<BI> bis = new LexicographicList<BI>(new BI(i));
132            assertTrue(m.containsKey(bis));
133        }
134    }
135
39      /**
40       * getOrDefault returns value if present, else default
41       */
# Line 152 | Line 55 | public class ConcurrentHashMap8Test exte
55      }
56  
57      /**
58 <     * computeIfAbsent does not replace  if the key is already present
58 >     * computeIfAbsent does not replace if the key is already present
59       */
60      public void testComputeIfAbsent2() {
61          ConcurrentHashMap map = map5();
# Line 169 | Line 72 | public class ConcurrentHashMap8Test exte
72      }
73  
74      /**
75 <     * computeIfPresent does not replace  if the key is already present
75 >     * computeIfPresent does not replace if the key is already present
76       */
77      public void testComputeIfPresent() {
78          ConcurrentHashMap map = map5();
# Line 186 | Line 89 | public class ConcurrentHashMap8Test exte
89      }
90  
91      /**
92 <     * compute does not replace  if the function returns null
92 >     * compute does not replace if the function returns null
93       */
94      public void testCompute() {
95          ConcurrentHashMap map = map5();
# Line 264 | Line 167 | public class ConcurrentHashMap8Test exte
167          return a;
168      }
169  
170 +    /*
171 +     * replaceAll replaces all matching values.
172 +     */
173 +    public void testReplaceAll() {
174 +        ConcurrentHashMap<Integer, String> map = map5();
175 +        map.replaceAll((x, y) -> {return x > 3 ? "Z" : y;});
176 +        assertEquals("A", map.get(one));
177 +        assertEquals("B", map.get(two));
178 +        assertEquals("C", map.get(three));
179 +        assertEquals("Z", map.get(four));
180 +        assertEquals("Z", map.get(five));
181 +    }
182 +
183      /**
184       * Default-constructed set is empty
185       */
# Line 273 | Line 189 | public class ConcurrentHashMap8Test exte
189      }
190  
191      /**
192 +     * keySet.add adds the key with the established value to the map;
193 +     * remove removes it.
194 +     */
195 +    public void testKeySetAddRemove() {
196 +        ConcurrentHashMap map = map5();
197 +        Set set1 = map.keySet();
198 +        Set set2 = map.keySet(true);
199 +        set2.add(six);
200 +        assertTrue(((KeySetView)set2).getMap() == map);
201 +        assertTrue(((KeySetView)set1).getMap() == map);
202 +        assertEquals(set2.size(), map.size());
203 +        assertEquals(set1.size(), map.size());
204 +        assertTrue((Boolean)map.get(six));
205 +        assertTrue(set1.contains(six));
206 +        assertTrue(set2.contains(six));
207 +        set2.remove(six);
208 +        assertNull(map.get(six));
209 +        assertFalse(set1.contains(six));
210 +        assertFalse(set2.contains(six));
211 +    }
212 +
213 +
214 +    /**
215       * keySet.addAll adds each element from the given collection
216       */
217      public void testAddAll() {
# Line 318 | Line 257 | public class ConcurrentHashMap8Test exte
257      }
258  
259      /**
260 +     * keySet.add throws UnsupportedOperationException if no default
261 +     * mapped value
262 +     */
263 +    public void testAdd4() {
264 +        Set full = map5().keySet();
265 +        try {
266 +            full.add(three);
267 +            shouldThrow();
268 +        } catch (UnsupportedOperationException e){}
269 +    }
270 +
271 +    /**
272 +     * keySet.add throws NullPointerException if the specified key is
273 +     * null
274 +     */
275 +    public void testAdd5() {
276 +        Set full = populatedSet(3);
277 +        try {
278 +            full.add(null);
279 +            shouldThrow();
280 +        } catch (NullPointerException e){}
281 +    }
282 +
283 +    /**
284 +     * KeySetView.getMappedValue returns the map's mapped value
285 +     */
286 +    public void testGetMappedValue() {
287 +        ConcurrentHashMap map = map5();
288 +        assertNull(map.keySet().getMappedValue());
289 +        try {
290 +            map.keySet(null);
291 +            shouldThrow();
292 +        } catch (NullPointerException e) {}
293 +        KeySetView set = map.keySet(one);
294 +        set.add(one);
295 +        set.add(six);
296 +        set.add(seven);
297 +        assertTrue(set.getMappedValue() == one);
298 +        assertTrue(map.get(one) != one);
299 +        assertTrue(map.get(six) == one);
300 +        assertTrue(map.get(seven) == one);
301 +    }
302 +
303 +    void checkSpliteratorCharacteristics(Spliterator<?> sp,
304 +                                         int requiredCharacteristics) {
305 +        assertEquals(requiredCharacteristics,
306 +                     requiredCharacteristics & sp.characteristics());
307 +    }
308 +
309 +    /**
310 +     * KeySetView.spliterator returns spliterator over the elements in this set
311 +     */
312 +    public void testKeySetSpliterator() {
313 +        LongAdder adder = new LongAdder();
314 +        ConcurrentHashMap map = map5();
315 +        Set set = map.keySet();
316 +        Spliterator<Integer> sp = set.spliterator();
317 +        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
318 +        assertEquals(sp.estimateSize(), map.size());
319 +        Spliterator<Integer> sp2 = sp.trySplit();
320 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
321 +        long v = adder.sumThenReset();
322 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
323 +        long v2 = adder.sum();
324 +        assertEquals(v + v2, 15);
325 +    }
326 +
327 +    /**
328       * keyset.clear removes all elements from the set
329       */
330      public void testClear() {
# Line 530 | Line 537 | public class ConcurrentHashMap8Test exte
537          Set x = populatedSet(size);
538          Set y = serialClone(x);
539  
540 <        assertTrue(x != y);
540 >        assertNotSame(x, y);
541          assertEquals(x.size(), y.size());
535        assertEquals(x.toString(), y.toString());
536        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
542          assertEquals(x, y);
543          assertEquals(y, x);
544      }
545  
541
546      static final int SIZE = 10000;
547      static ConcurrentHashMap<Long, Long> longMap;
548  
# Line 566 | Line 570 | public class ConcurrentHashMap8Test exte
570      public void testForEachKeySequentially() {
571          LongAdder adder = new LongAdder();
572          ConcurrentHashMap<Long, Long> m = longMap();
573 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
573 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
574          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
575      }
576  
# Line 576 | Line 580 | public class ConcurrentHashMap8Test exte
580      public void testForEachValueSequentially() {
581          LongAdder adder = new LongAdder();
582          ConcurrentHashMap<Long, Long> m = longMap();
583 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
583 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
584          assertEquals(adder.sum(), SIZE * (SIZE - 1));
585      }
586  
# Line 586 | Line 590 | public class ConcurrentHashMap8Test exte
590      public void testForEachSequentially() {
591          LongAdder adder = new LongAdder();
592          ConcurrentHashMap<Long, Long> m = longMap();
593 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
593 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
594          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
595      }
596  
# Line 596 | Line 600 | public class ConcurrentHashMap8Test exte
600      public void testForEachEntrySequentially() {
601          LongAdder adder = new LongAdder();
602          ConcurrentHashMap<Long, Long> m = longMap();
603 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
603 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
604          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
605      }
606  
# Line 606 | Line 610 | public class ConcurrentHashMap8Test exte
610      public void testForEachKeyInParallel() {
611          LongAdder adder = new LongAdder();
612          ConcurrentHashMap<Long, Long> m = longMap();
613 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
613 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
614          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
615      }
616  
# Line 616 | Line 620 | public class ConcurrentHashMap8Test exte
620      public void testForEachValueInParallel() {
621          LongAdder adder = new LongAdder();
622          ConcurrentHashMap<Long, Long> m = longMap();
623 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
623 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
624          assertEquals(adder.sum(), SIZE * (SIZE - 1));
625      }
626  
# Line 626 | Line 630 | public class ConcurrentHashMap8Test exte
630      public void testForEachInParallel() {
631          LongAdder adder = new LongAdder();
632          ConcurrentHashMap<Long, Long> m = longMap();
633 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
633 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
634          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
635      }
636  
# Line 636 | Line 640 | public class ConcurrentHashMap8Test exte
640      public void testForEachEntryInParallel() {
641          LongAdder adder = new LongAdder();
642          ConcurrentHashMap<Long, Long> m = longMap();
643 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
643 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
644          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
645      }
646  
# Line 647 | Line 651 | public class ConcurrentHashMap8Test exte
651      public void testMappedForEachKeySequentially() {
652          LongAdder adder = new LongAdder();
653          ConcurrentHashMap<Long, Long> m = longMap();
654 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
654 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
655                                   (Long x) -> adder.add(x.longValue()));
656          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
657      }
# Line 659 | Line 663 | public class ConcurrentHashMap8Test exte
663      public void testMappedForEachValueSequentially() {
664          LongAdder adder = new LongAdder();
665          ConcurrentHashMap<Long, Long> m = longMap();
666 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
666 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
667                                     (Long x) -> adder.add(x.longValue()));
668          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
669      }
# Line 671 | Line 675 | public class ConcurrentHashMap8Test exte
675      public void testMappedForEachSequentially() {
676          LongAdder adder = new LongAdder();
677          ConcurrentHashMap<Long, Long> m = longMap();
678 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
678 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
679                                (Long x) -> adder.add(x.longValue()));
680          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
681      }
# Line 683 | Line 687 | public class ConcurrentHashMap8Test exte
687      public void testMappedForEachEntrySequentially() {
688          LongAdder adder = new LongAdder();
689          ConcurrentHashMap<Long, Long> m = longMap();
690 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
690 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
691                                     (Long x) -> adder.add(x.longValue()));
692          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
693      }
# Line 695 | Line 699 | public class ConcurrentHashMap8Test exte
699      public void testMappedForEachKeyInParallel() {
700          LongAdder adder = new LongAdder();
701          ConcurrentHashMap<Long, Long> m = longMap();
702 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
702 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
703                                 (Long x) -> adder.add(x.longValue()));
704          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
705      }
# Line 707 | Line 711 | public class ConcurrentHashMap8Test exte
711      public void testMappedForEachValueInParallel() {
712          LongAdder adder = new LongAdder();
713          ConcurrentHashMap<Long, Long> m = longMap();
714 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
714 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
715                                   (Long x) -> adder.add(x.longValue()));
716          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
717      }
# Line 719 | Line 723 | public class ConcurrentHashMap8Test exte
723      public void testMappedForEachInParallel() {
724          LongAdder adder = new LongAdder();
725          ConcurrentHashMap<Long, Long> m = longMap();
726 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
726 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
727                              (Long x) -> adder.add(x.longValue()));
728          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
729      }
# Line 731 | Line 735 | public class ConcurrentHashMap8Test exte
735      public void testMappedForEachEntryInParallel() {
736          LongAdder adder = new LongAdder();
737          ConcurrentHashMap<Long, Long> m = longMap();
738 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
738 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
739                                   (Long x) -> adder.add(x.longValue()));
740          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
741      }
742  
739
743      /**
744       * reduceKeysSequentially accumulates across all keys,
745       */
746      public void testReduceKeysSequentially() {
747          ConcurrentHashMap<Long, Long> m = longMap();
748          Long r;
749 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
749 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
750          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
751      }
752  
# Line 753 | Line 756 | public class ConcurrentHashMap8Test exte
756      public void testReduceValuesSequentially() {
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  
760
763      /**
764       * reduceEntriesSequentially accumulates across all entries
765       */
766      public void testReduceEntriesSequentially() {
767          ConcurrentHashMap<Long, Long> m = longMap();
768          Map.Entry<Long,Long> r;
769 <        r = m.reduceEntriesSequentially(new AddKeys());
769 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
770          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
771      }
772  
# Line 774 | Line 776 | public class ConcurrentHashMap8Test exte
776      public void testReduceKeysInParallel() {
777          ConcurrentHashMap<Long, Long> m = longMap();
778          Long r;
779 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
779 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
780          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
781      }
782  
# Line 784 | Line 786 | public class ConcurrentHashMap8Test exte
786      public void testReduceValuesInParallel() {
787          ConcurrentHashMap<Long, Long> m = longMap();
788          Long r;
789 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
789 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
790          assertEquals((long)r, (long)SIZE * (SIZE - 1));
791      }
792  
# Line 794 | Line 796 | public class ConcurrentHashMap8Test exte
796      public void testReduceEntriesInParallel() {
797          ConcurrentHashMap<Long, Long> m = longMap();
798          Map.Entry<Long,Long> r;
799 <        r = m.reduceEntriesInParallel(new AddKeys());
799 >        r = m.reduceEntries(1L, new AddKeys());
800          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
801      }
802  
803 <    /*
803 >    /**
804       * Mapped reduceKeysSequentially accumulates mapped keys
805       */
806      public void testMapReduceKeysSequentially() {
807          ConcurrentHashMap<Long, Long> m = longMap();
808 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
808 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
809                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
810          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
811      }
812  
813 <    /*
813 >    /**
814       * Mapped reduceValuesSequentially accumulates mapped values
815       */
816      public void testMapReduceValuesSequentially() {
817          ConcurrentHashMap<Long, Long> m = longMap();
818 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
818 >        Long r = m.reduceValues(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));
821      }
# Line 823 | Line 825 | public class ConcurrentHashMap8Test exte
825       */
826      public void testMappedReduceSequentially() {
827          ConcurrentHashMap<Long, Long> m = longMap();
828 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
828 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
829                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
830  
831          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
832      }
833  
834 <    /*
834 >    /**
835       * Mapped reduceKeysInParallel, accumulates mapped keys
836       */
837      public void testMapReduceKeysInParallel() {
838          ConcurrentHashMap<Long, Long> m = longMap();
839 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
839 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
840                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
841          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
842      }
843  
844 <    /*
844 >    /**
845       * Mapped reduceValuesInParallel accumulates mapped values
846       */
847      public void testMapReduceValuesInParallel() {
848          ConcurrentHashMap<Long, Long> m = longMap();
849 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
849 >        Long r = m.reduceValues(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));
852      }
# Line 855 | Line 857 | public class ConcurrentHashMap8Test exte
857      public void testMappedReduceInParallel() {
858          ConcurrentHashMap<Long, Long> m = longMap();
859          Long r;
860 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
860 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
861                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
862          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
863      }
864  
865 <
864 <    /*
865 >    /**
866       * reduceKeysToLongSequentially accumulates mapped keys
867       */
868      public void testReduceKeysToLongSequentially() {
869          ConcurrentHashMap<Long, Long> m = longMap();
870 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
870 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
871          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
872      }
873  
874 <    /*
874 >    /**
875       * reduceKeysToIntSequentially accumulates mapped keys
876       */
877      public void testReduceKeysToIntSequentially() {
878          ConcurrentHashMap<Long, Long> m = longMap();
879 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
879 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
880          assertEquals(ir, SIZE * (SIZE - 1) / 2);
881      }
882  
883 <    /*
883 >    /**
884       * reduceKeysToDoubleSequentially accumulates mapped keys
885       */
886      public void testReduceKeysToDoubleSequentially() {
887          ConcurrentHashMap<Long, Long> m = longMap();
888 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
888 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
889          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
890      }
891  
892 <    /*
892 >    /**
893       * reduceValuesToLongSequentially accumulates mapped values
894       */
895      public void testReduceValuesToLongSequentially() {
896          ConcurrentHashMap<Long, Long> m = longMap();
897 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
897 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
898          assertEquals(lr, (long)SIZE * (SIZE - 1));
899      }
900  
901 <    /*
901 >    /**
902       * reduceValuesToIntSequentially accumulates mapped values
903       */
904      public void testReduceValuesToIntSequentially() {
905          ConcurrentHashMap<Long, Long> m = longMap();
906 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
906 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
907          assertEquals(ir, SIZE * (SIZE - 1));
908      }
909  
910 <    /*
910 >    /**
911       * reduceValuesToDoubleSequentially accumulates mapped values
912       */
913      public void testReduceValuesToDoubleSequentially() {
914          ConcurrentHashMap<Long, Long> m = longMap();
915 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
915 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
916          assertEquals(dr, (double)SIZE * (SIZE - 1));
917      }
918  
919 <    /*
919 >    /**
920       * reduceKeysToLongInParallel accumulates mapped keys
921       */
922      public void testReduceKeysToLongInParallel() {
923          ConcurrentHashMap<Long, Long> m = longMap();
924 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
924 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
925          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
926      }
927  
928 <    /*
928 >    /**
929       * reduceKeysToIntInParallel accumulates mapped keys
930       */
931      public void testReduceKeysToIntInParallel() {
932          ConcurrentHashMap<Long, Long> m = longMap();
933 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
933 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
934          assertEquals(ir, SIZE * (SIZE - 1) / 2);
935      }
936  
937 <    /*
937 >    /**
938       * reduceKeysToDoubleInParallel accumulates mapped values
939       */
940      public void testReduceKeysToDoubleInParallel() {
941          ConcurrentHashMap<Long, Long> m = longMap();
942 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
942 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
943          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
944      }
945  
946 <    /*
946 >    /**
947       * reduceValuesToLongInParallel accumulates mapped values
948       */
949      public void testReduceValuesToLongInParallel() {
950          ConcurrentHashMap<Long, Long> m = longMap();
951 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
951 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
952          assertEquals(lr, (long)SIZE * (SIZE - 1));
953      }
954  
955 <    /*
955 >    /**
956       * reduceValuesToIntInParallel accumulates mapped values
957       */
958      public void testReduceValuesToIntInParallel() {
959          ConcurrentHashMap<Long, Long> m = longMap();
960 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
960 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
961          assertEquals(ir, SIZE * (SIZE - 1));
962      }
963  
964 <    /*
964 >    /**
965       * reduceValuesToDoubleInParallel accumulates mapped values
966       */
967      public void testReduceValuesToDoubleInParallel() {
968          ConcurrentHashMap<Long, Long> m = longMap();
969 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
969 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
970          assertEquals(dr, (double)SIZE * (SIZE - 1));
971      }
972  
# Line 976 | Line 977 | public class ConcurrentHashMap8Test exte
977      public void testSearchKeysSequentially() {
978          ConcurrentHashMap<Long, Long> m = longMap();
979          Long r;
980 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
980 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
981          assertEquals((long)r, (long)(SIZE/2));
982 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
982 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
983          assertNull(r);
984      }
985  
# Line 989 | Line 990 | public class ConcurrentHashMap8Test exte
990      public void testSearchValuesSequentially() {
991          ConcurrentHashMap<Long, Long> m = longMap();
992          Long r;
993 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
993 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
994          assertEquals((long)r, (long)(SIZE/2));
995 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
995 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
996          assertNull(r);
997      }
998  
# Line 1002 | Line 1003 | public class ConcurrentHashMap8Test exte
1003      public void testSearchSequentially() {
1004          ConcurrentHashMap<Long, Long> m = longMap();
1005          Long r;
1006 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1006 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1007          assertEquals((long)r, (long)(SIZE/2));
1008 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1008 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1009          assertNull(r);
1010      }
1011  
# Line 1015 | Line 1016 | public class ConcurrentHashMap8Test exte
1016      public void testSearchEntriesSequentially() {
1017          ConcurrentHashMap<Long, Long> m = longMap();
1018          Long r;
1019 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1019 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1020          assertEquals((long)r, (long)(SIZE/2));
1021 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1021 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1022          assertNull(r);
1023      }
1024  
# Line 1028 | Line 1029 | public class ConcurrentHashMap8Test exte
1029      public void testSearchKeysInParallel() {
1030          ConcurrentHashMap<Long, Long> m = longMap();
1031          Long r;
1032 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1032 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1033          assertEquals((long)r, (long)(SIZE/2));
1034 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1034 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1035          assertNull(r);
1036      }
1037  
# Line 1041 | Line 1042 | public class ConcurrentHashMap8Test exte
1042      public void testSearchValuesInParallel() {
1043          ConcurrentHashMap<Long, Long> m = longMap();
1044          Long r;
1045 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1045 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1046          assertEquals((long)r, (long)(SIZE/2));
1047 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1047 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1048          assertNull(r);
1049      }
1050  
# Line 1054 | Line 1055 | public class ConcurrentHashMap8Test exte
1055      public void testSearchInParallel() {
1056          ConcurrentHashMap<Long, Long> m = longMap();
1057          Long r;
1058 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1058 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1059          assertEquals((long)r, (long)(SIZE/2));
1060 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1060 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1061          assertNull(r);
1062      }
1063  
# Line 1067 | Line 1068 | public class ConcurrentHashMap8Test exte
1068      public void testSearchEntriesInParallel() {
1069          ConcurrentHashMap<Long, Long> m = longMap();
1070          Long r;
1071 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1071 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1072          assertEquals((long)r, (long)(SIZE/2));
1073 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1073 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1074          assertNull(r);
1075      }
1076  
1076    /**
1077     * Invoking task versions of bulk methods has same effect as
1078     * parallel methods
1079     */
1080    public void testForkJoinTasks() {
1081        LongAdder adder = new LongAdder();
1082        ConcurrentHashMap<Long, Long> m = longMap();
1083        ConcurrentHashMap.ForkJoinTasks.forEachKey
1084            (m, (Long x) -> adder.add(x.longValue())).invoke();
1085        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
1086        adder.reset();
1087        ConcurrentHashMap.ForkJoinTasks.forEachValue
1088            (m, (Long x) -> adder.add(x.longValue())).invoke();
1089        assertEquals(adder.sum(), SIZE * (SIZE - 1));
1090        adder.reset();
1091        ConcurrentHashMap.ForkJoinTasks.forEach
1092            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
1093        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1094        adder.reset();
1095        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1096            (m,
1097             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
1098        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1099        adder.reset();
1100        ConcurrentHashMap.ForkJoinTasks.forEachKey
1101            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1102             (Long x) -> adder.add(x.longValue())).invoke();
1103        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
1104        adder.reset();
1105        ConcurrentHashMap.ForkJoinTasks.forEachValue
1106            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1107             (Long x) -> adder.add(x.longValue())).invoke();
1108        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
1109        adder.reset();
1110        ConcurrentHashMap.ForkJoinTasks.forEach
1111            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1112             (Long x) -> adder.add(x.longValue())).invoke();
1113        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1114        adder.reset();
1115        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1116            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1117             (Long x) -> adder.add(x.longValue())).invoke();
1118        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1119        adder.reset();
1120
1121        Long r; long lr; int ir; double dr;
1122        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1123            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1124        assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
1125        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1126            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1127        assertEquals((long)r, (long)SIZE * (SIZE - 1));
1128        r = ConcurrentHashMap.ForkJoinTasks.reduce
1129            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1130             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1131        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1132        r = ConcurrentHashMap.ForkJoinTasks.reduceEntries
1133            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1134             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1135        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1136        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1137            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1138             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1139        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
1140        lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong
1141            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1142        assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
1143        ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt
1144            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1145        assertEquals(ir, SIZE * (SIZE - 1) / 2);
1146        dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble
1147            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1148        assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
1149        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1150            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1151             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1152        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
1153        lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong
1154            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1155        assertEquals(lr, (long)SIZE * (SIZE - 1));
1156        ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt
1157            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1158        assertEquals(ir, SIZE * (SIZE - 1));
1159        dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble
1160            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1161        assertEquals(dr, (double)SIZE * (SIZE - 1));
1162        r = ConcurrentHashMap.ForkJoinTasks.searchKeys
1163            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1164        assertEquals((long)r, (long)(SIZE/2));
1165        r = ConcurrentHashMap.ForkJoinTasks.searchValues
1166            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1167        assertEquals((long)r, (long)(SIZE/2));
1168        r = ConcurrentHashMap.ForkJoinTasks.search
1169            (m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1170        assertEquals((long)r, (long)(SIZE/2));
1171        r = ConcurrentHashMap.ForkJoinTasks.searchEntries
1172            (m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke();
1173        assertEquals((long)r, (long)(SIZE/2));
1174    }
1077   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines