use of org.apache.zookeeper.server.quorum.Leader.Proposal in project zookeeper by apache.
the class RestoreCommittedLogTest method testRestoreCommittedLog.
/**
* test the purge
* @throws Exception an exception might be thrown here
*/
private void testRestoreCommittedLog(int totalTransactions, byte[] data, int minExpectedSnapshots) throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up ");
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
for (int i = 0; i < totalTransactions; i++) {
zk.create("/invalidsnap-" + i, data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} finally {
zk.close();
}
final int numSnaps = zks.getTxnLogFactory().findNRecentSnapshots(10 * minExpectedSnapshots).size();
LOG.info("number of snapshots taken {}", numSnaps);
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server to shutdown");
assertTrue(numSnaps > minExpectedSnapshots, "too few snapshot files");
assertTrue(numSnaps <= minExpectedSnapshots * 2, "too many snapshot files");
// start server again
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
zks.startdata();
Collection<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
int logsize = committedLog.size();
LOG.info("committedLog size = {}", logsize);
assertTrue((logsize != 0), "log size != 0");
zks.shutdown();
}
Aggregations