KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > callback > pull > memory > callbackstore > CallbackStoreCallbackTestCase


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.callback.pull.memory.callbackstore;
8
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11 import junit.textui.TestRunner;
12 import org.jboss.dtf.DistributedTestCase;
13 import org.jgroups.Address;
14
15 import java.io.IOException JavaDoc;
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 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 invoker, this is the class to use.
25  *
26  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
27  */

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

120    public void receiveAssert(Address source, String JavaDoc message)
121    {
122       super.receiveAssert(source, message);
123       results.add("Assert source: " + source + "\tmessage: " + message);
124    }
125
126    public static Test suite()
127    {
128       return new TestSuite(CallbackStoreCallbackTestCase.class);
129    }
130
131    public static void main(String JavaDoc[] args)
132    {
133       TestRunner.run(suite());
134       System.exit(0);
135    }
136
137
138 }
Popular Tags