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.31 by jsr166, Wed Aug 24 22:22:39 2016 UTC vs.
Revision 1.32 by jsr166, Sat Oct 15 18:51:12 2016 UTC

# Line 16 | Line 16 | import java.util.Map;
16   import java.util.NoSuchElementException;
17   import java.util.Set;
18   import java.util.Spliterator;
19 + import java.util.concurrent.ExecutorService;
20 + import java.util.concurrent.Executors;
21   import java.util.concurrent.ConcurrentHashMap;
22   import java.util.concurrent.atomic.LongAdder;
23   import java.util.function.BiFunction;
# Line 1087 | Line 1089 | public class ConcurrentHashMap8Test exte
1089          assertNull(r);
1090      }
1091  
1092 +    /**
1093 +     * Tests performance of computeIfAbsent when the element is present.
1094 +     * See JDK-8161372
1095 +     * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testcomputeIfAbsent_performance -Djsr166.expensiveTests=true tck
1096 +     */
1097 +    public void testcomputeIfAbsent_performance() {
1098 +        final int mapSize = 20;
1099 +        final int iterations = expensiveTests ? (1 << 23) : mapSize * 2;
1100 +        final int threads = expensiveTests ? 10 : 2;
1101 +        final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
1102 +        for (int i = 0; i < mapSize; i++)
1103 +            map.put(i, i);
1104 +        final ExecutorService pool = Executors.newFixedThreadPool(2);
1105 +        try (PoolCleaner cleaner = cleaner(pool)) {
1106 +            Runnable r = new CheckedRunnable() {
1107 +                public void realRun() {
1108 +                    int result = 0;
1109 +                    for (int i = 0; i < iterations; i++)
1110 +                        result += map.computeIfAbsent(i % mapSize, (k) -> k + k);
1111 +                    if (result == -42) throw new Error();
1112 +                }};
1113 +            for (int i = 0; i < threads; i++)
1114 +                pool.execute(r);
1115 +        }
1116 +    }
1117 +
1118   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines