1
package org.jboss.test.remoting.transport.socket.connection;
3
import junit.framework.TestCase;
4
import org.jboss.remoting.Client;
5
import org.jboss.remoting.InvokerLocator;
6
import org.jboss.remoting.transport.socket.SocketServerInvoker;
9
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
11
public class SocketConnectionCheckTestClient extends TestCase
13
// Default locator values
14
private static String transport = "socket";
15
private static String host = "localhost";
16
private static int port = 5400;
18
public void testInvocations() throws Throwable
20
Client remotingClient = null;
26
String locatorURI = getTransport() + "://" + host + ":" + getPort() + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
28
// create InvokerLocator with the url type string
29
// indicating the target remoting server to call upon.
30
InvokerLocator locator = new InvokerLocator(locatorURI);
31
System.out.println("Calling remoting server with locator uri of: " + locatorURI);
33
remotingClient = new Client(locator);
34
remotingClient.connect();
35
String request = "Do something";
36
System.out.println("Invoking server with request of '" + request + "'");
38
long startTime = System.currentTimeMillis();
40
int numOfCalls = 10000;
41
Object response = null;
42
for(int x = 0; x < numOfCalls; x++)
44
response = remotingClient.invoke(request);
45
// System.out.println("Invocation response: " + response);
48
long endTime = System.currentTimeMillis();
49
System.out.println("Time to make " + numOfCalls + " was " + (endTime -startTime) + " milliseconds.");
52
if(response instanceof Integer)
54
callValue = ((Integer) response).intValue();
56
assertEquals(numOfCalls, callValue);
61
if(remotingClient != null)
63
remotingClient.disconnect();
69
protected String getTransport()
74
protected int getPort()
80
* Can pass transport and port to be used as parameters.
81
* Valid transports are 'rmi' and 'socket'.
85
public static void main(String[] args)
87
if(args != null && args.length == 3)
91
port = Integer.parseInt(args[2]);
93
SocketConnectionCheckTestClient client = new SocketConnectionCheckTestClient();
96
client.testInvocations();