1 22 package org.jboss.test.recover.test; 23 24 import javax.rmi.PortableRemoteObject ; 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.XAResourceEnlisterCaller; 31 import org.jboss.test.recover.interfaces.XAResourceEnlisterCallerHome; 32 import org.jboss.tm.recovery.RecoveryTestingException; 33 34 40 public class CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase 41 extends JBossCrashRecoveryIIOPTestCase 42 { 43 private Logger log = Logger.getLogger(this.getClass()); 44 45 public CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase(String name) 46 throws Exception 47 { 48 super(name); 49 } 50 51 public void test() throws Exception 52 { 53 log.info("*** starting " + getUnqualifiedClassName() + " ***"); 54 55 DummyXAResource xaRes1 = getXAResource("DummyRecoverableProxy1"); 56 DummyXAResource xaRes2 = getXAResource("DummyRecoverableProxy2"); 57 DummyXAResource xaRes3 = getXAResource("DummyRecoverableProxy3"); 58 59 xaRes1.clear(); 60 xaRes2.clear(); 61 xaRes3.clear(); 62 63 Object obj; 64 XAResourceEnlisterCallerHome home; 65 66 obj = getInitialContext().lookup( 67 "dtmrectest/XAResourceEnlisterCallerEJB"); 68 home = (XAResourceEnlisterCallerHome) 69 PortableRemoteObject.narrow(obj, XAResourceEnlisterCallerHome.class); 70 XAResourceEnlisterCaller xaResEnlisterCaller = home.create(); 71 72 for (int i = 0; i < N; i++) 73 xaResEnlisterCaller.enlistOneXAResourcePerAppServerOverIIOP(); 74 75 int xa1CommitsBefore = xaRes1.getCommittedCount(); 76 int xa2CommitsBefore = xaRes2.getCommittedCount(); 77 int xa3CommitsBefore = xaRes3.getCommittedCount(); 78 79 log.info("Commits before crash of remote resource: " + xa1CommitsBefore + 80 ", " + xa2CommitsBefore + ", " + xa3CommitsBefore); 81 82 try 83 { 84 xaRes3.setCommitException(new RecoveryTestingException( 92 "FAILURE WHEN XA3 WAS ABOUT TO COMMIT")); 93 94 xaResEnlisterCaller.enlistOneXAResourcePerAppServerOverIIOP(); 98 99 xaRes3.clearCommitException(); 102 } 103 catch (Throwable e) 104 { 105 log.info("Unexpected throwable:", e); 106 fail("Unexpected throwable: " + e); 107 } 108 109 int xa1CommitsAfter = xaRes1.getCommittedCount(); 110 int xa2CommitsAfter = xaRes2.getCommittedCount(); 111 int xa3CommitsAfter = xaRes3.getCommittedCount(); 112 113 int xa1Rollbacks = xaRes1.getRollbackCount(); 114 int xa2Rollbacks = xaRes2.getRollbackCount(); 115 int xa3Rollbacks = xaRes3.getRollbackCount(); 116 117 log.info("Commits after crash of remote resource: " + xa1CommitsAfter + 118 ", " + xa2CommitsAfter + ", " + xa3CommitsAfter); 119 log.info("Rollbacks after crash of remote resource: " + xa1CommitsAfter + 120 ", " + xa2CommitsAfter + ", " + xa3CommitsAfter); 121 122 assertEquals(N, xa1CommitsBefore); 123 assertEquals(N, xa2CommitsBefore); 124 assertEquals(N, xa3CommitsBefore); 125 assertEquals(N + 1, xa1CommitsAfter); 126 assertEquals(N + 1, xa2CommitsAfter); 127 assertEquals(N, xa3CommitsAfter); 128 assertEquals(0, xa1Rollbacks); 129 assertEquals(0, xa2Rollbacks); 130 assertEquals(0, xa3Rollbacks); 131 } 132 133 public static Test suite() throws Exception 134 { 135 return suite(CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase.class); 136 } 137 138 } 139 | Popular Tags |