1 |
|
/* |
2 |
< |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
< |
* Expert Group and released to the public domain, as explained at |
2 |
> |
* Written by Doug Lea and Martin Buchholz with assistance from |
3 |
> |
* members of JCP JSR-166 Expert Group and released to the public |
4 |
> |
* domain, as explained at |
5 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
6 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
7 |
|
* Pat Fisher, Mike Judd. |
17 |
|
import java.util.Random; |
18 |
|
import java.util.Set; |
19 |
|
import java.util.concurrent.ConcurrentHashMap; |
19 |
– |
import java.util.concurrent.ExecutorService; |
20 |
– |
import java.util.concurrent.Executors; |
20 |
|
|
21 |
|
import junit.framework.Test; |
23 |
– |
import junit.framework.TestSuite; |
22 |
|
|
23 |
|
public class ConcurrentHashMapTest extends JSR166TestCase { |
24 |
|
public static void main(String[] args) { |
25 |
|
main(suite(), args); |
26 |
|
} |
27 |
|
public static Test suite() { |
28 |
< |
return new TestSuite(ConcurrentHashMapTest.class); |
28 |
> |
class Implementation implements MapImplementation { |
29 |
> |
public Class<?> klazz() { return ConcurrentHashMap.class; } |
30 |
> |
public Map emptyMap() { return new ConcurrentHashMap(); } |
31 |
> |
public Object makeKey(int i) { return i; } |
32 |
> |
public Object makeValue(int i) { return i; } |
33 |
> |
public boolean isConcurrent() { return true; } |
34 |
> |
public boolean permitsNullKeys() { return false; } |
35 |
> |
public boolean permitsNullValues() { return false; } |
36 |
> |
public boolean supportsSetValue() { return true; } |
37 |
> |
} |
38 |
> |
return newTestSuite( |
39 |
> |
ConcurrentHashMapTest.class, |
40 |
> |
MapTest.testSuite(new Implementation())); |
41 |
|
} |
42 |
|
|
43 |
|
/** |
131 |
|
ConcurrentHashMap<BI, Boolean> m = |
132 |
|
new ConcurrentHashMap<BI, Boolean>(); |
133 |
|
for (int i = 0; i < size; i++) { |
134 |
< |
assertTrue(m.put(new CI(i), true) == null); |
134 |
> |
assertNull(m.put(new CI(i), true)); |
135 |
|
} |
136 |
|
for (int i = 0; i < size; i++) { |
137 |
|
assertTrue(m.containsKey(new CI(i))); |
152 |
|
BS bs = new BS(String.valueOf(i)); |
153 |
|
LexicographicList<BI> bis = new LexicographicList<BI>(bi); |
154 |
|
LexicographicList<BS> bss = new LexicographicList<BS>(bs); |
155 |
< |
assertTrue(m.putIfAbsent(bis, true) == null); |
155 |
> |
assertNull(m.putIfAbsent(bis, true)); |
156 |
|
assertTrue(m.containsKey(bis)); |
157 |
|
if (m.putIfAbsent(bss, true) == null) |
158 |
|
assertTrue(m.containsKey(bss)); |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
< |
* A deserialized map equals original |
799 |
> |
* A deserialized/reserialized map equals original |
800 |
|
*/ |
801 |
|
public void testSerialization() throws Exception { |
802 |
|
Map x = map5(); |