1 22 23 package org.jboss.test.cluster.partition.test; 24 25 import javax.management.ObjectName ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 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 43 public class PartitionRestartUnitTestCase extends JBossClusteredTestCase 44 { 45 50 public PartitionRestartUnitTestCase(String name) 51 { 52 super(name); 53 } 54 55 public static Test suite() throws Exception 56 { 57 Test t1 = JBossClusteredTestCase.getDeploySetup(PartitionRestartUnitTestCase.class, "testbeancluster.jar"); 58 return t1; 59 } 60 61 public void testStatefulBeanFailover() 62 throws Exception 63 { 64 getLog().debug("testStatefulBeanFailover"); 65 66 RMIAdaptor[] adaptors = this.getAdaptors(); 67 68 Context ctx = new InitialContext (); 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 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 restartPartition(adaptors[0]); 99 100 sleep(2000); 102 103 statefulSession.setName ("Changed"); 106 107 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 122 { 123 ObjectName partition = new ObjectName ("jboss:service=DefaultPartition"); 124 125 Object [] params = new Object [0]; 126 String [] types = new String [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 |