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.14 by jsr166, Mon Jul 22 18:11:56 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 152 | Line 54 | public class ConcurrentHashMap8Test exte
54      }
55  
56      /**
57 <     * computeIfAbsent does not replace  if the key is already present
57 >     * computeIfAbsent does not replace if the key is already present
58       */
59      public void testComputeIfAbsent2() {
60          ConcurrentHashMap map = map5();
# Line 169 | Line 71 | public class ConcurrentHashMap8Test exte
71      }
72  
73      /**
74 <     * computeIfPresent does not replace  if the key is already present
74 >     * computeIfPresent does not replace if the key is already present
75       */
76      public void testComputeIfPresent() {
77          ConcurrentHashMap map = map5();
# Line 186 | Line 88 | public class ConcurrentHashMap8Test exte
88      }
89  
90      /**
91 <     * compute does not replace  if the function returns null
91 >     * compute does not replace if the function returns null
92       */
93      public void testCompute() {
94          ConcurrentHashMap map = map5();
# 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 318 | Line 256 | public class ConcurrentHashMap8Test exte
256      }
257  
258      /**
259 +     * keySet.add throws UnsupportedOperationException if no default
260 +     * mapped value
261 +     */
262 +    public void testAdd4() {
263 +        Set full = map5().keySet();
264 +        try {
265 +            full.add(three);
266 +            shouldThrow();
267 +        } catch (UnsupportedOperationException e){}
268 +    }
269 +
270 +    /**
271 +     * keySet.add throws NullPointerException if the specified key is
272 +     * null
273 +     */
274 +    public void testAdd5() {
275 +        Set full = populatedSet(3);
276 +        try {
277 +            full.add(null);
278 +            shouldThrow();
279 +        } catch (NullPointerException e){}
280 +    }
281 +
282 +    /**
283 +     * KeySetView.getMappedValue returns the map's mapped value
284 +     */
285 +    public void testGetMappedValue() {
286 +        ConcurrentHashMap map = map5();
287 +        assertNull(map.keySet().getMappedValue());
288 +        try {
289 +            map.keySet(null);
290 +            shouldThrow();
291 +        } catch (NullPointerException e) {}
292 +        KeySetView set = map.keySet(one);
293 +        set.add(one);
294 +        set.add(six);
295 +        set.add(seven);
296 +        assertTrue(set.getMappedValue() == one);
297 +        assertTrue(map.get(one) != one);
298 +        assertTrue(map.get(six) == one);
299 +        assertTrue(map.get(seven) == one);
300 +    }
301 +
302 +    /**
303 +     * KeySetView.spliterator returns spliterator over the elements in this set
304 +     */
305 +    public void testKeySetSpliterator() {
306 +        LongAdder adder = new LongAdder();
307 +        ConcurrentHashMap map = map5();
308 +        Set set = map.keySet();
309 +        Spliterator<Integer> sp = set.spliterator();
310 +        assertEquals(sp.estimateSize(), map.size());
311 +        Spliterator<Integer> sp2 = sp.trySplit();
312 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
313 +        long v = adder.sumThenReset();
314 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
315 +        long v2 = adder.sum();
316 +        assertEquals(v + v2, 15);
317 +    }
318 +
319 +    /**
320       * keyset.clear removes all elements from the set
321       */
322      public void testClear() {
# Line 530 | Line 529 | public class ConcurrentHashMap8Test exte
529          Set x = populatedSet(size);
530          Set y = serialClone(x);
531  
532 <        assertTrue(x != y);
532 >        assertNotSame(x, y);
533          assertEquals(x.size(), y.size());
534          assertEquals(x.toString(), y.toString());
535          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 538 | Line 537 | public class ConcurrentHashMap8Test exte
537          assertEquals(y, x);
538      }
539  
541
540      static final int SIZE = 10000;
541      static ConcurrentHashMap<Long, Long> longMap;
542  
# Line 566 | Line 564 | public class ConcurrentHashMap8Test exte
564      public void testForEachKeySequentially() {
565          LongAdder adder = new LongAdder();
566          ConcurrentHashMap<Long, Long> m = longMap();
567 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
567 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
568          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
569      }
570  
# Line 576 | Line 574 | public class ConcurrentHashMap8Test exte
574      public void testForEachValueSequentially() {
575          LongAdder adder = new LongAdder();
576          ConcurrentHashMap<Long, Long> m = longMap();
577 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
577 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
578          assertEquals(adder.sum(), SIZE * (SIZE - 1));
579      }
580  
# Line 586 | Line 584 | public class ConcurrentHashMap8Test exte
584      public void testForEachSequentially() {
585          LongAdder adder = new LongAdder();
586          ConcurrentHashMap<Long, Long> m = longMap();
587 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
587 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
588          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
589      }
590  
# Line 596 | Line 594 | public class ConcurrentHashMap8Test exte
594      public void testForEachEntrySequentially() {
595          LongAdder adder = new LongAdder();
596          ConcurrentHashMap<Long, Long> m = longMap();
597 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
597 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
598          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
599      }
600  
# Line 606 | Line 604 | public class ConcurrentHashMap8Test exte
604      public void testForEachKeyInParallel() {
605          LongAdder adder = new LongAdder();
606          ConcurrentHashMap<Long, Long> m = longMap();
607 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
607 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
608          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
609      }
610  
# Line 616 | Line 614 | public class ConcurrentHashMap8Test exte
614      public void testForEachValueInParallel() {
615          LongAdder adder = new LongAdder();
616          ConcurrentHashMap<Long, Long> m = longMap();
617 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
617 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
618          assertEquals(adder.sum(), SIZE * (SIZE - 1));
619      }
620  
# Line 626 | Line 624 | public class ConcurrentHashMap8Test exte
624      public void testForEachInParallel() {
625          LongAdder adder = new LongAdder();
626          ConcurrentHashMap<Long, Long> m = longMap();
627 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
627 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
628          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
629      }
630  
# Line 636 | Line 634 | public class ConcurrentHashMap8Test exte
634      public void testForEachEntryInParallel() {
635          LongAdder adder = new LongAdder();
636          ConcurrentHashMap<Long, Long> m = longMap();
637 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
637 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
638          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
639      }
640  
# Line 647 | Line 645 | public class ConcurrentHashMap8Test exte
645      public void testMappedForEachKeySequentially() {
646          LongAdder adder = new LongAdder();
647          ConcurrentHashMap<Long, Long> m = longMap();
648 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
648 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
649                                   (Long x) -> adder.add(x.longValue()));
650          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
651      }
# Line 659 | Line 657 | public class ConcurrentHashMap8Test exte
657      public void testMappedForEachValueSequentially() {
658          LongAdder adder = new LongAdder();
659          ConcurrentHashMap<Long, Long> m = longMap();
660 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
660 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
661                                     (Long x) -> adder.add(x.longValue()));
662          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
663      }
# Line 671 | Line 669 | public class ConcurrentHashMap8Test exte
669      public void testMappedForEachSequentially() {
670          LongAdder adder = new LongAdder();
671          ConcurrentHashMap<Long, Long> m = longMap();
672 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
672 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
673                                (Long x) -> adder.add(x.longValue()));
674          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
675      }
# Line 683 | Line 681 | public class ConcurrentHashMap8Test exte
681      public void testMappedForEachEntrySequentially() {
682          LongAdder adder = new LongAdder();
683          ConcurrentHashMap<Long, Long> m = longMap();
684 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
684 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
685                                     (Long x) -> adder.add(x.longValue()));
686          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
687      }
# Line 695 | Line 693 | public class ConcurrentHashMap8Test exte
693      public void testMappedForEachKeyInParallel() {
694          LongAdder adder = new LongAdder();
695          ConcurrentHashMap<Long, Long> m = longMap();
696 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
696 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
697                                 (Long x) -> adder.add(x.longValue()));
698          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
699      }
# Line 707 | Line 705 | public class ConcurrentHashMap8Test exte
705      public void testMappedForEachValueInParallel() {
706          LongAdder adder = new LongAdder();
707          ConcurrentHashMap<Long, Long> m = longMap();
708 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
708 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
709                                   (Long x) -> adder.add(x.longValue()));
710          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
711      }
# Line 719 | Line 717 | public class ConcurrentHashMap8Test exte
717      public void testMappedForEachInParallel() {
718          LongAdder adder = new LongAdder();
719          ConcurrentHashMap<Long, Long> m = longMap();
720 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
720 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
721                              (Long x) -> adder.add(x.longValue()));
722          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
723      }
# Line 731 | Line 729 | public class ConcurrentHashMap8Test exte
729      public void testMappedForEachEntryInParallel() {
730          LongAdder adder = new LongAdder();
731          ConcurrentHashMap<Long, Long> m = longMap();
732 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
732 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
733                                   (Long x) -> adder.add(x.longValue()));
734          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
735      }
736  
739
737      /**
738       * reduceKeysSequentially accumulates across all keys,
739       */
740      public void testReduceKeysSequentially() {
741          ConcurrentHashMap<Long, Long> m = longMap();
742          Long r;
743 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
743 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
744          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
745      }
746  
# Line 753 | Line 750 | public class ConcurrentHashMap8Test exte
750      public void testReduceValuesSequentially() {
751          ConcurrentHashMap<Long, Long> m = longMap();
752          Long r;
753 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
753 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
754          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
755      }
756  
760
757      /**
758       * reduceEntriesSequentially accumulates across all entries
759       */
760      public void testReduceEntriesSequentially() {
761          ConcurrentHashMap<Long, Long> m = longMap();
762          Map.Entry<Long,Long> r;
763 <        r = m.reduceEntriesSequentially(new AddKeys());
763 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
764          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
765      }
766  
# Line 774 | Line 770 | public class ConcurrentHashMap8Test exte
770      public void testReduceKeysInParallel() {
771          ConcurrentHashMap<Long, Long> m = longMap();
772          Long r;
773 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
773 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
774          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
775      }
776  
# Line 784 | Line 780 | public class ConcurrentHashMap8Test exte
780      public void testReduceValuesInParallel() {
781          ConcurrentHashMap<Long, Long> m = longMap();
782          Long r;
783 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
783 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
784          assertEquals((long)r, (long)SIZE * (SIZE - 1));
785      }
786  
# Line 794 | Line 790 | public class ConcurrentHashMap8Test exte
790      public void testReduceEntriesInParallel() {
791          ConcurrentHashMap<Long, Long> m = longMap();
792          Map.Entry<Long,Long> r;
793 <        r = m.reduceEntriesInParallel(new AddKeys());
793 >        r = m.reduceEntries(1L, new AddKeys());
794          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
795      }
796  
# Line 803 | Line 799 | public class ConcurrentHashMap8Test exte
799       */
800      public void testMapReduceKeysSequentially() {
801          ConcurrentHashMap<Long, Long> m = longMap();
802 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
802 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
803                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
804          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
805      }
# Line 813 | Line 809 | public class ConcurrentHashMap8Test exte
809       */
810      public void testMapReduceValuesSequentially() {
811          ConcurrentHashMap<Long, Long> m = longMap();
812 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
812 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
813                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
814          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
815      }
# Line 823 | Line 819 | public class ConcurrentHashMap8Test exte
819       */
820      public void testMappedReduceSequentially() {
821          ConcurrentHashMap<Long, Long> m = longMap();
822 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
822 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
823                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
824  
825          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 834 | Line 830 | public class ConcurrentHashMap8Test exte
830       */
831      public void testMapReduceKeysInParallel() {
832          ConcurrentHashMap<Long, Long> m = longMap();
833 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
833 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
834                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
835          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
836      }
# Line 844 | Line 840 | public class ConcurrentHashMap8Test exte
840       */
841      public void testMapReduceValuesInParallel() {
842          ConcurrentHashMap<Long, Long> m = longMap();
843 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
843 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
844                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
845          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
846      }
# Line 855 | Line 851 | public class ConcurrentHashMap8Test exte
851      public void testMappedReduceInParallel() {
852          ConcurrentHashMap<Long, Long> m = longMap();
853          Long r;
854 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
854 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
855                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
856          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
857      }
858  
863
859      /**
860       * reduceKeysToLongSequentially accumulates mapped keys
861       */
862      public void testReduceKeysToLongSequentially() {
863          ConcurrentHashMap<Long, Long> m = longMap();
864 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
864 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
865          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
866      }
867  
# Line 875 | Line 870 | public class ConcurrentHashMap8Test exte
870       */
871      public void testReduceKeysToIntSequentially() {
872          ConcurrentHashMap<Long, Long> m = longMap();
873 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
873 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
874          assertEquals(ir, SIZE * (SIZE - 1) / 2);
875      }
876  
# Line 884 | Line 879 | public class ConcurrentHashMap8Test exte
879       */
880      public void testReduceKeysToDoubleSequentially() {
881          ConcurrentHashMap<Long, Long> m = longMap();
882 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
882 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
883          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
884      }
885  
# Line 893 | Line 888 | public class ConcurrentHashMap8Test exte
888       */
889      public void testReduceValuesToLongSequentially() {
890          ConcurrentHashMap<Long, Long> m = longMap();
891 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
891 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
892          assertEquals(lr, (long)SIZE * (SIZE - 1));
893      }
894  
# Line 902 | Line 897 | public class ConcurrentHashMap8Test exte
897       */
898      public void testReduceValuesToIntSequentially() {
899          ConcurrentHashMap<Long, Long> m = longMap();
900 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
900 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
901          assertEquals(ir, SIZE * (SIZE - 1));
902      }
903  
# Line 911 | Line 906 | public class ConcurrentHashMap8Test exte
906       */
907      public void testReduceValuesToDoubleSequentially() {
908          ConcurrentHashMap<Long, Long> m = longMap();
909 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
909 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
910          assertEquals(dr, (double)SIZE * (SIZE - 1));
911      }
912  
# Line 920 | Line 915 | public class ConcurrentHashMap8Test exte
915       */
916      public void testReduceKeysToLongInParallel() {
917          ConcurrentHashMap<Long, Long> m = longMap();
918 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
918 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
919          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
920      }
921  
# Line 929 | Line 924 | public class ConcurrentHashMap8Test exte
924       */
925      public void testReduceKeysToIntInParallel() {
926          ConcurrentHashMap<Long, Long> m = longMap();
927 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
927 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
928          assertEquals(ir, SIZE * (SIZE - 1) / 2);
929      }
930  
# Line 938 | Line 933 | public class ConcurrentHashMap8Test exte
933       */
934      public void testReduceKeysToDoubleInParallel() {
935          ConcurrentHashMap<Long, Long> m = longMap();
936 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
936 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
937          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
938      }
939  
# Line 947 | Line 942 | public class ConcurrentHashMap8Test exte
942       */
943      public void testReduceValuesToLongInParallel() {
944          ConcurrentHashMap<Long, Long> m = longMap();
945 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
945 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
946          assertEquals(lr, (long)SIZE * (SIZE - 1));
947      }
948  
# Line 956 | Line 951 | public class ConcurrentHashMap8Test exte
951       */
952      public void testReduceValuesToIntInParallel() {
953          ConcurrentHashMap<Long, Long> m = longMap();
954 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
954 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
955          assertEquals(ir, SIZE * (SIZE - 1));
956      }
957  
# Line 965 | Line 960 | public class ConcurrentHashMap8Test exte
960       */
961      public void testReduceValuesToDoubleInParallel() {
962          ConcurrentHashMap<Long, Long> m = longMap();
963 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
963 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
964          assertEquals(dr, (double)SIZE * (SIZE - 1));
965      }
966  
# Line 976 | Line 971 | public class ConcurrentHashMap8Test exte
971      public void testSearchKeysSequentially() {
972          ConcurrentHashMap<Long, Long> m = longMap();
973          Long r;
974 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
974 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
975          assertEquals((long)r, (long)(SIZE/2));
976 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
976 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
977          assertNull(r);
978      }
979  
# Line 989 | Line 984 | public class ConcurrentHashMap8Test exte
984      public void testSearchValuesSequentially() {
985          ConcurrentHashMap<Long, Long> m = longMap();
986          Long r;
987 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
987 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
988          assertEquals((long)r, (long)(SIZE/2));
989 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
989 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
990          assertNull(r);
991      }
992  
# Line 1002 | Line 997 | public class ConcurrentHashMap8Test exte
997      public void testSearchSequentially() {
998          ConcurrentHashMap<Long, Long> m = longMap();
999          Long r;
1000 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1000 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1001          assertEquals((long)r, (long)(SIZE/2));
1002 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1002 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1003          assertNull(r);
1004      }
1005  
# Line 1015 | Line 1010 | public class ConcurrentHashMap8Test exte
1010      public void testSearchEntriesSequentially() {
1011          ConcurrentHashMap<Long, Long> m = longMap();
1012          Long r;
1013 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1013 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1014          assertEquals((long)r, (long)(SIZE/2));
1015 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1015 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1016          assertNull(r);
1017      }
1018  
# Line 1028 | Line 1023 | public class ConcurrentHashMap8Test exte
1023      public void testSearchKeysInParallel() {
1024          ConcurrentHashMap<Long, Long> m = longMap();
1025          Long r;
1026 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1026 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1027          assertEquals((long)r, (long)(SIZE/2));
1028 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1028 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1029          assertNull(r);
1030      }
1031  
# Line 1041 | Line 1036 | public class ConcurrentHashMap8Test exte
1036      public void testSearchValuesInParallel() {
1037          ConcurrentHashMap<Long, Long> m = longMap();
1038          Long r;
1039 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1039 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1040          assertEquals((long)r, (long)(SIZE/2));
1041 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1041 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1042          assertNull(r);
1043      }
1044  
# Line 1054 | Line 1049 | public class ConcurrentHashMap8Test exte
1049      public void testSearchInParallel() {
1050          ConcurrentHashMap<Long, Long> m = longMap();
1051          Long r;
1052 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1052 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1053          assertEquals((long)r, (long)(SIZE/2));
1054 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1054 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1055          assertNull(r);
1056      }
1057  
# Line 1067 | Line 1062 | public class ConcurrentHashMap8Test exte
1062      public void testSearchEntriesInParallel() {
1063          ConcurrentHashMap<Long, Long> m = longMap();
1064          Long r;
1065 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1065 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1066          assertEquals((long)r, (long)(SIZE/2));
1067 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1067 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1068          assertNull(r);
1069      }
1070  
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    }
1071   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines