1
package org.jboss.test.remoting.concurrent.local;
3
import junit.framework.TestCase;
4
import org.jboss.remoting.Client;
5
import org.jboss.remoting.InvocationRequest;
6
import org.jboss.remoting.InvokerLocator;
7
import org.jboss.remoting.ServerInvocationHandler;
8
import org.jboss.remoting.ServerInvoker;
9
import org.jboss.remoting.callback.InvokerCallbackHandler;
10
import org.jboss.remoting.transport.Connector;
12
import javax.management.MBeanServer;
15
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
17
public class ConcurrentTestCase extends TestCase
19
private String locatorUri = "socket://localhost:8777";
20
private boolean failure = false;
21
private Client client = null;
22
private Connector connector = null;
23
private int numOfThreads = 100;
24
private int numOfIterations = 100;
25
private int[][] results = null;
27
public void setUp() throws Exception
29
connector = new Connector(locatorUri);
31
connector.addInvocationHandler("test", new TestInvocationHandler());
34
client = new Client(new InvokerLocator(locatorUri));
36
results = new int[numOfThreads][numOfIterations];
40
public void testConcurrentInvocations() throws Exception
43
for(int x = 0; x < numOfThreads; x++)
46
new Thread(new Runnable() {
53
catch (Throwable throwable)
55
throwable.printStackTrace();
65
assertTrue(validateResults());
69
private boolean validateResults()
71
boolean failed = true;
73
for(int z = 0; z < numOfThreads; z++)
75
for(int q = 1; q < numOfIterations; q++)
77
int a = results[z][q -1];
78
int b = results[z][q];
79
//System.out.println("a = " + a + ", b = " + b + ((b -1 != a) ? " - FAILED" : ""));
89
private void runInvocations(int num) throws Throwable
91
for(int i = 0; i < numOfIterations; i++)
93
String param = num + "-" + i;
94
Object result = client.invoke(param);
95
//System.out.println(Thread.currentThread() + " - " + result);
96
assertEquals(param, result);
97
String subResult = ((String)result).substring(String.valueOf(num).length() + 1);
98
//System.out.println(Thread.currentThread() + " - " + subResult);
99
results[num][i] = Integer.parseInt(subResult);
103
public void tearDown()
105
if(connector != null)
117
public class TestInvocationHandler implements ServerInvocationHandler
120
public void setMBeanServer(MBeanServer server)
122
//TODO: -TME Implement
125
public void setInvoker(ServerInvoker invoker)
127
//TODO: -TME Implement
130
public Object invoke(InvocationRequest invocation) throws Throwable
132
return invocation.getParameter();
135
public void addListener(InvokerCallbackHandler callbackHandler)
137
//TODO: -TME Implement
140
public void removeListener(InvokerCallbackHandler callbackHandler)
142
//TODO: -TME Implement