return super.makeZooKeeperClient(connectString, sessionTimeout);
}
};
sessiong = session;
final ClusterId clusterId = new ClusterId(appname,"testRecoverWithIOException");
TestUtils.createClusterLevel(clusterId, session);
TestWatcher callback = new TestWatcher(session)
{
@Override public void process()
{
try {
session.getSubdirs(clusterId.asPath(),this);
called.set(true);
}
catch (ClusterInfoException cie) { throw new RuntimeException(cie); }
}
};
callback.process();
// force the ioexception to happen
forceIOException.set(true);
ZookeeperTestServer.forceSessionExpiration(session.zkref.get());
// now in the background it should be retrying but hosed.
assertTrue(forceIOExceptionLatch.await(baseTimeoutMillis * 3, TimeUnit.MILLISECONDS));
// now the getActiveSlots call should fail since i'm preventing the recovery by throwing IOExceptions
assertTrue(TestUtils.poll(baseTimeoutMillis, clusterId, new Condition<ClusterId>()
{
@Override
public boolean conditionMet(ClusterId o) throws Throwable {
try { session.mkdir(o.asPath() + "/join-1", null, DirMode.EPHEMERAL); return false; } catch (ClusterInfoException e) { return true; }
}
}));
callback.called.set(false); // reset the callbacker ...
// now we should allow the code to proceed.
forceIOException.set(false);
// wait for the callback
assertTrue(poll(baseTimeoutMillis,callback,new Condition<TestWatcher>() { @Override public boolean conditionMet(TestWatcher o) { return o.called.get(); } }));
// this should eventually recover.
assertTrue(TestUtils.poll(baseTimeoutMillis, clusterId, new Condition<ClusterId>()
{
@Override
public boolean conditionMet(ClusterId o) throws Throwable {
try { TestUtils.createClusterLevel(o, session); session.mkdir(o.asPath() + "/join-1", null, DirMode.EPHEMERAL); return true; } catch (ClusterInfoException e) { return false; }
}
}));
session.getSubdirs(clusterId.asPath(),callback);
// And join should work
// And join should work
assertTrue(TestUtils.poll(baseTimeoutMillis,clusterId , new Condition<ClusterId>()
{