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

# Line 9 | Line 9 | import java.util.*;
9   import java.util.function.*;
10   import java.util.concurrent.atomic.LongAdder;
11   import java.util.concurrent.ConcurrentHashMap;
12 + import java.util.concurrent.ConcurrentHashMap.KeySetView;
13  
14   public class ConcurrentHashMap8Test extends JSR166TestCase {
15      public static void main(String[] args) {
# Line 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 218 | Line 255 | public class ConcurrentHashMap8Test exte
255          assertTrue(full.contains(three));
256      }
257  
258 +
259 +      /**
260 +      * keySet.add throws UnsupportedOperationException if no default
261 +      * mapped value
262 +      */
263 +     public void testAdd4() {
264 +         Set full = map5().keySet();
265 +         try {
266 +             full.add(three);
267 +             shouldThrow();
268 +         } catch (UnsupportedOperationException e){}
269 +     }
270 +    
271 +     /**
272 +      * keySet.add throws NullPointerException if the specified key is
273 +      * null
274 +      */
275 +     public void testAdd5() {
276 +         Set full = populatedSet(3);
277 +         try {
278 +             full.add(null);
279 +             shouldThrow();
280 +         } catch (NullPointerException e){}
281 +     }
282 +    
283 +     /**
284 +      * KeySetView.getMappedValue returns the map's mapped value
285 +      */
286 +     public void testGetMappedValue() {
287 +         ConcurrentHashMap map = map5();
288 +         assertNull(map.keySet().getMappedValue());
289 +         try {
290 +             map.keySet(null);
291 +             shouldThrow();
292 +         } catch (NullPointerException e) {}
293 +         KeySetView set = map.keySet(one);
294 +         set.add(one);
295 +         set.add(six);
296 +         set.add(seven);
297 +         assertTrue(set.getMappedValue() == one);
298 +         assertTrue(map.get(one) != one);
299 +         assertTrue(map.get(six) == one);
300 +         assertTrue(map.get(seven) == one);
301 +     }
302 +    
303 +     /**
304 +      * KeySetView.spliterator returns spliterator over the elements in this set
305 +      */
306 +     public void testKeySetSpliterator() {
307 +         LongAdder adder = new LongAdder();
308 +         ConcurrentHashMap map = map5();
309 +         Set set = map.keySet();
310 +         Spliterator<Integer> sp = set.spliterator();
311 +         assertEquals(sp.estimateSize(), map.size());
312 +         Spliterator<Integer> sp2 = sp.trySplit();
313 +         sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
314 +         long v = adder.sumThenReset();
315 +         sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
316 +         long v2 = adder.sum();
317 +         assertEquals(v + v2, 15);
318 +     }
319 +
320 +
321      /**
322       * keyset.clear removes all elements from the set
323       */
# Line 431 | Line 531 | public class ConcurrentHashMap8Test exte
531          Set x = populatedSet(size);
532          Set y = serialClone(x);
533  
534 <        assertTrue(x != y);
534 >        assertNotSame(x, y);
535          assertEquals(x.size(), y.size());
536          assertEquals(x.toString(), y.toString());
537          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 439 | Line 539 | public class ConcurrentHashMap8Test exte
539          assertEquals(y, x);
540      }
541  
442
542      static final int SIZE = 10000;
543      static ConcurrentHashMap<Long, Long> longMap;
544  
# Line 467 | Line 566 | public class ConcurrentHashMap8Test exte
566      public void testForEachKeySequentially() {
567          LongAdder adder = new LongAdder();
568          ConcurrentHashMap<Long, Long> m = longMap();
569 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
569 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
570          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
571      }
572  
# Line 477 | Line 576 | public class ConcurrentHashMap8Test exte
576      public void testForEachValueSequentially() {
577          LongAdder adder = new LongAdder();
578          ConcurrentHashMap<Long, Long> m = longMap();
579 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
579 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
580          assertEquals(adder.sum(), SIZE * (SIZE - 1));
581      }
582  
# Line 487 | Line 586 | public class ConcurrentHashMap8Test exte
586      public void testForEachSequentially() {
587          LongAdder adder = new LongAdder();
588          ConcurrentHashMap<Long, Long> m = longMap();
589 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
589 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
590          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
591      }
592  
# Line 497 | Line 596 | public class ConcurrentHashMap8Test exte
596      public void testForEachEntrySequentially() {
597          LongAdder adder = new LongAdder();
598          ConcurrentHashMap<Long, Long> m = longMap();
599 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
599 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
600          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
601      }
602  
# Line 507 | Line 606 | public class ConcurrentHashMap8Test exte
606      public void testForEachKeyInParallel() {
607          LongAdder adder = new LongAdder();
608          ConcurrentHashMap<Long, Long> m = longMap();
609 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
609 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
610          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
611      }
612  
# Line 517 | Line 616 | public class ConcurrentHashMap8Test exte
616      public void testForEachValueInParallel() {
617          LongAdder adder = new LongAdder();
618          ConcurrentHashMap<Long, Long> m = longMap();
619 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
619 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
620          assertEquals(adder.sum(), SIZE * (SIZE - 1));
621      }
622  
# Line 527 | Line 626 | public class ConcurrentHashMap8Test exte
626      public void testForEachInParallel() {
627          LongAdder adder = new LongAdder();
628          ConcurrentHashMap<Long, Long> m = longMap();
629 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
629 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
630          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
631      }
632  
# Line 537 | Line 636 | public class ConcurrentHashMap8Test exte
636      public void testForEachEntryInParallel() {
637          LongAdder adder = new LongAdder();
638          ConcurrentHashMap<Long, Long> m = longMap();
639 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
639 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
640          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
641      }
642  
# Line 548 | Line 647 | public class ConcurrentHashMap8Test exte
647      public void testMappedForEachKeySequentially() {
648          LongAdder adder = new LongAdder();
649          ConcurrentHashMap<Long, Long> m = longMap();
650 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
650 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
651                                   (Long x) -> adder.add(x.longValue()));
652          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
653      }
# Line 560 | Line 659 | public class ConcurrentHashMap8Test exte
659      public void testMappedForEachValueSequentially() {
660          LongAdder adder = new LongAdder();
661          ConcurrentHashMap<Long, Long> m = longMap();
662 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
662 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
663                                     (Long x) -> adder.add(x.longValue()));
664          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
665      }
# Line 572 | Line 671 | public class ConcurrentHashMap8Test exte
671      public void testMappedForEachSequentially() {
672          LongAdder adder = new LongAdder();
673          ConcurrentHashMap<Long, Long> m = longMap();
674 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
674 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
675                                (Long x) -> adder.add(x.longValue()));
676          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
677      }
# Line 584 | Line 683 | public class ConcurrentHashMap8Test exte
683      public void testMappedForEachEntrySequentially() {
684          LongAdder adder = new LongAdder();
685          ConcurrentHashMap<Long, Long> m = longMap();
686 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
686 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
687                                     (Long x) -> adder.add(x.longValue()));
688          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
689      }
# Line 596 | Line 695 | public class ConcurrentHashMap8Test exte
695      public void testMappedForEachKeyInParallel() {
696          LongAdder adder = new LongAdder();
697          ConcurrentHashMap<Long, Long> m = longMap();
698 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
698 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
699                                 (Long x) -> adder.add(x.longValue()));
700          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
701      }
# Line 608 | Line 707 | public class ConcurrentHashMap8Test exte
707      public void testMappedForEachValueInParallel() {
708          LongAdder adder = new LongAdder();
709          ConcurrentHashMap<Long, Long> m = longMap();
710 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
710 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
711                                   (Long x) -> adder.add(x.longValue()));
712          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
713      }
# Line 620 | Line 719 | public class ConcurrentHashMap8Test exte
719      public void testMappedForEachInParallel() {
720          LongAdder adder = new LongAdder();
721          ConcurrentHashMap<Long, Long> m = longMap();
722 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
722 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
723                              (Long x) -> adder.add(x.longValue()));
724          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
725      }
# Line 632 | Line 731 | public class ConcurrentHashMap8Test exte
731      public void testMappedForEachEntryInParallel() {
732          LongAdder adder = new LongAdder();
733          ConcurrentHashMap<Long, Long> m = longMap();
734 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
734 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
735                                   (Long x) -> adder.add(x.longValue()));
736          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
737      }
738  
640
739      /**
740       * reduceKeysSequentially accumulates across all keys,
741       */
742      public void testReduceKeysSequentially() {
743          ConcurrentHashMap<Long, Long> m = longMap();
744          Long r;
745 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
745 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
746          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
747      }
748  
# Line 654 | Line 752 | public class ConcurrentHashMap8Test exte
752      public void testReduceValuesSequentially() {
753          ConcurrentHashMap<Long, Long> m = longMap();
754          Long r;
755 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
755 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
756          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
757      }
758  
661
759      /**
760       * reduceEntriesSequentially accumulates across all entries
761       */
762      public void testReduceEntriesSequentially() {
763          ConcurrentHashMap<Long, Long> m = longMap();
764          Map.Entry<Long,Long> r;
765 <        r = m.reduceEntriesSequentially(new AddKeys());
765 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
766          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
767      }
768  
# Line 675 | Line 772 | public class ConcurrentHashMap8Test exte
772      public void testReduceKeysInParallel() {
773          ConcurrentHashMap<Long, Long> m = longMap();
774          Long r;
775 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
775 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
776          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
777      }
778  
# Line 685 | Line 782 | public class ConcurrentHashMap8Test exte
782      public void testReduceValuesInParallel() {
783          ConcurrentHashMap<Long, Long> m = longMap();
784          Long r;
785 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
785 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
786          assertEquals((long)r, (long)SIZE * (SIZE - 1));
787      }
788  
# Line 695 | Line 792 | public class ConcurrentHashMap8Test exte
792      public void testReduceEntriesInParallel() {
793          ConcurrentHashMap<Long, Long> m = longMap();
794          Map.Entry<Long,Long> r;
795 <        r = m.reduceEntriesInParallel(new AddKeys());
795 >        r = m.reduceEntries(1L, new AddKeys());
796          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
797      }
798  
# Line 704 | Line 801 | public class ConcurrentHashMap8Test exte
801       */
802      public void testMapReduceKeysSequentially() {
803          ConcurrentHashMap<Long, Long> m = longMap();
804 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
804 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
805                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
806          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
807      }
# Line 714 | Line 811 | public class ConcurrentHashMap8Test exte
811       */
812      public void testMapReduceValuesSequentially() {
813          ConcurrentHashMap<Long, Long> m = longMap();
814 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
814 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
815                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
816          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
817      }
# Line 724 | Line 821 | public class ConcurrentHashMap8Test exte
821       */
822      public void testMappedReduceSequentially() {
823          ConcurrentHashMap<Long, Long> m = longMap();
824 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
824 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
825                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
826  
827          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 735 | Line 832 | public class ConcurrentHashMap8Test exte
832       */
833      public void testMapReduceKeysInParallel() {
834          ConcurrentHashMap<Long, Long> m = longMap();
835 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
835 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
836                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
837          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
838      }
# Line 745 | Line 842 | public class ConcurrentHashMap8Test exte
842       */
843      public void testMapReduceValuesInParallel() {
844          ConcurrentHashMap<Long, Long> m = longMap();
845 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
845 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
846                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
847          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
848      }
# Line 756 | Line 853 | public class ConcurrentHashMap8Test exte
853      public void testMappedReduceInParallel() {
854          ConcurrentHashMap<Long, Long> m = longMap();
855          Long r;
856 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
856 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
857                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
858          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
859      }
860  
764
861      /**
862       * reduceKeysToLongSequentially accumulates mapped keys
863       */
864      public void testReduceKeysToLongSequentially() {
865          ConcurrentHashMap<Long, Long> m = longMap();
866 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
866 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
867          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
868      }
869  
# Line 776 | Line 872 | public class ConcurrentHashMap8Test exte
872       */
873      public void testReduceKeysToIntSequentially() {
874          ConcurrentHashMap<Long, Long> m = longMap();
875 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
875 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
876          assertEquals(ir, SIZE * (SIZE - 1) / 2);
877      }
878  
# Line 785 | Line 881 | public class ConcurrentHashMap8Test exte
881       */
882      public void testReduceKeysToDoubleSequentially() {
883          ConcurrentHashMap<Long, Long> m = longMap();
884 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
884 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
885          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
886      }
887  
# Line 794 | Line 890 | public class ConcurrentHashMap8Test exte
890       */
891      public void testReduceValuesToLongSequentially() {
892          ConcurrentHashMap<Long, Long> m = longMap();
893 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
893 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
894          assertEquals(lr, (long)SIZE * (SIZE - 1));
895      }
896  
# Line 803 | Line 899 | public class ConcurrentHashMap8Test exte
899       */
900      public void testReduceValuesToIntSequentially() {
901          ConcurrentHashMap<Long, Long> m = longMap();
902 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
902 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
903          assertEquals(ir, SIZE * (SIZE - 1));
904      }
905  
# Line 812 | Line 908 | public class ConcurrentHashMap8Test exte
908       */
909      public void testReduceValuesToDoubleSequentially() {
910          ConcurrentHashMap<Long, Long> m = longMap();
911 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
911 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
912          assertEquals(dr, (double)SIZE * (SIZE - 1));
913      }
914  
# Line 821 | Line 917 | public class ConcurrentHashMap8Test exte
917       */
918      public void testReduceKeysToLongInParallel() {
919          ConcurrentHashMap<Long, Long> m = longMap();
920 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
920 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
921          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
922      }
923  
# Line 830 | Line 926 | public class ConcurrentHashMap8Test exte
926       */
927      public void testReduceKeysToIntInParallel() {
928          ConcurrentHashMap<Long, Long> m = longMap();
929 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
929 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
930          assertEquals(ir, SIZE * (SIZE - 1) / 2);
931      }
932  
# Line 839 | Line 935 | public class ConcurrentHashMap8Test exte
935       */
936      public void testReduceKeysToDoubleInParallel() {
937          ConcurrentHashMap<Long, Long> m = longMap();
938 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
938 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
939          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
940      }
941  
# Line 848 | Line 944 | public class ConcurrentHashMap8Test exte
944       */
945      public void testReduceValuesToLongInParallel() {
946          ConcurrentHashMap<Long, Long> m = longMap();
947 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
947 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
948          assertEquals(lr, (long)SIZE * (SIZE - 1));
949      }
950  
# Line 857 | Line 953 | public class ConcurrentHashMap8Test exte
953       */
954      public void testReduceValuesToIntInParallel() {
955          ConcurrentHashMap<Long, Long> m = longMap();
956 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
956 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
957          assertEquals(ir, SIZE * (SIZE - 1));
958      }
959  
# Line 866 | Line 962 | public class ConcurrentHashMap8Test exte
962       */
963      public void testReduceValuesToDoubleInParallel() {
964          ConcurrentHashMap<Long, Long> m = longMap();
965 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
965 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
966          assertEquals(dr, (double)SIZE * (SIZE - 1));
967      }
968  
# Line 877 | Line 973 | public class ConcurrentHashMap8Test exte
973      public void testSearchKeysSequentially() {
974          ConcurrentHashMap<Long, Long> m = longMap();
975          Long r;
976 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
976 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
977          assertEquals((long)r, (long)(SIZE/2));
978 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
978 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
979          assertNull(r);
980      }
981  
# Line 890 | Line 986 | public class ConcurrentHashMap8Test exte
986      public void testSearchValuesSequentially() {
987          ConcurrentHashMap<Long, Long> m = longMap();
988          Long r;
989 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
989 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
990          assertEquals((long)r, (long)(SIZE/2));
991 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
991 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
992          assertNull(r);
993      }
994  
# Line 903 | Line 999 | public class ConcurrentHashMap8Test exte
999      public void testSearchSequentially() {
1000          ConcurrentHashMap<Long, Long> m = longMap();
1001          Long r;
1002 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1002 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1003          assertEquals((long)r, (long)(SIZE/2));
1004 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1004 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1005          assertNull(r);
1006      }
1007  
# Line 916 | Line 1012 | public class ConcurrentHashMap8Test exte
1012      public void testSearchEntriesSequentially() {
1013          ConcurrentHashMap<Long, Long> m = longMap();
1014          Long r;
1015 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1015 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1016          assertEquals((long)r, (long)(SIZE/2));
1017 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1017 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1018          assertNull(r);
1019      }
1020  
# Line 929 | Line 1025 | public class ConcurrentHashMap8Test exte
1025      public void testSearchKeysInParallel() {
1026          ConcurrentHashMap<Long, Long> m = longMap();
1027          Long r;
1028 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1028 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1029          assertEquals((long)r, (long)(SIZE/2));
1030 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1030 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1031          assertNull(r);
1032      }
1033  
# Line 942 | Line 1038 | public class ConcurrentHashMap8Test exte
1038      public void testSearchValuesInParallel() {
1039          ConcurrentHashMap<Long, Long> m = longMap();
1040          Long r;
1041 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1041 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1042          assertEquals((long)r, (long)(SIZE/2));
1043 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1043 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1044          assertNull(r);
1045      }
1046  
# Line 955 | Line 1051 | public class ConcurrentHashMap8Test exte
1051      public void testSearchInParallel() {
1052          ConcurrentHashMap<Long, Long> m = longMap();
1053          Long r;
1054 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1054 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1055          assertEquals((long)r, (long)(SIZE/2));
1056 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1056 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1057          assertNull(r);
1058      }
1059  
# Line 968 | Line 1064 | public class ConcurrentHashMap8Test exte
1064      public void testSearchEntriesInParallel() {
1065          ConcurrentHashMap<Long, Long> m = longMap();
1066          Long r;
1067 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1067 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1068          assertEquals((long)r, (long)(SIZE/2));
1069 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1069 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1070          assertNull(r);
1071      }
1072  
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    }
1073   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines