1 7 8 package org.jboss.ejb3.test.clusteredsession.unit; 9 10 import org.jboss.test.JBossClusteredTestCase; 11 import org.jboss.ejb3.test.clusteredsession.NodeAnswer; 12 import org.jboss.ejb3.test.clusteredsession.ClusteredStatelessRemote; 13 14 import javax.naming.Context ; 15 import javax.naming.InitialContext ; 16 import java.util.Date ; 17 import java.util.Properties ; 18 19 import junit.framework.Test; 20 21 27 public class StatelessUnitTestCase extends JBossClusteredTestCase 28 { 29 static boolean deployed = false; 30 public static int test = 0; 31 static Date startDate = new Date (); 32 33 protected final String namingFactory = 34 System.getProperty(Context.INITIAL_CONTEXT_FACTORY); 35 36 protected final String providerURL = 37 System.getProperty(Context.PROVIDER_URL); 38 39 public StatelessUnitTestCase (String name) 40 { 41 super(name); 42 } 43 44 public static Test suite() throws Exception 45 { 46 final String jarName = "clusteredsession-test.jar"; 47 return JBossClusteredTestCase.getDeploySetup(StatelessUnitTestCase.class, 48 jarName); 49 } 50 51 protected InitialContext getInitialContext(int node) throws Exception { 52 String [] urls = getNamingURLs(); 54 Properties env1 = new Properties (); 55 env1.setProperty(Context.INITIAL_CONTEXT_FACTORY, 56 "org.jnp.interfaces.NamingContextFactory"); 57 env1.setProperty(Context.PROVIDER_URL, urls[node]); 58 return new InitialContext (env1); 59 } 60 61 public void testLoadbalance() 62 throws Exception 63 { 64 getLog().debug(++StatelessUnitTestCase.test +"- "+"Trying the context..."); 65 66 InitialContext ctx = getInitialContext(0); 67 68 getLog().debug("Test Stateless Bean loadbalancing"); 69 getLog().debug("=================================="); 70 getLog().debug(++StatelessUnitTestCase.test +"- " 71 +"Looking up testStatless..."); 72 ClusteredStatelessRemote stateless = (ClusteredStatelessRemote) ctx.lookup("clusteredStateless/remote"); 73 74 NodeAnswer node1 = stateless.getNodeState (); 75 getLog ().debug ("Node 1 ID: " +node1); 76 77 stateless = (ClusteredStatelessRemote) ctx.lookup("clusteredStateless/remote"); 78 NodeAnswer node2 = stateless.getNodeState (); 79 getLog ().debug ("Node 2 ID : " +node2); 80 81 assertNotSame (node1.nodeId, node2.nodeId); 82 } 83 } 84 | Popular Tags |