helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: HELIX-44: ZkHelix property store is not checking the validity of path
Date Thu, 07 Feb 2013 19:34:33 GMT
Updated Branches:
  refs/heads/master 98b6c97ad -> e0fc35aaf


HELIX-44: ZkHelix property store is not checking the validity of path


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/e0fc35aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/e0fc35aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/e0fc35aa

Branch: refs/heads/master
Commit: e0fc35aaf8d457c9c2104bcfe0d9fed96192ec1c
Parents: 98b6c97
Author: zzhang <zzhang5@uci.edu>
Authored: Thu Feb 7 11:34:25 2013 -0800
Committer: zzhang <zzhang5@uci.edu>
Committed: Thu Feb 7 11:34:25 2013 -0800

----------------------------------------------------------------------
 .../helix/manager/zk/ZkCacheBaseDataAccessor.java  |    2 +
 .../helix/store/zk/TestZkHelixPropertyStore.java   |   21 +++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e0fc35aa/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
index 5543d39..9eb926d 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
@@ -160,6 +160,8 @@ public class ZkCacheBaseDataAccessor<T> implements HelixPropertyStore<T>
 
   private String prependChroot(String clientPath)
   {
+    PathUtils.validatePath(clientPath);
+
     if (_chrootPath != null)
     {
       // handle clientPath = "/"

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/e0fc35aa/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
index fc4032a..8be8c52 100644
--- a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
+++ b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
@@ -96,6 +96,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase
                                            subRoot,
                                            subscribedPaths);
 
+    // test set
     setNodes(store, 'a', false);
     for (int i = 0; i < 10; i++)
     {
@@ -108,6 +109,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase
       }
     }
 
+    // test get from cache
     long startT = System.currentTimeMillis();
     for (int i = 0; i < 1000; i++)
     {
@@ -122,6 +124,25 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase
     store.stop();
     System.out.println("END testSet() at " + new Date(System.currentTimeMillis()));
   }
+  
+  @Test
+  public void testSetInvalidPath()
+  {
+	    String subRoot = _root + "/" + "setInvalidPath";
+	    ZkHelixPropertyStore<ZNRecord> store =
+	        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient),
+	                                           subRoot,
+	                                           null);
+	    try {
+	    	store.set("abc/xyz", new ZNRecord("testInvalid"), AccessOption.PERSISTENT);
+	    	Assert.fail("Should throw illegal-argument-exception since path doesn't start with
/");
+	    } catch (IllegalArgumentException e) {
+	    	// e.printStackTrace();
+	    	// OK
+	    } catch (Exception e) {
+	    	Assert.fail("Should not throw exceptions other than illegal-argument");
+	    }
+  }
 
   @Test
   public void testLocalTriggeredCallback() throws Exception


Mime
View raw message