KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Test;
25
26 import org.jboss.logging.Logger;
27 import org.jboss.test.recover.interfaces.DummyXAResource;
28 import org.jboss.test.recover.interfaces.StatelessFoo;
29 import org.jboss.tm.recovery.RecoveryTestingException;
30
31 /**
32  * A CrashAfterOneResourceButNotAllHaveCommittedTestCase.
33  *
34  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
35  * @version $Revision: 37929 $
36  */

37 public class CrashAfterOneResourceButNotAllHaveCommittedTestCase
38       extends JBossCrashRecoveryTestCase
39 {
40    private Logger log = Logger.getLogger(this.getClass());
41
42    public CrashAfterOneResourceButNotAllHaveCommittedTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46    
47    public void test() throws Exception JavaDoc
48    {
49       log.info("*** starting " + getUnqualifiedClassName() + " ***");
50       
51       DummyXAResource xaRes1 = getXAResource("DummyRecoverableProxy1");
52       DummyXAResource xaRes2 = getXAResource("DummyRecoverableProxy2");
53       DummyXAResource xaRes3 = getXAResource("DummyRecoverableProxy3");
54
55       xaRes1.clear();
56       xaRes2.clear();
57       xaRes3.clear();
58
59       StatelessFoo foo =
60          (StatelessFoo) getInitialContext().lookup("StatelessFoo");
61
62       for (int i = 0; i < N; i++)
63          foo.method();
64          
65       int xa1CommitsBefore = xaRes1.getCommittedCount();
66       int xa2CommitsBefore = xaRes2.getCommittedCount();
67       int xa3CommitsBefore = xaRes3.getCommittedCount();
68
69       log.info("Commits before crash: " + xa1CommitsBefore + ", "
70                + xa2CommitsBefore + ", " + xa3CommitsBefore);
71
72       try
73       {
74          xaRes2.setCommitException(new RecoveryTestingException(
75                                        "FAILURE WHEN XA2 WAS ABOUT TO COMMIT"));
76          foo.method();
77          fail("Server crash expected.");
78       }
79       catch (Throwable JavaDoc e)
80       {
81          if (e instanceof java.lang.reflect.UndeclaredThrowableException JavaDoc
82                && e.getCause() != null
83                && e.getCause() instanceof java.rmi.MarshalException JavaDoc)
84          {
85             log.info("Expected throwable:", e);
86             xaRes2.clearCommitException();
87          }
88          else
89          {
90             log.info("Unexpected throwable:", e);
91             fail("Unexpected throwable: " + e);
92          }
93       }
94
95       int xa1CommitsAfter = xaRes1.getCommittedCount();
96       int xa2CommitsAfter = xaRes2.getCommittedCount();
97       int xa3CommitsAfter = xaRes3.getCommittedCount();
98
99       log.info("Commits after crash: " + xa1CommitsAfter + ", "
100             + xa2CommitsAfter + ", " + xa3CommitsAfter);
101
102       assertEquals(N, xa1CommitsBefore);
103       assertEquals(N, xa2CommitsBefore);
104       assertEquals(N, xa3CommitsBefore);
105       assertEquals(N + 1, xa1CommitsAfter);
106       assertEquals(N, xa2CommitsAfter);
107       assertEquals(N, xa3CommitsAfter);
108    }
109
110    public static Test suite() throws Exception JavaDoc
111    {
112       return suite(CrashAfterOneResourceButNotAllHaveCommittedTestCase.class);
113    }
114
115 }
116
Popular Tags