zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1551625 - in /zookeeper/branches/branch-3.4: ./ src/java/main/org/apache/zookeeper/ src/java/test/org/apache/zookeeper/test/
Date Tue, 17 Dec 2013 16:57:03 GMT
Author: phunt
Date: Tue Dec 17 16:57:03 2013
New Revision: 1551625

URL: http://svn.apache.org/r1551625
Log:
ZOOKEEPER-1388. Client side 'PathValidation' is missing for the multi-transaction api. (Rakesh
R via marshallm, phunt)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/CreateMode.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Op.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1551625&r1=1551624&r2=1551625&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Tue Dec 17 16:57:03 2013
@@ -194,6 +194,9 @@ BUGFIXES:
   ZOOKEEPER-1756. zookeeper_interest() in C client can return a timeval of 0
   (Eric Lindvall via michim)
 
+  ZOOKEEPER-1388. Client side 'PathValidation' is missing for the
+  multi-transaction api. (Rakesh R via marshallm, phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1564. Allow JUnit test build with IBM Java

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/CreateMode.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/CreateMode.java?rev=1551625&r1=1551624&r2=1551625&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/CreateMode.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/CreateMode.java Tue Dec
17 16:57:03 2013
@@ -83,8 +83,10 @@ public enum CreateMode {
         case 3: return CreateMode.EPHEMERAL_SEQUENTIAL ;
 
         default:
-            LOG.error("Received an invalid flag value to convert to a CreateMode");
-            throw new KeeperException.BadArgumentsException(); 
+            String errMsg = "Received an invalid flag value: " + flag
+                    + " to convert to a CreateMode";
+            LOG.error(errMsg);
+            throw new KeeperException.BadArgumentsException(errMsg);
         }
     }
 }

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Op.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Op.java?rev=1551625&r1=1551624&r2=1551625&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Op.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Op.java Tue Dec 17 16:57:03
2013
@@ -18,6 +18,7 @@
 package org.apache.zookeeper;
 
 import org.apache.jute.Record;
+import org.apache.zookeeper.common.PathUtils;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.proto.CheckVersionRequest;
 import org.apache.zookeeper.proto.CreateRequest;
@@ -162,6 +163,18 @@ public abstract class Op {
      */
     abstract Op withChroot(String addRootPrefix);
 
+    /**
+     * Performs client path validations.
+     * 
+     * @throws IllegalArgumentException
+     *             if an invalid path is specified
+     * @throws KeeperException.BadArgumentsException
+     *             if an invalid create mode flag is specified
+     */
+    void validate() throws KeeperException {
+        PathUtils.validatePath(path);
+    }
+
     //////////////////
     // these internal classes are public, but should not generally be referenced.
     //
@@ -222,6 +235,12 @@ public abstract class Op {
         Op withChroot(String path) {
             return new Create(path, data, acl, flags);
         }
+
+        @Override
+        void validate() throws KeeperException {
+            CreateMode createMode = CreateMode.fromFlag(flags);
+            PathUtils.validatePath(getPath(), createMode.isSequential());
+        }
     }
 
     public static class Delete extends Op {

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=1551625&r1=1551624&r2=1551625&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java Tue Dec
17 16:57:03 2013
@@ -899,10 +899,14 @@ public class ZooKeeper {
      * partially succeeded if this exception is thrown.
      * @throws KeeperException If the operation could not be completed
      * due to some error in doing one of the specified ops.
+     * @throws IllegalArgumentException if an invalid path is specified
      *
      * @since 3.4.0
      */
     public List<OpResult> multi(Iterable<Op> ops) throws InterruptedException,
KeeperException {
+        for (Op op : ops) {
+            op.validate();
+        }
         // reconstructing transaction with the chroot prefix
         List<Op> transaction = new ArrayList<Op>();
         for (Op op : ops) {

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java?rev=1551625&r1=1551624&r2=1551625&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
Tue Dec 17 16:57:03 2013
@@ -60,7 +60,106 @@ public class MultiTransactionTest extend
         zk = createClient();
     }
 
-    
+        /**
+         * Test verifies the multi calls with invalid znode path
+         */
+        @Test(timeout = 90000)
+        public void testInvalidPath() throws Exception {
+        // create with CreateMode
+        List<Op> opList = Arrays.asList(Op.create("/multi0", new byte[0],
+                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(
+                "/multi1/", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT), Op.create("/multi2", new byte[0],
+                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // create with valid sequential flag
+        opList = Arrays.asList(Op.create("/multi0", new byte[0],
+                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(
+                "multi1/", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.EPHEMERAL_SEQUENTIAL.toFlag()), Op.create("/multi2",
+                new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // check
+        opList = Arrays.asList(Op.check("/multi0", -1),
+                Op.check("/multi1/", 100), Op.check("/multi2", 5));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // delete
+        opList = Arrays.asList(Op.delete("/multi0", -1),
+                Op.delete("/multi1/", 100), Op.delete("/multi2", 5));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // setdata
+        opList = Arrays.asList(Op.setData("/multi0", new byte[0], -1),
+                Op.setData("/multi1/", new byte[0], -1),
+                Op.setData("/multi2", new byte[0], -1),
+                Op.setData("multi3", new byte[0], -1));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test verifies the multi calls with blank znode path
+     */
+    @Test(timeout = 90000)
+    public void testBlankPath() throws Exception {
+        // delete
+        List<Op> opList = Arrays.asList(Op.delete("/multi0", -1),
+                Op.delete(null, 100), Op.delete("/multi2", 5),
+                Op.delete("", -1));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test verifies the multi.create with invalid createModeFlag
+     */
+    @Test(timeout = 90000)
+    public void testInvalidCreateModeFlag() throws Exception {
+        int createModeFlag = 6789;
+        List<Op> opList = Arrays.asList(Op.create("/multi0", new byte[0],
+                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(
+                "/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, createModeFlag),
+                Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                        CreateMode.PERSISTENT));
+        try {
+            zk.multi(opList);
+            Assert.fail("Shouldn't have validated in ZooKeeper client!");
+        } catch (KeeperException.BadArgumentsException e) {
+            // expected
+        }
+    }
+
     @Test
     public void testChRootCreateDelete() throws Exception {
         // creating the subtree for chRoot clients.



Mime
View raw message