KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > performance > PerformanceTest


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.performance;
8
9 import org.jboss.dtf.DistributedTestCase;
10 import org.jgroups.Address;
11
12 import java.io.IOException JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
19  */

20 public abstract class PerformanceTest extends DistributedTestCase
21 {
22    public static final int NUM_OF_THREADS = 10;
23    public static final int NUM_OF_CALLS = 500;
24
25    private List JavaDoc results = new ArrayList JavaDoc();
26    protected String JavaDoc transport = "socket";
27    protected int port = 4555;
28
29    public PerformanceTest(String JavaDoc name)
30    {
31       super(name);
32    }
33
34    protected void setUp() throws Exception JavaDoc
35    {
36       transport = System.getProperty("remoting.transport", transport);
37       port = Integer.valueOf(System.getProperty("remoting.port", String.valueOf(port))).intValue();
38
39       String JavaDoc clientFQN = getClientFQN();
40       String JavaDoc serverFQN = getServerFQN();
41
42       String JavaDoc clientcmd = "java -cp " + System.getProperty("java.class.path") +
43 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.local.dir") +
44
" " + clientFQN + " " + transport + " " + port + " 3";
45       System.out.println("clientcmd: " + clientcmd);
46       String JavaDoc svrcmd = "java -cp " + System.getProperty("java.class.path") +
47 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.remote.dir") +
48
" " + serverFQN + " " + transport + " " + port + " 3";
49       System.out.println("svrcmd: " + svrcmd);
50
51       final Process JavaDoc local = Runtime.getRuntime().exec(clientcmd);
52       final Process JavaDoc remote = Runtime.getRuntime().exec(svrcmd);
53    }
54
55    public abstract String JavaDoc getClientFQN();
56
57    public abstract String JavaDoc getServerFQN();
58
59    protected void tearDown() throws Exception JavaDoc
60    {
61       //NO OP since manually controlling shutdown
62
}
63
64    public void testInvokers()
65    {
66       try
67       {
68          startup(3);
69          System.out.println("startup() called");
70          shutdown();
71          System.out.println("shutdown() called");
72       }
73       catch(Exception JavaDoc e)
74       {
75          e.printStackTrace();
76          try
77          {
78             PerformanceReporter.writeReport("Error in test. Instances either failed to start or stop.", 0, 0, null);
79          }
80          catch(IOException JavaDoc e1)
81          {
82             e1.printStackTrace();
83          }
84          assertTrue("Problem starting or stopping client/server processes.", false);
85       }
86       finally
87       {
88          // assert results
89
try
90          {
91             Thread.currentThread().sleep(10000);
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 }
127
Popular Tags