Author: jmesnil
Date: 2009-11-18 13:10:11 -0500 (Wed, 18 Nov 2009)
New Revision: 8313
Modified:
trunk/tests/src/org/hornetq/tests/integration/remoting/PingTest.java
Log:
rewrite testClientFailureNoServerPing using latch
Modified: trunk/tests/src/org/hornetq/tests/integration/remoting/PingTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/remoting/PingTest.java 2009-11-18
16:58:55 UTC (rev 8312)
+++ trunk/tests/src/org/hornetq/tests/integration/remoting/PingTest.java 2009-11-18
18:10:11 UTC (rev 8313)
@@ -14,6 +14,8 @@
package org.hornetq.tests.integration.remoting;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.client.ClientSessionFactory;
@@ -25,6 +27,7 @@
import org.hornetq.core.config.TransportConfiguration;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.remoting.CloseListener;
import org.hornetq.core.remoting.RemotingConnection;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.ServiceTestBase;
@@ -298,8 +301,28 @@
assertEquals(1, ((ClientSessionFactoryInternal)csf).numConnections());
- Listener clientListener = new Listener();
+ final CountDownLatch clientLatch = new CountDownLatch(1);
+ SessionFailureListener clientListener = new SessionFailureListener()
+ {
+ public void connectionFailed(HornetQException me)
+ {
+ clientLatch.countDown();
+ }
+ public void beforeReconnect(HornetQException exception)
+ {
+ }
+ };
+
+ final CountDownLatch serverLatch = new CountDownLatch(1);
+ CloseListener serverListener = new CloseListener()
+ {
+ public void connectionClosed()
+ {
+ serverLatch.countDown();
+ }
+ };
+
session.addFailureListener(clientListener);
RemotingConnection serverConn = null;
@@ -317,28 +340,29 @@
Thread.sleep(10);
}
}
+
+ serverConn.addCloseListener(serverListener);
- Listener serverListener = new Listener();
-
- serverConn.addFailureListener(serverListener);
-
//Setting the handler to null will prevent server sending pings back to client
serverConn.getChannel(0, -1).setHandler(null);
- for (int i = 0; i < 2000; i++)
+ assertTrue(clientLatch.await(4 * CLIENT_FAILURE_CHECK_PERIOD,
TimeUnit.MILLISECONDS));
+
+ //Server connection will be closed too, when client closes client side connection
after failure is detected
+ assertTrue(serverLatch.await(8 * CLIENT_FAILURE_CHECK_PERIOD,
TimeUnit.MILLISECONDS));
+
+ long start = System.currentTimeMillis();
+ while (true)
{
- // a few tries to avoid a possible race caused by GCs or similar issues
- if (server.getRemotingService().getConnections().isEmpty() &&
clientListener.getException() != null)
+ if (!server.getRemotingService().getConnections().isEmpty() &&
System.currentTimeMillis() - start < 10000)
{
+ Thread.sleep(500);
+ }
+ else
+ {
break;
}
-
- Thread.sleep(10);
}
-
- assertNotNull(clientListener.getException());
-
- //Server connection will be closed too, when client closes client side connection
after failure is detected
assertTrue(server.getRemotingService().getConnections().isEmpty());
session.close();
Show replies by date