curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [11/16] curator git commit: more tests, fixes
Date Tue, 03 May 2016 15:21:03 GMT
more tests, fixes


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/4e667686
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/4e667686
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/4e667686

Branch: refs/heads/CURATOR-322
Commit: 4e667686332fe43114b7e093569a988a1a85c819
Parents: 734f453
Author: randgalt <randgalt@apache.org>
Authored: Mon May 2 23:36:48 2016 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Mon May 2 23:36:48 2016 -0500

----------------------------------------------------------------------
 .../apache/curator/framework/schema/Schema.java |  6 ++--
 .../curator/framework/schema/SchemaSet.java     |  2 +-
 .../curator/framework/imps/TestSchema.java      | 38 +++++++++++++++++++-
 .../src/test/resources/schema2.json             | 17 +++++++++
 4 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/4e667686/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 7cb9d76..1f91397 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
@@ -200,10 +200,10 @@ public class Schema
 
     public String toDocumentation()
     {
-        return pathRegex.pattern() + '\n'
-            + documentation + '\n'
+        return "Path: " + 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'
+            + 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/4e667686/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
index 768f6c6..ff650f5 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
@@ -136,7 +136,7 @@ public class SchemaSet
         StringBuilder str = new StringBuilder("Curator Schemas:\n\n");
         for ( Map.Entry<SchemaKey, Schema> schemaEntry : schemas.entrySet() )
         {
-            str.append(schemaEntry.getKey()).append('\n').append(schemaEntry.getValue()).append('\n');
+            str.append(schemaEntry.getKey()).append('\n').append(schemaEntry.getValue().toDocumentation()).append('\n');
         }
         return str.toString();
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/4e667686/curator-framework/src/test/java/org/apache/curator/framework/imps/TestSchema.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestSchema.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestSchema.java
index a55ad8e..9359fff 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestSchema.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestSchema.java
@@ -4,6 +4,7 @@ import com.google.common.base.Charsets;
 import com.google.common.io.Resources;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.schema.SchemaKey;
 import org.apache.curator.framework.schema.SchemaSet;
 import org.apache.curator.framework.schema.SchemaSetLoader;
 import org.apache.curator.framework.schema.SchemaViolation;
@@ -28,7 +29,7 @@ public class TestSchema extends BaseClassForTests
 
             try
             {
-                client.create().creatingParentsIfNeeded().forPath("/a/b/c");
+                client.create().creatingParentsIfNeeded().forPath(schemaSet.getNamedSchema(SchemaKey.named("test")).getRawPath());
                 Assert.fail("Should've violated schema");
             }
             catch ( SchemaViolation dummy )
@@ -44,6 +45,41 @@ public class TestSchema extends BaseClassForTests
         }
     }
 
+    @Test
+    public void testMulti() throws Exception
+    {
+        SchemaSet schemaSet = loadSchemaSet("schema2.json");
+        CuratorFramework client = newClient(schemaSet);
+        try
+        {
+            client.start();
+
+            try
+            {
+                client.create().creatingParentsIfNeeded().forPath("/a/b/c");
+                Assert.fail("Should've violated schema: test");
+            }
+            catch ( SchemaViolation dummy )
+            {
+                // expected
+            }
+
+            try
+            {
+                client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/a/b/c/d/e");
+                Assert.fail("Should've violated schema: test2");
+            }
+            catch ( SchemaViolation dummy )
+            {
+                // expected
+            }
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+
     private CuratorFramework newClient(SchemaSet schemaSet)
     {
         return CuratorFrameworkFactory.builder()

http://git-wip-us.apache.org/repos/asf/curator/blob/4e667686/curator-framework/src/test/resources/schema2.json
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/resources/schema2.json b/curator-framework/src/test/resources/schema2.json
new file mode 100644
index 0000000..28a9a92
--- /dev/null
+++ b/curator-framework/src/test/resources/schema2.json
@@ -0,0 +1,17 @@
+[
+  {
+    "name": "test",
+    "path": "/a/b/c",
+    "documentation": "This is a schema",
+    "ephemeral": "must",
+    "sequential": "cannot"
+  },
+
+  {
+    "name": "test2",
+    "path": "/a/.*",
+    "isRegex": true,
+    "ephemeral": "cannot",
+    "canBeDeleted": false
+  }
+]
\ No newline at end of file


Mime
View raw message