[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/lease/synchronization ...
Ron Sigal
ron_sigal at yahoo.com
Fri Aug 17 16:03:19 EDT 2007
User: rsigal
Date: 07/08/17 16:03:19
Modified: src/tests/org/jboss/test/remoting/lease/synchronization
Tag: remoting_2_2_2_experimental
MultipleClientSynchronizationTestCase.java
Log:
JBREM-783, JBREM-793: Checks that all disconnect notifications are made. Thereby serves as unit test for JBREM-793.
Revision Changes Path
No revision
No revision
1.1.4.4.2.1 +146 -24 JBossRemoting/src/tests/org/jboss/test/remoting/lease/synchronization/Attic/MultipleClientSynchronizationTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MultipleClientSynchronizationTestCase.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/lease/synchronization/Attic/MultipleClientSynchronizationTestCase.java,v
retrieving revision 1.1.4.4
retrieving revision 1.1.4.4.2.1
diff -u -b -r1.1.4.4 -r1.1.4.4.2.1
--- MultipleClientSynchronizationTestCase.java 9 Aug 2007 02:56:55 -0000 1.1.4.4
+++ MultipleClientSynchronizationTestCase.java 17 Aug 2007 20:03:19 -0000 1.1.4.4.2.1
@@ -35,6 +35,7 @@
import org.apache.log4j.PatternLayout;
import org.jboss.logging.XLevel;
import org.jboss.remoting.Client;
+import org.jboss.remoting.ClientDisconnectedException;
import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
@@ -46,9 +47,10 @@
/**
+ * Unit test for JBREM-783 and JBREM-793.
*
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.4.4 $
+ * @version $Revision: 1.1.4.4.2.1 $
* <p>
* Copyright Jul 31, 2007
* </p>
@@ -62,7 +64,8 @@
protected static BooleanHolder stop1 = new BooleanHolder();
protected static BooleanHolder stop2 = new BooleanHolder();
protected static InvokerLocator locator;
- protected static int counter;
+ protected static int startCounter;
+ protected static int stopCounter;
protected static Object lock = new Object();
public void setUp() throws Exception
@@ -78,7 +81,8 @@
Logger.getRootLogger().addAppender(consoleAppender);
}
- counter = 0;
+ startCounter = 0;
+ stopCounter = 0;
}
@@ -92,7 +96,8 @@
Connector connector = new Connector(locator);
connector.create();
connector.setLeasePeriod(1000);
- connector.addConnectionListener(new TestListener());
+ TestListener listener = new TestListener();
+ connector.addConnectionListener(listener);
TestHandler handler = new TestHandler();
connector.addInvocationHandler("test", handler);
connector.start();
@@ -100,26 +105,68 @@
int INVOCATIONS = 1000;
ClientThread[] threads = new ClientThread[INVOCATIONS];
- // Start clients 0..499.
+ // Create clients 0..499.
for (int i = 0; i < INVOCATIONS / 2; i++)
{
threads[i] = new ClientThread(i, go1, stop1);
threads[i].start();
}
+ // Start clients 0..499.
go1.value = true;
- Thread.sleep(5000);
- // Stop clients 0..499 and start clients 500..999.
+ // Wait for clients 0..499 to connect.
+ for (int i = 0; i < 30; i++)
+ {
+ synchronized (lock)
+ {
+ log.debug("startCounter: " + startCounter);
+ if (startCounter == INVOCATIONS / 2)
+ break;
+ }
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ assertEquals(INVOCATIONS / 2, startCounter);
+
+ // Create clients 500..999.
for (int i = INVOCATIONS / 2; i < INVOCATIONS; i++)
{
threads[i] = new ClientThread(i, go2, stop2);
threads[i].start();
}
+ // Stop clients 0..499 and start clients 500..999.
stop1.value = true;
go2.value = true;
- Thread.sleep(5000);
+
+ // Wait for clients 500..999 to connect.
+ for (int i = 0; i < 30; i++)
+ {
+ synchronized (lock)
+ {
+ log.debug("startCounter: " + startCounter);
+ if (startCounter == INVOCATIONS)
+ break;
+ }
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ assertEquals(INVOCATIONS, startCounter);
// Stop clients 500..999.
stop2.value = true;
@@ -129,8 +176,8 @@
{
synchronized (lock)
{
- log.info("counter: " + counter);
- if (counter == INVOCATIONS)
+ log.debug("stopCounter: " + stopCounter);
+ if (stopCounter == INVOCATIONS)
break;
}
@@ -149,6 +196,11 @@
assertTrue(new Date() + ": failure in thread: " + i, threads[i].ok);
}
+ log.info("disonnects: " + listener.disconnectCounter);
+ log.info("failures: " + listener.failureCounter);
+ assertEquals(INVOCATIONS, listener.disconnectCounter);
+ assertEquals(0, listener.failureCounter);
+
connector.stop();
log.info(getName() + " PASSES");
}
@@ -162,8 +214,9 @@
locator = new InvokerLocator(locatorURI);
Connector connector = new Connector(locator);
connector.create();
- connector.setLeasePeriod(1000);
- connector.addConnectionListener(new TestListener());
+ connector.setLeasePeriod(2000);
+ TestListener listener = new TestListener();
+ connector.addConnectionListener(listener);
TestHandler handler = new TestHandler();
connector.addInvocationHandler("test", handler);
connector.start();
@@ -171,28 +224,70 @@
int INVOCATIONS = 1000;
ClientThread[] threads = new ClientThread[INVOCATIONS];
- // Start clients 0..499.
+ // Create clients 0..499.
for (int i = 0; i < INVOCATIONS / 2; i++)
{
threads[i] = new ClientThread(i, go1, stop1);
threads[i].start();
}
+ // Start clients 0..499.
go1.value = true;
- Thread.sleep(5000);
+
+ // Wait for clients 0..499 to connect.
+ for (int i = 0; i < 30; i++)
+ {
+ synchronized (lock)
+ {
+ log.debug("startCounter: " + startCounter);
+ if (startCounter == INVOCATIONS / 2)
+ break;
+ }
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ assertEquals(INVOCATIONS / 2, startCounter);
// Stop clients 0..499.
stop1.value = true;
- // Start clients 500..999.
+ // Create clients 500..999.
for (int i = INVOCATIONS / 2; i < INVOCATIONS; i++)
{
threads[i] = new ClientThread(i, go2, stop2);
threads[i].start();
}
+ // Start clients 500..999.
go2.value = true;
- Thread.sleep(5000);
+
+ // Wait for clients 500..999 to connect.
+ for (int i = 0; i < 30; i++)
+ {
+ synchronized (lock)
+ {
+ log.debug("startCounter: " + startCounter);
+ if (startCounter == INVOCATIONS)
+ break;
+ }
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ assertEquals(INVOCATIONS, startCounter);
// Stop clients 500..999.
stop2.value = true;
@@ -202,8 +297,8 @@
{
synchronized (lock)
{
- log.info("counter: " + counter);
- if (counter == INVOCATIONS)
+ log.debug("stopCounter: " + stopCounter);
+ if (stopCounter == INVOCATIONS)
break;
}
@@ -222,6 +317,10 @@
assertTrue(new Date() + ": failure in thread: " + threads[i], threads[i].ok);
}
+ log.info("disonnects: " + listener.disconnectCounter);
+ log.info("failures: " + listener.failureCounter);
+ assertEquals(INVOCATIONS, listener.disconnectCounter);
+ assertEquals(0, listener.failureCounter);
connector.stop();
log.info(getName() + " PASSES");
}
@@ -247,7 +346,7 @@
config.put(InvokerLocator.CLIENT_LEASE_PERIOD, "1000");
client = new Client(locator, config);
setName("ClientThread-" + id);
- log.info("client created (" + id + "): " + client.getSessionId());
+ log.debug("client created (" + id + "): " + client.getSessionId());
}
public void run()
@@ -261,7 +360,12 @@
log.debug("client got start flag (" + id + "): " + client.getSessionId());
client.connect();
- log.info("client connected (" + id + "): " + client.getSessionId());
+ log.debug("client connected (" + id + "): " + client.getSessionId());
+
+ synchronized (lock)
+ {
+ startCounter++;
+ }
}
catch (Throwable e)
{
@@ -280,11 +384,11 @@
client.disconnect();
// log.info("client disconnected (" + id + "): " + client.getSessionId());
ok = true;
- log.info("client ok (" + id + "):" + client.getSessionId());
+ log.debug("client ok (" + id + "):" + client.getSessionId());
synchronized (lock)
{
- counter++;
+ stopCounter++;
}
}
catch (Throwable e)
@@ -307,9 +411,27 @@
public static class TestListener implements ConnectionListener
{
+ static Object lock = new Object();
+ int disconnectCounter;
+ int failureCounter;
+
public void handleConnectionException(Throwable throwable, Client client)
{
- log.debug("got connection exception: " + throwable);
+ synchronized (lock)
+ {
+ if (throwable == null)
+ {
+ failureCounter++;
+ log.info("connection failure: " + client.getSessionId());
+ }
+ else if (throwable instanceof ClientDisconnectedException)
+ {
+ disconnectCounter++;
+ log.debug("disconnect: " + client.getSessionId());
+ }
+ else
+ log.error("received unrecognized exception: " + client.getSessionId(), throwable);
+ }
}
}
More information about the jboss-cvs-commits
mailing list