@Test
public void testEnsureBaseNodeFails() throws Exception {

  Mockito.doThrow(new KeeperException.ConnectionLossException())
    .when(mockZK).create(
        Mockito.eq(ZK_PARENT_NAME), Mockito.<byte[]>any(),
        Mockito.eq(Ids.OPEN_ACL_UNSAFE), Mockito.eq(CreateMode.PERSISTENT));
  try {
    elector.ensureParentZNode();
    Assert.fail("Did not throw!");
  } catch (IOException ioe) {
    if (!(ioe.getCause() instanceof KeeperException.ConnectionLossException)) {
      throw ioe;
    }
  }
  // Should have tried three times
  Mockito.verify(mockZK, Mockito.times(3)).create(
      Mockito.eq(ZK_PARENT_NAME), Mockito.<byte[]>any(),
      Mockito.eq(Ids.OPEN_ACL_UNSAFE), Mockito.eq(CreateMode.PERSISTENT));
}