ZKFailoverController { private int formatZK(boolean force, boolean interactive) throws IOException, InterruptedException, KeeperException { if (elector.parentZNodeExists()) { if (!force && (!interactive || !confirmFormat())) { return ERR_CODE_FORMAT_DENIED; } try { elector.clearParentZNode(); } catch (IOException e) { LOG.error("Unable to clear zk parent znode", e); return 1; } } elector.ensureParentZNode(); return 0; } protected  ZKFailoverController(Configuration conf, HAServiceTarget localTarget); HAServiceTarget getLocalTarget(); @VisibleForTesting HAServiceState getServiceState(); int run(final String[] args); @VisibleForTesting ActiveStandbyElector getElectorForTests(); static final String ZK_QUORUM_KEY; static final String ZK_ACL_KEY; static final String ZK_AUTH_KEY; }
@Test public void testFormatZK() throws Exception { DummyHAService svc = cluster.getService(1); assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE, runFC(svc)); assertEquals(0, runFC(svc, "-formatZK")); assertEquals(ZKFailoverController.ERR_CODE_FORMAT_DENIED, runFC(svc, "-formatZK", "-nonInteractive")); assertEquals(0, runFC(svc, "-formatZK", "-force")); }