ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentHashMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentHashMapTest.java (file contents):
Revision 1.50 by jsr166, Mon Aug 22 18:38:28 2016 UTC vs.
Revision 1.55 by jsr166, Fri Aug 4 03:30:21 2017 UTC

# Line 16 | Line 16 | import java.util.Map;
16   import java.util.Random;
17   import java.util.Set;
18   import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.ExecutorService;
20 import java.util.concurrent.Executors;
19  
20   import junit.framework.Test;
21   import junit.framework.TestSuite;
# Line 34 | Line 32 | public class ConcurrentHashMapTest exten
32       * Returns a new map from Integers 1-5 to Strings "A"-"E".
33       */
34      private static ConcurrentHashMap<Integer, String> map5() {
35 <        ConcurrentHashMap map = new ConcurrentHashMap<Integer, String>(5);
35 >        ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>(5);
36          assertTrue(map.isEmpty());
37          map.put(one, "A");
38          map.put(two, "B");
# Line 121 | Line 119 | public class ConcurrentHashMapTest exten
119          ConcurrentHashMap<BI, Boolean> m =
120              new ConcurrentHashMap<BI, Boolean>();
121          for (int i = 0; i < size; i++) {
122 <            assertTrue(m.put(new CI(i), true) == null);
122 >            assertNull(m.put(new CI(i), true));
123          }
124          for (int i = 0; i < size; i++) {
125              assertTrue(m.containsKey(new CI(i)));
# Line 142 | Line 140 | public class ConcurrentHashMapTest exten
140              BS bs = new BS(String.valueOf(i));
141              LexicographicList<BI> bis = new LexicographicList<BI>(bi);
142              LexicographicList<BS> bss = new LexicographicList<BS>(bs);
143 <            assertTrue(m.putIfAbsent(bis, true) == null);
143 >            assertNull(m.putIfAbsent(bis, true));
144              assertTrue(m.containsKey(bis));
145              if (m.putIfAbsent(bss, true) == null)
146                  assertTrue(m.containsKey(bss));
# Line 786 | Line 784 | public class ConcurrentHashMapTest exten
784      }
785  
786      /**
787 <     * A deserialized map equals original
787 >     * A deserialized/reserialized map equals original
788       */
789      public void testSerialization() throws Exception {
790          Map x = map5();
# Line 837 | Line 835 | public class ConcurrentHashMapTest exten
835          assertEquals(mapSize, map.size());
836      }
837  
840    /**
841     * Tests performance of computeIfAbsent when the element is present.
842     * See JDK-8161372
843     * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testcomputeIfAbsent_performance -Djsr166.expensiveTests=true tck
844     */
845    public void testcomputeIfAbsent_performance() {
846        final int mapSize = 20;
847        final int iterations = expensiveTests ? (1 << 23) : mapSize * 2;
848        final int threads = expensiveTests ? 10 : 2;
849        final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
850        for (int i = 0; i < mapSize; i++)
851            map.put(i, i);
852        final ExecutorService pool = Executors.newFixedThreadPool(2);
853        try (PoolCleaner cleaner = cleaner(pool)) {
854            Runnable r = new CheckedRunnable() {
855                public void realRun() {
856                    int result = 0;
857                    for (int i = 0; i < iterations; i++)
858                        result += map.computeIfAbsent(i % mapSize, (k) -> k + k);
859                    if (result == -42) throw new Error();
860                }};
861            for (int i = 0; i < threads; i++)
862                pool.execute(r);
863        }
864    }
865
838   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines