1
package org.jboss.test.remoting.transport.socket.timeout.idle;
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;
10
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
12
public class IdleTimeoutClientTest extends TestCase
15
// private static int numOfRunnerThreads = 10;
16
private static int numOfRunnerThreads = 2;
17
private static SynchronizedInt responseCount = new SynchronizedInt(0);
19
private Logger logger = Logger.getRootLogger();
21
protected String getTransport()
26
public static void main(String[] args) throws Throwable
28
IdleTimeoutClientTest rt = new IdleTimeoutClientTest();
29
// rt.runMultipleClients(Integer.parseInt(args[1]));
30
rt.runMultipleClients(numOfRunnerThreads);
33
public void testRunClients() throws Throwable
35
String locatorURI = getTransport() + "://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
36
InvokerLocator locator = new InvokerLocator(locatorURI);
37
Client client = new Client(locator);
39
Object resp = client.invoke(Boolean.TRUE);
40
Boolean isFirst = (Boolean)resp;
41
System.out.println("client is first = " + isFirst);
43
Thread.currentThread().sleep(10000);
45
if(isFirst.booleanValue())
47
Thread.currentThread().sleep(10000);
50
runMultipleClients(numOfRunnerThreads);
51
Thread.currentThread().sleep(30000);
52
System.out.println("done with first timeout.");
53
runMultipleClients(numOfRunnerThreads);
54
Thread.currentThread().sleep(12000);
56
System.out.println("response count = " + responseCount.get());
57
assertEquals(4, responseCount.get());
60
public void runClient(String clientId) throws Throwable
62
String locatorURI = "socket://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
63
InvokerLocator locator = new InvokerLocator(locatorURI);
64
Client client = new Client(locator);
66
String req = clientId;
67
Object resp = client.invoke(req);
68
responseCount.increment();
69
System.out.println("Received response of: " + resp + ". Response count = " + responseCount);
72
public void runMultipleClients(int cnt) throws Throwable {
73
for (int i = 0; i < cnt; i++) {
74
Thread t = new Thread(new Runnable() {
78
runClient(Thread.currentThread().getName());
79
} catch (Throwable e) {
84
}, Integer.toString(i));