6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
10 |
< |
import java.util.*; |
9 |
> |
import java.util.ArrayList; |
10 |
> |
import java.util.Arrays; |
11 |
> |
import java.util.Collection; |
12 |
> |
import java.util.Collections; |
13 |
> |
import java.util.Enumeration; |
14 |
> |
import java.util.Iterator; |
15 |
> |
import java.util.Map; |
16 |
> |
import java.util.Random; |
17 |
> |
import java.util.Set; |
18 |
|
import java.util.concurrent.ConcurrentHashMap; |
19 |
|
|
20 |
+ |
import junit.framework.Test; |
21 |
+ |
import junit.framework.TestSuite; |
22 |
+ |
|
23 |
|
public class ConcurrentHashMapTest extends JSR166TestCase { |
24 |
|
public static void main(String[] args) { |
25 |
|
junit.textui.TestRunner.run(suite()); |
113 |
|
* class are found. |
114 |
|
*/ |
115 |
|
public void testComparableFamily() { |
116 |
+ |
int size = 500; // makes measured test run time -> 60ms |
117 |
|
ConcurrentHashMap<BI, Boolean> m = |
118 |
|
new ConcurrentHashMap<BI, Boolean>(); |
119 |
< |
for (int i = 0; i < 1000; i++) { |
119 |
> |
for (int i = 0; i < size; i++) { |
120 |
|
assertTrue(m.put(new CI(i), true) == null); |
121 |
|
} |
122 |
< |
for (int i = 0; i < 1000; i++) { |
122 |
> |
for (int i = 0; i < size; i++) { |
123 |
|
assertTrue(m.containsKey(new CI(i))); |
124 |
|
assertTrue(m.containsKey(new DI(i))); |
125 |
|
} |
130 |
|
* on Comparable can be inserted and found. |
131 |
|
*/ |
132 |
|
public void testGenericComparable() { |
133 |
+ |
int size = 120; // makes measured test run time -> 60ms |
134 |
|
ConcurrentHashMap<Object, Boolean> m = |
135 |
|
new ConcurrentHashMap<Object, Boolean>(); |
136 |
< |
for (int i = 0; i < 1000; i++) { |
136 |
> |
for (int i = 0; i < size; i++) { |
137 |
|
BI bi = new BI(i); |
138 |
|
BS bs = new BS(String.valueOf(i)); |
139 |
|
LexicographicList<BI> bis = new LexicographicList<BI>(bi); |
144 |
|
assertTrue(m.containsKey(bss)); |
145 |
|
assertTrue(m.containsKey(bis)); |
146 |
|
} |
147 |
< |
for (int i = 0; i < 1000; i++) { |
148 |
< |
assertTrue(m.containsKey(new ArrayList(Collections.singleton(new BI(i))))); |
147 |
> |
for (int i = 0; i < size; i++) { |
148 |
> |
assertTrue(m.containsKey(Collections.singletonList(new BI(i)))); |
149 |
|
} |
150 |
|
} |
151 |
|
|
155 |
|
* inserted and found. |
156 |
|
*/ |
157 |
|
public void testGenericComparable2() { |
158 |
+ |
int size = 500; // makes measured test run time -> 60ms |
159 |
|
ConcurrentHashMap<Object, Boolean> m = |
160 |
|
new ConcurrentHashMap<Object, Boolean>(); |
161 |
< |
for (int i = 0; i < 1000; i++) { |
162 |
< |
m.put(new ArrayList(Collections.singleton(new BI(i))), true); |
161 |
> |
for (int i = 0; i < size; i++) { |
162 |
> |
m.put(Collections.singletonList(new BI(i)), true); |
163 |
|
} |
164 |
|
|
165 |
< |
for (int i = 0; i < 1000; i++) { |
165 |
> |
for (int i = 0; i < size; i++) { |
166 |
|
LexicographicList<BI> bis = new LexicographicList<BI>(new BI(i)); |
167 |
|
assertTrue(m.containsKey(bis)); |
168 |
|
} |
589 |
|
assertFalse(map2.equals(map1)); |
590 |
|
} |
591 |
|
|
579 |
– |
|
592 |
|
/** |
593 |
|
* get(null) throws NPE |
594 |
|
*/ |