1 22 package org.jboss.test.jbossmq.test; 23 24 import java.util.List ; 25 26 import javax.jms.Topic ; 27 import javax.naming.InitialContext ; 28 import javax.transaction.xa.XAResource ; 29 import javax.transaction.xa.Xid ; 30 31 37 public class RecoveryDurableTopicReceiveUnitTestCase extends RecoveryTest 38 { 39 static String RECOVERY_TOPIC = "topic/recoveryDurableTopic"; 40 41 Topic recoveryTopic; 42 43 public RecoveryDurableTopicReceiveUnitTestCase(String name) throws Exception 44 { 45 super(name); 46 } 47 48 54 public void testReceivePrepareShowsInRecovery() throws Exception 55 { 56 deployRecoveryService(); 57 try 58 { 59 makeSubscription(recoveryTopic); 60 try 61 { 62 reset(recoveryTopic); 63 setup(recoveryTopic, 1); 64 JMSClient client = new JMSClient(recoveryTopic); 65 try 66 { 67 Xid xid = new MyXid(); 68 client.enlist(xid); 69 assertNotNull(client.receiveNoWait()); 70 client.delist(xid); 71 int result = client.prepare(xid); 72 try 73 { 74 assertEquals(XAResource.XA_OK, result); 75 List xids = client.recover(); 76 assertEquals(1, xids.size()); 77 assertXidEquals(xid, (Xid ) xids.get(0)); 78 } 79 finally 80 { 81 client.rollback(xid); 82 } 83 } 84 finally 85 { 86 client.close(); 87 } 88 assertEquals(1, clearDestination(recoveryTopic)); 89 } 90 finally 91 { 92 removeSubscription(recoveryTopic); 93 } 94 } 95 finally 96 { 97 undeployRecoveryService(); 98 } 99 } 100 101 108 public void testReceivePrepareRollbackDoesntShowInRecovery() throws Exception 109 { 110 deployRecoveryService(); 111 try 112 { 113 makeSubscription(recoveryTopic); 114 try 115 { 116 reset(recoveryTopic); 117 setup(recoveryTopic, 1); 118 JMSClient client = new JMSClient(recoveryTopic); 119 try 120 { 121 Xid xid = new MyXid(); 122 client.enlist(xid); 123 assertNotNull(client.receiveNoWait()); 124 client.delist(xid); 125 int result = client.prepare(xid); 126 try 127 { 128 assertEquals(XAResource.XA_OK, result); 129 List xids = client.recover(); 130 assertEquals(1, xids.size()); 131 assertXidEquals(xid, (Xid ) xids.get(0)); 132 client.rollback(xid); 133 xids = client.recover(); 134 assertEquals(0, xids.size()); 135 } 136 finally 137 { 138 try 139 { 140 client.rollback(xid); 141 } 142 catch (Exception ignored) 143 { 144 } 145 } 146 } 147 finally 148 { 149 client.close(); 150 } 151 assertEquals(1, clearDestination(recoveryTopic)); 152 } 153 finally 154 { 155 removeSubscription(recoveryTopic); 156 } 157 } 158 finally 159 { 160 undeployRecoveryService(); 161 } 162 } 163 164 171 public void testReceivePrepareForgetDoesntShowInRecovery() throws Exception 172 { 173 deployRecoveryService(); 174 try 175 { 176 makeSubscription(recoveryTopic); 177 try 178 { 179 reset(recoveryTopic); 180 setup(recoveryTopic, 1); 181 JMSClient client = new JMSClient(recoveryTopic); 182 try 183 { 184 Xid xid = new MyXid(); 185 client.enlist(xid); 186 assertNotNull(client.receiveNoWait()); 187 client.delist(xid); 188 int result = client.prepare(xid); 189 try 190 { 191 assertEquals(XAResource.XA_OK, result); 192 List xids = client.recover(); 193 assertEquals(1, xids.size()); 194 assertXidEquals(xid, (Xid ) xids.get(0)); 195 client.forget(xid); 196 xids = client.recover(); 197 assertEquals(0, xids.size()); 198 } 199 finally 200 { 201 try 202 { 203 client.rollback(xid); 204 } 205 catch (Exception ignored) 206 { 207 } 208 } 209 } 210 finally 211 { 212 client.close(); 213 } 214 assertEquals(1, clearDestination(recoveryTopic)); 215 } 216 finally 217 { 218 removeSubscription(recoveryTopic); 219 } 220 } 221 finally 222 { 223 undeployRecoveryService(); 224 } 225 } 226 227 233 public void testReceivePrepareCommitDoesntShowInRecovery() throws Exception 234 { 235 deployRecoveryService(); 236 try 237 { 238 makeSubscription(recoveryTopic); 239 try 240 { 241 reset(recoveryTopic); 242 setup(recoveryTopic, 1); 243 JMSClient client = new JMSClient(recoveryTopic); 244 try 245 { 246 Xid xid = new MyXid(); 247 client.enlist(xid); 248 assertNotNull(client.receiveNoWait()); 249 client.delist(xid); 250 int result = client.prepare(xid); 251 try 252 { 253 assertEquals(XAResource.XA_OK, result); 254 List xids = client.recover(); 255 assertEquals(1, xids.size()); 256 assertXidEquals(xid, (Xid ) xids.get(0)); 257 client.commit(xid); 258 xids = client.recover(); 259 assertEquals(0, xids.size()); 260 } 261 finally 262 { 263 try 264 { 265 client.rollback(xid); 266 } 267 catch (Exception ignored) 268 { 269 } 270 } 271 } 272 finally 273 { 274 client.close(); 275 } 276 assertEquals(0, clearDestination(recoveryTopic)); 277 } 278 finally 279 { 280 removeSubscription(recoveryTopic); 281 } 282 } 283 finally 284 { 285 undeployRecoveryService(); 286 } 287 } 288 289 298 public void testReceivePrepareCommitDifferentConnection() throws Exception 299 { 300 deployRecoveryService(); 301 try 302 { 303 makeSubscription(recoveryTopic); 304 try 305 { 306 reset(recoveryTopic); 307 setup(recoveryTopic, 1); 308 Xid xid = new MyXid(); 309 JMSClient client = new JMSClient(recoveryTopic); 310 try 311 { 312 client.enlist(xid); 313 assertNotNull(client.receiveNoWait()); 314 client.delist(xid); 315 int result = client.prepare(xid); 316 assertEquals(XAResource.XA_OK, result); 317 List xids = client.recover(); 318 assertEquals(1, xids.size()); 319 assertXidEquals(xid, (Xid ) xids.get(0)); 320 } 321 finally 322 { 323 client.close(); 324 } 325 326 assertEquals(0, clearDestination(recoveryTopic)); 327 328 client = new JMSClient(recoveryTopic); 329 try 330 { 331 List xids = client.recover(); 332 assertEquals(1, xids.size()); 333 assertXidEquals(xid, (Xid ) xids.get(0)); 334 client.commit(xid); 335 xids = client.recover(); 336 assertEquals(0, xids.size()); 337 } 338 finally 339 { 340 client.close(); 341 } 342 assertEquals(0, clearDestination(recoveryTopic)); 343 } 344 finally 345 { 346 removeSubscription(recoveryTopic); 347 } 348 } 349 finally 350 { 351 undeployRecoveryService(); 352 } 353 } 354 355 364 public void testReceivePrepareRollbackDifferentConnection() throws Exception 365 { 366 deployRecoveryService(); 367 try 368 { 369 makeSubscription(recoveryTopic); 370 try 371 { 372 reset(recoveryTopic); 373 setup(recoveryTopic, 1); 374 Xid xid = new MyXid(); 375 JMSClient client = new JMSClient(recoveryTopic); 376 try 377 { 378 client.enlist(xid); 379 assertNotNull(client.receiveNoWait()); 380 client.delist(xid); 381 int result = client.prepare(xid); 382 assertEquals(XAResource.XA_OK, result); 383 List xids = client.recover(); 384 assertEquals(1, xids.size()); 385 assertXidEquals(xid, (Xid ) xids.get(0)); 386 } 387 finally 388 { 389 client.close(); 390 } 391 assertEquals(0, clearDestination(recoveryTopic)); 392 393 client = new JMSClient(recoveryTopic); 394 try 395 { 396 List xids = client.recover(); 397 assertEquals(1, xids.size()); 398 assertXidEquals(xid, (Xid ) xids.get(0)); 399 client.rollback(xid); 400 xids = client.recover(); 401 assertEquals(0, xids.size()); 402 } 403 finally 404 { 405 client.close(); 406 } 407 assertEquals(1, clearDestination(recoveryTopic)); 408 } 409 finally 410 { 411 removeSubscription(recoveryTopic); 412 } 413 } 414 finally 415 { 416 undeployRecoveryService(); 417 } 418 } 419 420 429 public void testReceivePrepareForgetDifferentConnection() throws Exception 430 { 431 deployRecoveryService(); 432 try 433 { 434 makeSubscription(recoveryTopic); 435 try 436 { 437 reset(recoveryTopic); 438 setup(recoveryTopic, 1); 439 Xid xid = new MyXid(); 440 JMSClient client = new JMSClient(recoveryTopic); 441 try 442 { 443 client.enlist(xid); 444 assertNotNull(client.receiveNoWait()); 445 client.delist(xid); 446 int result = client.prepare(xid); 447 assertEquals(XAResource.XA_OK, result); 448 List xids = client.recover(); 449 assertEquals(1, xids.size()); 450 assertXidEquals(xid, (Xid ) xids.get(0)); 451 } 452 finally 453 { 454 client.close(); 455 } 456 assertEquals(0, clearDestination(recoveryTopic)); 457 458 client = new JMSClient(recoveryTopic); 459 try 460 { 461 List xids = client.recover(); 462 assertEquals(1, xids.size()); 463 assertXidEquals(xid, (Xid ) xids.get(0)); 464 client.forget(xid); 465 xids = client.recover(); 466 assertEquals(0, xids.size()); 467 } 468 finally 469 { 470 client.close(); 471 } 472 assertEquals(1, clearDestination(recoveryTopic)); 473 } 474 finally 475 { 476 removeSubscription(recoveryTopic); 477 } 478 } 479 finally 480 { 481 undeployRecoveryService(); 482 } 483 } 484 485 494 public void testReceivePrepareCommitDifferentConnectionRestart() throws Exception 495 { 496 deployRecoveryService(); 497 try 498 { 499 makeSubscription(recoveryTopic); 500 try 501 { 502 reset(recoveryTopic); 503 setup(recoveryTopic, 1); 504 Xid xid = new MyXid(); 505 JMSClient client = new JMSClient(recoveryTopic); 506 try 507 { 508 client.enlist(xid); 509 assertNotNull(client.receiveNoWait()); 510 client.delist(xid); 511 int result = client.prepare(xid); 512 assertEquals(XAResource.XA_OK, result); 513 List xids = client.recover(); 514 assertEquals(1, xids.size()); 515 assertXidEquals(xid, (Xid ) xids.get(0)); 516 } 517 finally 518 { 519 client.close(); 520 } 521 522 assertEquals(0, clearDestination(recoveryTopic)); 523 524 restartRecoveryService(); 525 assertEquals(0, clearDestination(recoveryTopic)); 526 527 client = new JMSClient(recoveryTopic); 528 try 529 { 530 List xids = client.recover(); 531 assertEquals(1, xids.size()); 532 assertXidEquals(xid, (Xid ) xids.get(0)); 533 client.commit(xid); 534 xids = client.recover(); 535 assertEquals(0, xids.size()); 536 } 537 finally 538 { 539 client.close(); 540 } 541 assertEquals(0, clearDestination(recoveryTopic)); 542 } 543 finally 544 { 545 removeSubscription(recoveryTopic); 546 } 547 } 548 finally 549 { 550 undeployRecoveryService(); 551 } 552 } 553 554 563 public void testReceivePrepareRollbackDifferentConnectionRestart() throws Exception 564 { 565 deployRecoveryService(); 566 try 567 { 568 makeSubscription(recoveryTopic); 569 try 570 { 571 reset(recoveryTopic); 572 setup(recoveryTopic, 1); 573 Xid xid = new MyXid(); 574 JMSClient client = new JMSClient(recoveryTopic); 575 try 576 { 577 client.enlist(xid); 578 assertNotNull(client.receiveNoWait()); 579 client.delist(xid); 580 int result = client.prepare(xid); 581 assertEquals(XAResource.XA_OK, result); 582 List xids = client.recover(); 583 assertEquals(1, xids.size()); 584 assertXidEquals(xid, (Xid ) xids.get(0)); 585 } 586 finally 587 { 588 client.close(); 589 } 590 assertEquals(0, clearDestination(recoveryTopic)); 591 592 restartRecoveryService(); 593 assertEquals(0, clearDestination(recoveryTopic)); 594 595 client = new JMSClient(recoveryTopic); 596 try 597 { 598 List xids = client.recover(); 599 assertEquals(1, xids.size()); 600 assertXidEquals(xid, (Xid ) xids.get(0)); 601 client.rollback(xid); 602 xids = client.recover(); 603 assertEquals(0, xids.size()); 604 } 605 finally 606 { 607 client.close(); 608 } 609 assertEquals(1, clearDestination(recoveryTopic)); 610 } 611 finally 612 { 613 removeSubscription(recoveryTopic); 614 } 615 } 616 finally 617 { 618 undeployRecoveryService(); 619 } 620 } 621 622 631 public void testReceivePrepareForgetDifferentConnectionRestart() throws Exception 632 { 633 deployRecoveryService(); 634 try 635 { 636 makeSubscription(recoveryTopic); 637 try 638 { 639 reset(recoveryTopic); 640 setup(recoveryTopic, 1); 641 Xid xid = new MyXid(); 642 JMSClient client = new JMSClient(recoveryTopic); 643 try 644 { 645 client.enlist(xid); 646 assertNotNull(client.receiveNoWait()); 647 client.delist(xid); 648 int result = client.prepare(xid); 649 assertEquals(XAResource.XA_OK, result); 650 List xids = client.recover(); 651 assertEquals(1, xids.size()); 652 assertXidEquals(xid, (Xid ) xids.get(0)); 653 } 654 finally 655 { 656 client.close(); 657 } 658 assertEquals(0, clearDestination(recoveryTopic)); 659 660 restartRecoveryService(); 661 assertEquals(0, clearDestination(recoveryTopic)); 662 663 client = new JMSClient(recoveryTopic); 664 try 665 { 666 List xids = client.recover(); 667 assertEquals(1, xids.size()); 668 assertXidEquals(xid, (Xid ) xids.get(0)); 669 client.forget(xid); 670 xids = client.recover(); 671 assertEquals(0, xids.size()); 672 } 673 finally 674 { 675 client.close(); 676 } 677 assertEquals(1, clearDestination(recoveryTopic)); 678 } 679 finally 680 { 681 removeSubscription(recoveryTopic); 682 } 683 } 684 finally 685 { 686 undeployRecoveryService(); 687 } 688 } 689 690 protected void deployRecoveryService() throws Exception 691 { 692 super.deployRecoveryService(); 693 InitialContext ctx = getInitialContext(); 694 recoveryTopic = (Topic ) ctx.lookup(RECOVERY_TOPIC); 695 } 696 } 697 | Popular Tags |