From ffcd4d424f69b4ecac1bd9f5980c14bb4b61a3fa Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Thu, 28 May 2015 14:33:19 -0700 Subject: [PATCH] HBASE 13796 - Fixed ZKUtil's cleaning of the zookeeper quorum setting Signed-off-by: stack --- .../apache/hadoop/hbase/zookeeper/ZKUtil.java | 4 +- .../hadoop/hbase/zookeeper/TestZKUtil.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 5519dc59ec5..0f57206f6bf 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -381,8 +381,8 @@ public class ZKUtil { * @return ensemble key with a name (if any) */ public static String getZooKeeperClusterKey(Configuration conf, String name) { - String ensemble = conf.get(HConstants.ZOOKEEPER_QUORUM.replaceAll( - "[\\t\\n\\x0B\\f\\r]", "")); + String ensemble = conf.get(HConstants.ZOOKEEPER_QUORUM).replaceAll( + "[\\t\\n\\x0B\\f\\r]", ""); StringBuilder builder = new StringBuilder(ensemble); builder.append(":"); builder.append(conf.get(HConstants.ZOOKEEPER_CLIENT_PORT)); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java new file mode 100644 index 00000000000..9e0f5ce551c --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java @@ -0,0 +1,43 @@ +/* + * Copyright 2015 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.zookeeper; + +import org.apache.hadoop.conf.Configuration; + +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * + */ +@Category({SmallTests.class}) +public class TestZKUtil { + + @Test + public void testGetZooKeeperClusterKey() { + Configuration conf = HBaseConfiguration.create(); + conf.set(HConstants.ZOOKEEPER_QUORUM, "\tlocalhost\n"); + conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "3333"); + conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "hbase"); + String clusterKey = ZKUtil.getZooKeeperClusterKey(conf, "test"); + Assert.assertTrue(!clusterKey.contains("\t") && !clusterKey.contains("\n")); + Assert.assertEquals("localhost:3333:hbase,test", clusterKey); + } +}