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.3 by dl, Fri Mar 22 14:11:32 2013 UTC vs.
Revision 1.8 by jsr166, Thu Apr 11 20:03:44 2013 UTC

# Line 68 | Line 68 | public class ConcurrentHashMap8Test exte
68          map.computeIfAbsent(six, (x) -> null);
69          assertFalse(map.containsKey(six));
70      }
71 <    
71 >
72      /**
73       * computeIfPresent does not replace  if the key is already present
74       */
# Line 380 | Line 380 | public class ConcurrentHashMap8Test exte
380              elements[i] = i;
381          Collections.shuffle(Arrays.asList(elements));
382          Collection<Integer> full = populatedSet(elements);
383 <        
383 >
384          assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray())));
385          assertTrue(full.containsAll(Arrays.asList(full.toArray())));
386          assertSame(Object[].class, full.toArray().getClass());
# Line 442 | Line 442 | public class ConcurrentHashMap8Test exte
442  
443      static final int SIZE = 10000;
444      static ConcurrentHashMap<Long, Long> longMap;
445 <    
445 >
446      static ConcurrentHashMap<Long, Long> longMap() {
447          if (longMap == null) {
448              longMap = new ConcurrentHashMap<Long, Long>(SIZE);
# Line 456 | Line 456 | public class ConcurrentHashMap8Test exte
456      static class AddKeys implements BiFunction<Map.Entry<Long,Long>, Map.Entry<Long,Long>, Map.Entry<Long,Long>> {
457          public Map.Entry<Long,Long> apply(Map.Entry<Long,Long> x, Map.Entry<Long,Long> y) {
458              return new AbstractMap.SimpleEntry<Long,Long>
459 <             (Long.valueOf(x.getKey().longValue() + y.getKey().longValue()),
459 >             (Long.valueOf(x.getKey().longValue() + y.getKey().longValue()),
460                Long.valueOf(1L));
461          }
462      }
# Line 699 | Line 699 | public class ConcurrentHashMap8Test exte
699          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
700      }
701  
702 <    /*
702 >    /**
703       * Mapped reduceKeysSequentially accumulates mapped keys
704       */
705      public void testMapReduceKeysSequentially() {
# Line 709 | Line 709 | public class ConcurrentHashMap8Test exte
709          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
710      }
711  
712 <    /*
712 >    /**
713       * Mapped reduceValuesSequentially accumulates mapped values
714       */
715      public void testMapReduceValuesSequentially() {
# Line 726 | Line 726 | public class ConcurrentHashMap8Test exte
726          ConcurrentHashMap<Long, Long> m = longMap();
727          Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
728                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
729 <        
729 >
730          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
731      }
732  
733 <    /*
733 >    /**
734       * Mapped reduceKeysInParallel, accumulates mapped keys
735       */
736      public void testMapReduceKeysInParallel() {
# Line 740 | Line 740 | public class ConcurrentHashMap8Test exte
740          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
741      }
742  
743 <    /*
743 >    /**
744       * Mapped reduceValuesInParallel accumulates mapped values
745       */
746      public void testMapReduceValuesInParallel() {
# Line 762 | Line 762 | public class ConcurrentHashMap8Test exte
762      }
763  
764  
765 <    /*
765 >    /**
766       * reduceKeysToLongSequentially accumulates mapped keys
767       */
768      public void testReduceKeysToLongSequentially() {
# Line 771 | Line 771 | public class ConcurrentHashMap8Test exte
771          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
772      }
773  
774 <    /*
774 >    /**
775       * reduceKeysToIntSequentially accumulates mapped keys
776       */
777      public void testReduceKeysToIntSequentially() {
778          ConcurrentHashMap<Long, Long> m = longMap();
779          int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
780 <        assertEquals(ir, (int)SIZE * (SIZE - 1) / 2);
780 >        assertEquals(ir, SIZE * (SIZE - 1) / 2);
781      }
782  
783 <    /*
783 >    /**
784       * reduceKeysToDoubleSequentially accumulates mapped keys
785       */
786      public void testReduceKeysToDoubleSequentially() {
# Line 789 | Line 789 | public class ConcurrentHashMap8Test exte
789          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
790      }
791  
792 <    /*
792 >    /**
793       * reduceValuesToLongSequentially accumulates mapped values
794       */
795      public void testReduceValuesToLongSequentially() {
# Line 798 | Line 798 | public class ConcurrentHashMap8Test exte
798          assertEquals(lr, (long)SIZE * (SIZE - 1));
799      }
800  
801 <    /*
801 >    /**
802       * reduceValuesToIntSequentially accumulates mapped values
803       */
804      public void testReduceValuesToIntSequentially() {
805          ConcurrentHashMap<Long, Long> m = longMap();
806          int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
807 <        assertEquals(ir, (int)SIZE * (SIZE - 1));
807 >        assertEquals(ir, SIZE * (SIZE - 1));
808      }
809  
810 <    /*
810 >    /**
811       * reduceValuesToDoubleSequentially accumulates mapped values
812       */
813      public void testReduceValuesToDoubleSequentially() {
# Line 816 | Line 816 | public class ConcurrentHashMap8Test exte
816          assertEquals(dr, (double)SIZE * (SIZE - 1));
817      }
818  
819 <    /*
819 >    /**
820       * reduceKeysToLongInParallel accumulates mapped keys
821       */
822      public void testReduceKeysToLongInParallel() {
# Line 825 | Line 825 | public class ConcurrentHashMap8Test exte
825          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
826      }
827  
828 <    /*
828 >    /**
829       * reduceKeysToIntInParallel accumulates mapped keys
830       */
831      public void testReduceKeysToIntInParallel() {
832          ConcurrentHashMap<Long, Long> m = longMap();
833          int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
834 <        assertEquals(ir, (int)SIZE * (SIZE - 1) / 2);
834 >        assertEquals(ir, SIZE * (SIZE - 1) / 2);
835      }
836  
837 <    /*
837 >    /**
838       * reduceKeysToDoubleInParallel accumulates mapped values
839       */
840      public void testReduceKeysToDoubleInParallel() {
# Line 843 | Line 843 | public class ConcurrentHashMap8Test exte
843          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
844      }
845  
846 <    /*
846 >    /**
847       * reduceValuesToLongInParallel accumulates mapped values
848       */
849      public void testReduceValuesToLongInParallel() {
# Line 852 | Line 852 | public class ConcurrentHashMap8Test exte
852          assertEquals(lr, (long)SIZE * (SIZE - 1));
853      }
854  
855 <    /*
855 >    /**
856       * reduceValuesToIntInParallel accumulates mapped values
857       */
858      public void testReduceValuesToIntInParallel() {
859          ConcurrentHashMap<Long, Long> m = longMap();
860          int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
861 <        assertEquals(ir, (int)SIZE * (SIZE - 1));
861 >        assertEquals(ir, SIZE * (SIZE - 1));
862      }
863  
864 <    /*
864 >    /**
865       * reduceValuesToDoubleInParallel accumulates mapped values
866       */
867      public void testReduceValuesToDoubleInParallel() {
# Line 877 | Line 877 | public class ConcurrentHashMap8Test exte
877      public void testSearchKeysSequentially() {
878          ConcurrentHashMap<Long, Long> m = longMap();
879          Long r;
880 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
880 >        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
881          assertEquals((long)r, (long)(SIZE/2));
882 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L? x : null);
882 >        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
883          assertNull(r);
884      }
885  
# Line 892 | Line 892 | public class ConcurrentHashMap8Test exte
892          Long r;
893          r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
894          assertEquals((long)r, (long)(SIZE/2));
895 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L? x : null);
895 >        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
896          assertNull(r);
897      }
898  
# Line 903 | Line 903 | public class ConcurrentHashMap8Test exte
903      public void testSearchSequentially() {
904          ConcurrentHashMap<Long, Long> m = longMap();
905          Long r;
906 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null);
906 >        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
907          assertEquals((long)r, (long)(SIZE/2));
908 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L? x : null);
908 >        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
909          assertNull(r);
910      }
911  
# Line 916 | Line 916 | public class ConcurrentHashMap8Test exte
916      public void testSearchEntriesSequentially() {
917          ConcurrentHashMap<Long, Long> m = longMap();
918          Long r;
919 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null);
919 >        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
920          assertEquals((long)r, (long)(SIZE/2));
921 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null);
921 >        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
922          assertNull(r);
923      }
924  
# Line 929 | Line 929 | public class ConcurrentHashMap8Test exte
929      public void testSearchKeysInParallel() {
930          ConcurrentHashMap<Long, Long> m = longMap();
931          Long r;
932 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
932 >        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
933          assertEquals((long)r, (long)(SIZE/2));
934 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L? x : null);
934 >        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
935          assertNull(r);
936      }
937  
# Line 942 | Line 942 | public class ConcurrentHashMap8Test exte
942      public void testSearchValuesInParallel() {
943          ConcurrentHashMap<Long, Long> m = longMap();
944          Long r;
945 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
945 >        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
946          assertEquals((long)r, (long)(SIZE/2));
947 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L? x : null);
947 >        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
948          assertNull(r);
949      }
950  
# Line 955 | Line 955 | public class ConcurrentHashMap8Test exte
955      public void testSearchInParallel() {
956          ConcurrentHashMap<Long, Long> m = longMap();
957          Long r;
958 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null);
958 >        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
959          assertEquals((long)r, (long)(SIZE/2));
960 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L? x : null);
960 >        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
961          assertNull(r);
962      }
963  
# Line 968 | Line 968 | public class ConcurrentHashMap8Test exte
968      public void testSearchEntriesInParallel() {
969          ConcurrentHashMap<Long, Long> m = longMap();
970          Long r;
971 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null);
971 >        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
972          assertEquals((long)r, (long)(SIZE/2));
973 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null);
973 >        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
974          assertNull(r);
975      }
976  
# Line 994 | Line 994 | public class ConcurrentHashMap8Test exte
994          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
995          adder.reset();
996          ConcurrentHashMap.ForkJoinTasks.forEachEntry
997 <            (m,
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();
# Line 1043 | Line 1043 | public class ConcurrentHashMap8Test exte
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, (int)SIZE * (SIZE - 1) / 2);
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);
# Line 1056 | Line 1056 | public class ConcurrentHashMap8Test exte
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, (int)SIZE * (SIZE - 1));
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));
# Line 1072 | Line 1072 | public class ConcurrentHashMap8Test exte
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 <    }            
1075 >    }
1076   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines