Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
node.start();
final CountDownLatch connectedLatch = new CountDownLatch(1);
final CountDownLatch reconnectedLatch = new CountDownLatch(1);
final AtomicReference<ConnectionState> lastState = new AtomicReference<ConnectionState>();
ConnectionStateListener listener = new ConnectionStateListener()
{
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
lastState.set(newState);
if ( newState == ConnectionState.CONNECTED )
{
connectedLatch.countDown();
}
if ( newState == ConnectionState.RECONNECTED )
{
reconnectedLatch.countDown();
}
}
};
client.getConnectionStateListenable().addListener(listener);
timing.sleepABit();
server = new TestingServer(server.getPort());
Assert.assertTrue(timing.awaitLatch(connectedLatch));
timing.sleepABit();
Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
server.close();
timing.sleepABit();
server = new TestingServer(server.getPort());
timing.sleepABit();
Assert.assertTrue(timing.awaitLatch(reconnectedLatch));