22 |
|
|
23 |
|
public class ConcurrentHashMapTest extends JSR166TestCase { |
24 |
|
public static void main(String[] args) { |
25 |
< |
junit.textui.TestRunner.run(suite()); |
25 |
> |
main(suite(), args); |
26 |
|
} |
27 |
|
public static Test suite() { |
28 |
|
return new TestSuite(ConcurrentHashMapTest.class); |
32 |
|
* Returns a new map from Integers 1-5 to Strings "A"-"E". |
33 |
|
*/ |
34 |
|
private static ConcurrentHashMap<Integer, String> map5() { |
35 |
< |
ConcurrentHashMap map = new ConcurrentHashMap<Integer, String>(5); |
35 |
> |
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>(5); |
36 |
|
assertTrue(map.isEmpty()); |
37 |
|
map.put(one, "A"); |
38 |
|
map.put(two, "B"); |
45 |
|
} |
46 |
|
|
47 |
|
/** Re-implement Integer.compare for old java versions */ |
48 |
< |
static int compare(int x, int y) { return x < y ? -1 : x > y ? 1 : 0; } |
48 |
> |
static int compare(int x, int y) { |
49 |
> |
return (x < y) ? -1 : (x > y) ? 1 : 0; |
50 |
> |
} |
51 |
|
|
52 |
|
// classes for testing Comparable fallbacks |
53 |
|
static class BI implements Comparable<BI> { |
331 |
|
} |
332 |
|
|
333 |
|
/** |
334 |
+ |
* Test keySet().removeAll on empty map |
335 |
+ |
*/ |
336 |
+ |
public void testKeySet_empty_removeAll() { |
337 |
+ |
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>(); |
338 |
+ |
Set<Integer> set = map.keySet(); |
339 |
+ |
set.removeAll(Collections.emptyList()); |
340 |
+ |
assertTrue(map.isEmpty()); |
341 |
+ |
assertTrue(set.isEmpty()); |
342 |
+ |
// following is test for JDK-8163353 |
343 |
+ |
set.removeAll(Collections.emptySet()); |
344 |
+ |
assertTrue(map.isEmpty()); |
345 |
+ |
assertTrue(set.isEmpty()); |
346 |
+ |
} |
347 |
+ |
|
348 |
+ |
/** |
349 |
|
* keySet.toArray returns contains all keys |
350 |
|
*/ |
351 |
|
public void testKeySetToArray() { |
550 |
|
/** |
551 |
|
* Constructor (initialCapacity, loadFactor) throws |
552 |
|
* IllegalArgumentException if either argument is negative |
553 |
< |
*/ |
553 |
> |
*/ |
554 |
|
public void testConstructor2() { |
555 |
|
try { |
556 |
|
new ConcurrentHashMap(-1, .75f); |
818 |
|
} |
819 |
|
} |
820 |
|
|
821 |
+ |
/** |
822 |
+ |
* Tests performance of removeAll when the other collection is much smaller. |
823 |
+ |
* ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testRemoveAll_performance -Djsr166.expensiveTests=true tck |
824 |
+ |
*/ |
825 |
+ |
public void testRemoveAll_performance() { |
826 |
+ |
final int mapSize = expensiveTests ? 1_000_000 : 100; |
827 |
+ |
final int iterations = expensiveTests ? 500 : 2; |
828 |
+ |
final ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(); |
829 |
+ |
for (int i = 0; i < mapSize; i++) |
830 |
+ |
map.put(i, i); |
831 |
+ |
Set<Integer> keySet = map.keySet(); |
832 |
+ |
Collection<Integer> removeMe = Arrays.asList(new Integer[] { -99, -86 }); |
833 |
+ |
for (int i = 0; i < iterations; i++) |
834 |
+ |
assertFalse(keySet.removeAll(removeMe)); |
835 |
+ |
assertEquals(mapSize, map.size()); |
836 |
+ |
} |
837 |
+ |
|
838 |
|
} |