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.49 by jsr166, Sun Jul 17 19:02:07 2016 UTC vs.
Revision 1.51 by jsr166, Sat Oct 15 18:51:12 2016 UTC

# Line 333 | Line 333 | public class ConcurrentHashMapTest exten
333      }
334  
335      /**
336 +     * Test keySet().removeAll on empty map
337 +     */
338 +    public void testKeySet_empty_removeAll() {
339 +        ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
340 +        Set<Integer> set = map.keySet();
341 +        set.removeAll(Collections.emptyList());
342 +        assertTrue(map.isEmpty());
343 +        assertTrue(set.isEmpty());
344 +        // following is test for JDK-8163353
345 +        set.removeAll(Collections.emptySet());
346 +        assertTrue(map.isEmpty());
347 +        assertTrue(set.isEmpty());
348 +    }
349 +
350 +    /**
351       * keySet.toArray returns contains all keys
352       */
353      public void testKeySetToArray() {
# Line 822 | Line 837 | public class ConcurrentHashMapTest exten
837          assertEquals(mapSize, map.size());
838      }
839  
825    /**
826     * Tests performance of computeIfAbsent when the element is present.
827     * See JDK-8161372
828     * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testcomputeIfAbsent_performance -Djsr166.expensiveTests=true tck
829     */
830    public void testcomputeIfAbsent_performance() {
831        final int mapSize = 20;
832        final int iterations = expensiveTests ? (1 << 23) : mapSize * 2;
833        final int threads = expensiveTests ? 10 : 2;
834        final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
835        for (int i = 0; i < mapSize; i++)
836            map.put(i, i);
837        final ExecutorService pool = Executors.newFixedThreadPool(2);
838        try (PoolCleaner cleaner = cleaner(pool)) {
839            Runnable r = new CheckedRunnable() {
840                public void realRun() {
841                    int result = 0;
842                    for (int i = 0; i < iterations; i++)
843                        result += map.computeIfAbsent(i % mapSize, (k) -> k + k);
844                    if (result == -42) throw new Error();
845                }};
846            for (int i = 0; i < threads; i++)
847                pool.execute(r);
848        }
849    }
850
840   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines