ZkManager { public static CuratorFramework curatorFramework() { if (curatorFramework != null) { return curatorFramework; } else synchronized (ZkManager.class) { if (curatorFramework == null) { final String quorum = System.getProperty("zk.quorum", "localhost"); final int sessionTimeout = Integer.parseInt( System.getProperty("zk.session.timeout", "30000")); final int connectionTimeout = Integer.parseInt( System.getProperty("zk.connection.timeout", "15000")); final int initialDelay = Integer.parseInt( System.getProperty("zk.retry.initialDelay", "10")); final int maxDelay = Integer.parseInt( System.getProperty("zk.retry.maxDelay", "200")); final int maxCount = Integer.parseInt( System.getProperty("zk.retry.maxCount", "10")); logger.info("Initializing the Zookeeper client for quorum: {}", quorum); final CuratorFramework curator = CuratorFrameworkFactory.newClient(quorum, sessionTimeout, connectionTimeout, new BoundedExponentialBackoffRetry(initialDelay, maxDelay, maxCount)); curator.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { logger.info("Shutting down the Zookeeper client..."); curator.close(); })); curatorFramework = curator.usingNamespace(namespace("/")); } return curatorFramework; } } private  ZkManager(); static CuratorFramework curatorFramework();  }
@Test public void shouldExposeAValidCurator() throws Exception { final CuratorFramework curator = ZkManager.curatorFramework(); assertEquals(curator.getState(), CuratorFrameworkState.STARTED); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void shouldNotAllowClosingTheFramework() { ZkManager.curatorFramework().close(); }