1 22 package org.jboss.test.recover.test; 23 24 import javax.management.Attribute ; 25 import javax.management.MBeanServerConnection ; 26 import javax.management.ObjectName ; 27 import javax.rmi.PortableRemoteObject ; 28 import javax.transaction.TransactionRolledbackException ; 29 30 import junit.framework.Test; 31 32 import org.jboss.logging.Logger; 33 import org.jboss.test.recover.interfaces.DummyXAResource; 34 import org.jboss.test.recover.interfaces.XAResourceEnlisterCaller; 35 import org.jboss.test.recover.interfaces.XAResourceEnlisterCallerHome; 36 37 43 public class CrashOfSecondRemoteResourceBeforeItPreparesIIOPTestCase 44 extends JBossCrashRecoveryIIOPTestCase 45 { 46 private Logger log = Logger.getLogger(this.getClass()); 47 48 public CrashOfSecondRemoteResourceBeforeItPreparesIIOPTestCase(String name) 49 throws Exception 50 { 51 super(name); 52 } 53 54 public void test() throws Exception 55 { 56 log.info("*** starting " + getUnqualifiedClassName() + " ***"); 57 58 DummyXAResource xaRes1 = getXAResource("DummyRecoverableProxy1"); 59 DummyXAResource xaRes2 = getXAResource("DummyRecoverableProxy2"); 60 DummyXAResource xaRes3 = getXAResource("DummyRecoverableProxy3"); 61 62 xaRes1.clear(); 63 xaRes2.clear(); 64 xaRes3.clear(); 65 66 Object obj; 67 XAResourceEnlisterCallerHome home; 68 69 obj = getInitialContext().lookup( 70 "dtmrectest/XAResourceEnlisterCallerEJB"); 71 home = (XAResourceEnlisterCallerHome) 72 PortableRemoteObject.narrow(obj, XAResourceEnlisterCallerHome.class); 73 XAResourceEnlisterCaller xaResEnlisterCaller = home.create(); 74 75 for (int i = 0; i < N; i++) 76 xaResEnlisterCaller.callXAResourceEnlistersOverIIOP(); 77 78 int xa1CommitsBefore = xaRes1.getCommittedCount(); 79 int xa2CommitsBefore = xaRes2.getCommittedCount(); 80 int xa3CommitsBefore = xaRes3.getCommittedCount(); 81 82 log.info("Commits before crash of remote resource: " + xa1CommitsBefore + 83 ", " + xa2CommitsBefore + ", " + xa3CommitsBefore); 84 85 ObjectName logger = new ObjectName ("jboss:service=RecoveryLogger"); 86 MBeanServerConnection secondResource = getResource2Server(); 87 try 88 { 89 secondResource.setAttribute(logger, new Attribute ("CrashOnFailure", 95 Boolean.TRUE)); 96 secondResource.setAttribute(logger, new Attribute ("FailBeforePreparing", 97 Boolean.TRUE)); 98 secondResource.setAttribute(logger, new Attribute ("FailBefore", 99 new Integer (0))); 100 xaResEnlisterCaller.callXAResourceEnlistersOverIIOP(); 101 fail("TransactionRolledbackException expected."); 102 } 103 catch (TransactionRolledbackException e) 104 { 105 log.info("Expected exception: ", e); 106 } 107 catch (Throwable e) 108 { 109 log.info("Unexpected throwable:", e); 110 fail("Unexpected throwable: " + e); 111 } 112 113 int xa1CommitsAfter = xaRes1.getCommittedCount(); 114 int xa2CommitsAfter = xaRes2.getCommittedCount(); 115 int xa3CommitsAfter = xaRes3.getCommittedCount(); 116 117 int xa1Rollbacks = xaRes1.getRollbackCount(); 118 int xa2Rollbacks = xaRes2.getRollbackCount(); 119 int xa3Rollbacks = xaRes3.getRollbackCount(); 120 121 log.info("Commits after crash of remote resource: " + xa1CommitsAfter + 122 ", " + xa2CommitsAfter + ", " + xa3CommitsAfter); 123 log.info("Rollbacks after crash of remote resource: " + xa1CommitsAfter + 124 ", " + xa2CommitsAfter + ", " + xa3CommitsAfter); 125 126 assertEquals(3 * N, xa1CommitsBefore); 127 assertEquals(3 * N, xa2CommitsBefore); 128 assertEquals(2 * N, xa3CommitsBefore); 129 assertEquals(3 * N, xa1CommitsAfter); 130 assertEquals(3 * N, xa2CommitsAfter); 131 assertEquals(2 * N, xa3CommitsAfter); 132 assertEquals(2, xa1Rollbacks); 138 assertEquals(2, xa2Rollbacks); 139 assertEquals(1, xa3Rollbacks); 140 } 141 142 public static Test suite() throws Exception 143 { 144 return suite(CrashOfSecondRemoteResourceBeforeItPreparesIIOPTestCase.class); 145 } 146 147 } 148 | Popular Tags |