You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2021/08/18 15:28:45 UTC
[curator] 02/02: This commit reverts changes that altered the ZPath
parse method based on incorrect assumptions about what a "resolved" ZPath
actually is.
This is an automated email from the ASF dual-hosted git repository.
randgalt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
commit 137159bb919cb7915eb1ddb3a3dfe369bd2253b9
Author: Ryan Ruel <ry...@ryanruel.com>
AuthorDate: Wed Aug 18 10:57:42 2021 -0400
This commit reverts changes that altered the ZPath parse method based on incorrect assumptions about what a "resolved" ZPath actually is.
I've added a few notes to the JavaDoc and unit tests to hopefully clear up confusion in this area in the future.
---
.../org/apache/curator/x/async/modeled/ZPath.java | 20 +++++++++++++-------
.../curator/x/async/modeled/details/ZPathImpl.java | 7 ++-----
.../apache/curator/x/async/modeled/TestZPath.java | 16 ++++++----------
3 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
index e15a6bc..0958975 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
@@ -31,9 +31,6 @@ import static org.apache.curator.utils.ZKPaths.PATH_SEPARATOR;
*/
public interface ZPath extends Resolvable
{
- String PARAMETER_OPENING_DELIMITER = "{";
- String PARAMETER_CLOSING_DELIMITER = "}";
-
/**
* The root path: "/"
*/
@@ -55,11 +52,14 @@ public interface ZPath extends Resolvable
*/
static String parameter(String name)
{
- return PATH_SEPARATOR + PARAMETER_OPENING_DELIMITER + name + PARAMETER_CLOSING_DELIMITER;
+ return PATH_SEPARATOR + "{" + name + "}";
}
/**
- * Take a string path and return a ZPath
+ * Take a string path and return a ZPath.
+ * <p>
+ * Note: This method always produces a fully resolved path despite the presence of any parameter-like elements (i.e, {@code {one}}).
+ * For substituting parameter elements and for proper parameter resolution status checks, use {@code parseWithIds()} instead.
*
* @param fullPath the path to parse
* @return ZPath
@@ -82,7 +82,7 @@ public interface ZPath extends Resolvable
*/
static ZPath parseWithIds(String fullPath)
{
- return ZPathImpl.parse(fullPath, s -> isId(s) ? (PATH_SEPARATOR + s) : s); // TODO
+ return ZPathImpl.parse(fullPath, s -> isId(s) ? (PATH_SEPARATOR + s) : s);
}
/**
@@ -244,7 +244,13 @@ public interface ZPath extends Resolvable
boolean isRoot();
/**
- * Return true if this path is fully resolved (i.e. has no unresolved parameters)
+ * Return true if this path is fully resolved (i.e. has no unresolved parameters).
+ * <p>
+ * Note: ZPath's returned by the {@code parse()} method are always considered fully resolved, despite if there are
+ * remaining elements in the path which appear to be parameters (but are not, i.e. {@code {one}}).
+ * <p>
+ * When working with parameters, use the {@code parseWithIds()} method, which returns a ZPath with a
+ * resolved state based on the presence of unresolved parameter elements in the ZPath.
*
* @return true/false
*/
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
index b04c4b4..fff742e 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
@@ -210,9 +210,7 @@ public class ZPathImpl implements ZPath
.map(name -> {
if ( isParameter(name) && iterator.hasNext() )
{
- // Eliminate any leading path separator from substituted parameters, as ZPathImpl() will
- // add in all required path separators as part of it's build operation.
- return NodeName.nameFrom(iterator.next()).replaceAll(String.format("^%s+", PATH_SEPARATOR), "");
+ return NodeName.nameFrom(iterator.next());
}
return name;
})
@@ -228,8 +226,7 @@ public class ZPathImpl implements ZPath
private static boolean isParameter(String name)
{
- return name.matches(String.format(".*\\%s.*\\%s", PARAMETER_OPENING_DELIMITER,
- PARAMETER_CLOSING_DELIMITER));
+ return (name.length() > 1) && name.startsWith(PATH_SEPARATOR);
}
private ZPathImpl(List<String> nodes, String child)
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
index c1d4697..6dc4018 100644
--- a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
@@ -56,12 +56,15 @@ public class TestZPath
assertTrue(path.startsWith(ZPath.root.child("one")));
assertFalse(path.startsWith(ZPath.root.child("two")));
+ // Despite these paths containing elements which appear to be parameters, ZPath.parse() always returns
+ // a ZPath which is considered fully resolved. This allows users to include parameter-like elements in their
+ // ZPath's that aren't treated as parameters.
ZPath checkIdLike = ZPath.parse("/one/{two}/three");
- assertFalse(checkIdLike.isResolved());
+ assertTrue(checkIdLike.isResolved(), "parse method always returns a fully resolved ZPath");
checkIdLike = ZPath.parse("/one/" + ZPath.parameter() + "/three");
- assertFalse(checkIdLike.isResolved());
+ assertTrue(checkIdLike.isResolved(), "parse method always returns a fully resolved ZPath");
checkIdLike = ZPath.parse("/one/" + ZPath.parameter("others") + "/three");
- assertFalse(checkIdLike.isResolved());
+ assertTrue(checkIdLike.isResolved(), "parse method always returns a fully resolved ZPath");
}
@Test
@@ -71,13 +74,6 @@ public class TestZPath
assertEquals(ZPath.parse("/one/two/three"), ZPath.root.child("one").child("two").child("three"));
assertEquals(ZPath.parse("/one/two/three"), ZPath.from("one", "two", "three"));
assertEquals(ZPath.parseWithIds("/one/{id}/two/{id}"), ZPath.from("one", parameter(), "two", parameter()));
-
- final ZPath rootPath = ZPath.parse("/root");
- ZPath path = ZPath.parseWithIds("{root}/one/{id}/two/{id}");
- assertFalse(path.isResolved());
- path = path.resolved(rootPath.toString(), "foo", "bar");
- assertEquals(ZPath.from("root", "one", "foo", "two", "bar").toString(), path.toString());
- assertTrue(path.isResolved());
}
@Test