KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > clusteredsession > unit > StatelessUnitTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 JavaDoc;
15 import javax.naming.InitialContext JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.Properties JavaDoc;
18
19 import junit.framework.Test;
20
21 /**
22  * Test slsb for load-balancing behaviour and others.
23  *
24  * @author Ben.Wang@jboss.org
25  * @version $Revision: 46483 $
26  */

27 public class StatelessUnitTestCase extends JBossClusteredTestCase
28 {
29    static boolean deployed = false;
30    public static int test = 0;
31    static Date JavaDoc startDate = new Date JavaDoc();
32
33    protected final String JavaDoc namingFactory =
34    System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
35
36    protected final String JavaDoc providerURL =
37    System.getProperty(Context.PROVIDER_URL);
38
39    public StatelessUnitTestCase (String JavaDoc name)
40    {
41       super(name);
42    }
43
44    public static Test suite() throws Exception JavaDoc
45    {
46       final String JavaDoc jarName = "clusteredsession-test.jar";
47       return JBossClusteredTestCase.getDeploySetup(StatelessUnitTestCase.class,
48               jarName);
49    }
50
51    protected InitialContext JavaDoc getInitialContext(int node) throws Exception JavaDoc {
52       // Connect to the server0 JNDI
53
String JavaDoc[] urls = getNamingURLs();
54       Properties JavaDoc env1 = new Properties JavaDoc();
55       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
56          "org.jnp.interfaces.NamingContextFactory");
57       env1.setProperty(Context.PROVIDER_URL, urls[node]);
58       return new InitialContext JavaDoc(env1);
59    }
60
61    public void testLoadbalance()
62    throws Exception JavaDoc
63    {
64       getLog().debug(++StatelessUnitTestCase.test +"- "+"Trying the context...");
65
66       InitialContext JavaDoc 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