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.11 by jsr166, Sun Jul 14 16:35:48 2013 UTC

# Line 34 | Line 34 | public class ConcurrentHashMap8Test exte
34          return map;
35      }
36  
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
37      /**
38       * getOrDefault returns value if present, else default
39       */
# Line 530 | Line 431 | public class ConcurrentHashMap8Test exte
431          Set x = populatedSet(size);
432          Set y = serialClone(x);
433  
434 <        assertTrue(x != y);
434 >        assertNotSame(x, y);
435          assertEquals(x.size(), y.size());
436          assertEquals(x.toString(), y.toString());
437          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 538 | Line 439 | public class ConcurrentHashMap8Test exte
439          assertEquals(y, x);
440      }
441  
541
442      static final int SIZE = 10000;
443      static ConcurrentHashMap<Long, Long> longMap;
444  
# Line 566 | Line 466 | public class ConcurrentHashMap8Test exte
466      public void testForEachKeySequentially() {
467          LongAdder adder = new LongAdder();
468          ConcurrentHashMap<Long, Long> m = longMap();
469 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
469 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
470          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
471      }
472  
# Line 576 | Line 476 | public class ConcurrentHashMap8Test exte
476      public void testForEachValueSequentially() {
477          LongAdder adder = new LongAdder();
478          ConcurrentHashMap<Long, Long> m = longMap();
479 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
479 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
480          assertEquals(adder.sum(), SIZE * (SIZE - 1));
481      }
482  
# Line 586 | Line 486 | public class ConcurrentHashMap8Test exte
486      public void testForEachSequentially() {
487          LongAdder adder = new LongAdder();
488          ConcurrentHashMap<Long, Long> m = longMap();
489 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
489 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
490          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
491      }
492  
# Line 596 | Line 496 | public class ConcurrentHashMap8Test exte
496      public void testForEachEntrySequentially() {
497          LongAdder adder = new LongAdder();
498          ConcurrentHashMap<Long, Long> m = longMap();
499 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
499 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
500          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
501      }
502  
# Line 606 | Line 506 | public class ConcurrentHashMap8Test exte
506      public void testForEachKeyInParallel() {
507          LongAdder adder = new LongAdder();
508          ConcurrentHashMap<Long, Long> m = longMap();
509 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
509 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
510          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
511      }
512  
# Line 616 | Line 516 | public class ConcurrentHashMap8Test exte
516      public void testForEachValueInParallel() {
517          LongAdder adder = new LongAdder();
518          ConcurrentHashMap<Long, Long> m = longMap();
519 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
519 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
520          assertEquals(adder.sum(), SIZE * (SIZE - 1));
521      }
522  
# Line 626 | Line 526 | public class ConcurrentHashMap8Test exte
526      public void testForEachInParallel() {
527          LongAdder adder = new LongAdder();
528          ConcurrentHashMap<Long, Long> m = longMap();
529 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
529 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
530          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
531      }
532  
# Line 636 | Line 536 | public class ConcurrentHashMap8Test exte
536      public void testForEachEntryInParallel() {
537          LongAdder adder = new LongAdder();
538          ConcurrentHashMap<Long, Long> m = longMap();
539 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
539 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
540          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
541      }
542  
# Line 647 | Line 547 | public class ConcurrentHashMap8Test exte
547      public void testMappedForEachKeySequentially() {
548          LongAdder adder = new LongAdder();
549          ConcurrentHashMap<Long, Long> m = longMap();
550 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
550 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
551                                   (Long x) -> adder.add(x.longValue()));
552          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
553      }
# Line 659 | Line 559 | public class ConcurrentHashMap8Test exte
559      public void testMappedForEachValueSequentially() {
560          LongAdder adder = new LongAdder();
561          ConcurrentHashMap<Long, Long> m = longMap();
562 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
562 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
563                                     (Long x) -> adder.add(x.longValue()));
564          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
565      }
# Line 671 | Line 571 | public class ConcurrentHashMap8Test exte
571      public void testMappedForEachSequentially() {
572          LongAdder adder = new LongAdder();
573          ConcurrentHashMap<Long, Long> m = longMap();
574 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
574 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
575                                (Long x) -> adder.add(x.longValue()));
576          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
577      }
# Line 683 | Line 583 | public class ConcurrentHashMap8Test exte
583      public void testMappedForEachEntrySequentially() {
584          LongAdder adder = new LongAdder();
585          ConcurrentHashMap<Long, Long> m = longMap();
586 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
586 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
587                                     (Long x) -> adder.add(x.longValue()));
588          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
589      }
# Line 695 | Line 595 | public class ConcurrentHashMap8Test exte
595      public void testMappedForEachKeyInParallel() {
596          LongAdder adder = new LongAdder();
597          ConcurrentHashMap<Long, Long> m = longMap();
598 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
598 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
599                                 (Long x) -> adder.add(x.longValue()));
600          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
601      }
# Line 707 | Line 607 | public class ConcurrentHashMap8Test exte
607      public void testMappedForEachValueInParallel() {
608          LongAdder adder = new LongAdder();
609          ConcurrentHashMap<Long, Long> m = longMap();
610 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
610 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
611                                   (Long x) -> adder.add(x.longValue()));
612          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
613      }
# Line 719 | Line 619 | public class ConcurrentHashMap8Test exte
619      public void testMappedForEachInParallel() {
620          LongAdder adder = new LongAdder();
621          ConcurrentHashMap<Long, Long> m = longMap();
622 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
622 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
623                              (Long x) -> adder.add(x.longValue()));
624          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
625      }
# Line 731 | Line 631 | public class ConcurrentHashMap8Test exte
631      public void testMappedForEachEntryInParallel() {
632          LongAdder adder = new LongAdder();
633          ConcurrentHashMap<Long, Long> m = longMap();
634 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
634 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
635                                   (Long x) -> adder.add(x.longValue()));
636          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
637      }
638  
739
639      /**
640       * reduceKeysSequentially accumulates across all keys,
641       */
642      public void testReduceKeysSequentially() {
643          ConcurrentHashMap<Long, Long> m = longMap();
644          Long r;
645 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
645 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
646          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
647      }
648  
# Line 753 | Line 652 | public class ConcurrentHashMap8Test exte
652      public void testReduceValuesSequentially() {
653          ConcurrentHashMap<Long, Long> m = longMap();
654          Long r;
655 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
655 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
656          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
657      }
658  
760
659      /**
660       * reduceEntriesSequentially accumulates across all entries
661       */
662      public void testReduceEntriesSequentially() {
663          ConcurrentHashMap<Long, Long> m = longMap();
664          Map.Entry<Long,Long> r;
665 <        r = m.reduceEntriesSequentially(new AddKeys());
665 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
666          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
667      }
668  
# Line 774 | Line 672 | public class ConcurrentHashMap8Test exte
672      public void testReduceKeysInParallel() {
673          ConcurrentHashMap<Long, Long> m = longMap();
674          Long r;
675 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
675 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
676          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
677      }
678  
# Line 784 | Line 682 | public class ConcurrentHashMap8Test exte
682      public void testReduceValuesInParallel() {
683          ConcurrentHashMap<Long, Long> m = longMap();
684          Long r;
685 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
685 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
686          assertEquals((long)r, (long)SIZE * (SIZE - 1));
687      }
688  
# Line 794 | Line 692 | public class ConcurrentHashMap8Test exte
692      public void testReduceEntriesInParallel() {
693          ConcurrentHashMap<Long, Long> m = longMap();
694          Map.Entry<Long,Long> r;
695 <        r = m.reduceEntriesInParallel(new AddKeys());
695 >        r = m.reduceEntries(1L, new AddKeys());
696          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
697      }
698  
# Line 803 | Line 701 | public class ConcurrentHashMap8Test exte
701       */
702      public void testMapReduceKeysSequentially() {
703          ConcurrentHashMap<Long, Long> m = longMap();
704 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
704 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
705                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
706          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
707      }
# Line 813 | Line 711 | public class ConcurrentHashMap8Test exte
711       */
712      public void testMapReduceValuesSequentially() {
713          ConcurrentHashMap<Long, Long> m = longMap();
714 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
714 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
715                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
716          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
717      }
# Line 823 | Line 721 | public class ConcurrentHashMap8Test exte
721       */
722      public void testMappedReduceSequentially() {
723          ConcurrentHashMap<Long, Long> m = longMap();
724 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
724 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
725                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
726  
727          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 834 | Line 732 | public class ConcurrentHashMap8Test exte
732       */
733      public void testMapReduceKeysInParallel() {
734          ConcurrentHashMap<Long, Long> m = longMap();
735 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
735 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
736                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
737          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
738      }
# Line 844 | Line 742 | public class ConcurrentHashMap8Test exte
742       */
743      public void testMapReduceValuesInParallel() {
744          ConcurrentHashMap<Long, Long> m = longMap();
745 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
745 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
746                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
747          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
748      }
# Line 855 | Line 753 | public class ConcurrentHashMap8Test exte
753      public void testMappedReduceInParallel() {
754          ConcurrentHashMap<Long, Long> m = longMap();
755          Long r;
756 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
756 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
757                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
758          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
759      }
760  
863
761      /**
762       * reduceKeysToLongSequentially accumulates mapped keys
763       */
764      public void testReduceKeysToLongSequentially() {
765          ConcurrentHashMap<Long, Long> m = longMap();
766 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
766 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
767          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
768      }
769  
# Line 875 | Line 772 | public class ConcurrentHashMap8Test exte
772       */
773      public void testReduceKeysToIntSequentially() {
774          ConcurrentHashMap<Long, Long> m = longMap();
775 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
775 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
776          assertEquals(ir, SIZE * (SIZE - 1) / 2);
777      }
778  
# Line 884 | Line 781 | public class ConcurrentHashMap8Test exte
781       */
782      public void testReduceKeysToDoubleSequentially() {
783          ConcurrentHashMap<Long, Long> m = longMap();
784 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
784 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
785          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
786      }
787  
# Line 893 | Line 790 | public class ConcurrentHashMap8Test exte
790       */
791      public void testReduceValuesToLongSequentially() {
792          ConcurrentHashMap<Long, Long> m = longMap();
793 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
793 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
794          assertEquals(lr, (long)SIZE * (SIZE - 1));
795      }
796  
# Line 902 | Line 799 | public class ConcurrentHashMap8Test exte
799       */
800      public void testReduceValuesToIntSequentially() {
801          ConcurrentHashMap<Long, Long> m = longMap();
802 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
802 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
803          assertEquals(ir, SIZE * (SIZE - 1));
804      }
805  
# Line 911 | Line 808 | public class ConcurrentHashMap8Test exte
808       */
809      public void testReduceValuesToDoubleSequentially() {
810          ConcurrentHashMap<Long, Long> m = longMap();
811 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
811 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
812          assertEquals(dr, (double)SIZE * (SIZE - 1));
813      }
814  
# Line 920 | Line 817 | public class ConcurrentHashMap8Test exte
817       */
818      public void testReduceKeysToLongInParallel() {
819          ConcurrentHashMap<Long, Long> m = longMap();
820 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
820 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
821          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
822      }
823  
# Line 929 | Line 826 | public class ConcurrentHashMap8Test exte
826       */
827      public void testReduceKeysToIntInParallel() {
828          ConcurrentHashMap<Long, Long> m = longMap();
829 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
829 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
830          assertEquals(ir, SIZE * (SIZE - 1) / 2);
831      }
832  
# Line 938 | Line 835 | public class ConcurrentHashMap8Test exte
835       */
836      public void testReduceKeysToDoubleInParallel() {
837          ConcurrentHashMap<Long, Long> m = longMap();
838 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
838 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
839          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
840      }
841  
# Line 947 | Line 844 | public class ConcurrentHashMap8Test exte
844       */
845      public void testReduceValuesToLongInParallel() {
846          ConcurrentHashMap<Long, Long> m = longMap();
847 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
847 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
848          assertEquals(lr, (long)SIZE * (SIZE - 1));
849      }
850  
# Line 956 | Line 853 | public class ConcurrentHashMap8Test exte
853       */
854      public void testReduceValuesToIntInParallel() {
855          ConcurrentHashMap<Long, Long> m = longMap();
856 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
856 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
857          assertEquals(ir, SIZE * (SIZE - 1));
858      }
859  
# Line 965 | Line 862 | public class ConcurrentHashMap8Test exte
862       */
863      public void testReduceValuesToDoubleInParallel() {
864          ConcurrentHashMap<Long, Long> m = longMap();
865 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
865 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
866          assertEquals(dr, (double)SIZE * (SIZE - 1));
867      }
868  
# Line 976 | Line 873 | public class ConcurrentHashMap8Test exte
873      public void testSearchKeysSequentially() {
874          ConcurrentHashMap<Long, Long> m = longMap();
875          Long r;
876 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
876 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
877          assertEquals((long)r, (long)(SIZE/2));
878 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
878 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
879          assertNull(r);
880      }
881  
# Line 989 | Line 886 | public class ConcurrentHashMap8Test exte
886      public void testSearchValuesSequentially() {
887          ConcurrentHashMap<Long, Long> m = longMap();
888          Long r;
889 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
889 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
890          assertEquals((long)r, (long)(SIZE/2));
891 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
891 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
892          assertNull(r);
893      }
894  
# Line 1002 | Line 899 | public class ConcurrentHashMap8Test exte
899      public void testSearchSequentially() {
900          ConcurrentHashMap<Long, Long> m = longMap();
901          Long r;
902 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
902 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
903          assertEquals((long)r, (long)(SIZE/2));
904 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
904 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
905          assertNull(r);
906      }
907  
# Line 1015 | Line 912 | public class ConcurrentHashMap8Test exte
912      public void testSearchEntriesSequentially() {
913          ConcurrentHashMap<Long, Long> m = longMap();
914          Long r;
915 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
915 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
916          assertEquals((long)r, (long)(SIZE/2));
917 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
917 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
918          assertNull(r);
919      }
920  
# Line 1028 | Line 925 | public class ConcurrentHashMap8Test exte
925      public void testSearchKeysInParallel() {
926          ConcurrentHashMap<Long, Long> m = longMap();
927          Long r;
928 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
928 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
929          assertEquals((long)r, (long)(SIZE/2));
930 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
930 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
931          assertNull(r);
932      }
933  
# Line 1041 | Line 938 | public class ConcurrentHashMap8Test exte
938      public void testSearchValuesInParallel() {
939          ConcurrentHashMap<Long, Long> m = longMap();
940          Long r;
941 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
941 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
942          assertEquals((long)r, (long)(SIZE/2));
943 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
943 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
944          assertNull(r);
945      }
946  
# Line 1054 | Line 951 | public class ConcurrentHashMap8Test exte
951      public void testSearchInParallel() {
952          ConcurrentHashMap<Long, Long> m = longMap();
953          Long r;
954 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
954 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
955          assertEquals((long)r, (long)(SIZE/2));
956 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
956 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
957          assertNull(r);
958      }
959  
# Line 1067 | Line 964 | public class ConcurrentHashMap8Test exte
964      public void testSearchEntriesInParallel() {
965          ConcurrentHashMap<Long, Long> m = longMap();
966          Long r;
967 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
967 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
968          assertEquals((long)r, (long)(SIZE/2));
969 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
969 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
970          assertNull(r);
971      }
972  
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    }
973   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines