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.12 by dl, Sun Jul 21 22:24:18 2013 UTC

# Line 9 | Line 9 | import java.util.*;
9   import java.util.function.*;
10   import java.util.concurrent.atomic.LongAdder;
11   import java.util.concurrent.ConcurrentHashMap;
12 + import java.util.concurrent.ConcurrentHashMap.KeySetView;
13  
14   public class ConcurrentHashMap8Test extends JSR166TestCase {
15      public static void main(String[] args) {
# Line 34 | Line 35 | public class ConcurrentHashMap8Test exte
35          return map;
36      }
37  
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
38      /**
39       * getOrDefault returns value if present, else default
40       */
# Line 264 | Line 166 | public class ConcurrentHashMap8Test exte
166          return a;
167      }
168  
169 +    /*
170 +     * replaceAll replaces all matching values.
171 +     */
172 +    public void testReplaceAll() {
173 +        ConcurrentHashMap<Integer, String> map = map5();
174 +        map.replaceAll((x, y) -> {return x > 3 ? "Z" : y;});
175 +        assertEquals("A", map.get(one));
176 +        assertEquals("B", map.get(two));
177 +        assertEquals("C", map.get(three));
178 +        assertEquals("Z", map.get(four));
179 +        assertEquals("Z", map.get(five));
180 +    }
181 +
182      /**
183       * Default-constructed set is empty
184       */
# Line 273 | Line 188 | public class ConcurrentHashMap8Test exte
188      }
189  
190      /**
191 +     * keySet.add adds the key with the established value to the map;
192 +     * remove removes it.
193 +     */
194 +    public void testKeySetAddRemove() {
195 +        ConcurrentHashMap map = map5();
196 +        Set set1 = map.keySet();
197 +        Set set2 = map.keySet(true);
198 +        set2.add(six);
199 +        assertTrue(((KeySetView)set2).getMap() == map);
200 +        assertTrue(((KeySetView)set1).getMap() == map);
201 +        assertEquals(set2.size(), map.size());
202 +        assertEquals(set1.size(), map.size());
203 +        assertTrue((Boolean)map.get(six));
204 +        assertTrue(set1.contains(six));
205 +        assertTrue(set2.contains(six));
206 +        set2.remove(six);
207 +        assertNull(map.get(six));
208 +        assertFalse(set1.contains(six));
209 +        assertFalse(set2.contains(six));
210 +    }
211 +
212 +
213 +    /**
214       * keySet.addAll adds each element from the given collection
215       */
216      public void testAddAll() {
# Line 317 | Line 255 | public class ConcurrentHashMap8Test exte
255          assertTrue(full.contains(three));
256      }
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 +     /**
304 +      * KeySetView.spliterator returns spliterator over the elements in this set
305 +      */
306 +     public void testKeySetSpliterator() {
307 +         LongAdder adder = new LongAdder();
308 +         ConcurrentHashMap map = map5();
309 +         Set set = map.keySet();
310 +         Spliterator<Integer> sp = set.spliterator();
311 +         assertEquals(sp.estimateSize(), map.size());
312 +         Spliterator<Integer> sp2 = sp.trySplit();
313 +         sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
314 +         long v = adder.sumThenReset();
315 +         sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
316 +         long v2 = adder.sum();
317 +         assertEquals(v + v2, 15);
318 +     }
319 +
320 +
321      /**
322       * keyset.clear removes all elements from the set
323       */
# Line 530 | Line 531 | public class ConcurrentHashMap8Test exte
531          Set x = populatedSet(size);
532          Set y = serialClone(x);
533  
534 <        assertTrue(x != y);
534 >        assertNotSame(x, y);
535          assertEquals(x.size(), y.size());
536          assertEquals(x.toString(), y.toString());
537          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 538 | Line 539 | public class ConcurrentHashMap8Test exte
539          assertEquals(y, x);
540      }
541  
541
542      static final int SIZE = 10000;
543      static ConcurrentHashMap<Long, Long> longMap;
544  
# Line 566 | Line 566 | public class ConcurrentHashMap8Test exte
566      public void testForEachKeySequentially() {
567          LongAdder adder = new LongAdder();
568          ConcurrentHashMap<Long, Long> m = longMap();
569 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
569 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
570          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
571      }
572  
# Line 576 | Line 576 | public class ConcurrentHashMap8Test exte
576      public void testForEachValueSequentially() {
577          LongAdder adder = new LongAdder();
578          ConcurrentHashMap<Long, Long> m = longMap();
579 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
579 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
580          assertEquals(adder.sum(), SIZE * (SIZE - 1));
581      }
582  
# Line 586 | Line 586 | public class ConcurrentHashMap8Test exte
586      public void testForEachSequentially() {
587          LongAdder adder = new LongAdder();
588          ConcurrentHashMap<Long, Long> m = longMap();
589 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
589 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
590          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
591      }
592  
# Line 596 | Line 596 | public class ConcurrentHashMap8Test exte
596      public void testForEachEntrySequentially() {
597          LongAdder adder = new LongAdder();
598          ConcurrentHashMap<Long, Long> m = longMap();
599 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
599 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
600          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
601      }
602  
# Line 606 | Line 606 | public class ConcurrentHashMap8Test exte
606      public void testForEachKeyInParallel() {
607          LongAdder adder = new LongAdder();
608          ConcurrentHashMap<Long, Long> m = longMap();
609 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
609 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
610          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
611      }
612  
# Line 616 | Line 616 | public class ConcurrentHashMap8Test exte
616      public void testForEachValueInParallel() {
617          LongAdder adder = new LongAdder();
618          ConcurrentHashMap<Long, Long> m = longMap();
619 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
619 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
620          assertEquals(adder.sum(), SIZE * (SIZE - 1));
621      }
622  
# Line 626 | Line 626 | public class ConcurrentHashMap8Test exte
626      public void testForEachInParallel() {
627          LongAdder adder = new LongAdder();
628          ConcurrentHashMap<Long, Long> m = longMap();
629 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
629 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
630          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
631      }
632  
# Line 636 | Line 636 | public class ConcurrentHashMap8Test exte
636      public void testForEachEntryInParallel() {
637          LongAdder adder = new LongAdder();
638          ConcurrentHashMap<Long, Long> m = longMap();
639 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
639 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
640          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
641      }
642  
# Line 647 | Line 647 | public class ConcurrentHashMap8Test exte
647      public void testMappedForEachKeySequentially() {
648          LongAdder adder = new LongAdder();
649          ConcurrentHashMap<Long, Long> m = longMap();
650 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
650 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
651                                   (Long x) -> adder.add(x.longValue()));
652          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
653      }
# Line 659 | Line 659 | public class ConcurrentHashMap8Test exte
659      public void testMappedForEachValueSequentially() {
660          LongAdder adder = new LongAdder();
661          ConcurrentHashMap<Long, Long> m = longMap();
662 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
662 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
663                                     (Long x) -> adder.add(x.longValue()));
664          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
665      }
# Line 671 | Line 671 | public class ConcurrentHashMap8Test exte
671      public void testMappedForEachSequentially() {
672          LongAdder adder = new LongAdder();
673          ConcurrentHashMap<Long, Long> m = longMap();
674 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
674 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
675                                (Long x) -> adder.add(x.longValue()));
676          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
677      }
# Line 683 | Line 683 | public class ConcurrentHashMap8Test exte
683      public void testMappedForEachEntrySequentially() {
684          LongAdder adder = new LongAdder();
685          ConcurrentHashMap<Long, Long> m = longMap();
686 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
686 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
687                                     (Long x) -> adder.add(x.longValue()));
688          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
689      }
# Line 695 | Line 695 | public class ConcurrentHashMap8Test exte
695      public void testMappedForEachKeyInParallel() {
696          LongAdder adder = new LongAdder();
697          ConcurrentHashMap<Long, Long> m = longMap();
698 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
698 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
699                                 (Long x) -> adder.add(x.longValue()));
700          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
701      }
# Line 707 | Line 707 | public class ConcurrentHashMap8Test exte
707      public void testMappedForEachValueInParallel() {
708          LongAdder adder = new LongAdder();
709          ConcurrentHashMap<Long, Long> m = longMap();
710 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
710 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
711                                   (Long x) -> adder.add(x.longValue()));
712          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
713      }
# Line 719 | Line 719 | public class ConcurrentHashMap8Test exte
719      public void testMappedForEachInParallel() {
720          LongAdder adder = new LongAdder();
721          ConcurrentHashMap<Long, Long> m = longMap();
722 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
722 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
723                              (Long x) -> adder.add(x.longValue()));
724          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
725      }
# Line 731 | Line 731 | public class ConcurrentHashMap8Test exte
731      public void testMappedForEachEntryInParallel() {
732          LongAdder adder = new LongAdder();
733          ConcurrentHashMap<Long, Long> m = longMap();
734 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
734 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
735                                   (Long x) -> adder.add(x.longValue()));
736          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
737      }
738  
739
739      /**
740       * reduceKeysSequentially accumulates across all keys,
741       */
742      public void testReduceKeysSequentially() {
743          ConcurrentHashMap<Long, Long> m = longMap();
744          Long r;
745 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
745 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
746          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
747      }
748  
# Line 753 | Line 752 | public class ConcurrentHashMap8Test exte
752      public void testReduceValuesSequentially() {
753          ConcurrentHashMap<Long, Long> m = longMap();
754          Long r;
755 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
755 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
756          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
757      }
758  
760
759      /**
760       * reduceEntriesSequentially accumulates across all entries
761       */
762      public void testReduceEntriesSequentially() {
763          ConcurrentHashMap<Long, Long> m = longMap();
764          Map.Entry<Long,Long> r;
765 <        r = m.reduceEntriesSequentially(new AddKeys());
765 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
766          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
767      }
768  
# Line 774 | Line 772 | public class ConcurrentHashMap8Test exte
772      public void testReduceKeysInParallel() {
773          ConcurrentHashMap<Long, Long> m = longMap();
774          Long r;
775 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
775 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
776          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
777      }
778  
# Line 784 | Line 782 | public class ConcurrentHashMap8Test exte
782      public void testReduceValuesInParallel() {
783          ConcurrentHashMap<Long, Long> m = longMap();
784          Long r;
785 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
785 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
786          assertEquals((long)r, (long)SIZE * (SIZE - 1));
787      }
788  
# Line 794 | Line 792 | public class ConcurrentHashMap8Test exte
792      public void testReduceEntriesInParallel() {
793          ConcurrentHashMap<Long, Long> m = longMap();
794          Map.Entry<Long,Long> r;
795 <        r = m.reduceEntriesInParallel(new AddKeys());
795 >        r = m.reduceEntries(1L, new AddKeys());
796          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
797      }
798  
799 <    /*
799 >    /**
800       * Mapped reduceKeysSequentially accumulates mapped keys
801       */
802      public void testMapReduceKeysSequentially() {
803          ConcurrentHashMap<Long, Long> m = longMap();
804 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
804 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
805                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
806          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
807      }
808  
809 <    /*
809 >    /**
810       * Mapped reduceValuesSequentially accumulates mapped values
811       */
812      public void testMapReduceValuesSequentially() {
813          ConcurrentHashMap<Long, Long> m = longMap();
814 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
814 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
815                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
816          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
817      }
# Line 823 | Line 821 | public class ConcurrentHashMap8Test exte
821       */
822      public void testMappedReduceSequentially() {
823          ConcurrentHashMap<Long, Long> m = longMap();
824 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
824 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
825                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
826  
827          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
828      }
829  
830 <    /*
830 >    /**
831       * Mapped reduceKeysInParallel, accumulates mapped keys
832       */
833      public void testMapReduceKeysInParallel() {
834          ConcurrentHashMap<Long, Long> m = longMap();
835 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
835 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
836                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
837          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
838      }
839  
840 <    /*
840 >    /**
841       * Mapped reduceValuesInParallel accumulates mapped values
842       */
843      public void testMapReduceValuesInParallel() {
844          ConcurrentHashMap<Long, Long> m = longMap();
845 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
845 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
846                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
847          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
848      }
# Line 855 | Line 853 | public class ConcurrentHashMap8Test exte
853      public void testMappedReduceInParallel() {
854          ConcurrentHashMap<Long, Long> m = longMap();
855          Long r;
856 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
856 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
857                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
858          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
859      }
860  
861 <
864 <    /*
861 >    /**
862       * reduceKeysToLongSequentially accumulates mapped keys
863       */
864      public void testReduceKeysToLongSequentially() {
865          ConcurrentHashMap<Long, Long> m = longMap();
866 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
866 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
867          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
868      }
869  
870 <    /*
870 >    /**
871       * reduceKeysToIntSequentially accumulates mapped keys
872       */
873      public void testReduceKeysToIntSequentially() {
874          ConcurrentHashMap<Long, Long> m = longMap();
875 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
875 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
876          assertEquals(ir, SIZE * (SIZE - 1) / 2);
877      }
878  
879 <    /*
879 >    /**
880       * reduceKeysToDoubleSequentially accumulates mapped keys
881       */
882      public void testReduceKeysToDoubleSequentially() {
883          ConcurrentHashMap<Long, Long> m = longMap();
884 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
884 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
885          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
886      }
887  
888 <    /*
888 >    /**
889       * reduceValuesToLongSequentially accumulates mapped values
890       */
891      public void testReduceValuesToLongSequentially() {
892          ConcurrentHashMap<Long, Long> m = longMap();
893 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
893 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
894          assertEquals(lr, (long)SIZE * (SIZE - 1));
895      }
896  
897 <    /*
897 >    /**
898       * reduceValuesToIntSequentially accumulates mapped values
899       */
900      public void testReduceValuesToIntSequentially() {
901          ConcurrentHashMap<Long, Long> m = longMap();
902 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
902 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
903          assertEquals(ir, SIZE * (SIZE - 1));
904      }
905  
906 <    /*
906 >    /**
907       * reduceValuesToDoubleSequentially accumulates mapped values
908       */
909      public void testReduceValuesToDoubleSequentially() {
910          ConcurrentHashMap<Long, Long> m = longMap();
911 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
911 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
912          assertEquals(dr, (double)SIZE * (SIZE - 1));
913      }
914  
915 <    /*
915 >    /**
916       * reduceKeysToLongInParallel accumulates mapped keys
917       */
918      public void testReduceKeysToLongInParallel() {
919          ConcurrentHashMap<Long, Long> m = longMap();
920 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
920 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
921          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
922      }
923  
924 <    /*
924 >    /**
925       * reduceKeysToIntInParallel accumulates mapped keys
926       */
927      public void testReduceKeysToIntInParallel() {
928          ConcurrentHashMap<Long, Long> m = longMap();
929 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
929 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
930          assertEquals(ir, SIZE * (SIZE - 1) / 2);
931      }
932  
933 <    /*
933 >    /**
934       * reduceKeysToDoubleInParallel accumulates mapped values
935       */
936      public void testReduceKeysToDoubleInParallel() {
937          ConcurrentHashMap<Long, Long> m = longMap();
938 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
938 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
939          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
940      }
941  
942 <    /*
942 >    /**
943       * reduceValuesToLongInParallel accumulates mapped values
944       */
945      public void testReduceValuesToLongInParallel() {
946          ConcurrentHashMap<Long, Long> m = longMap();
947 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
947 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
948          assertEquals(lr, (long)SIZE * (SIZE - 1));
949      }
950  
951 <    /*
951 >    /**
952       * reduceValuesToIntInParallel accumulates mapped values
953       */
954      public void testReduceValuesToIntInParallel() {
955          ConcurrentHashMap<Long, Long> m = longMap();
956 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
956 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
957          assertEquals(ir, SIZE * (SIZE - 1));
958      }
959  
960 <    /*
960 >    /**
961       * reduceValuesToDoubleInParallel accumulates mapped values
962       */
963      public void testReduceValuesToDoubleInParallel() {
964          ConcurrentHashMap<Long, Long> m = longMap();
965 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
965 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
966          assertEquals(dr, (double)SIZE * (SIZE - 1));
967      }
968  
# Line 976 | Line 973 | public class ConcurrentHashMap8Test exte
973      public void testSearchKeysSequentially() {
974          ConcurrentHashMap<Long, Long> m = longMap();
975          Long r;
976 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
976 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
977          assertEquals((long)r, (long)(SIZE/2));
978 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
978 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
979          assertNull(r);
980      }
981  
# Line 989 | Line 986 | public class ConcurrentHashMap8Test exte
986      public void testSearchValuesSequentially() {
987          ConcurrentHashMap<Long, Long> m = longMap();
988          Long r;
989 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
989 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
990          assertEquals((long)r, (long)(SIZE/2));
991 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
991 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
992          assertNull(r);
993      }
994  
# Line 1002 | Line 999 | public class ConcurrentHashMap8Test exte
999      public void testSearchSequentially() {
1000          ConcurrentHashMap<Long, Long> m = longMap();
1001          Long r;
1002 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1002 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1003          assertEquals((long)r, (long)(SIZE/2));
1004 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1004 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1005          assertNull(r);
1006      }
1007  
# Line 1015 | Line 1012 | public class ConcurrentHashMap8Test exte
1012      public void testSearchEntriesSequentially() {
1013          ConcurrentHashMap<Long, Long> m = longMap();
1014          Long r;
1015 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1015 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1016          assertEquals((long)r, (long)(SIZE/2));
1017 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1017 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1018          assertNull(r);
1019      }
1020  
# Line 1028 | Line 1025 | public class ConcurrentHashMap8Test exte
1025      public void testSearchKeysInParallel() {
1026          ConcurrentHashMap<Long, Long> m = longMap();
1027          Long r;
1028 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1028 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1029          assertEquals((long)r, (long)(SIZE/2));
1030 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1030 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1031          assertNull(r);
1032      }
1033  
# Line 1041 | Line 1038 | public class ConcurrentHashMap8Test exte
1038      public void testSearchValuesInParallel() {
1039          ConcurrentHashMap<Long, Long> m = longMap();
1040          Long r;
1041 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1041 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1042          assertEquals((long)r, (long)(SIZE/2));
1043 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1043 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1044          assertNull(r);
1045      }
1046  
# Line 1054 | Line 1051 | public class ConcurrentHashMap8Test exte
1051      public void testSearchInParallel() {
1052          ConcurrentHashMap<Long, Long> m = longMap();
1053          Long r;
1054 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1054 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1055          assertEquals((long)r, (long)(SIZE/2));
1056 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1056 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1057          assertNull(r);
1058      }
1059  
# Line 1067 | Line 1064 | public class ConcurrentHashMap8Test exte
1064      public void testSearchEntriesInParallel() {
1065          ConcurrentHashMap<Long, Long> m = longMap();
1066          Long r;
1067 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1067 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1068          assertEquals((long)r, (long)(SIZE/2));
1069 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1069 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1070          assertNull(r);
1071      }
1072  
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    }
1073   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines