Browse Source

ZOOKEEPER-1307. zkCli.sh is exiting when an Invalid ACL exception is thrown from setACL command through client (Kavita Sharma via phunt)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1301840 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt 13 years ago
parent
commit
9ab32ca0df

+ 3 - 0
CHANGES.txt

@@ -148,6 +148,9 @@ BUGFIXES:
 
   ZOOKEEPER-1344. ZooKeeper client multi-update command is not
   considering the Chroot request (Rakesh R via phunt)
+
+  ZOOKEEPER-1307. zkCli.sh is exiting when an Invalid ACL exception is
+  thrown from setACL command through client (Kavita Sharma via phunt)
   
 IMPROVEMENTS:
 

+ 1 - 1
src/java/main/org/apache/zookeeper/ZooKeeper.java

@@ -1380,7 +1380,7 @@ public class ZooKeeper {
         SetACLRequest request = new SetACLRequest();
         request.setPath(serverPath);
         if (acl != null && acl.size() == 0) {
-            throw new KeeperException.InvalidACLException();
+            throw new KeeperException.InvalidACLException(clientPath);
         }
         request.setAcl(acl);
         request.setVersion(version);

+ 8 - 0
src/java/main/org/apache/zookeeper/ZooKeeperMain.java

@@ -604,6 +604,14 @@ public class ZooKeeperMain {
             System.err.println("Node not empty: " + e.getPath());
         } catch (KeeperException.NotReadOnlyException e) {
             System.err.println("Not a read-only call: " + e.getPath());
+        }catch (KeeperException.InvalidACLException  e) {
+            System.err.println("Acl is not valid : "+e.getPath());
+        }catch (KeeperException.NoAuthException  e) {
+            System.err.println("Authentication is not valid : "+e.getPath());
+        }catch (KeeperException.BadArgumentsException   e) {
+            System.err.println("Arguments are not valid : "+e.getPath());
+        }catch (KeeperException.BadVersionException e) {
+            System.err.println("version No is not valid : "+e.getPath());
         }
         return false;
     }

+ 30 - 0
src/java/test/org/apache/zookeeper/ZooKeeperTest.java

@@ -17,6 +17,8 @@
  */
 package org.apache.zookeeper;
 
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -314,4 +316,32 @@ public class ZooKeeperTest extends ClientBase {
         zkMain.cl.parseCommand(cmdstring3);
         Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
     }
+
+    @Test
+    public void testCheckInvalidAcls() throws Exception {
+         final ZooKeeper zk = createClient();
+            ZooKeeperMain zkMain = new ZooKeeperMain(zk);
+            String cmdstring = "create -s -e /node data ip:scheme:gggsd"; //invalid acl's
+            try{
+                 zkMain.executeLine(cmdstring);
+            }catch(KeeperException.InvalidACLException e){
+                fail("For Invalid ACls should not throw exception");
+            }
+    }
+
+    @Test
+    public void testDeleteWithInvalidVersionNo() throws Exception {
+         final ZooKeeper zk = createClient();
+            ZooKeeperMain zkMain = new ZooKeeperMain(zk);
+            String cmdstring = "create -s -e /node1 data "; 
+            String cmdstring1 = "delete /node1 2";//invalid dataversion no
+                 zkMain.executeLine(cmdstring);
+           try{
+               zkMain.executeLine(cmdstring1);
+                     
+            }catch(KeeperException.BadVersionException e){
+                fail("For Invalid dataversion number should not throw exception");
+            }
+    }
+
 }