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.7 by jsr166, Thu Apr 11 19:54:13 2013 UTC vs.
Revision 1.16 by jsr166, Thu Aug 8 19:39:48 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());
542          assertEquals(x.toString(), y.toString());
543          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 538 | Line 545 | public class ConcurrentHashMap8Test exte
545          assertEquals(y, x);
546      }
547  
541
548      static final int SIZE = 10000;
549      static ConcurrentHashMap<Long, Long> longMap;
550  
# Line 566 | Line 572 | public class ConcurrentHashMap8Test exte
572      public void testForEachKeySequentially() {
573          LongAdder adder = new LongAdder();
574          ConcurrentHashMap<Long, Long> m = longMap();
575 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
575 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
576          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
577      }
578  
# Line 576 | Line 582 | public class ConcurrentHashMap8Test exte
582      public void testForEachValueSequentially() {
583          LongAdder adder = new LongAdder();
584          ConcurrentHashMap<Long, Long> m = longMap();
585 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
585 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
586          assertEquals(adder.sum(), SIZE * (SIZE - 1));
587      }
588  
# Line 586 | Line 592 | public class ConcurrentHashMap8Test exte
592      public void testForEachSequentially() {
593          LongAdder adder = new LongAdder();
594          ConcurrentHashMap<Long, Long> m = longMap();
595 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
595 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
596          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
597      }
598  
# Line 596 | Line 602 | public class ConcurrentHashMap8Test exte
602      public void testForEachEntrySequentially() {
603          LongAdder adder = new LongAdder();
604          ConcurrentHashMap<Long, Long> m = longMap();
605 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
605 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
606          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
607      }
608  
# Line 606 | Line 612 | public class ConcurrentHashMap8Test exte
612      public void testForEachKeyInParallel() {
613          LongAdder adder = new LongAdder();
614          ConcurrentHashMap<Long, Long> m = longMap();
615 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
615 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
616          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
617      }
618  
# Line 616 | Line 622 | public class ConcurrentHashMap8Test exte
622      public void testForEachValueInParallel() {
623          LongAdder adder = new LongAdder();
624          ConcurrentHashMap<Long, Long> m = longMap();
625 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
625 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
626          assertEquals(adder.sum(), SIZE * (SIZE - 1));
627      }
628  
# Line 626 | Line 632 | public class ConcurrentHashMap8Test exte
632      public void testForEachInParallel() {
633          LongAdder adder = new LongAdder();
634          ConcurrentHashMap<Long, Long> m = longMap();
635 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
635 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
636          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
637      }
638  
# Line 636 | Line 642 | public class ConcurrentHashMap8Test exte
642      public void testForEachEntryInParallel() {
643          LongAdder adder = new LongAdder();
644          ConcurrentHashMap<Long, Long> m = longMap();
645 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
645 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
646          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
647      }
648  
# Line 647 | Line 653 | public class ConcurrentHashMap8Test exte
653      public void testMappedForEachKeySequentially() {
654          LongAdder adder = new LongAdder();
655          ConcurrentHashMap<Long, Long> m = longMap();
656 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
656 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
657                                   (Long x) -> adder.add(x.longValue()));
658          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
659      }
# Line 659 | Line 665 | public class ConcurrentHashMap8Test exte
665      public void testMappedForEachValueSequentially() {
666          LongAdder adder = new LongAdder();
667          ConcurrentHashMap<Long, Long> m = longMap();
668 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
668 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
669                                     (Long x) -> adder.add(x.longValue()));
670          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
671      }
# Line 671 | Line 677 | public class ConcurrentHashMap8Test exte
677      public void testMappedForEachSequentially() {
678          LongAdder adder = new LongAdder();
679          ConcurrentHashMap<Long, Long> m = longMap();
680 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
680 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
681                                (Long x) -> adder.add(x.longValue()));
682          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
683      }
# Line 683 | Line 689 | public class ConcurrentHashMap8Test exte
689      public void testMappedForEachEntrySequentially() {
690          LongAdder adder = new LongAdder();
691          ConcurrentHashMap<Long, Long> m = longMap();
692 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
692 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
693                                     (Long x) -> adder.add(x.longValue()));
694          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
695      }
# Line 695 | Line 701 | public class ConcurrentHashMap8Test exte
701      public void testMappedForEachKeyInParallel() {
702          LongAdder adder = new LongAdder();
703          ConcurrentHashMap<Long, Long> m = longMap();
704 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
704 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
705                                 (Long x) -> adder.add(x.longValue()));
706          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
707      }
# Line 707 | Line 713 | public class ConcurrentHashMap8Test exte
713      public void testMappedForEachValueInParallel() {
714          LongAdder adder = new LongAdder();
715          ConcurrentHashMap<Long, Long> m = longMap();
716 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
716 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
717                                   (Long x) -> adder.add(x.longValue()));
718          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
719      }
# Line 719 | Line 725 | public class ConcurrentHashMap8Test exte
725      public void testMappedForEachInParallel() {
726          LongAdder adder = new LongAdder();
727          ConcurrentHashMap<Long, Long> m = longMap();
728 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
728 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
729                              (Long x) -> adder.add(x.longValue()));
730          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
731      }
# Line 731 | Line 737 | public class ConcurrentHashMap8Test exte
737      public void testMappedForEachEntryInParallel() {
738          LongAdder adder = new LongAdder();
739          ConcurrentHashMap<Long, Long> m = longMap();
740 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
740 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
741                                   (Long x) -> adder.add(x.longValue()));
742          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
743      }
744  
739
745      /**
746       * reduceKeysSequentially accumulates across all keys,
747       */
748      public void testReduceKeysSequentially() {
749          ConcurrentHashMap<Long, Long> m = longMap();
750          Long r;
751 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
751 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
752          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
753      }
754  
# Line 753 | Line 758 | public class ConcurrentHashMap8Test exte
758      public void testReduceValuesSequentially() {
759          ConcurrentHashMap<Long, Long> m = longMap();
760          Long r;
761 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
761 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
762          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
763      }
764  
760
765      /**
766       * reduceEntriesSequentially accumulates across all entries
767       */
768      public void testReduceEntriesSequentially() {
769          ConcurrentHashMap<Long, Long> m = longMap();
770          Map.Entry<Long,Long> r;
771 <        r = m.reduceEntriesSequentially(new AddKeys());
771 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
772          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
773      }
774  
# Line 774 | Line 778 | public class ConcurrentHashMap8Test exte
778      public void testReduceKeysInParallel() {
779          ConcurrentHashMap<Long, Long> m = longMap();
780          Long r;
781 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
781 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
782          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
783      }
784  
# Line 784 | Line 788 | public class ConcurrentHashMap8Test exte
788      public void testReduceValuesInParallel() {
789          ConcurrentHashMap<Long, Long> m = longMap();
790          Long r;
791 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
791 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
792          assertEquals((long)r, (long)SIZE * (SIZE - 1));
793      }
794  
# Line 794 | Line 798 | public class ConcurrentHashMap8Test exte
798      public void testReduceEntriesInParallel() {
799          ConcurrentHashMap<Long, Long> m = longMap();
800          Map.Entry<Long,Long> r;
801 <        r = m.reduceEntriesInParallel(new AddKeys());
801 >        r = m.reduceEntries(1L, new AddKeys());
802          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
803      }
804  
# Line 803 | Line 807 | public class ConcurrentHashMap8Test exte
807       */
808      public void testMapReduceKeysSequentially() {
809          ConcurrentHashMap<Long, Long> m = longMap();
810 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
810 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
811                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
812          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
813      }
# Line 813 | Line 817 | public class ConcurrentHashMap8Test exte
817       */
818      public void testMapReduceValuesSequentially() {
819          ConcurrentHashMap<Long, Long> m = longMap();
820 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
820 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
821                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
822          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
823      }
# Line 823 | Line 827 | public class ConcurrentHashMap8Test exte
827       */
828      public void testMappedReduceSequentially() {
829          ConcurrentHashMap<Long, Long> m = longMap();
830 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
830 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
831                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
832  
833          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 834 | Line 838 | public class ConcurrentHashMap8Test exte
838       */
839      public void testMapReduceKeysInParallel() {
840          ConcurrentHashMap<Long, Long> m = longMap();
841 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
841 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
842                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
843          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
844      }
# Line 844 | Line 848 | public class ConcurrentHashMap8Test exte
848       */
849      public void testMapReduceValuesInParallel() {
850          ConcurrentHashMap<Long, Long> m = longMap();
851 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
851 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
852                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
853          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
854      }
# Line 855 | Line 859 | public class ConcurrentHashMap8Test exte
859      public void testMappedReduceInParallel() {
860          ConcurrentHashMap<Long, Long> m = longMap();
861          Long r;
862 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
862 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
863                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
864          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
865      }
866  
863
867      /**
868       * reduceKeysToLongSequentially accumulates mapped keys
869       */
870      public void testReduceKeysToLongSequentially() {
871          ConcurrentHashMap<Long, Long> m = longMap();
872 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
872 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
873          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
874      }
875  
# Line 875 | Line 878 | public class ConcurrentHashMap8Test exte
878       */
879      public void testReduceKeysToIntSequentially() {
880          ConcurrentHashMap<Long, Long> m = longMap();
881 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
881 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
882          assertEquals(ir, SIZE * (SIZE - 1) / 2);
883      }
884  
# Line 884 | Line 887 | public class ConcurrentHashMap8Test exte
887       */
888      public void testReduceKeysToDoubleSequentially() {
889          ConcurrentHashMap<Long, Long> m = longMap();
890 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
890 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
891          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
892      }
893  
# Line 893 | Line 896 | public class ConcurrentHashMap8Test exte
896       */
897      public void testReduceValuesToLongSequentially() {
898          ConcurrentHashMap<Long, Long> m = longMap();
899 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
899 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
900          assertEquals(lr, (long)SIZE * (SIZE - 1));
901      }
902  
# Line 902 | Line 905 | public class ConcurrentHashMap8Test exte
905       */
906      public void testReduceValuesToIntSequentially() {
907          ConcurrentHashMap<Long, Long> m = longMap();
908 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
908 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
909          assertEquals(ir, SIZE * (SIZE - 1));
910      }
911  
# Line 911 | Line 914 | public class ConcurrentHashMap8Test exte
914       */
915      public void testReduceValuesToDoubleSequentially() {
916          ConcurrentHashMap<Long, Long> m = longMap();
917 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
917 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
918          assertEquals(dr, (double)SIZE * (SIZE - 1));
919      }
920  
# Line 920 | Line 923 | public class ConcurrentHashMap8Test exte
923       */
924      public void testReduceKeysToLongInParallel() {
925          ConcurrentHashMap<Long, Long> m = longMap();
926 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
926 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
927          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
928      }
929  
# Line 929 | Line 932 | public class ConcurrentHashMap8Test exte
932       */
933      public void testReduceKeysToIntInParallel() {
934          ConcurrentHashMap<Long, Long> m = longMap();
935 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
935 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
936          assertEquals(ir, SIZE * (SIZE - 1) / 2);
937      }
938  
# Line 938 | Line 941 | public class ConcurrentHashMap8Test exte
941       */
942      public void testReduceKeysToDoubleInParallel() {
943          ConcurrentHashMap<Long, Long> m = longMap();
944 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
944 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
945          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
946      }
947  
# Line 947 | Line 950 | public class ConcurrentHashMap8Test exte
950       */
951      public void testReduceValuesToLongInParallel() {
952          ConcurrentHashMap<Long, Long> m = longMap();
953 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
953 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
954          assertEquals(lr, (long)SIZE * (SIZE - 1));
955      }
956  
# Line 956 | Line 959 | public class ConcurrentHashMap8Test exte
959       */
960      public void testReduceValuesToIntInParallel() {
961          ConcurrentHashMap<Long, Long> m = longMap();
962 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
962 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
963          assertEquals(ir, SIZE * (SIZE - 1));
964      }
965  
# Line 965 | Line 968 | public class ConcurrentHashMap8Test exte
968       */
969      public void testReduceValuesToDoubleInParallel() {
970          ConcurrentHashMap<Long, Long> m = longMap();
971 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
971 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
972          assertEquals(dr, (double)SIZE * (SIZE - 1));
973      }
974  
# Line 976 | Line 979 | public class ConcurrentHashMap8Test exte
979      public void testSearchKeysSequentially() {
980          ConcurrentHashMap<Long, Long> m = longMap();
981          Long r;
982 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
982 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
983          assertEquals((long)r, (long)(SIZE/2));
984 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
984 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
985          assertNull(r);
986      }
987  
# Line 989 | Line 992 | public class ConcurrentHashMap8Test exte
992      public void testSearchValuesSequentially() {
993          ConcurrentHashMap<Long, Long> m = longMap();
994          Long r;
995 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
995 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
996          assertEquals((long)r, (long)(SIZE/2));
997 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
997 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
998          assertNull(r);
999      }
1000  
# Line 1002 | Line 1005 | public class ConcurrentHashMap8Test exte
1005      public void testSearchSequentially() {
1006          ConcurrentHashMap<Long, Long> m = longMap();
1007          Long r;
1008 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1008 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1009          assertEquals((long)r, (long)(SIZE/2));
1010 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1010 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1011          assertNull(r);
1012      }
1013  
# Line 1015 | Line 1018 | public class ConcurrentHashMap8Test exte
1018      public void testSearchEntriesSequentially() {
1019          ConcurrentHashMap<Long, Long> m = longMap();
1020          Long r;
1021 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1021 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1022          assertEquals((long)r, (long)(SIZE/2));
1023 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1023 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1024          assertNull(r);
1025      }
1026  
# Line 1028 | Line 1031 | public class ConcurrentHashMap8Test exte
1031      public void testSearchKeysInParallel() {
1032          ConcurrentHashMap<Long, Long> m = longMap();
1033          Long r;
1034 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1034 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1035          assertEquals((long)r, (long)(SIZE/2));
1036 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1036 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1037          assertNull(r);
1038      }
1039  
# Line 1041 | Line 1044 | public class ConcurrentHashMap8Test exte
1044      public void testSearchValuesInParallel() {
1045          ConcurrentHashMap<Long, Long> m = longMap();
1046          Long r;
1047 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1047 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1048          assertEquals((long)r, (long)(SIZE/2));
1049 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1049 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1050          assertNull(r);
1051      }
1052  
# Line 1054 | Line 1057 | public class ConcurrentHashMap8Test exte
1057      public void testSearchInParallel() {
1058          ConcurrentHashMap<Long, Long> m = longMap();
1059          Long r;
1060 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1060 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1061          assertEquals((long)r, (long)(SIZE/2));
1062 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1062 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1063          assertNull(r);
1064      }
1065  
# Line 1067 | Line 1070 | public class ConcurrentHashMap8Test exte
1070      public void testSearchEntriesInParallel() {
1071          ConcurrentHashMap<Long, Long> m = longMap();
1072          Long r;
1073 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1073 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1074          assertEquals((long)r, (long)(SIZE/2));
1075 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1075 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1076          assertNull(r);
1077      }
1078  
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    }
1079   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines