@Test
public void testConnectionLossWillLeadToStartupFailure() {

    ZookeeperConfiguration config = mock(ZookeeperConfiguration.class);
    when(config.getZkConnectionString()).thenReturn("127.0.0.1:44444");
    ZookeeperClusterResolver clusterResolver = new DefaultZookeeperClusterResolver(config);
    try {
        CuratorServiceImpl cs = closeable.autoCloseable(new CuratorServiceImpl(config, clusterResolver, new DefaultRegistry()), CuratorServiceImpl::shutdown);
        cs.start();
        ZookeeperLeaderElector elector = new ZookeeperLeaderElector(leaderActivator, cs, zkPaths, masterDescription, titusRuntime);
        elector.join();
        fail("The elector should fail fast");
    } catch (IllegalStateException e) {
        assertEquals("The cause should be from ZK connection failure", CuratorConnectionLossException.class, e.getCause().getClass());
        assertTrue("The error message is unexpected: " + e.getMessage(), e.getCause().getMessage().contains("ConnectionLoss"));
    }
}