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.51 by jsr166, Sat Oct 15 18:51:12 2016 UTC

# Line 837 | Line 837 | public class ConcurrentHashMapTest exten
837          assertEquals(mapSize, map.size());
838      }
839  
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
840   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines