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.46 by jsr166, Sun May 24 01:23:17 2015 UTC vs.
Revision 1.51 by jsr166, Sat Oct 15 18:51:12 2016 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;
21  
22   import junit.framework.Test;
23   import junit.framework.TestSuite;
# Line 331 | 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 535 | Line 552 | public class ConcurrentHashMapTest exten
552      /**
553       * Constructor (initialCapacity, loadFactor) throws
554       * IllegalArgumentException if either argument is negative
555 <      */
555 >     */
556      public void testConstructor2() {
557          try {
558              new ConcurrentHashMap(-1, .75f);
# Line 803 | Line 820 | public class ConcurrentHashMapTest exten
820          }
821      }
822  
823 +    /**
824 +     * Tests performance of removeAll when the other collection is much smaller.
825 +     * ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testRemoveAll_performance -Djsr166.expensiveTests=true tck
826 +     */
827 +    public void testRemoveAll_performance() {
828 +        final int mapSize = expensiveTests ? 1_000_000 : 100;
829 +        final int iterations = expensiveTests ? 500 : 2;
830 +        final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
831 +        for (int i = 0; i < mapSize; i++)
832 +            map.put(i, i);
833 +        Set<Integer> keySet = map.keySet();
834 +        Collection<Integer> removeMe = Arrays.asList(new Integer[] { -99, -86 });
835 +        for (int i = 0; i < iterations; i++)
836 +            assertFalse(keySet.removeAll(removeMe));
837 +        assertEquals(mapSize, map.size());
838 +    }
839 +
840   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines