locator.setBlockOnDurableSend(true);
locator.setFailoverOnInitialConnection(true);
locator.setReconnectAttempts(-1);
((ServerLocatorInternal)locator).setIdentity("testAutoFailback");
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
final CountDownLatch latch = new CountDownLatch(1);
ClientSession session = sendAndConsume(sf, true);
System.out.println(locator.getTopology().describe());
MyListener listener = new MyListener(latch);
session.addFailureListener(listener);
System.out.println(locator.getTopology().describe());
liveServer.crash();
assertTrue(latch.await(5, TimeUnit.SECONDS));
log.info("backup (nowLive) topology = " + backupServer.getServer().getClusterManager().getDefaultConnection().getTopology().describe());
log.info("Server Crash!!!");
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
ClientMessage message = session.createMessage(true);
setBody(0, message);
producer.send(message);
verifyMessageOnServer(1, 1);
System.out.println(locator.getTopology().describe());
session.removeFailureListener(listener);
final CountDownLatch latch2 = new CountDownLatch(1);
listener = new MyListener(latch2);
session.addFailureListener(listener);
log.info("******* starting live server back");
liveServer.start();
Thread.sleep(1000);
System.out.println("After failback: " + locator.getTopology().describe());
assertTrue(latch2.await(5, TimeUnit.SECONDS));
message = session.createMessage(true);
setBody(1, message);
producer.send(message);
session.close();
verifyMessageOnServer(0, 1);
sf.close();
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(0, sf.numConnections());
}