You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by in...@apache.org on 2018/09/06 23:50:51 UTC

[1/5] hadoop git commit: HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

Repository: hadoop
Updated Branches:
  refs/heads/branch-2 3eb70d4dc -> 1b12925d6
  refs/heads/branch-2.9 4c66a6791 -> 5c3c9431c
  refs/heads/branch-3.0 09e1851b0 -> a9392bdb1
  refs/heads/branch-3.1 4a55092c6 -> a400ed3aa
  refs/heads/trunk c5bf43a8e -> 527288ef8


HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/527288ef
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/527288ef
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/527288ef

Branch: refs/heads/trunk
Commit: 527288ef891dc26019d003bd85ddfd50eb4f3b7b
Parents: c5bf43a
Author: Inigo Goiri <in...@apache.org>
Authored: Thu Sep 6 16:47:54 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu Sep 6 16:47:54 2018 -0700

----------------------------------------------------------------------
 .../hadoop/util/curator/ZKCuratorManager.java   | 10 +++-
 .../util/curator/TestZKCuratorManager.java      | 23 +++++++++
 .../store/driver/TestStateStoreZK.java          | 53 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/527288ef/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
index 8276b6e..d164138 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
@@ -196,7 +196,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path) throws Exception {
     byte[] bytes = getData(path);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**
@@ -208,7 +211,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path, Stat stat) throws Exception {
     byte[] bytes = getData(path, stat);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/527288ef/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
index 486e89a..a2156ee 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.util.curator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.ZKUtil;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,6 +100,27 @@ public class TestZKCuratorManager {
   }
 
   @Test
+  public void testGetStringData() throws Exception {
+    String node1 = "/node1";
+    String node2 = "/node2";
+    assertFalse(curator.exists(node1));
+    curator.create(node1);
+    assertNull(curator.getStringData(node1));
+
+    byte[] setData = "setData".getBytes("UTF-8");
+    curator.setData(node1, setData, -1);
+    assertEquals("setData", curator.getStringData(node1));
+
+    Stat stat = new Stat();
+    assertFalse(curator.exists(node2));
+    curator.create(node2);
+    assertNull(curator.getStringData(node2, stat));
+
+    curator.setData(node2, setData, -1);
+    assertEquals("setData", curator.getStringData(node2, stat));
+
+  }
+  @Test
   public void testTransaction() throws Exception {
     List<ACL> zkAcl = ZKUtil.parseACLs(CommonConfigurationKeys.ZK_ACL_DEFAULT);
     String fencingNodePath = "/fencing";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/527288ef/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
index 3cf7c91..f8be9f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
@@ -18,6 +18,10 @@
 package org.apache.hadoop.hdfs.server.federation.store.driver;
 
 import static org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils.getStateStoreConfiguration;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -29,7 +33,14 @@ import org.apache.curator.test.TestingServer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
 import org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl;
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
+import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
+import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
+import org.apache.hadoop.hdfs.server.federation.store.records.RouterState;
+import org.apache.zookeeper.CreateMode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -42,6 +53,7 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
 
   private static TestingServer curatorTestingServer;
   private static CuratorFramework curatorFramework;
+  private static String baseZNode;
 
   @BeforeClass
   public static void setupCluster() throws Exception {
@@ -61,6 +73,9 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     // Disable auto-repair of connection
     conf.setLong(RBFConfigKeys.FEDERATION_STORE_CONNECTION_TEST_MS,
         TimeUnit.HOURS.toMillis(1));
+
+    baseZNode = conf.get(FEDERATION_STORE_ZK_PARENT_PATH,
+        FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT);
     getStateStore(conf);
   }
 
@@ -78,6 +93,44 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     removeAll(getStateStoreDriver());
   }
 
+  private <T extends BaseRecord> String generateFakeZNode(
+      Class<T> recordClass) throws IOException {
+    String nodeName = StateStoreUtils.getRecordName(recordClass);
+    String primaryKey = "test";
+
+    if (nodeName != null) {
+      return baseZNode + "/" + nodeName + "/" + primaryKey;
+    }
+    return null;
+  }
+
+  private void testGetNullRecord(StateStoreDriver driver) throws Exception {
+    testGetNullRecord(driver, MembershipState.class);
+    testGetNullRecord(driver, MountTable.class);
+    testGetNullRecord(driver, RouterState.class);
+    testGetNullRecord(driver, DisabledNameservice.class);
+  }
+
+  private <T extends BaseRecord> void testGetNullRecord(
+      StateStoreDriver driver, Class<T> recordClass) throws Exception {
+    driver.removeAll(recordClass);
+
+    String znode = generateFakeZNode(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+
+    curatorFramework.create().withMode(CreateMode.PERSISTENT)
+        .withACL(null).forPath(znode, null);
+    assertNotNull(curatorFramework.checkExists().forPath(znode));
+
+    driver.get(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+  }
+
+  @Test
+  public void testGetNullRecord() throws Exception {
+    testGetNullRecord(getStateStoreDriver());
+  }
+
   @Test
   public void testInsert()
       throws IllegalArgumentException, IllegalAccessException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


[2/5] hadoop git commit: HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

Posted by in...@apache.org.
HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

(cherry picked from commit 527288ef891dc26019d003bd85ddfd50eb4f3b7b)


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

Branch: refs/heads/branch-3.1
Commit: a400ed3aab7712f137e79aab6690a67f28746aea
Parents: 4a55092
Author: Inigo Goiri <in...@apache.org>
Authored: Thu Sep 6 16:47:54 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu Sep 6 16:48:44 2018 -0700

----------------------------------------------------------------------
 .../hadoop/util/curator/ZKCuratorManager.java   | 10 +++-
 .../util/curator/TestZKCuratorManager.java      | 23 +++++++++
 .../store/driver/TestStateStoreZK.java          | 53 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a400ed3a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
index 8276b6e..d164138 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
@@ -196,7 +196,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path) throws Exception {
     byte[] bytes = getData(path);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**
@@ -208,7 +211,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path, Stat stat) throws Exception {
     byte[] bytes = getData(path, stat);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a400ed3a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
index 486e89a..a2156ee 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.util.curator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.ZKUtil;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,6 +100,27 @@ public class TestZKCuratorManager {
   }
 
   @Test
+  public void testGetStringData() throws Exception {
+    String node1 = "/node1";
+    String node2 = "/node2";
+    assertFalse(curator.exists(node1));
+    curator.create(node1);
+    assertNull(curator.getStringData(node1));
+
+    byte[] setData = "setData".getBytes("UTF-8");
+    curator.setData(node1, setData, -1);
+    assertEquals("setData", curator.getStringData(node1));
+
+    Stat stat = new Stat();
+    assertFalse(curator.exists(node2));
+    curator.create(node2);
+    assertNull(curator.getStringData(node2, stat));
+
+    curator.setData(node2, setData, -1);
+    assertEquals("setData", curator.getStringData(node2, stat));
+
+  }
+  @Test
   public void testTransaction() throws Exception {
     List<ACL> zkAcl = ZKUtil.parseACLs(CommonConfigurationKeys.ZK_ACL_DEFAULT);
     String fencingNodePath = "/fencing";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a400ed3a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
index 3cf7c91..f8be9f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
@@ -18,6 +18,10 @@
 package org.apache.hadoop.hdfs.server.federation.store.driver;
 
 import static org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils.getStateStoreConfiguration;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -29,7 +33,14 @@ import org.apache.curator.test.TestingServer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
 import org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl;
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
+import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
+import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
+import org.apache.hadoop.hdfs.server.federation.store.records.RouterState;
+import org.apache.zookeeper.CreateMode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -42,6 +53,7 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
 
   private static TestingServer curatorTestingServer;
   private static CuratorFramework curatorFramework;
+  private static String baseZNode;
 
   @BeforeClass
   public static void setupCluster() throws Exception {
@@ -61,6 +73,9 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     // Disable auto-repair of connection
     conf.setLong(RBFConfigKeys.FEDERATION_STORE_CONNECTION_TEST_MS,
         TimeUnit.HOURS.toMillis(1));
+
+    baseZNode = conf.get(FEDERATION_STORE_ZK_PARENT_PATH,
+        FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT);
     getStateStore(conf);
   }
 
@@ -78,6 +93,44 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     removeAll(getStateStoreDriver());
   }
 
+  private <T extends BaseRecord> String generateFakeZNode(
+      Class<T> recordClass) throws IOException {
+    String nodeName = StateStoreUtils.getRecordName(recordClass);
+    String primaryKey = "test";
+
+    if (nodeName != null) {
+      return baseZNode + "/" + nodeName + "/" + primaryKey;
+    }
+    return null;
+  }
+
+  private void testGetNullRecord(StateStoreDriver driver) throws Exception {
+    testGetNullRecord(driver, MembershipState.class);
+    testGetNullRecord(driver, MountTable.class);
+    testGetNullRecord(driver, RouterState.class);
+    testGetNullRecord(driver, DisabledNameservice.class);
+  }
+
+  private <T extends BaseRecord> void testGetNullRecord(
+      StateStoreDriver driver, Class<T> recordClass) throws Exception {
+    driver.removeAll(recordClass);
+
+    String znode = generateFakeZNode(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+
+    curatorFramework.create().withMode(CreateMode.PERSISTENT)
+        .withACL(null).forPath(znode, null);
+    assertNotNull(curatorFramework.checkExists().forPath(znode));
+
+    driver.get(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+  }
+
+  @Test
+  public void testGetNullRecord() throws Exception {
+    testGetNullRecord(getStateStoreDriver());
+  }
+
   @Test
   public void testInsert()
       throws IllegalArgumentException, IllegalAccessException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


[5/5] hadoop git commit: HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

Posted by in...@apache.org.
HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

(cherry picked from commit 527288ef891dc26019d003bd85ddfd50eb4f3b7b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5c3c9431
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5c3c9431
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5c3c9431

Branch: refs/heads/branch-2.9
Commit: 5c3c9431c3f77d619cfcf5265bfbbaab227a43f8
Parents: 4c66a67
Author: Inigo Goiri <in...@apache.org>
Authored: Thu Sep 6 16:47:54 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu Sep 6 16:50:26 2018 -0700

----------------------------------------------------------------------
 .../hadoop/util/curator/ZKCuratorManager.java   | 10 +++-
 .../util/curator/TestZKCuratorManager.java      | 23 +++++++++
 .../store/driver/TestStateStoreZK.java          | 53 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/5c3c9431/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
index 345f91e..6c3dfbd 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
@@ -207,7 +207,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path) throws Exception {
     byte[] bytes = getData(path);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**
@@ -219,7 +222,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path, Stat stat) throws Exception {
     byte[] bytes = getData(path, stat);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/5c3c9431/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
index 486e89a..a2156ee 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.util.curator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.ZKUtil;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,6 +100,27 @@ public class TestZKCuratorManager {
   }
 
   @Test
+  public void testGetStringData() throws Exception {
+    String node1 = "/node1";
+    String node2 = "/node2";
+    assertFalse(curator.exists(node1));
+    curator.create(node1);
+    assertNull(curator.getStringData(node1));
+
+    byte[] setData = "setData".getBytes("UTF-8");
+    curator.setData(node1, setData, -1);
+    assertEquals("setData", curator.getStringData(node1));
+
+    Stat stat = new Stat();
+    assertFalse(curator.exists(node2));
+    curator.create(node2);
+    assertNull(curator.getStringData(node2, stat));
+
+    curator.setData(node2, setData, -1);
+    assertEquals("setData", curator.getStringData(node2, stat));
+
+  }
+  @Test
   public void testTransaction() throws Exception {
     List<ACL> zkAcl = ZKUtil.parseACLs(CommonConfigurationKeys.ZK_ACL_DEFAULT);
     String fencingNodePath = "/fencing";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/5c3c9431/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
index 3cf7c91..f8be9f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
@@ -18,6 +18,10 @@
 package org.apache.hadoop.hdfs.server.federation.store.driver;
 
 import static org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils.getStateStoreConfiguration;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -29,7 +33,14 @@ import org.apache.curator.test.TestingServer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
 import org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl;
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
+import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
+import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
+import org.apache.hadoop.hdfs.server.federation.store.records.RouterState;
+import org.apache.zookeeper.CreateMode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -42,6 +53,7 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
 
   private static TestingServer curatorTestingServer;
   private static CuratorFramework curatorFramework;
+  private static String baseZNode;
 
   @BeforeClass
   public static void setupCluster() throws Exception {
@@ -61,6 +73,9 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     // Disable auto-repair of connection
     conf.setLong(RBFConfigKeys.FEDERATION_STORE_CONNECTION_TEST_MS,
         TimeUnit.HOURS.toMillis(1));
+
+    baseZNode = conf.get(FEDERATION_STORE_ZK_PARENT_PATH,
+        FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT);
     getStateStore(conf);
   }
 
@@ -78,6 +93,44 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     removeAll(getStateStoreDriver());
   }
 
+  private <T extends BaseRecord> String generateFakeZNode(
+      Class<T> recordClass) throws IOException {
+    String nodeName = StateStoreUtils.getRecordName(recordClass);
+    String primaryKey = "test";
+
+    if (nodeName != null) {
+      return baseZNode + "/" + nodeName + "/" + primaryKey;
+    }
+    return null;
+  }
+
+  private void testGetNullRecord(StateStoreDriver driver) throws Exception {
+    testGetNullRecord(driver, MembershipState.class);
+    testGetNullRecord(driver, MountTable.class);
+    testGetNullRecord(driver, RouterState.class);
+    testGetNullRecord(driver, DisabledNameservice.class);
+  }
+
+  private <T extends BaseRecord> void testGetNullRecord(
+      StateStoreDriver driver, Class<T> recordClass) throws Exception {
+    driver.removeAll(recordClass);
+
+    String znode = generateFakeZNode(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+
+    curatorFramework.create().withMode(CreateMode.PERSISTENT)
+        .withACL(null).forPath(znode, null);
+    assertNotNull(curatorFramework.checkExists().forPath(znode));
+
+    driver.get(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+  }
+
+  @Test
+  public void testGetNullRecord() throws Exception {
+    testGetNullRecord(getStateStoreDriver());
+  }
+
   @Test
   public void testInsert()
       throws IllegalArgumentException, IllegalAccessException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


[4/5] hadoop git commit: HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

Posted by in...@apache.org.
HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

(cherry picked from commit 527288ef891dc26019d003bd85ddfd50eb4f3b7b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/1b12925d
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/1b12925d
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/1b12925d

Branch: refs/heads/branch-2
Commit: 1b12925d6927a46b9229b652a9fe589883e33e78
Parents: 3eb70d4
Author: Inigo Goiri <in...@apache.org>
Authored: Thu Sep 6 16:47:54 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu Sep 6 16:50:09 2018 -0700

----------------------------------------------------------------------
 .../hadoop/util/curator/ZKCuratorManager.java   | 10 +++-
 .../util/curator/TestZKCuratorManager.java      | 23 +++++++++
 .../store/driver/TestStateStoreZK.java          | 53 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/1b12925d/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
index 345f91e..6c3dfbd 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
@@ -207,7 +207,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path) throws Exception {
     byte[] bytes = getData(path);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**
@@ -219,7 +222,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path, Stat stat) throws Exception {
     byte[] bytes = getData(path, stat);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/1b12925d/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
index 486e89a..a2156ee 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.util.curator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.ZKUtil;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,6 +100,27 @@ public class TestZKCuratorManager {
   }
 
   @Test
+  public void testGetStringData() throws Exception {
+    String node1 = "/node1";
+    String node2 = "/node2";
+    assertFalse(curator.exists(node1));
+    curator.create(node1);
+    assertNull(curator.getStringData(node1));
+
+    byte[] setData = "setData".getBytes("UTF-8");
+    curator.setData(node1, setData, -1);
+    assertEquals("setData", curator.getStringData(node1));
+
+    Stat stat = new Stat();
+    assertFalse(curator.exists(node2));
+    curator.create(node2);
+    assertNull(curator.getStringData(node2, stat));
+
+    curator.setData(node2, setData, -1);
+    assertEquals("setData", curator.getStringData(node2, stat));
+
+  }
+  @Test
   public void testTransaction() throws Exception {
     List<ACL> zkAcl = ZKUtil.parseACLs(CommonConfigurationKeys.ZK_ACL_DEFAULT);
     String fencingNodePath = "/fencing";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/1b12925d/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
index 3cf7c91..f8be9f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
@@ -18,6 +18,10 @@
 package org.apache.hadoop.hdfs.server.federation.store.driver;
 
 import static org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils.getStateStoreConfiguration;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -29,7 +33,14 @@ import org.apache.curator.test.TestingServer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
 import org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl;
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
+import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
+import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
+import org.apache.hadoop.hdfs.server.federation.store.records.RouterState;
+import org.apache.zookeeper.CreateMode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -42,6 +53,7 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
 
   private static TestingServer curatorTestingServer;
   private static CuratorFramework curatorFramework;
+  private static String baseZNode;
 
   @BeforeClass
   public static void setupCluster() throws Exception {
@@ -61,6 +73,9 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     // Disable auto-repair of connection
     conf.setLong(RBFConfigKeys.FEDERATION_STORE_CONNECTION_TEST_MS,
         TimeUnit.HOURS.toMillis(1));
+
+    baseZNode = conf.get(FEDERATION_STORE_ZK_PARENT_PATH,
+        FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT);
     getStateStore(conf);
   }
 
@@ -78,6 +93,44 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     removeAll(getStateStoreDriver());
   }
 
+  private <T extends BaseRecord> String generateFakeZNode(
+      Class<T> recordClass) throws IOException {
+    String nodeName = StateStoreUtils.getRecordName(recordClass);
+    String primaryKey = "test";
+
+    if (nodeName != null) {
+      return baseZNode + "/" + nodeName + "/" + primaryKey;
+    }
+    return null;
+  }
+
+  private void testGetNullRecord(StateStoreDriver driver) throws Exception {
+    testGetNullRecord(driver, MembershipState.class);
+    testGetNullRecord(driver, MountTable.class);
+    testGetNullRecord(driver, RouterState.class);
+    testGetNullRecord(driver, DisabledNameservice.class);
+  }
+
+  private <T extends BaseRecord> void testGetNullRecord(
+      StateStoreDriver driver, Class<T> recordClass) throws Exception {
+    driver.removeAll(recordClass);
+
+    String znode = generateFakeZNode(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+
+    curatorFramework.create().withMode(CreateMode.PERSISTENT)
+        .withACL(null).forPath(znode, null);
+    assertNotNull(curatorFramework.checkExists().forPath(znode));
+
+    driver.get(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+  }
+
+  @Test
+  public void testGetNullRecord() throws Exception {
+    testGetNullRecord(getStateStoreDriver());
+  }
+
   @Test
   public void testInsert()
       throws IllegalArgumentException, IllegalAccessException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


[3/5] hadoop git commit: HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

Posted by in...@apache.org.
HDFS-13836. RBF: Handle mount table znode with null value. Contributed by yanghuafeng.

(cherry picked from commit 527288ef891dc26019d003bd85ddfd50eb4f3b7b)


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

Branch: refs/heads/branch-3.0
Commit: a9392bdb17f3484e373793cd3575a8f1683896dc
Parents: 09e1851
Author: Inigo Goiri <in...@apache.org>
Authored: Thu Sep 6 16:47:54 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu Sep 6 16:49:14 2018 -0700

----------------------------------------------------------------------
 .../hadoop/util/curator/ZKCuratorManager.java   | 10 +++-
 .../util/curator/TestZKCuratorManager.java      | 23 +++++++++
 .../store/driver/TestStateStoreZK.java          | 53 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9392bdb/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
index 3879060..8a4a146 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/curator/ZKCuratorManager.java
@@ -207,7 +207,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path) throws Exception {
     byte[] bytes = getData(path);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**
@@ -219,7 +222,10 @@ public final class ZKCuratorManager {
    */
   public String getStringData(final String path, Stat stat) throws Exception {
     byte[] bytes = getData(path, stat);
-    return new String(bytes, Charset.forName("UTF-8"));
+    if (bytes != null) {
+      return new String(bytes, Charset.forName("UTF-8"));
+    }
+    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9392bdb/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
index 486e89a..a2156ee 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestZKCuratorManager.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.util.curator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
@@ -30,6 +31,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.ZKUtil;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,6 +100,27 @@ public class TestZKCuratorManager {
   }
 
   @Test
+  public void testGetStringData() throws Exception {
+    String node1 = "/node1";
+    String node2 = "/node2";
+    assertFalse(curator.exists(node1));
+    curator.create(node1);
+    assertNull(curator.getStringData(node1));
+
+    byte[] setData = "setData".getBytes("UTF-8");
+    curator.setData(node1, setData, -1);
+    assertEquals("setData", curator.getStringData(node1));
+
+    Stat stat = new Stat();
+    assertFalse(curator.exists(node2));
+    curator.create(node2);
+    assertNull(curator.getStringData(node2, stat));
+
+    curator.setData(node2, setData, -1);
+    assertEquals("setData", curator.getStringData(node2, stat));
+
+  }
+  @Test
   public void testTransaction() throws Exception {
     List<ACL> zkAcl = ZKUtil.parseACLs(CommonConfigurationKeys.ZK_ACL_DEFAULT);
     String fencingNodePath = "/fencing";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9392bdb/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
index 3cf7c91..f8be9f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreZK.java
@@ -18,6 +18,10 @@
 package org.apache.hadoop.hdfs.server.federation.store.driver;
 
 import static org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils.getStateStoreConfiguration;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH;
+import static org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl.FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -29,7 +33,14 @@ import org.apache.curator.test.TestingServer;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
 import org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreZooKeeperImpl;
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
+import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
+import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
+import org.apache.hadoop.hdfs.server.federation.store.records.RouterState;
+import org.apache.zookeeper.CreateMode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -42,6 +53,7 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
 
   private static TestingServer curatorTestingServer;
   private static CuratorFramework curatorFramework;
+  private static String baseZNode;
 
   @BeforeClass
   public static void setupCluster() throws Exception {
@@ -61,6 +73,9 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     // Disable auto-repair of connection
     conf.setLong(RBFConfigKeys.FEDERATION_STORE_CONNECTION_TEST_MS,
         TimeUnit.HOURS.toMillis(1));
+
+    baseZNode = conf.get(FEDERATION_STORE_ZK_PARENT_PATH,
+        FEDERATION_STORE_ZK_PARENT_PATH_DEFAULT);
     getStateStore(conf);
   }
 
@@ -78,6 +93,44 @@ public class TestStateStoreZK extends TestStateStoreDriverBase {
     removeAll(getStateStoreDriver());
   }
 
+  private <T extends BaseRecord> String generateFakeZNode(
+      Class<T> recordClass) throws IOException {
+    String nodeName = StateStoreUtils.getRecordName(recordClass);
+    String primaryKey = "test";
+
+    if (nodeName != null) {
+      return baseZNode + "/" + nodeName + "/" + primaryKey;
+    }
+    return null;
+  }
+
+  private void testGetNullRecord(StateStoreDriver driver) throws Exception {
+    testGetNullRecord(driver, MembershipState.class);
+    testGetNullRecord(driver, MountTable.class);
+    testGetNullRecord(driver, RouterState.class);
+    testGetNullRecord(driver, DisabledNameservice.class);
+  }
+
+  private <T extends BaseRecord> void testGetNullRecord(
+      StateStoreDriver driver, Class<T> recordClass) throws Exception {
+    driver.removeAll(recordClass);
+
+    String znode = generateFakeZNode(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+
+    curatorFramework.create().withMode(CreateMode.PERSISTENT)
+        .withACL(null).forPath(znode, null);
+    assertNotNull(curatorFramework.checkExists().forPath(znode));
+
+    driver.get(recordClass);
+    assertNull(curatorFramework.checkExists().forPath(znode));
+  }
+
+  @Test
+  public void testGetNullRecord() throws Exception {
+    testGetNullRecord(getStateStoreDriver());
+  }
+
   @Test
   public void testInsert()
       throws IllegalArgumentException, IllegalAccessException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org