*/
public void testServerFailureNoPing() throws Exception
{
TransportConfiguration transportConfig = new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory");
ClientSessionFactoryImpl csf = (ClientSessionFactoryImpl) HornetQClient.createClientSessionFactory(transportConfig);
csf.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
csf.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);
Listener clientListener = new Listener();
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, csf.numConnections());
session.addFailureListener(clientListener);
// We need to get it to stop pinging after one
((FailoverManagerImpl)csf.getFailoverManagers()[0]).stopPingingAfterOne();
RemotingConnection serverConn = null;
while (serverConn == null)
{
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty())
{
serverConn = server.getRemotingService().getConnections().iterator().next();
}
else
{
// It's async so need to wait a while
Thread.sleep(10);
}
}
Listener serverListener = new Listener();
serverConn.addFailureListener(serverListener);
for (int i = 0; i < 1000; i++)
{
// a few tries to avoid a possible race caused by GCs or similar issues
if (server.getRemotingService().getConnections().isEmpty() && clientListener.getException() != null)
{
break;
}
Thread.sleep(10);
}
if (!server.getRemotingService().getConnections().isEmpty())
{
RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
PingTest.log.info("Serverconn2 is " + serverConn2);
}
Assert.assertTrue(server.getRemotingService().getConnections().isEmpty());
// The client listener should be called too since the server will close it from the server side which will result
// in the
// netty detecting closure on the client side and then calling failure listener
Assert.assertNotNull(clientListener.getException());
Assert.assertNotNull(serverListener.getException());
session.close();
csf.close();
}