KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > partition > test > PartitionRestartUnitTestCase


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
23 package org.jboss.test.cluster.partition.test;
24
25 import javax.management.ObjectName JavaDoc;
26 import javax.naming.Context JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
32 import org.jboss.test.JBossClusteredTestCase;
33 import org.jboss.test.testbean.interfaces.StatefulSessionHome;
34 import org.jboss.test.testbeancluster.interfaces.NodeAnswer;
35 import org.jboss.test.testbeancluster.interfaces.StatefulSession;
36
37 /**
38  * Tests that a restart of ClusterPartition works properly.
39  *
40  * @author <a HREF="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
41  * @version $Revision$
42  */

43 public class PartitionRestartUnitTestCase extends JBossClusteredTestCase
44 {
45    /**
46     * Create a new PartitionRestartUnitTestCase.
47     *
48     * @param name
49     */

50    public PartitionRestartUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public static Test suite() throws Exception JavaDoc
56    {
57       Test t1 = JBossClusteredTestCase.getDeploySetup(PartitionRestartUnitTestCase.class, "testbeancluster.jar");
58       return t1;
59    }
60    
61    public void testStatefulBeanFailover()
62    throws Exception JavaDoc
63    {
64       getLog().debug("testStatefulBeanFailover");
65       
66       RMIAdaptor[] adaptors = this.getAdaptors();
67       
68       Context JavaDoc ctx = new InitialContext JavaDoc();
69       getLog().debug("OK");
70       
71       getLog().debug("");
72       getLog().debug("Looking up the home nextgen.StatefulSession...");
73       StatefulSessionHome statefulSessionHome =
74       (StatefulSessionHome) ctx.lookup("nextgen_StatefulSession");
75       if (statefulSessionHome!= null ) getLog().debug("ok");
76          getLog().debug("Calling create on StatefulSessionHome...");
77       StatefulSession statefulSession =
78          (StatefulSession)statefulSessionHome.create("Bupple-Dupple");
79       assertTrue("statefulSessionHome.create() != null", statefulSession != null);
80       getLog().debug("ok");
81       
82       NodeAnswer node1 = statefulSession.getNodeState ();
83       getLog ().debug (node1);
84       
85       // Now we switch to the other node, simulating a failure on node 1
86
//
87
System.setProperty ("JBossCluster-DoFail", "once");
88       NodeAnswer node2 = statefulSession.getNodeState ();
89       getLog ().debug (node2);
90       
91       assertTrue ("Failover has occured", !node1.nodeId.equals (node2.nodeId));
92       
93       assertTrue ("Value is identical on replicated node",
94                   "Bupple-Dupple".equals (node1.answer) &&
95                   node1.answer.equals (node2.answer) );
96
97       // Stop and restart the ClusterPartition on node1
98
restartPartition(adaptors[0]);
99       
100       // Let the cluster stabilize
101
sleep(2000);
102       
103       // we change our name to see if it replicates to node 1
104
//
105
statefulSession.setName ("Changed");
106       
107       // now we travel back to node 1
108
System.setProperty ("JBossCluster-DoFail", "once");
109       node1 = statefulSession.getNodeState ();
110       getLog ().debug (node1);
111       
112       assertTrue ("Failover has occured", !node1.nodeId.equals (node2.nodeId));
113       
114       assertTrue ("Value is identical on replicated node", "Changed".equals (node1.answer) );
115       
116       statefulSession.remove();
117       getLog().debug("ok");
118    }
119    
120    
121    protected void restartPartition(RMIAdaptor adaptor) throws Exception JavaDoc
122    {
123       ObjectName JavaDoc partition = new ObjectName JavaDoc("jboss:service=DefaultPartition");
124       
125       Object JavaDoc[] params = new Object JavaDoc[0];
126       String JavaDoc[] types = new String JavaDoc[0];
127       adaptor.invoke(partition, "stop", params, types);
128       
129       sleep(2000);
130       
131       adaptor.invoke(partition, "start", params, types);
132       
133       sleep(2000);
134    }
135
136 }
137
Popular Tags