KickJava   Java API By Example, From Geeks To Geeks.

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


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.transaction.xa.XAException 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.StatelessFoo;
31 import org.jboss.tm.recovery.RecoveryTestingException;
32
33 /**
34  * A CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase.
35  *
36  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
37  * @version $Revision: 37929 $
38  */

39 public class CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase
40       extends JBossCrashRecoveryTestCase
41 {
42    private Logger log = Logger.getLogger(this.getClass());
43
44    public CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase(
45                                                                   String JavaDoc name)
46    {
47       super(name);
48    }
49    
50    public void test() throws Exception JavaDoc
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 JavaDoc e)
84       {
85          if (e instanceof java.lang.reflect.UndeclaredThrowableException JavaDoc
86                && e.getCause() != null
87                && e.getCause() instanceof java.rmi.MarshalException JavaDoc)
88          {
89             log.info("Expected throwable:", e);
90             xaRes2.clearCommitErrorCode();
91             xaRes3.clearAfterCommitException();
92          }
93          else
94          {
95             log.info("Unexpected throwable:", e);
96             fail("Unexpected throwable: " + e);
97          }
98       }
99
100       int xa1CommitsAfter = xaRes1.getCommittedCount();
101       int xa2CommitsAfter = xaRes2.getCommittedCount();
102       int xa3CommitsAfter = xaRes3.getCommittedCount();
103
104       log.info("Commits after crash: " + xa1CommitsAfter + ", "
105             + xa2CommitsAfter + ", " + xa3CommitsAfter);
106
107       assertEquals(N, xa1CommitsBefore);
108       assertEquals(N, xa2CommitsBefore);
109       assertEquals(N, xa3CommitsBefore);
110       assertEquals(N + 1, xa1CommitsAfter);
111       assertEquals(N, xa2CommitsAfter);
112       assertEquals(N + 1, xa3CommitsAfter);
113    }
114
115    public static Test suite() throws Exception JavaDoc
116    {
117       return suite(CrashAfterTxCommittedWithSuccessfulXARetryAtRecoveryTimeTestCase.class);
118    }
119
120 }
121
Popular Tags