From 050e8df8969ce5e6197e892047d344ac01cae7ae Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 5 Apr 2012 22:02:38 +0000 Subject: [PATCH] HBASE-5711 Tests are failing with incorrect data directory permissions -- REVERT git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1310095 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/zookeeper/ZKUtil.java | 21 ++++++++++++------- .../hadoop/hbase/HBaseTestingUtility.java | 3 --- .../apache/hadoop/hbase/TestZooKeeper.java | 12 +++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 037e354b7e2..ba064668e39 100644 --- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -26,6 +26,7 @@ import java.io.PrintWriter; import java.net.InetSocketAddress; import java.net.Socket; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; @@ -35,17 +36,19 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.*; +import org.apache.hadoop.hbase.EmptyWatcher; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.executor.RegionTransitionData; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; @@ -596,11 +599,13 @@ public class ZKUtil { ZooKeeperWatcher zkw, String baseNode) throws KeeperException { List nodes = ZKUtil.listChildrenAndWatchForNewChildren(zkw, baseNode); - List newNodes = new ArrayList(); - for (String node: nodes) { - String nodePath = ZKUtil.joinZNode(baseNode, node); - byte [] data = ZKUtil.getDataAndWatch(zkw, nodePath); - newNodes.add(new NodeAndData(nodePath, data)); + List newNodes = Collections.emptyList(); + if (nodes != null) { + for (String node : nodes) { + String nodePath = ZKUtil.joinZNode(baseNode, node); + byte[] data = ZKUtil.getDataAndWatch(zkw, nodePath); + newNodes.add(new NodeAndData(nodePath, data)); + } } return newNodes; } diff --git a/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 64dc2c0555b..3f239e06814 100644 --- a/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -432,9 +432,6 @@ public class HBaseTestingUtility { // It's also deprecated System.setProperty("test.cache.data", this.clusterTestDir.toString()); - // Set the permissions for dfs data directories - this.conf.set("dfs.datanode.data.dir.perm", "700"); - // Ok, now we can start this.dfsCluster = new MiniDFSCluster(0, this.conf, servers, true, true, true, null, null, hosts, null); diff --git a/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java b/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java index 27b858b735c..d4f76e96058 100644 --- a/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java +++ b/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java @@ -342,6 +342,18 @@ public class TestZooKeeper { ZKUtil.createAndFailSilent(zk2, aclZnode); } + + @Test + /** + * Test should not fail with NPE when getChildDataAndWatchForNewChildren + * invoked with wrongNode + */ + public void testGetChildDataAndWatchForNewChildrenShouldNotThrowNPE() + throws Exception { + ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(), + "testGetChildDataAndWatchForNewChildrenShouldNotThrowNPE", null); + ZKUtil.getChildDataAndWatchForNewChildren(zkw, "/wrongNode"); + } @org.junit.Rule public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =