*/
public void testRecovery() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
int oldSnapCount = SyncRequestProcessor.snapCount;
SyncRequestProcessor.snapCount = 1000;
try {
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(PORT);
f.startup(zs);
LOG.info("starting up the the server, waiting");
assertTrue("waiting for server up",
ClientBase.waitForServerUp(HOSTPORT,
CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
String path;
LOG.info("starting creating nodes");
for (int i = 0; i < 10; i++) {
path = "/" + i;
zk.create(path,
(path + "!").getBytes(),
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
for (int j = 0; j < 10; j++) {
String subpath = path + "/" + j;
zk.create(subpath, (subpath + "!").getBytes(),
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
for (int k = 0; k < 20; k++) {
String subsubpath = subpath + "/" + k;
zk.create(subsubpath, (subsubpath + "!").getBytes(),
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
}
f.shutdown();
assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
CONNECTION_TIMEOUT));
zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
f = new NIOServerCnxn.Factory(PORT);
startSignal = new CountDownLatch(1);
f.startup(zs);
assertTrue("waiting for server up",
ClientBase.waitForServerUp(HOSTPORT,
CONNECTION_TIMEOUT));
startSignal.await(CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS);
assertTrue("count == 0", startSignal.getCount() == 0);
Stat stat = new Stat();
for (int i = 0; i < 10; i++) {
path = "/" + i;
LOG.info("Checking " + path);
assertEquals(new String(zk.getData(path, false, stat)), path
+ "!");
for (int j = 0; j < 10; j++) {
String subpath = path + "/" + j;
assertEquals(new String(zk.getData(subpath, false, stat)),
subpath + "!");
for (int k = 0; k < 20; k++) {
String subsubpath = subpath + "/" + k;
assertEquals(new String(zk.getData(subsubpath, false,
stat)), subsubpath + "!");
}
}
}
f.shutdown();
assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT));
zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
f = new NIOServerCnxn.Factory(PORT);
startSignal = new CountDownLatch(1);
f.startup(zs);