1
package org.jboss.test.remoting.transport.socket.load;
3
import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
4
import junit.framework.TestCase;
5
import org.apache.log4j.Logger;
6
import org.jboss.remoting.Client;
7
import org.jboss.remoting.InvokerLocator;
8
import org.jboss.remoting.transport.Connector;
10
public class PooledConnectionTestCase extends TestCase
12
private static int numOfRunnerThreads = 10;
13
// private static int numOfRunnerThreads = 3;
14
private static SynchronizedInt responseCount = new SynchronizedInt(0);
15
private Connector connector;
19
// BasicConfigurator.configure();
20
// Logger.getRootLogger().setLevel(Level.INFO);
21
// Logger.getInstance("org.jboss.remoting.transport.socket").setLevel(Level.ALL);
24
private Logger logger = Logger.getRootLogger();
26
protected String getTransport()
31
public static void main(String[] args) throws Throwable
33
PooledConnectionTestCase rt = new PooledConnectionTestCase();
35
// rt.runMultipleClients(Integer.parseInt(args[1]));
36
rt.runMultipleClients(PooledConnectionTestCase.numOfRunnerThreads);
39
public void setUp() throws Exception
44
public void tearDown() throws Exception
53
public void startServer() throws Exception
55
String locatorURI = getTransport() + "://localhost:54000/?maxPoolSize=10&timeout=10000";
56
InvokerLocator locator = new InvokerLocator(locatorURI);
58
connector = new Connector();
60
connector.setInvokerLocator(locator.getLocatorURI());
63
SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
64
connector.addInvocationHandler("sample", invocationHandler);
68
public void testRunClients() throws Throwable
70
runMultipleClients(PooledConnectionTestCase.numOfRunnerThreads);
71
// waiting 8 seconds as the server handler will have waited client calls
72
// 5 seconds, but should only be able to make client invocations 2 at a time.
73
Thread.currentThread().sleep(8000);
74
// should not have all invocations as should be blocking within client invoker (as only
75
// allows 2 concurrent client connections).
76
assertFalse(10 == PooledConnectionTestCase.responseCount.get());
78
Thread.currentThread().sleep(120000);
79
System.out.println("Response count = " + PooledConnectionTestCase.responseCount + ". Expected 10.");
80
assertEquals(10, PooledConnectionTestCase.responseCount.get());
83
public void runClient(String clientId) throws Throwable
85
String locatorURI = getTransport() + "://localhost:54000/?clientMaxPoolSize=2";
86
InvokerLocator locator = new InvokerLocator(locatorURI);
87
Client client = new Client(locator);
89
String req = clientId;
90
Object resp = client.invoke(req);
91
PooledConnectionTestCase.responseCount.increment();
92
System.out.println("Received response of: " + resp + ". Response count = " + PooledConnectionTestCase.responseCount);
96
public void runMultipleClients(int cnt) throws Throwable {
97
for (int i = 0; i < cnt; i++) {
98
Thread t = new Thread(new Runnable() {
102
runClient(Thread.currentThread().getName());
103
} catch (Throwable e) {
108
}, Integer.toString(i));