| 1 4 package com.tctest; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOClientConfigHelper; 8 import com.tc.object.config.TransparencyClassSpec; 9 import com.tc.simulator.app.ApplicationConfig; 10 import com.tc.simulator.listener.ListenerProvider; 11 import com.tc.util.Assert; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 import java.util.Set ; 20 import java.util.Map.Entry; 21 import java.util.concurrent.ConcurrentHashMap ; 22 23 public class ConcurrentHashMapTestApp extends GenericTestApp { 24 25 private final DataKey[] keyRoots = new DataKey[]{ new DataKey(1), new DataKey(2), new DataKey(3), new DataKey(4)}; 26 private final DataValue[] valueRoots = new DataValue[]{ new DataValue(10), new DataValue(20), new DataValue(30), new DataValue(40) }; 27 28 private final HashKey[] hashKeys = new HashKey[]{ new HashKey(1), new HashKey(2), new HashKey(3), new HashKey(4)}; 29 private final HashValue[] hashValues = new HashValue[]{ new HashValue(10), new HashValue(20), new HashValue(30), new HashValue(40) }; 30 31 public ConcurrentHashMapTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 32 super(appId, cfg, listenerProvider, ConcurrentHashMap .class); 33 } 34 35 protected Object getTestObject(String test) { 36 return sharedMap.get("map"); 37 } 38 39 protected void setupTestObject(String test) { 40 List listOfMaps = new ArrayList (); 41 listOfMaps.add(new ConcurrentHashMap ()); 42 sharedMap.put("maps", listOfMaps); 43 sharedMap.put("map", new ConcurrentHashMap ()); 44 sharedMap.put("arrayforConcurrentHashMap", new Object [4]); 45 sharedMap.put("arrayforConcurrentHashMapWithHashKeys", new Object [4]); 46 } 47 48 void testPut1(ConcurrentHashMap map, boolean validate) throws Exception { 49 if (validate) { 50 Assert.assertFalse(map.isEmpty()); 51 Assert.assertEquals(1, map.size()); 52 Assert.assertEquals(20, ((DataValue) (map.get(keyRoots[0]))).getInt()); 53 } else { 54 DataValue value1 = new DataValue(10); 55 DataValue value2 = new DataValue(20); 56 Object o = map.put(keyRoots[0], value1); 57 Assert.assertNull(o); 58 59 o = map.put(keyRoots[0], value2); 60 Assert.assertTrue(o == value1); 61 } 62 } 63 64 void testPut2(ConcurrentHashMap map, boolean validate) throws Exception { 65 if (validate) { 66 Assert.assertFalse(map.isEmpty()); 67 Assert.assertEquals(1, map.size()); 68 Assert.assertEquals(hashValues[1], map.get(hashKeys[0])); 69 } else { 70 Object o = map.put(hashKeys[0], hashValues[0]); 71 Assert.assertNull(o); 72 73 o = map.put(hashKeys[0], hashValues[1]); 74 Assert.assertTrue(o == hashValues[0]); 75 } 76 } 77 78 void testPutIfAbsent(ConcurrentHashMap map, boolean validate) throws Exception { 79 if (validate) { 80 Assert.assertFalse(map.isEmpty()); 81 Assert.assertEquals(1, map.size()); 82 Assert.assertEquals(10, ((DataValue) (map.get(keyRoots[0]))).getInt()); 83 } else { 84 DataValue value1 = new DataValue(10); 85 DataValue value2 = new DataValue(20); 86 Object o = map.put(keyRoots[0], value1); 87 88 o = map.putIfAbsent(keyRoots[0], value2); 89 Assert.assertTrue(o == value1); 90 } 91 } 92 93 void testPutIfAbsent2(ConcurrentHashMap map, boolean validate) throws Exception { 94 if (validate) { 95 Assert.assertFalse(map.isEmpty()); 96 Assert.assertEquals(1, map.size()); 97 Assert.assertEquals(hashValues[0], map.get(hashKeys[0])); 98 } else { 99 Object o = map.put(hashKeys[0], hashValues[0]); 100 101 o = map.putIfAbsent(hashKeys[0], hashValues[1]); 102 Assert.assertTrue(o == hashValues[0]); 103 } 104 } 105 106 void testPutAll1(ConcurrentHashMap map, boolean validate) throws Exception { 107 Map toPut = new HashMap (); 108 toPut.put(keyRoots[0], valueRoots[0]); 109 toPut.put(keyRoots[1], valueRoots[1]); 110 toPut.put(keyRoots[2], valueRoots[2]); 111 toPut.put(keyRoots[3], valueRoots[3]); 112 113 if (validate) { 114 assertMappingsEqual(toPut, map); 115 } else { 116 map.putAll(toPut); 117 } 118 } 119 120 void testPutAll2(ConcurrentHashMap map, boolean validate) throws Exception { 121 Map toPut = new HashMap (); 122 toPut.put(hashKeys[0], hashValues[0]); 123 toPut.put(hashKeys[1], hashValues[1]); 124 toPut.put(hashKeys[2], hashValues[2]); 125 toPut.put(hashKeys[3], hashValues[3]); 126 127 if (validate) { 128 assertMappingsHashEqual(toPut, map); 129 } else { 130 map.putAll(toPut); 131 } 132 } 133 134 void testRemove1(ConcurrentHashMap map, boolean validate) throws Exception { 135 Map toPut = new HashMap (); 136 toPut.put(keyRoots[0], valueRoots[0]); 137 toPut.put(keyRoots[1], valueRoots[1]); 138 toPut.put(keyRoots[2], valueRoots[2]); 139 toPut.put(keyRoots[3], valueRoots[3]); 140 141 if (validate) { 142 toPut.remove(keyRoots[1]); 143 assertMappingsEqual(toPut, map); 144 } else { 145 map.putAll(toPut); 146 map.remove(keyRoots[1]); 147 } 148 } 149 150 void testHashRemove1(ConcurrentHashMap map, boolean validate) throws Exception { 151 Map toPut = new HashMap (); 152 toPut.put(hashKeys[0], hashValues[0]); 153 toPut.put(hashKeys[1], hashValues[1]); 154 toPut.put(hashKeys[2], hashValues[2]); 155 toPut.put(hashKeys[3], hashValues[3]); 156 157 if (validate) { 158 toPut.remove(hashKeys[1]); 159 assertMappingsHashEqual(toPut, map); 160 } else { 161 map.putAll(toPut); 162 map.remove(hashKeys[1]); 163 } 164 } 165 166 void testRemove2(ConcurrentHashMap map, boolean validate) throws Exception { 167 Map toPut = new HashMap (); 168 toPut.put(keyRoots[0], valueRoots[0]); 169 toPut.put(keyRoots[1], valueRoots[1]); 170 toPut.put(keyRoots[2], valueRoots[2]); 171 toPut.put(keyRoots[3], valueRoots[3]); 172 173 if (validate) { 174 assertMappingsEqual(toPut, map); 175 } else { 176 map.putAll(toPut); 177 map.remove(keyRoots[1], new DataValue(30)); 178 } 179 } 180 181 void testHashRemove2(ConcurrentHashMap map, boolean validate) throws Exception { 182 Map toPut = new HashMap (); 183 toPut.put(hashKeys[0], hashValues[0]); 184 toPut.put(hashKeys[1], hashValues[1]); 185 toPut.put(hashKeys[2], hashValues[2]); 186 toPut.put(hashKeys[3], hashValues[3]); 187 188 if (validate) { 189 assertMappingsHashEqual(toPut, map); 190 } else { 191 map.putAll(toPut); 192 map.remove(hashKeys[1], new HashValue(30)); 193 } 194 } 195 196 void testRemove3(ConcurrentHashMap map, boolean validate) throws Exception { 197 Map toPut = new HashMap (); 198 toPut.put(keyRoots[0], valueRoots[0]); 199 toPut.put(keyRoots[1], valueRoots[1]); 200 toPut.put(keyRoots[2], valueRoots[2]); 201 toPut.put(keyRoots[3], valueRoots[3]); 202 203 if (validate) { 204 toPut.remove(keyRoots[3]); 205 assertMappingsEqual(toPut, map); 206 } else { 207 map.putAll(toPut); 208 map.remove(keyRoots[3], valueRoots[3]); 209 } 210 } 211 212 void testHashRemove3(ConcurrentHashMap map, boolean validate) throws Exception { 213 Map toPut = new HashMap (); 214 toPut.put(hashKeys[0], hashValues[0]); 215 toPut.put(hashKeys[1], hashValues[1]); 216 toPut.put(hashKeys[2], hashValues[2]); 217 toPut.put(hashKeys[3], hashValues[3]); 218 219 if (validate) { 220 toPut.remove(hashKeys[3]); 221 assertMappingsHashEqual(toPut, map); 222 } else { 223 map.putAll(toPut); 224 map.remove(hashKeys[3], hashValues[3]); 226 } 227 } 228 229 void testReplace1(ConcurrentHashMap map, boolean validate) throws Exception { 230 if (validate) { 231 Assert.assertEquals(10, ((DataValue) map.get(keyRoots[0])).getInt()); 232 } else { 233 DataValue value1 = new DataValue(10); 234 Object o = map.put(keyRoots[0], value1); 235 Assert.assertNull(o); 236 o = map.replace(new DataKey(1), new DataValue(20)); 237 Assert.assertNull(o); 238 } 239 } 240 241 void testHashReplace1(ConcurrentHashMap map, boolean validate) throws Exception { 242 if (validate) { 243 assertSingleHashMapping(hashKeys[0], hashValues[0], map); 244 } else { 245 Object o = map.put(hashKeys[0], hashValues[0]); 246 Assert.assertNull(o); 247 o = map.replace(hashKeys[1], hashValues[1]); 248 Assert.assertNull(o); 249 } 250 } 251 252 void testReplace2(ConcurrentHashMap map, boolean validate) throws Exception { 253 if (validate) { 254 Assert.assertEquals(20, ((DataValue) map.get(keyRoots[0])).getInt()); 255 } else { 256 DataValue value1 = new DataValue(10); 257 Object o = map.put(keyRoots[0], value1); 258 Assert.assertNull(o); 259 o = map.replace(keyRoots[0], new DataValue(20)); 260 Assert.assertEquals(10, ((DataValue) o).getInt()); 261 } 262 } 263 264 void testHashReplace2(ConcurrentHashMap map, boolean validate) throws Exception { 265 if (validate) { 266 assertSingleHashMapping(hashKeys[0], hashValues[1], map); 267 } else { 268 Object o = map.put(hashKeys[0], hashValues[0]); 269 Assert.assertNull(o); 270 Object o2 = new HashKey(1); 271 o = map.replace(o2, new HashValue(20)); 272 Assert.assertEquals(o, hashValues[0]); 273 } 274 } 275 276 void testReplaceIfValueEqual1(ConcurrentHashMap map, boolean validate) throws Exception { 277 if (validate) { 278 Assert.assertEquals(valueRoots[0], map.get(keyRoots[0])); 279 } else { 280 Object o = map.put(keyRoots[0], valueRoots[0]); 281 Assert.assertNull(o); 282 boolean returnValue = map.replace(keyRoots[0], new DataValue(10), new DataValue(20)); 283 Assert.assertFalse(returnValue); 284 } 285 } 286 287 void testHashReplaceIfValueEqual1(ConcurrentHashMap map, boolean validate) throws Exception { 288 if (validate) { 289 Assert.assertEquals(hashValues[0], map.get(hashKeys[0])); 290 } else { 291 Object o = map.put(hashKeys[0], hashValues[0]); 292 Assert.assertNull(o); 293 boolean returnValue = map.replace(new HashKey(1), new HashValue(15), new DataValue(20)); 294 Assert.assertFalse(returnValue); 295 } 296 } 297 298 void testReplaceIfValueEqual2(ConcurrentHashMap map, boolean validate) throws Exception { 299 if (validate) { 300 Assert.assertEquals(20, ((DataValue) map.get(keyRoots[0])).getInt()); 301 } else { 302 Object o = map.put(keyRoots[0], valueRoots[0]); 303 Assert.assertNull(o); 304 boolean returnValue = map.replace(keyRoots[0], valueRoots[0], new DataValue(20)); 305 Assert.assertTrue(returnValue); 306 } 307 } 308 309 void testHashReplaceIfValueEqual2(ConcurrentHashMap map, boolean validate) throws Exception { 310 if (validate) { 311 Assert.assertEquals(hashValues[1], map.get(hashKeys[0])); 312 } else { 313 Object o = map.put(hashKeys[0], hashValues[0]); 314 Assert.assertNull(o); 315 boolean returnValue = map.replace(new HashKey(1), new HashValue(10), new HashValue(20)); 316 Assert.assertTrue(returnValue); 317 } 318 } 319 320 void testContains1(ConcurrentHashMap map, boolean validate) throws Exception { 321 if (validate) { 322 Assert.assertTrue(map.containsKey(keyRoots[0])); 323 Assert.assertFalse(map.containsKey(new DataKey(1))); 324 325 Assert.assertTrue(map.containsValue(valueRoots[0])); 326 Assert.assertFalse(map.containsValue(new DataValue(10))); 327 328 Assert.assertTrue(map.contains(valueRoots[0])); 329 Assert.assertFalse(map.contains(new DataValue(10))); 330 } else { 331 map.put(keyRoots[0], valueRoots[0]); 332 } 333 } 334 335 void testContains2(ConcurrentHashMap map, boolean validate) throws Exception { 336 if (validate) { 337 Assert.assertTrue(map.containsKey(hashKeys[0])); 338 Assert.assertTrue(map.containsKey(new HashKey(1))); 339 340 Assert.assertTrue(map.containsValue(hashValues[0])); 341 Assert.assertTrue(map.containsValue(new HashValue(10))); 342 343 Assert.assertTrue(map.contains(hashValues[0])); 344 Assert.assertTrue(map.contains(new HashValue(10))); 345 } else { 346 map.put(hashKeys[0], hashValues[0]); 347 } 348 } 349 350 void testEntrySetClear(ConcurrentHashMap map, boolean validate) throws Exception { 351 Map toPut = new HashMap (); 352 DataKey key1 = new DataKey(1); 353 DataKey key2 = new DataKey(2); 354 DataKey key3 = new DataKey(3); 355 356 DataValue value1 = new DataValue(10); 357 DataValue value2 = new DataValue(20); 358 DataValue value3 = new DataValue(30); 359 toPut.put(key1, value1); 360 toPut.put(key2, value2); 361 toPut.put(key3, value3); 362 if (validate) { 363 Assert.assertEquals(0, map.size()); 364 } else { 365 map.putAll(toPut); 366 367 map.entrySet().clear(); 368 } 369 } 370 371 void testEntrySetContains1(ConcurrentHashMap map, boolean validate) throws Exception { 372 SimpleEntry entry = new SimpleEntry(keyRoots[0], valueRoots[0]); 373 if (validate) { 374 Assert.assertTrue(map.entrySet().contains(entry)); 375 } else { 376 map.put(keyRoots[0], valueRoots[0]); 377 } 378 } 379 380 void testEntrySetContains2(ConcurrentHashMap map, boolean validate) throws Exception { 381 SimpleEntry entry = new SimpleEntry(new HashKey(1), new HashValue(10)); 382 if (validate) { 383 Assert.assertTrue(map.entrySet().contains(entry)); 384 } else { 385 map.put(hashKeys[0], hashValues[0]); 386 } 387 } 388 389 void testEntrySetContainsAll1(ConcurrentHashMap map, boolean validate) throws Exception { 390 Map toPut = new HashMap (); 391 toPut.put(keyRoots[0], valueRoots[0]); 392 toPut.put(keyRoots[1], valueRoots[1]); 393 toPut.put(keyRoots[2], valueRoots[2]); 394 toPut.put(keyRoots[3], valueRoots[3]); 395 396 if (validate) { 397 SimpleEntry entry1 = new SimpleEntry(keyRoots[1], valueRoots[1]); 398 SimpleEntry entry2 = new SimpleEntry(keyRoots[2], valueRoots[2]); 399 List containsList = new ArrayList (2); 400 containsList.add(entry1); 401 containsList.add(entry2); 402 Assert.assertTrue(map.entrySet().containsAll(containsList)); 403 } else { 404 map.putAll(toPut); 405 } 406 } 407 408 void testEntrySetContainsAll2(ConcurrentHashMap map, boolean validate) throws Exception { 409 Map toPut = new HashMap (); 410 toPut.put(hashKeys[0], hashValues[0]); 411 toPut.put(hashKeys[1], hashValues[1]); 412 toPut.put(hashKeys[2], hashValues[2]); 413 toPut.put(hashKeys[3], hashValues[3]); 414 415 if (validate) { 416 SimpleEntry entry1 = new SimpleEntry(hashKeys[1], hashValues[1]); 417 SimpleEntry entry2 = new SimpleEntry(new HashKey(3), new HashValue(30)); 418 List containsList = new ArrayList (2); 419 containsList.add(entry1); 420 containsList.add(entry2); 421 Assert.assertTrue(map.entrySet().containsAll(containsList)); 422 } else { 423 map.putAll(toPut); 424 } 425 } 426 427 void testEntrySetRetainAll1(ConcurrentHashMap map, boolean validate) throws Exception { 428 Map toPut = new HashMap (); 429 toPut.put(keyRoots[0], valueRoots[0]); 430 toPut.put(keyRoots[1], valueRoots[1]); 431 toPut.put(keyRoots[2], valueRoots[2]); 432 toPut.put(keyRoots[3], valueRoots[3]); 433 if (validate) { 434 toPut.remove(keyRoots[0]); 435 toPut.remove(keyRoots[3]); 436 assertMappingsEqual(toPut, map); 437 } else { 438 map.putAll(toPut); 439 SimpleEntry entry1 = new SimpleEntry(keyRoots[1], valueRoots[1]); 440 SimpleEntry entry2 = new SimpleEntry(keyRoots[2], valueRoots[2]); 441 List containsList = new ArrayList (2); 442 containsList.add(entry1); 443 containsList.add(entry2); 444 map.entrySet().retainAll(containsList); 445 } 446 } 447 448 void testEntrySetRetainAll2(ConcurrentHashMap map, boolean validate) throws Exception { 449 Map toPut = new HashMap (); 450 toPut.put(hashKeys[0], hashValues[0]); 451 toPut.put(hashKeys[1], hashValues[1]); 452 toPut.put(hashKeys[2], hashValues[2]); 453 toPut.put(hashKeys[3], hashValues[3]); 454 455 if (validate) { 456 toPut.remove(hashKeys[0]); 457 toPut.remove(hashKeys[3]); 458 assertMappingsHashEqual(toPut, map); 459 } else { 460 map.putAll(toPut); 461 SimpleEntry entry1 = new SimpleEntry(hashKeys[1], hashValues[1]); 462 SimpleEntry entry2 = new SimpleEntry(new HashKey(3), new HashValue(30)); 463 List containsList = new ArrayList (2); 464 containsList.add(entry1); 465 containsList.add(entry2); 466 map.entrySet().retainAll(containsList); 467 } 468 } 469 470 void testEntrySetRemove1(ConcurrentHashMap map, boolean validate) throws Exception { 471 if (validate) { 472 Assert.assertEquals(0, map.size()); 473 } else { 474 map.put(keyRoots[0], valueRoots[0]); 475 SimpleEntry entry = new SimpleEntry(keyRoots[0], valueRoots[0]); 476 map.entrySet().remove(entry); 477 } 478 } 479 480 void testEntrySetRemove2(ConcurrentHashMap map, boolean validate) throws Exception { 481 if (validate) { 482 Assert.assertEquals(0, map.size()); 483 } else { 484 map.put(hashKeys[0], hashValues[0]); 485 SimpleEntry entry = new SimpleEntry(hashKeys[0], hashValues[0]); 486 map.entrySet().remove(entry); 487 } 488 } 489 490 void testEntrySetRemoveAll1(ConcurrentHashMap map, boolean validate) throws Exception { 491 Map toPut = new HashMap (); 492 toPut.put(keyRoots[0], valueRoots[0]); 493 toPut.put(keyRoots[1], valueRoots[1]); 494 toPut.put(keyRoots[2], valueRoots[2]); 495 toPut.put(keyRoots[3], valueRoots[3]); 496 if (validate) { 497 toPut.remove(keyRoots[1]); 498 toPut.remove(keyRoots[2]); 499 assertMappingsEqual(toPut, map); 500 } else { 501 map.putAll(toPut); 502 503 SimpleEntry entry1 = new SimpleEntry(keyRoots[1], valueRoots[1]); 504 SimpleEntry entry2 = new SimpleEntry(keyRoots[2], valueRoots[2]); 505 List toRemove = new ArrayList (2); 506 toRemove.add(entry1); 507 toRemove.add(entry2); 508 map.entrySet().removeAll(toRemove); 509 } 510 } 511 512 void testEntrySetRemoveAll2(ConcurrentHashMap map, boolean validate) throws Exception { 513 Map toPut = new HashMap (); 514 toPut.put(hashKeys[0], hashValues[0]); 515 toPut.put(hashKeys[1], hashValues[1]); 516 toPut.put(hashKeys[2], hashValues[2]); 517 toPut.put(hashKeys[3], hashValues[3]); 518 if (validate) { 519 toPut.remove(hashKeys[1]); 520 toPut.remove(hashKeys[2]); 521 assertMappingsHashEqual(toPut, map); 522 } else { 523 map.putAll(toPut); 524 525 SimpleEntry entry1 = new SimpleEntry(hashKeys[1], hashValues[1]); 526 SimpleEntry entry2 = new SimpleEntry(new HashKey(3), new HashValue(30)); 527 List toRemove = new ArrayList (2); 528 toRemove.add(entry1); 529 toRemove.add(entry2); 530 map.entrySet().removeAll(toRemove); 531 } 532 } 533 534 void testEntrySetSize1(ConcurrentHashMap map, boolean validate) throws Exception { 535 if (validate) { 536 Assert.assertEquals(1, map.entrySet().size()); 537 } else { 538 map.put(keyRoots[0], valueRoots[0]); 539 } 540 } 541 542 void testEntrySetSize2(ConcurrentHashMap map, boolean validate) throws Exception { 543 if (validate) { 544 Assert.assertEquals(1, map.entrySet().size()); 545 } else { 546 map.put(hashKeys[0], hashValues[0]); 547 } 548 } 549 550 void testEntrySetSetValue1(ConcurrentHashMap map, boolean validate) throws Exception { 551 Map toPut = new HashMap (); 552 toPut.put(keyRoots[0], valueRoots[0]); 553 toPut.put(keyRoots[1], valueRoots[1]); 554 toPut.put(keyRoots[2], valueRoots[2]); 555 toPut.put(keyRoots[3], valueRoots[3]); 556 if (validate) { 557 Assert.assertEquals(15, ((DataValue)map.get(keyRoots[1])).getInt()); 558 } else { 559 map.putAll(toPut); 560 for (Iterator i=map.entrySet().iterator(); i.hasNext(); ) { 561 Map.Entry entry = (Map.Entry )i.next(); 562 if (((DataKey)entry.getKey()).getInt() == 2) { 563 entry.setValue(new DataValue(15)); 564 } 565 } 566 } 567 } 568 569 void testEntrySetSetValue2(ConcurrentHashMap map, boolean validate) throws Exception { 570 Map toPut = new HashMap (); 571 toPut.put(hashKeys[0], hashValues[0]); 572 toPut.put(hashKeys[1], hashValues[1]); 573 toPut.put(hashKeys[2], hashValues[2]); 574 toPut.put(hashKeys[3], hashValues[3]); 575 if (validate) { 576 Assert.assertEquals(new HashValue(15), map.get(hashKeys[1])); 577 } else { 578 map.putAll(toPut); 579 for (Iterator i=map.entrySet().iterator(); i.hasNext(); ) { 580 Map.Entry entry = (Map.Entry )i.next(); 581 if (((HashKey)entry.getKey()).getInt() == 2) { 582 entry.setValue(new HashValue(15)); 583 } 584 } 585 } 586 } 587 588 void testEntrySetIteratorRemove1(ConcurrentHashMap map, boolean validate) { 589 Map toPut = new HashMap (); 590 toPut.put(keyRoots[0], valueRoots[0]); 591 toPut.put(keyRoots[1], valueRoots[1]); 592 toPut.put(keyRoots[2], valueRoots[2]); 593 toPut.put(keyRoots[3], valueRoots[3]); 594 if (validate) { 595 toPut.remove(keyRoots[1]); 596 assertMappingsEqual(toPut, map); 597 } else { 598 map.putAll(toPut); 599 assertMappingsEqual(toPut, map); 600 601 for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) { 602 Map.Entry e = (Map.Entry ) i.next(); 603 if (e.getKey().equals(keyRoots[1])) { 604 i.remove(); 605 break; 606 } 607 } 608 } 609 } 610 611 void testEntrySetIteratorRemove2(ConcurrentHashMap map, boolean validate) { 612 Map toPut = new HashMap (); 613 toPut.put(hashKeys[0], hashValues[0]); 614 toPut.put(hashKeys[1], hashValues[1]); 615 toPut.put(hashKeys[2], hashValues[2]); 616 toPut.put(hashKeys[3], hashValues[3]); 617 if (validate) { 618 toPut.remove(hashKeys[1]); 619 assertMappingsHashEqual(toPut, map); 620 } else { 621 map.putAll(toPut); 622 assertMappingsHashEqual(toPut, map); 623 624 for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) { 625 Map.Entry e = (Map.Entry ) i.next(); 626 if (e.getKey().equals(hashKeys[1])) { 627 i.remove(); 628 break; 629 } 630 } 631 } 632 } 633 634 void testEntrySetToArray1(ConcurrentHashMap map, boolean validate) { 635 Map toPut = new HashMap (); 636 toPut.put(keyRoots[0], valueRoots[0]); 637 toPut.put(keyRoots[1], valueRoots[1]); 638 toPut.put(keyRoots[2], valueRoots[2]); 639 toPut.put(keyRoots[3], valueRoots[3]); 640 Object [] array = getArray(map, false); 641 642 if (validate) { 643 assertMappingsEqual(array, map); 644 } else { 645 map.putAll(toPut); 646 synchronized (array) { 647 Object [] returnArray = map.entrySet().toArray(array); 648 Assert.assertTrue(returnArray == array); 649 } 650 } 651 } 652 653 void testEntrySetToArray2(ConcurrentHashMap map, boolean validate) { 654 Map toPut = new HashMap (); 655 toPut.put(hashKeys[0], hashValues[0]); 656 toPut.put(hashKeys[1], hashValues[1]); 657 toPut.put(hashKeys[2], hashValues[2]); 658 toPut.put(hashKeys[3], hashValues[3]); 659 Object [] array = getArray(map, true); 660 661 if (validate) { 662 assertMappingsEqual(array, map); 663 } else { 664 map.putAll(toPut); 665 synchronized (array) { 666 Object [] returnArray = map.entrySet().toArray(array); 667 Assert.assertTrue(returnArray == array); 668 } 669 } 670 } 671 672 void testValuesClear1(ConcurrentHashMap map, boolean validate) { 673 Map toPut = new HashMap (); 674 toPut.put(keyRoots[0], valueRoots[0]); 675 toPut.put(keyRoots[1], valueRoots[1]); 676 toPut.put(keyRoots[2], valueRoots[2]); 677 toPut.put(keyRoots[3], valueRoots[3]); 678 679 if (validate) { 680 Assert.assertEquals(0, map.size()); 681 } else { 682 map.putAll(toPut); 683 map.values().clear(); 684 } 685 } 686 687 void testValuesClear2(ConcurrentHashMap map, boolean validate) { 688 Map toPut = new HashMap (); 689 toPut.put(hashKeys[0], hashValues[0]); 690 toPut.put(hashKeys[1], hashValues[1]); 691 toPut.put(hashKeys[2], hashValues[2]); 692 toPut.put(hashKeys[3], hashValues[3]); 693 694 if (validate) { 695 Assert.assertEquals(0, map.size()); 696 } else { 697 map.putAll(toPut); 698 map.values().clear(); 699 } 700 } 701 702 void testValuesContains1(ConcurrentHashMap map, boolean validate) { 703 Map toPut = new HashMap (); 704 toPut.put(keyRoots[0], valueRoots[0]); 705 toPut.put(keyRoots[1], valueRoots[1]); 706 toPut.put(keyRoots[2], valueRoots[2]); 707 toPut.put(keyRoots[3], valueRoots[3]); 708 709 if (validate) { 710 Assert.assertTrue(map.values().contains(valueRoots[2])); 711 } else { 712 map.putAll(toPut); 713 } 714 } 715 716 void testValuesContains2(ConcurrentHashMap map, boolean validate) { 717 Map toPut = new HashMap (); 718 toPut.put(hashKeys[0], hashValues[0]); 719 toPut.put(hashKeys[1], hashValues[1]); 720 toPut.put(hashKeys[2], hashValues[2]); 721 toPut.put(hashKeys[3], hashValues[3]); 722 723 if (validate) { 724 Assert.assertTrue(map.values().contains(new HashValue(20))); 725 } else { 726 map.putAll(toPut); 727 } 728 } 729 730 void testValuesContainsAll1(ConcurrentHashMap map, boolean validate) { 731 Map toPut = new HashMap (); 732 toPut.put(keyRoots[0], valueRoots[0]); 733 toPut.put(keyRoots[1], valueRoots[1]); 734 toPut.put(keyRoots[2], valueRoots[2]); 735 toPut.put(keyRoots[3], valueRoots[3]); 736 737 if (validate) { 738 Assert.assertTrue(map.values().containsAll(toPut.values())); 739 } else { 740 map.putAll(toPut); 741 } 742 } 743 744 void testValuesContainsAll2(ConcurrentHashMap map, boolean validate) { 745 Map toPut = new HashMap (); 746 toPut.put(hashKeys[0], hashValues[0]); 747 toPut.put(hashKeys[1], hashValues[1]); 748 toPut.put(hashKeys[2], hashValues[2]); 749 toPut.put(hashKeys[3], hashValues[3]); 750 751 if (validate) { 752 Assert.assertTrue(map.values().containsAll(toPut.values())); 753 } else {
|