8 |
|
|
9 |
|
import junit.framework.*; |
10 |
|
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
12 |
< |
import java.util.Enumeration; |
13 |
< |
import java.io.*; |
11 |
> |
import java.util.concurrent.ConcurrentHashMap; |
12 |
|
|
13 |
|
public class ConcurrentHashMapTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
19 |
|
} |
20 |
|
|
21 |
|
/** |
22 |
< |
* Create a map from Integers 1-5 to Strings "A"-"E". |
22 |
> |
* Creates a map from Integers 1-5 to Strings "A"-"E". |
23 |
|
*/ |
24 |
|
private static ConcurrentHashMap map5() { |
25 |
|
ConcurrentHashMap map = new ConcurrentHashMap(5); |
40 |
|
public void testClear() { |
41 |
|
ConcurrentHashMap map = map5(); |
42 |
|
map.clear(); |
43 |
< |
assertEquals(map.size(), 0); |
43 |
> |
assertEquals(0, map.size()); |
44 |
|
} |
45 |
|
|
46 |
|
/** |
273 |
|
assertEquals("Z", map.get(one)); |
274 |
|
} |
275 |
|
|
278 |
– |
|
276 |
|
/** |
277 |
|
* replace value fails when the given key not mapped to expected value |
278 |
|
*/ |
293 |
|
assertEquals("Z", map.get(one)); |
294 |
|
} |
295 |
|
|
299 |
– |
|
296 |
|
/** |
297 |
|
* remove removes the correct key-value pair from the map |
298 |
|
*/ |
333 |
|
ConcurrentHashMap map = map5(); |
334 |
|
String s = map.toString(); |
335 |
|
for (int i = 1; i <= 5; ++i) { |
336 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
336 |
> |
assertTrue(s.contains(String.valueOf(i))); |
337 |
|
} |
338 |
|
} |
339 |
|
|
479 |
|
} catch (NullPointerException success) {} |
480 |
|
} |
481 |
|
|
486 |
– |
|
482 |
|
/** |
483 |
|
* replace(x, null) throws NPE |
484 |
|
*/ |
512 |
|
} catch (NullPointerException success) {} |
513 |
|
} |
514 |
|
|
520 |
– |
|
515 |
|
/** |
516 |
|
* remove(null) throws NPE |
517 |
|
*/ |
549 |
|
* A deserialized map equals original |
550 |
|
*/ |
551 |
|
public void testSerialization() throws Exception { |
552 |
< |
ConcurrentHashMap q = map5(); |
552 |
> |
Map x = map5(); |
553 |
> |
Map y = serialClone(x); |
554 |
|
|
555 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
556 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
557 |
< |
out.writeObject(q); |
558 |
< |
out.close(); |
564 |
< |
|
565 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
566 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
567 |
< |
ConcurrentHashMap r = (ConcurrentHashMap)in.readObject(); |
568 |
< |
assertEquals(q.size(), r.size()); |
569 |
< |
assertTrue(q.equals(r)); |
570 |
< |
assertTrue(r.equals(q)); |
555 |
> |
assertTrue(x != y); |
556 |
> |
assertEquals(x.size(), y.size()); |
557 |
> |
assertEquals(x, y); |
558 |
> |
assertEquals(y, x); |
559 |
|
} |
560 |
|
|
573 |
– |
|
561 |
|
/** |
562 |
|
* SetValue of an EntrySet entry sets value in the map. |
563 |
|
*/ |