Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A2C1817D7C for ; Wed, 6 May 2015 04:55:59 +0000 (UTC) Received: (qmail 67019 invoked by uid 500); 6 May 2015 04:55:59 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 66886 invoked by uid 500); 6 May 2015 04:55:59 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 66602 invoked by uid 99); 6 May 2015 04:55:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 May 2015 04:55:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0ECC8E30F3; Wed, 6 May 2015 04:55:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Wed, 06 May 2015 04:56:03 -0000 Message-Id: <7a1d0905efca4f7eb9e23386b672e1c1@git.apache.org> In-Reply-To: <34422cdf5d34428891ea339c0ed20424@git.apache.org> References: <34422cdf5d34428891ea339c0ed20424@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/50] curator git commit: CURATOR-190 - Modified to always use the base name when creating protected ephemeral nodes. This prevents the current protected name being appended to the name each time the node is created, which in turn prevents multiple nod CURATOR-190 - Modified to always use the base name when creating protected ephemeral nodes. This prevents the current protected name being appended to the name each time the node is created, which in turn prevents multiple nodes being created. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/9fe802ec Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/9fe802ec Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/9fe802ec Branch: refs/heads/CURATOR-160 Commit: 9fe802ec238b8ae7b5f77e61cac7e25c8f42f6d9 Parents: 49eb02a Author: Cameron McKenzie Authored: Wed Mar 4 09:09:01 2015 +1100 Committer: Cameron McKenzie Committed: Wed Mar 4 09:09:01 2015 +1100 ---------------------------------------------------------------------- .../recipes/nodes/PersistentEphemeralNode.java | 2 +- .../nodes/TestPersistentEphemeralNode.java | 39 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/9fe802ec/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java index d78573c..cfc4cbc 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java @@ -336,7 +336,7 @@ public class PersistentEphemeralNode implements Closeable try { String existingPath = nodePath.get(); - String createPath = (existingPath != null) ? existingPath : basePath; + String createPath = (existingPath != null && !mode.isProtected()) ? existingPath : basePath; createMethod.withMode(mode.getCreateMode(existingPath != null)).inBackground(backgroundCallback).forPath(createPath, data.get()); } catch ( Exception e ) http://git-wip-us.apache.org/repos/asf/curator/blob/9fe802ec/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java index 47ae757..8bc8d3d 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java @@ -20,6 +20,7 @@ package org.apache.curator.framework.recipes.nodes; import com.google.common.base.Throwables; import com.google.common.collect.Lists; + import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.state.ConnectionState; @@ -37,9 +38,11 @@ import org.apache.zookeeper.data.Stat; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -459,6 +462,42 @@ public class TestPersistentEphemeralNode extends BaseClassForTests node.close(); } } + + /** + * See CURATOR-190 + * For protected nodes on reconnect the current protected name was passed to the create builder meaning that it got + * appended to the new protected node name. This meant that a new node got created on each reconnect. + * @throws Exception + */ + @Test + public void testProtected() throws Exception + { + CuratorFramework curator = newCurator(); + + PersistentEphemeralNode node = new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.PROTECTED_EPHEMERAL, PATH, + new byte[0]); + node.start(); + try + { + node.waitForInitialCreate(timing.forWaiting().seconds(), TimeUnit.SECONDS); + assertNodeExists(curator, node.getActualPath()); + + server.restart(); + + curator.blockUntilConnected(5, TimeUnit.SECONDS); + + assertNodeExists(curator, node.getActualPath()); + + //There should only be a single child, the persisted ephemeral node + List children = curator.getChildren().forPath(DIR); + assertFalse(children == null); + assertEquals(children.size(), 1); + } + finally + { + node.close(); + } + } private void assertNodeExists(CuratorFramework curator, String path) throws Exception {