1 22 package org.jboss.test.testbeancluster.test; 23 24 25 import java.util.Date ; 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 30 import junit.framework.Test; 31 32 import org.jboss.test.testbeancluster.interfaces.StatelessSession; 33 import org.jboss.test.testbean.interfaces.StatelessSessionHome; 34 import org.jboss.test.testbeancluster.interfaces.StatefulSession; 35 import org.jboss.test.testbean.interfaces.StatefulSessionHome; 36 37 import org.jboss.test.JBossClusteredTestCase; 38 import org.jboss.test.testbeancluster.interfaces.NodeAnswer; 39 40 56 57 public class BeanUnitTestCaseNew extends JBossClusteredTestCase 58 { 59 static boolean deployed = false; 60 public static int test = 0; 61 static Date startDate = new Date (); 62 63 private String [] servernames= {"jnp://localhost:1099", "jnp://localhost:1199"}; 64 65 protected final String namingFactory = 66 System.getProperty(Context.INITIAL_CONTEXT_FACTORY); 67 68 protected final String providerURL = 69 System.getProperty(Context.PROVIDER_URL); 70 71 public BeanUnitTestCaseNew (String name) { 72 super(name); 73 try{ 74 this.setServerNames(servernames); 78 }catch(Exception e){ 79 getLog().debug( "Passing servernames croacked"); 80 } 81 } 82 83 public static Test suite() throws Exception 84 { 85 Test t1 = JBossClusteredTestCase.getDeploySetup(BeanUnitTestCaseNew.class, "testbeancluster.jar"); 86 return t1; 87 } 88 89 public void testStatelessBeanLoadBalancing() 90 throws Exception 91 { 92 getLog().debug(++test+"- "+"Trying the context..."); 93 94 Context ctx = new InitialContext (); 95 getLog().debug("OK"); 96 97 getLog().debug(""); 99 getLog().debug("Test Stateless Bean load-balancing"); 100 getLog().debug("=================================="); 101 getLog().debug(""); 102 getLog().debug(++test+"- "+"Looking up the home nextgen.StatelessSession..."); 103 StatelessSessionHome statelessSessionHome = 104 (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession"); 105 if (statelessSessionHome!= null ) getLog().debug("ok"); 106 getLog().debug(++test+"- "+"Calling create on StatelessSessionHome..."); 107 StatelessSession statelessSession = 108 (StatelessSession)statelessSessionHome.create(); 109 assertTrue("statelessSessionHome.create() != null", statelessSession != null); 110 getLog().debug("ok"); 111 112 getLog().debug(++test+"- "+"Calling getEJBHome() on StatelessSession..."); 113 assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null); 114 getLog().debug("ok"); 115 116 getLog().debug(++test+"- "+"Reseting the number of calls made on beans (making 2 calls)... "); 117 for (int i=0; i<6; i++) 118 { 119 getLog().debug(++test+"- "+" Reseting number... "); 120 statelessSession.resetNumberOfCalls (); 121 } 122 123 getLog().debug(++test+"- "+"Now making 20 calls on this remote... "); 124 for (int i=0; i<20; i++) 125 { 126 getLog().debug(++test+"- "+" Calling remote... "); 127 statelessSession.makeCountedCall (); 128 } 129 130 getLog().debug(++test+"- "+"Getting the number of calls that have been performed on each bean... "); 131 long node1 = statelessSession.getCallCount(); 132 getLog().debug(++test+"- "+"One node has received: " + node1); 133 134 long node2 = statelessSession.getCallCount(); 135 getLog().debug(++test+"- "+"The other node has received: " + node2); 136 137 if (node1 == node2 && 138 node1 == 10) 139 { 140 getLog().debug(++test+"- "+"Test is ok."); 141 } 142 else 143 { 144 getLog().debug(++test+"- "+"Something wrong has happened! Calls seems not to have been load-balanced."); 145 fail ("Calls have not been correctly load-balanced on the SLSB remote interface."); 146 } 147 148 statelessSession.remove(); 149 getLog().debug("ok"); 150 } 151 152 public void testStatefulBeanFailover() 153 throws Exception 154 { 155 getLog().debug(++test+"- "+"Trying the context..."); 156 157 Context ctx = new InitialContext (); 158 getLog().debug("OK"); 159 160 getLog().debug(""); 162 getLog().debug("Test Stateful Bean Failover"); 163 getLog().debug("=================================="); 164 getLog().debug(""); 165 getLog().debug(++test+"- "+"Looking up the home nextgen.StatefulSession..."); 166 StatefulSessionHome statefulSessionHome = 167 (StatefulSessionHome) ctx.lookup("nextgen.StatefulSession"); 168 if (statefulSessionHome!= null ) getLog().debug("ok"); 169 getLog().debug(++test+"- "+"Calling create on StatefulSessionHome..."); 170 StatefulSession statefulSession = 171 (StatefulSession)statefulSessionHome.create("Bupple-Dupple"); 172 assertTrue("statefulSessionHome.create() != null", statefulSession != null); 173 getLog().debug("ok"); 174 175 NodeAnswer node1 = statefulSession.getNodeState (); 176 getLog ().debug (node1); 177 178 System.setProperty ("JBossCluster-DoFail", "once"); 181 NodeAnswer node2 = statefulSession.getNodeState (); 182 getLog ().debug (node2); 183 184 assertTrue ("No failover has occured!", !node1.nodeId.equals (node2.nodeId)); 185 186 assertTrue ("Value is not identical on replicated node", "Bupple-Dupple".equals (node1.answer) && 187 node1.answer.equals (node2.answer) ); 188 189 statefulSession.setName ("Changed"); 192 193 System.setProperty ("JBossCluster-DoFail", "once"); 196 node1 = statefulSession.getNodeState (); 197 getLog ().debug (node1); 198 199 assertTrue ("No failover has occured!", !node1.nodeId.equals (node2.nodeId)); 200 201 assertTrue ("Value is not identical on replicated node", "Changed".equals (node1.answer) ); 202 203 statefulSession.remove(); 204 getLog().debug("ok"); 205 } 206 207 } 208 | Popular Tags |