KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > oneway > OnewayInvokerTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.oneway;
8
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11 import junit.textui.TestRunner;
12 import org.apache.log4j.Level;
13 import org.jboss.dtf.DistributedTestCase;
14 import org.jgroups.Address;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 /**
21  * This should be used as the main test case for the oneway invoker client/server.
22  * It will start one instance of the client and one of the server and will
23  * gather the test results and report them in standard JUnit format. When
24  * wanting to run JUnit test for oneway invoker, this is the class to use.
25  *
26  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
27  */

28 public class OnewayInvokerTestCase extends DistributedTestCase
29 {
30    private List JavaDoc results = new ArrayList JavaDoc();
31
32    public OnewayInvokerTestCase(String JavaDoc name)
33    {
34       super(name);
35    }
36
37    protected void setUp() throws Exception JavaDoc
38    {
39       Thread.currentThread().sleep(4000);
40
41       String JavaDoc clientcmd = "java -cp " + System.getProperty("java.class.path") +
42 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.local.dir") +
43
" " + OnewayInvokerClientTest.class.getName() + " 3";
44       System.out.println("clientcmd: " + clientcmd);
45       String JavaDoc svrcmd = "java -cp " + System.getProperty("java.class.path") +
46 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.remote.dir") +
47
" " + OnewayInvokerServer.class.getName() + " 3";
48       System.out.println("svrcmd: " + svrcmd);
49
50       final Process JavaDoc local = Runtime.getRuntime().exec(clientcmd);
51       final Process JavaDoc remote = Runtime.getRuntime().exec(svrcmd);
52
53    }
54
55    protected void tearDown() throws Exception JavaDoc
56    {
57       //NO OP since manually controlling shutdown
58
}
59
60    public void testInvokers()
61    {
62       try
63       {
64          startup(3);
65          System.out.println("startup() called");
66          shutdown();
67          System.out.println("shutdown() called");
68       }
69       catch(Exception JavaDoc e)
70       {
71          e.printStackTrace();
72          assertTrue("Problem starting or stopping client/server processes.", false);
73       }
74       finally
75       {
76          // assert results
77
try
78          {
79             Thread.currentThread().sleep(10000);
80          }
81          catch(InterruptedException JavaDoc e)
82          {
83             e.printStackTrace();
84          }
85          System.out.println("results.size() = " + results.size());
86          if(results.size() > 0)
87          {
88             Iterator JavaDoc itr = results.iterator();
89             while(itr.hasNext())
90             {
91                String JavaDoc message = (String JavaDoc) itr.next();
92                assertTrue(message, false);
93             }
94          }
95          else
96          {
97             assertTrue("No test failures or errors.", true);
98          }
99
100       }
101    }
102
103    /**
104     * **********************************
105     * Driver callback for JUnit asserts *
106     * ***********************************
107     */

108    public void receiveAssert(Address source, String JavaDoc message)
109    {
110       super.receiveAssert(source, message);
111       results.add("Assert source: " + source + "\tmessage: " + message);
112    }
113
114    public static Test suite()
115    {
116       return new TestSuite(OnewayInvokerTestCase.class);
117    }
118
119    public static void main(String JavaDoc[] args)
120    {
121       org.apache.log4j.BasicConfigurator.configure();
122       org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
123       org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO);
124       org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
125       org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG);
126
127       TestRunner.run(suite());
128       System.exit(0);
129    }
130
131
132 }
Popular Tags