DefaultLeaderElector extends AbstractLifecycle implements LeaderElector { @Override public void elect() throws Exception { zkClient.createContainers(ctx.getLeaderElectionZKPath()); latch = new LeaderLatch(zkClient, ctx.getLeaderElectionZKPath(), ctx.getLeaderElectionID()); latch.addListener(new LeaderLatchListener() { @Override public void notLeader() { } @Override public void isLeader() { } }); latch.start(); logger.info("[elect]{}", ctx); } DefaultLeaderElector(ElectContext ctx, CuratorFramework zkClient); @Override void elect(); @Override void doStop();  }
@Test public void testElect() throws Exception{ String zkPath = "/" + getTestName(); ElectContext electContext = new ElectContext(zkPath, "hi"); DefaultLeaderElector leaderElector = new DefaultLeaderElector(electContext, client); leaderElector.elect(); Assert.assertNotNull(client.checkExists().forPath(zkPath)); }