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 CrashAfterTxCommittedWithFailedXARetryAtRecoveryTimeTestCase 40 extends JBossCrashRecoveryTestCase 41 { 42 private Logger log = Logger.getLogger(this.getClass()); 43 44 public CrashAfterTxCommittedWithFailedXARetryAtRecoveryTimeTestCase( 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 xaRes3.clearAfterCommitException(); 91 } 92 else 93 { 94 log.info("Unexpected throwable:", e); 95 fail("Unexpected throwable: " + e); 96 } 97 } 98 99 int xa1CommitsAfter = xaRes1.getCommittedCount(); 100 int xa2CommitsAfter = xaRes2.getCommittedCount(); 101 int xa3CommitsAfter = xaRes3.getCommittedCount(); 102 103 log.info("Commits after crash: " + xa1CommitsAfter + ", " 104 + xa2CommitsAfter + ", " + xa3CommitsAfter); 105 106 assertEquals(N, xa1CommitsBefore); 107 assertEquals(N, xa2CommitsBefore); 108 assertEquals(N, xa3CommitsBefore); 109 assertEquals(N + 1, xa1CommitsAfter); 110 assertEquals(N, xa2CommitsAfter); 111 assertEquals(N + 1, xa3CommitsAfter); 112 } 113 114 public static Test suite() throws Exception 115 { 116 return suite(CrashAfterTxCommittedWithFailedXARetryAtRecoveryTimeTestCase.class); 117 } 118 119 } 120 | Popular Tags |