1 22 package org.jboss.test.jbossmq.test; 23 24 import java.util.List ; 25 26 import javax.jms.Queue ; 27 import javax.naming.InitialContext ; 28 import javax.transaction.xa.XAResource ; 29 import javax.transaction.xa.Xid ; 30 31 37 public class RecoveryQueueReceiveUnitTestCase extends RecoveryTest 38 { 39 static String RECOVERY_QUEUE = "queue/recoveryQueue"; 40 41 Queue recoveryQueue; 42 43 public RecoveryQueueReceiveUnitTestCase(String name) throws Exception 44 { 45 super(name); 46 } 47 48 54 public void testReceivePrepareShowsInRecovery() throws Exception 55 { 56 deployRecoveryService(); 57 try 58 { 59 reset(recoveryQueue); 60 setup(recoveryQueue, 1); 61 JMSClient client = new JMSClient(recoveryQueue); 62 try 63 { 64 Xid xid = new MyXid(); 65 client.enlist(xid); 66 assertNotNull(client.receiveNoWait()); 67 client.delist(xid); 68 int result = client.prepare(xid); 69 try 70 { 71 assertEquals(XAResource.XA_OK, result); 72 List xids = client.recover(); 73 assertEquals(1, xids.size()); 74 assertXidEquals(xid, (Xid ) xids.get(0)); 75 } 76 finally 77 { 78 client.rollback(xid); 79 } 80 } 81 finally 82 { 83 client.close(); 84 } 85 assertEquals(1, clearDestination(recoveryQueue)); 86 } 87 finally 88 { 89 undeployRecoveryService(); 90 } 91 } 92 93 100 public void testReceivePrepareRollbackDoesntShowInRecovery() throws Exception 101 { 102 deployRecoveryService(); 103 try 104 { 105 reset(recoveryQueue); 106 setup(recoveryQueue, 1); 107 JMSClient client = new JMSClient(recoveryQueue); 108 try 109 { 110 Xid xid = new MyXid(); 111 client.enlist(xid); 112 assertNotNull(client.receiveNoWait()); 113 client.delist(xid); 114 int result = client.prepare(xid); 115 try 116 { 117 assertEquals(XAResource.XA_OK, result); 118 List xids = client.recover(); 119 assertEquals(1, xids.size()); 120 assertXidEquals(xid, (Xid ) xids.get(0)); 121 client.rollback(xid); 122 xids = client.recover(); 123 assertEquals(0, xids.size()); 124 } 125 finally 126 { 127 try 128 { 129 client.rollback(xid); 130 } 131 catch (Exception ignored) 132 { 133 } 134 } 135 } 136 finally 137 { 138 client.close(); 139 } 140 assertEquals(1, clearDestination(recoveryQueue)); 141 } 142 finally 143 { 144 undeployRecoveryService(); 145 } 146 } 147 148 155 public void testReceivePrepareForgetDoesntShowInRecovery() throws Exception 156 { 157 deployRecoveryService(); 158 try 159 { 160 reset(recoveryQueue); 161 setup(recoveryQueue, 1); 162 JMSClient client = new JMSClient(recoveryQueue); 163 try 164 { 165 Xid xid = new MyXid(); 166 client.enlist(xid); 167 assertNotNull(client.receiveNoWait()); 168 client.delist(xid); 169 int result = client.prepare(xid); 170 try 171 { 172 assertEquals(XAResource.XA_OK, result); 173 List xids = client.recover(); 174 assertEquals(1, xids.size()); 175 assertXidEquals(xid, (Xid ) xids.get(0)); 176 client.forget(xid); 177 xids = client.recover(); 178 assertEquals(0, xids.size()); 179 } 180 finally 181 { 182 try 183 { 184 client.rollback(xid); 185 } 186 catch (Exception ignored) 187 { 188 } 189 } 190 } 191 finally 192 { 193 client.close(); 194 } 195 assertEquals(1, clearDestination(recoveryQueue)); 196 } 197 finally 198 { 199 undeployRecoveryService(); 200 } 201 } 202 203 209 public void testReceivePrepareCommitDoesntShowInRecovery() throws Exception 210 { 211 deployRecoveryService(); 212 try 213 { 214 reset(recoveryQueue); 215 setup(recoveryQueue, 1); 216 JMSClient client = new JMSClient(recoveryQueue); 217 try 218 { 219 Xid xid = new MyXid(); 220 client.enlist(xid); 221 assertNotNull(client.receiveNoWait()); 222 client.delist(xid); 223 int result = client.prepare(xid); 224 try 225 { 226 assertEquals(XAResource.XA_OK, result); 227 List xids = client.recover(); 228 assertEquals(1, xids.size()); 229 assertXidEquals(xid, (Xid ) xids.get(0)); 230 client.commit(xid); 231 xids = client.recover(); 232 assertEquals(0, xids.size()); 233 } 234 finally 235 { 236 try 237 { 238 client.rollback(xid); 239 } 240 catch (Exception ignored) 241 { 242 } 243 } 244 } 245 finally 246 { 247 client.close(); 248 } 249 assertEquals(0, clearDestination(recoveryQueue)); 250 } 251 finally 252 { 253 undeployRecoveryService(); 254 } 255 } 256 257 266 public void testReceivePrepareCommitDifferentConnection() throws Exception 267 { 268 deployRecoveryService(); 269 try 270 { 271 reset(recoveryQueue); 272 setup(recoveryQueue, 1); 273 Xid xid = new MyXid(); 274 JMSClient client = new JMSClient(recoveryQueue); 275 try 276 { 277 client.enlist(xid); 278 assertNotNull(client.receiveNoWait()); 279 client.delist(xid); 280 int result = client.prepare(xid); 281 assertEquals(XAResource.XA_OK, result); 282 List xids = client.recover(); 283 assertEquals(1, xids.size()); 284 assertXidEquals(xid, (Xid ) xids.get(0)); 285 } 286 finally 287 { 288 client.close(); 289 } 290 291 assertEquals(0, clearDestination(recoveryQueue)); 292 293 client = new JMSClient(recoveryQueue); 294 try 295 { 296 List xids = client.recover(); 297 assertEquals(1, xids.size()); 298 assertXidEquals(xid, (Xid ) xids.get(0)); 299 client.commit(xid); 300 xids = client.recover(); 301 assertEquals(0, xids.size()); 302 } 303 finally 304 { 305 client.close(); 306 } 307 assertEquals(0, clearDestination(recoveryQueue)); 308 } 309 finally 310 { 311 undeployRecoveryService(); 312 } 313 } 314 315 324 public void testReceivePrepareRollbackDifferentConnection() throws Exception 325 { 326 deployRecoveryService(); 327 try 328 { 329 reset(recoveryQueue); 330 setup(recoveryQueue, 1); 331 Xid xid = new MyXid(); 332 JMSClient client = new JMSClient(recoveryQueue); 333 try 334 { 335 client.enlist(xid); 336 assertNotNull(client.receiveNoWait()); 337 client.delist(xid); 338 int result = client.prepare(xid); 339 assertEquals(XAResource.XA_OK, result); 340 List xids = client.recover(); 341 assertEquals(1, xids.size()); 342 assertXidEquals(xid, (Xid ) xids.get(0)); 343 } 344 finally 345 { 346 client.close(); 347 } 348 assertEquals(0, clearDestination(recoveryQueue)); 349 350 client = new JMSClient(recoveryQueue); 351 try 352 { 353 List xids = client.recover(); 354 assertEquals(1, xids.size()); 355 assertXidEquals(xid, (Xid ) xids.get(0)); 356 client.rollback(xid); 357 xids = client.recover(); 358 assertEquals(0, xids.size()); 359 } 360 finally 361 { 362 client.close(); 363 } 364 assertEquals(1, clearDestination(recoveryQueue)); 365 } 366 finally 367 { 368 undeployRecoveryService(); 369 } 370 } 371 372 381 public void testReceivePrepareForgetDifferentConnection() throws Exception 382 { 383 deployRecoveryService(); 384 try 385 { 386 reset(recoveryQueue); 387 setup(recoveryQueue, 1); 388 Xid xid = new MyXid(); 389 JMSClient client = new JMSClient(recoveryQueue); 390 try 391 { 392 client.enlist(xid); 393 assertNotNull(client.receiveNoWait()); 394 client.delist(xid); 395 int result = client.prepare(xid); 396 assertEquals(XAResource.XA_OK, result); 397 List xids = client.recover(); 398 assertEquals(1, xids.size()); 399 assertXidEquals(xid, (Xid ) xids.get(0)); 400 } 401 finally 402 { 403 client.close(); 404 } 405 assertEquals(0, clearDestination(recoveryQueue)); 406 407 client = new JMSClient(recoveryQueue); 408 try 409 { 410 List xids = client.recover(); 411 assertEquals(1, xids.size()); 412 assertXidEquals(xid, (Xid ) xids.get(0)); 413 client.forget(xid); 414 xids = client.recover(); 415 assertEquals(0, xids.size()); 416 } 417 finally 418 { 419 client.close(); 420 } 421 assertEquals(1, clearDestination(recoveryQueue)); 422 } 423 finally 424 { 425 undeployRecoveryService(); 426 } 427 } 428 429 438 public void testReceivePrepareCommitDifferentConnectionRestart() throws Exception 439 { 440 deployRecoveryService(); 441 try 442 { 443 reset(recoveryQueue); 444 setup(recoveryQueue, 1); 445 Xid xid = new MyXid(); 446 JMSClient client = new JMSClient(recoveryQueue); 447 try 448 { 449 client.enlist(xid); 450 assertNotNull(client.receiveNoWait()); 451 client.delist(xid); 452 int result = client.prepare(xid); 453 assertEquals(XAResource.XA_OK, result); 454 List xids = client.recover(); 455 assertEquals(1, xids.size()); 456 assertXidEquals(xid, (Xid ) xids.get(0)); 457 } 458 finally 459 { 460 client.close(); 461 } 462 463 assertEquals(0, clearDestination(recoveryQueue)); 464 465 restartRecoveryService(); 466 assertEquals(0, clearDestination(recoveryQueue)); 467 468 client = new JMSClient(recoveryQueue); 469 try 470 { 471 List xids = client.recover(); 472 assertEquals(1, xids.size()); 473 assertXidEquals(xid, (Xid ) xids.get(0)); 474 client.commit(xid); 475 xids = client.recover(); 476 assertEquals(0, xids.size()); 477 } 478 finally 479 { 480 client.close(); 481 } 482 assertEquals(0, clearDestination(recoveryQueue)); 483 } 484 finally 485 { 486 undeployRecoveryService(); 487 } 488 } 489 490 499 public void testReceivePrepareRollbackDifferentConnectionRestart() throws Exception 500 { 501 deployRecoveryService(); 502 try 503 { 504 reset(recoveryQueue); 505 setup(recoveryQueue, 1); 506 Xid xid = new MyXid(); 507 JMSClient client = new JMSClient(recoveryQueue); 508 try 509 { 510 client.enlist(xid); 511 assertNotNull(client.receiveNoWait()); 512 client.delist(xid); 513 int result = client.prepare(xid); 514 assertEquals(XAResource.XA_OK, result); 515 List xids = client.recover(); 516 assertEquals(1, xids.size()); 517 assertXidEquals(xid, (Xid ) xids.get(0)); 518 } 519 finally 520 { 521 client.close(); 522 } 523 assertEquals(0, clearDestination(recoveryQueue)); 524 525 restartRecoveryService(); 526 assertEquals(0, clearDestination(recoveryQueue)); 527 528 client = new JMSClient(recoveryQueue); 529 try 530 { 531 List xids = client.recover(); 532 assertEquals(1, xids.size()); 533 assertXidEquals(xid, (Xid ) xids.get(0)); 534 client.rollback(xid); 535 xids = client.recover(); 536 assertEquals(0, xids.size()); 537 } 538 finally 539 { 540 client.close(); 541 } 542 assertEquals(1, clearDestination(recoveryQueue)); 543 } 544 finally 545 { 546 undeployRecoveryService(); 547 } 548 } 549 550 559 public void testReceivePrepareForgetDifferentConnectionRestart() throws Exception 560 { 561 deployRecoveryService(); 562 try 563 { 564 reset(recoveryQueue); 565 setup(recoveryQueue, 1); 566 Xid xid = new MyXid(); 567 JMSClient client = new JMSClient(recoveryQueue); 568 try 569 { 570 client.enlist(xid); 571 assertNotNull(client.receiveNoWait()); 572 client.delist(xid); 573 int result = client.prepare(xid); 574 assertEquals(XAResource.XA_OK, result); 575 List xids = client.recover(); 576 assertEquals(1, xids.size()); 577 assertXidEquals(xid, (Xid ) xids.get(0)); 578 } 579 finally 580 { 581 client.close(); 582 } 583 assertEquals(0, clearDestination(recoveryQueue)); 584 585 restartRecoveryService(); 586 assertEquals(0, clearDestination(recoveryQueue)); 587 588 client = new JMSClient(recoveryQueue); 589 try 590 { 591 List xids = client.recover(); 592 assertEquals(1, xids.size()); 593 assertXidEquals(xid, (Xid ) xids.get(0)); 594 client.forget(xid); 595 xids = client.recover(); 596 assertEquals(0, xids.size()); 597 } 598 finally 599 { 600 client.close(); 601 } 602 assertEquals(1, clearDestination(recoveryQueue)); 603 } 604 finally 605 { 606 undeployRecoveryService(); 607 } 608 } 609 610 protected void deployRecoveryService() throws Exception 611 { 612 super.deployRecoveryService(); 613 InitialContext ctx = getInitialContext(); 614 recoveryQueue = (Queue ) ctx.lookup(RECOVERY_QUEUE); 615 } 616 } 617 | Popular Tags |