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; |
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"); |
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() { |
825 |
|
* ant -Djsr166.tckTestClass=ConcurrentHashMapTest -Djsr166.methodFilter=testRemoveAll_performance -Djsr166.expensiveTests=true tck |
826 |
|
*/ |
827 |
|
public void testRemoveAll_performance() { |
828 |
< |
int mapSize = expensiveTests ? 1_000_000 : 100; |
829 |
< |
int iterations = expensiveTests ? 500 : 2; |
830 |
< |
ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(); |
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(); |
836 |
|
assertFalse(keySet.removeAll(removeMe)); |
837 |
|
assertEquals(mapSize, map.size()); |
838 |
|
} |
839 |
+ |
|
840 |
|
} |