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.8 by jsr166, Thu Apr 11 20:03:44 2013 UTC vs.
Revision 1.13 by jsr166, Mon Jul 22 15:55:43 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 165 | 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 174 | 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 219 | 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 431 | 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 439 | Line 537 | public class ConcurrentHashMap8Test exte
537          assertEquals(y, x);
538      }
539  
442
540      static final int SIZE = 10000;
541      static ConcurrentHashMap<Long, Long> longMap;
542  
# Line 467 | 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 477 | 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 487 | 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 497 | 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 507 | 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 517 | 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 527 | 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 537 | 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 548 | 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 560 | 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 572 | 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 584 | 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 596 | 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 608 | 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 620 | 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 632 | 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  
640
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 654 | 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  
661
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 675 | 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 685 | 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 695 | 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 704 | 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 714 | 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 724 | 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 735 | 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 745 | 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 756 | 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  
764
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 776 | 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 785 | 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 794 | 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 803 | 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 812 | 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 821 | 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 830 | 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 839 | 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 848 | 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 857 | 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 866 | 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 877 | 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 890 | 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 903 | 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 916 | 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 929 | 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 942 | 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 955 | 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 968 | 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  
977    /**
978     * Invoking task versions of bulk methods has same effect as
979     * parallel methods
980     */
981    public void testForkJoinTasks() {
982        LongAdder adder = new LongAdder();
983        ConcurrentHashMap<Long, Long> m = longMap();
984        ConcurrentHashMap.ForkJoinTasks.forEachKey
985            (m, (Long x) -> adder.add(x.longValue())).invoke();
986        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
987        adder.reset();
988        ConcurrentHashMap.ForkJoinTasks.forEachValue
989            (m, (Long x) -> adder.add(x.longValue())).invoke();
990        assertEquals(adder.sum(), SIZE * (SIZE - 1));
991        adder.reset();
992        ConcurrentHashMap.ForkJoinTasks.forEach
993            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
994        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
995        adder.reset();
996        ConcurrentHashMap.ForkJoinTasks.forEachEntry
997            (m,
998             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
999        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1000        adder.reset();
1001        ConcurrentHashMap.ForkJoinTasks.forEachKey
1002            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1003             (Long x) -> adder.add(x.longValue())).invoke();
1004        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
1005        adder.reset();
1006        ConcurrentHashMap.ForkJoinTasks.forEachValue
1007            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1008             (Long x) -> adder.add(x.longValue())).invoke();
1009        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
1010        adder.reset();
1011        ConcurrentHashMap.ForkJoinTasks.forEach
1012            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1013             (Long x) -> adder.add(x.longValue())).invoke();
1014        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1015        adder.reset();
1016        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1017            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1018             (Long x) -> adder.add(x.longValue())).invoke();
1019        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1020        adder.reset();
1021
1022        Long r; long lr; int ir; double dr;
1023        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1024            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1025        assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
1026        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1027            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1028        assertEquals((long)r, (long)SIZE * (SIZE - 1));
1029        r = ConcurrentHashMap.ForkJoinTasks.reduce
1030            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1031             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1032        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1033        r = ConcurrentHashMap.ForkJoinTasks.reduceEntries
1034            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1035             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1036        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1037        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1038            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1039             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1040        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
1041        lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong
1042            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1043        assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
1044        ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt
1045            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1046        assertEquals(ir, SIZE * (SIZE - 1) / 2);
1047        dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble
1048            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1049        assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
1050        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1051            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1052             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1053        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
1054        lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong
1055            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1056        assertEquals(lr, (long)SIZE * (SIZE - 1));
1057        ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt
1058            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1059        assertEquals(ir, SIZE * (SIZE - 1));
1060        dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble
1061            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1062        assertEquals(dr, (double)SIZE * (SIZE - 1));
1063        r = ConcurrentHashMap.ForkJoinTasks.searchKeys
1064            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1065        assertEquals((long)r, (long)(SIZE/2));
1066        r = ConcurrentHashMap.ForkJoinTasks.searchValues
1067            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1068        assertEquals((long)r, (long)(SIZE/2));
1069        r = ConcurrentHashMap.ForkJoinTasks.search
1070            (m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1071        assertEquals((long)r, (long)(SIZE/2));
1072        r = ConcurrentHashMap.ForkJoinTasks.searchEntries
1073            (m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke();
1074        assertEquals((long)r, (long)(SIZE/2));
1075    }
1071   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines