1 22 package org.jboss.test.recover.test; 23 24 import javax.transaction.xa.XAException ; 25 26 import junit.framework.Test; 27 28 import org.jboss.logging.Logger; 29 import org.jboss.test.recover.interfaces.DummyXAResource; 30 import org.jboss.test.recover.interfaces.StatelessFoo; 31 import org.jboss.tm.recovery.RecoveryTestingException; 32 33 39 public class CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase 40 extends JBossCrashRecoveryTestCase 41 { 42 private Logger log = Logger.getLogger(this.getClass()); 43 44 public CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase( 45 String name) 46 { 47 super(name); 48 } 49 50 public void test() throws Exception 51 { 52 log.info("*** starting " + getUnqualifiedClassName() + " ***"); 53 54 DummyXAResource xaRes1 = getXAResource("DummyRecoverableProxy1"); 55 DummyXAResource xaRes2 = getXAResource("DummyRecoverableProxy2"); 56 DummyXAResource xaRes3 = getXAResource("DummyRecoverableProxy3"); 57 58 xaRes1.clear(); 59 xaRes2.clear(); 60 xaRes3.clear(); 61 62 StatelessFoo foo = 63 (StatelessFoo) getInitialContext().lookup("StatelessFoo"); 64 65 for (int i = 0; i < N; i++) 66 foo.method(); 67 68 int xa1CommitsBefore = xaRes1.getCommittedCount(); 69 int xa2CommitsBefore = xaRes2.getCommittedCount(); 70 int xa3CommitsBefore = xaRes3.getCommittedCount(); 71 72 log.info("Commits before crash: " + xa1CommitsBefore + ", " 73 + xa2CommitsBefore + ", " + xa3CommitsBefore); 74 75 try 76 { 77 xaRes2.setCommitErrorCode(XAException.XA_RETRY); 78 xaRes3.setAfterCommitException(new RecoveryTestingException( 79 "FAILURE AFTER XA3 WAS COMMITTED")); 80 foo.method(); 81 fail("Server crash expected."); 82 } 83 catch (Throwable e) 84 { 85 if (e instanceof java.lang.reflect.UndeclaredThrowableException 86 && e.getCause() != null 87 && e.getCause() instanceof java.rmi.MarshalException ) 88 { 89 log.info("Expected throwable:", e); 90 xaRes2.clearCommitErrorCode(); 91 xaRes3.clearAfterCommitException(); 92 } 93 else 94 { 95 log.info("Unexpected throwable:", e); 96 fail("Unexpected throwable: " + e); 97 } 98 } 99 100 int xa1CommitsAfter = xaRes1.getCommittedCount(); 101 int xa2CommitsAfter = xaRes2.getCommittedCount(); 102 int xa3CommitsAfter = xaRes3.getCommittedCount(); 103 104 log.info("Commits after crash: " + xa1CommitsAfter + ", " 105 + xa2CommitsAfter + ", " + xa3CommitsAfter); 106 107 assertEquals(N, xa1CommitsBefore); 108 assertEquals(N, xa2CommitsBefore); 109 assertEquals(N, xa3CommitsBefore); 110 assertEquals(N + 1, xa1CommitsAfter); 111 assertEquals(N, xa2CommitsAfter); 112 assertEquals(N + 1, xa3CommitsAfter); 113 } 114 115 public static Test suite() throws Exception 116 { 117 return suite(CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase.class); 118 } 119 120 } 121 | Popular Tags |