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.44 by jsr166, Sat Feb 28 18:27:31 2015 UTC vs.
Revision 1.52 by jsr166, Wed Jan 4 06:09:58 2017 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;
24  
25   public class ConcurrentHashMapTest extends JSR166TestCase {
26      public static void main(String[] args) {
27 <        junit.textui.TestRunner.run(suite());
27 >        main(suite(), args);
28      }
29      public static Test suite() {
30          return new TestSuite(ConcurrentHashMapTest.class);
# Line 32 | Line 34 | public class ConcurrentHashMapTest exten
34       * Returns a new map from Integers 1-5 to Strings "A"-"E".
35       */
36      private static ConcurrentHashMap<Integer, String> map5() {
37 <        ConcurrentHashMap map = new ConcurrentHashMap<Integer, String>(5);
37 >        ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>(5);
38          assertTrue(map.isEmpty());
39          map.put(one, "A");
40          map.put(two, "B");
# Line 45 | Line 47 | public class ConcurrentHashMapTest exten
47      }
48  
49      /** Re-implement Integer.compare for old java versions */
50 <    static int compare(int x, int y) { return x < y ? -1 : x > y ? 1 : 0; }
50 >    static int compare(int x, int y) {
51 >        return (x < y) ? -1 : (x > y) ? 1 : 0;
52 >    }
53  
54      // classes for testing Comparable fallbacks
55      static class BI implements Comparable<BI> {
# Line 329 | 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 533 | 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 801 | 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