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 2016/05/03 18:38:16 UTC
[2/2] curator git commit: Added test for ordering
Added test for ordering
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/93a2a74c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/93a2a74c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/93a2a74c
Branch: refs/heads/CURATOR-322
Commit: 93a2a74c443bb2281bad80160bfaf834e462fa76
Parents: 8d4a946
Author: randgalt <ra...@apache.org>
Authored: Tue May 3 11:37:14 2016 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 3 11:37:14 2016 -0500
----------------------------------------------------------------------
.../apache/curator/framework/schema/Schema.java | 3 +-
.../curator/framework/schema/TestSchema.java | 49 ++++++++++++++++++++
.../src/test/resources/schema5.json | 25 ++++++++++
3 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/93a2a74c/curator-framework/src/main/java/org/apache/curator/framework/schema/Schema.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/schema/Schema.java b/curator-framework/src/main/java/org/apache/curator/framework/schema/Schema.java
index 86732e0..3710dd8 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/schema/Schema.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/schema/Schema.java
@@ -238,8 +238,9 @@ public class Schema
public String toDocumentation()
{
+ String pathLabel = (pathRegex != null) ? "Path Regex: " : "Path: ";
return "Name: " + name + '\n'
- + "Path: " + getRawPath() + '\n'
+ + pathLabel + getRawPath() + '\n'
+ "Documentation: " + documentation + '\n'
+ "Validator: " + dataValidator.getClass().getSimpleName() + '\n'
+ String.format("ephemeral: %s | sequential: %s | watched: %s | canBeDeleted: %s", ephemeral, sequential, watched, canBeDeleted) + '\n'
http://git-wip-us.apache.org/repos/asf/curator/blob/93a2a74c/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
index e094c0e..237c3a0 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
@@ -222,6 +222,55 @@ public class TestSchema extends BaseClassForTests
}
}
+ @Test
+ public void testOrdering() throws Exception
+ {
+ SchemaSet schemaSet = loadSchemaSet("schema5.json", null);
+ CuratorFramework client = newClient(schemaSet);
+ try
+ {
+ client.start();
+
+ try
+ {
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/exact/match");
+ Assert.fail("Should've violated schema");
+ }
+ catch ( SchemaViolation dummy )
+ {
+ // expected
+ }
+
+ try
+ {
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/exact/foo/bar");
+ Assert.fail("Should've violated schema");
+ }
+ catch ( SchemaViolation dummy )
+ {
+ // expected
+ }
+
+ try
+ {
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/exact/other/bar");
+ Assert.fail("Should've violated schema");
+ }
+ catch ( SchemaViolation dummy )
+ {
+ // expected
+ }
+
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/exact/match"); // schema "1"
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/exact/other/thing"); // schema "2"
+ client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/exact/foo/bar"); // schema "3"
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
+
@Override
protected boolean enabledSessionExpiredStateAware()
{
http://git-wip-us.apache.org/repos/asf/curator/blob/93a2a74c/curator-framework/src/test/resources/schema5.json
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/resources/schema5.json b/curator-framework/src/test/resources/schema5.json
new file mode 100644
index 0000000..31165c9
--- /dev/null
+++ b/curator-framework/src/test/resources/schema5.json
@@ -0,0 +1,25 @@
+[
+ {
+ "name": "1",
+ "path": "/exact/match",
+ "isRegex": false,
+ "ephemeral": "cannot",
+ "sequential": "must"
+ },
+
+ {
+ "name": "2",
+ "path": "/exact/other/.*",
+ "isRegex": true,
+ "ephemeral": "must",
+ "sequential": "can"
+ },
+
+ {
+ "name": "3",
+ "path": "/exact/.*",
+ "isRegex": true,
+ "ephemeral": "can",
+ "sequential": "cannot"
+ }
+]
\ No newline at end of file