< prev index next >

test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java

Print this page
8211283: Miscellaneous changes imported from jsr166 CVS 2018-11
Reviewed-by: martin, chegar


 848         }
 849     }
 850 
 851     /**
 852      * Tests performance of removeAll when the other collection is much smaller.
 853      * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testRemoveAll_performance -Djsr166.expensiveTests=true tck
 854      */
 855     public void testRemoveAll_performance() {
 856         final int mapSize = expensiveTests ? 1_000_000 : 100;
 857         final int iterations = expensiveTests ? 500 : 2;
 858         final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
 859         for (int i = 0; i < mapSize; i++)
 860             map.put(i, i);
 861         Set<Integer> keySet = map.keySet();
 862         Collection<Integer> removeMe = Arrays.asList(new Integer[] { -99, -86 });
 863         for (int i = 0; i < iterations; i++)
 864             assertFalse(keySet.removeAll(removeMe));
 865         assertEquals(mapSize, map.size());
 866     }
 867 
















 868 }


 848         }
 849     }
 850 
 851     /**
 852      * Tests performance of removeAll when the other collection is much smaller.
 853      * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testRemoveAll_performance -Djsr166.expensiveTests=true tck
 854      */
 855     public void testRemoveAll_performance() {
 856         final int mapSize = expensiveTests ? 1_000_000 : 100;
 857         final int iterations = expensiveTests ? 500 : 2;
 858         final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
 859         for (int i = 0; i < mapSize; i++)
 860             map.put(i, i);
 861         Set<Integer> keySet = map.keySet();
 862         Collection<Integer> removeMe = Arrays.asList(new Integer[] { -99, -86 });
 863         for (int i = 0; i < iterations; i++)
 864             assertFalse(keySet.removeAll(removeMe));
 865         assertEquals(mapSize, map.size());
 866     }
 867 
 868     public void testReentrantComputeIfAbsent() {
 869         ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(16);
 870         try {
 871             for (int i = 0; i < 100; i++) { // force a resize
 872                 map.computeIfAbsent(i, key -> findValue(map, key));
 873             }
 874             fail("recursive computeIfAbsent should throw IllegalStateException");
 875         } catch (IllegalStateException success) {}
 876     }
 877 
 878     private Integer findValue(ConcurrentHashMap<Integer, Integer> map,
 879                               Integer key) {
 880         return (key % 5 == 0) ?  key :
 881             map.computeIfAbsent(key + 1, k -> findValue(map, k));
 882     }
 883 
 884 }
< prev index next >