zkClient.createEphemeral("/" + clusterName + "/CONFIGS/CLUSTER/verify"); } catch (ZkNodeExistsException ex) { LOG.error("There is already a verification in progress", ex);
@Test public void testCloseZkClient() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); ZkClient client = new ZkClient(ZK_ADDR, HelixZkClient.DEFAULT_SESSION_TIMEOUT, HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); String path = String.format("/%s", clusterName); client.createEphemeral(path); client.close(); Assert.assertFalse(_gZkClient.exists(path), "Ephemeral node: " + path + " should be removed after ZkClient#close()"); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
@Test public void testZkSessionExpiry() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); ZkClient client = new ZkClient(ZK_ADDR, HelixZkClient.DEFAULT_SESSION_TIMEOUT, HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); String path = String.format("/%s", clusterName); client.createEphemeral(path); String oldSessionId = ZkTestHelper.getSessionId(client); ZkTestHelper.expireSession(client); String newSessionId = ZkTestHelper.getSessionId(client); Assert.assertNotSame(newSessionId, oldSessionId); Assert.assertFalse(client.exists(path), "Ephemeral znode should be gone after session expiry"); client.close(); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
@Test public void testCloseZkClientInZkClientEventThread() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); final CountDownLatch waitCallback = new CountDownLatch(1); final ZkClient client = new ZkClient(ZK_ADDR, HelixZkClient.DEFAULT_SESSION_TIMEOUT, HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); String path = String.format("/%s", clusterName); client.createEphemeral(path); client.subscribeDataChanges(path, new IZkDataListener() { @Override public void handleDataDeleted(String dataPath) throws Exception { } @Override public void handleDataChange(String dataPath, Object data) throws Exception { client.close(); waitCallback.countDown(); } }); client.writeData(path, new ZNRecord("test")); waitCallback.await(); Assert.assertFalse(_gZkClient.exists(path), "Ephemeral node: " + path + " should be removed after ZkClient#close() in its own event-thread"); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
retry = false; try { _zkclient.createEphemeral(liveInstancePath, liveInstance.getRecord()); LOG.info("LiveInstance created, path: " + liveInstancePath + ", sessionId: " + liveInstance.getSessionId()); } catch (ZkNodeExistsException e) { _zkclient.createEphemeral(liveInstancePath, liveInstance.getRecord()); LOG.info("LiveInstance created, path: " + liveInstancePath + ", sessionId: " + liveInstance.getSessionId()); } catch (Exception e) {