PersistentNode implements Closeable { public void start() { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Already started"); client.getConnectionStateListenable().addListener(connectionStateListener); createNode(); } PersistentNode(CuratorFramework givenClient, final CreateMode mode, boolean useProtection, final String basePath, byte[] initData);  PersistentNode(CuratorFramework givenClient, final CreateMode mode, boolean useProtection, final String basePath, byte[] initData, long ttl); void start(); boolean waitForInitialCreate(long timeout, TimeUnit unit); @Override void close(); ListenerContainer<PersistentNodeListener> getListenable(); String getActualPath(); void setData(byte[] data); byte[] getData();  }
@Test public void testEphemeralSequentialWithProtectionReconnection() throws Exception { Timing timing = new Timing(); PersistentNode pen = null; CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try { client.start(); client.create().creatingParentsIfNeeded().forPath("/test/one"); pen = new PersistentNode(client, CreateMode.EPHEMERAL_SEQUENTIAL, true, "/test/one/two", new byte[0]); pen.start(); List<String> children = client.getChildren().forPath("/test/one"); System.out.println("children before restart: "+children); Assert.assertEquals(1, children.size()); server.stop(); timing.sleepABit(); server.restart(); timing.sleepABit(); List<String> childrenAfter = client.getChildren().forPath("/test/one"); System.out.println("children after restart: "+childrenAfter); Assert.assertEquals(children, childrenAfter, "unexpected znodes: "+childrenAfter); } finally { CloseableUtils.closeQuietly(pen); CloseableUtils.closeQuietly(client); } }