KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > callback > pull > memory > nullstore > NullStoreCallbackTestCase


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.nullstore;
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 NullStoreCallbackTestCase extends DistributedTestCase
29 {
30    private List JavaDoc results = new ArrayList JavaDoc();
31
32    public NullStoreCallbackTestCase(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          startup(3);
76          System.out.println("startup() called");
77          shutdown();
78          System.out.println("shutdown() called");
79       }
80       catch(Exception JavaDoc e)
81       {
82          e.printStackTrace();
83          assertTrue("Problem starting or stopping client/server processes.", false);
84       }
85       finally
86       {
87          // assert results
88
try
89          {
90             Thread.currentThread().sleep(5000);
91          }
92          catch(InterruptedException JavaDoc e)
93          {
94             e.printStackTrace();
95          }
96          System.out.println("results.size() = " + results.size());
97          if(results.size() > 0)
98          {
99             Iterator JavaDoc itr = results.iterator();
100             while(itr.hasNext())
101             {
102                String JavaDoc message = (String JavaDoc) itr.next();
103                assertTrue(message, false);
104             }
105          }
106          else
107          {
108             assertTrue("No test failures or errors.", true);
109          }
110
111       }
112    }
113
114    /**
115     * **********************************
116     * Driver callback for JUnit asserts *
117     * ***********************************
118     */

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