KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > test > CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.recover.test;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
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 /**
35  * A CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase.
36  *
37  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
38  * @version $Revision: 37406 $
39  */

40 public class CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase
41       extends JBossCrashRecoveryIIOPTestCase
42 {
43    private Logger log = Logger.getLogger(this.getClass());
44
45    public CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase(String JavaDoc name)
46       throws Exception JavaDoc
47    {
48       super(name);
49    }
50    
51    public void test() throws Exception JavaDoc
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 JavaDoc 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          // XAResource usage is as follows:
85
// - xaResEnlisterCaller (the root coordinator) enlists xaRes1
86
// - the first XAResourceEnlister (remote resource 1) enlists xaRes2
87
// - the second XAResourceEnlister (remote resource 2) enlists xaRes3
88
//
89
// This will make remote resource 2 crash after prepare,
90
// when it issues commit to xaRes3:
91
xaRes3.setCommitException(new RecoveryTestingException(
92                                        "FAILURE WHEN XA3 WAS ABOUT TO COMMIT"));
93
94          // Run the transaction. The commit call to xaRes2 will not be
95
// performed now, due to the resource crash. It will be performed
96
// by the recovery procedure of appserver that contains resource 1.
97
xaResEnlisterCaller.enlistOneXAResourcePerAppServerOverIIOP();
98
99          // Clear crash-causing exception so that commit will succeed at
100
// recovery time.
101
xaRes3.clearCommitException();
102       }
103       catch (Throwable JavaDoc 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 JavaDoc
134    {
135       return suite(CrashOfSecondRemoteResourceAfterPrepareIIOPTestCase.class);
136    }
137
138 }
139
Popular Tags