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 28 import junit.framework.Test; 29 30 import org.jboss.logging.Logger; 31 import org.jboss.test.recover.interfaces.DummyXAResource; 32 import org.jboss.test.recover.interfaces.StatelessFoo; 33 34 40 public class CrashAfterTxCommittedTestCase 41 extends JBossCrashRecoveryTestCase 42 { 43 private Logger log = Logger.getLogger(this.getClass()); 44 private MBeanServerConnection server = delegate.getServer(); 45 46 public CrashAfterTxCommittedTestCase(String name) 47 throws Exception 48 { 49 super(name); 50 } 51 52 public void test() throws Exception 53 { 54 log.info("*** starting " + getUnqualifiedClassName() + " ***"); 55 56 DummyXAResource xaRes1 = getXAResource("DummyRecoverableProxy1"); 57 DummyXAResource xaRes2 = getXAResource("DummyRecoverableProxy2"); 58 DummyXAResource xaRes3 = getXAResource("DummyRecoverableProxy3"); 59 60 xaRes1.clear(); 61 xaRes2.clear(); 62 xaRes3.clear(); 63 64 StatelessFoo foo = 65 (StatelessFoo) getInitialContext().lookup("StatelessFoo"); 66 67 for (int i = 0; i < N; i++) 68 foo.method(); 69 70 int xa1CommitsBefore = xaRes1.getCommittedCount(); 71 int xa2CommitsBefore = xaRes2.getCommittedCount(); 72 int xa3CommitsBefore = xaRes3.getCommittedCount(); 73 74 log.info("Commits before crash: " + xa1CommitsBefore + ", " 75 + xa2CommitsBefore + ", " + xa3CommitsBefore); 76 77 ObjectName logger = new ObjectName ("jboss:service=RecoveryLogger"); 78 try 79 { 80 server.setAttribute(logger, new Attribute ("CrashOnFailure", 81 Boolean.TRUE)); 82 server.setAttribute(logger, new Attribute ("FailAfterCommitting", 83 Boolean.TRUE)); 84 server.setAttribute(logger, new Attribute ("FailAfter", 85 new Integer (0))); 86 foo.method(); 87 fail("Server crash expected."); 88 } 89 catch (Throwable e) 90 { 91 if (e instanceof java.lang.reflect.UndeclaredThrowableException 92 && e.getCause() != null 93 && e.getCause() instanceof java.rmi.MarshalException ) 94 { 95 log.info("Expected throwable:", e); 96 } 97 else 98 { 99 log.info("Unexpected throwable:", e); 100 fail("Unexpected throwable: " + e); 101 } 102 } 103 104 int xa1CommitsAfter = xaRes1.getCommittedCount(); 105 int xa2CommitsAfter = xaRes2.getCommittedCount(); 106 int xa3CommitsAfter = xaRes3.getCommittedCount(); 107 108 log.info("Commits after crash: " + xa1CommitsAfter + ", " 109 + xa2CommitsAfter + ", " + xa3CommitsAfter); 110 111 assertEquals(N, xa1CommitsBefore); 112 assertEquals(N, xa2CommitsBefore); 113 assertEquals(N, xa3CommitsBefore); 114 assertEquals(N, xa1CommitsAfter); 115 assertEquals(N, xa2CommitsAfter); 116 assertEquals(N, xa3CommitsAfter); 117 } 118 119 public static Test suite() throws Exception 120 { 121 return suite(CrashAfterTxCommittedTestCase.class); 122 } 123 124 } 125 | Popular Tags |