private void testKey(String ensemble, int port, String znode, Boolean multiplePortSupport) throws IOException { Configuration conf = new Configuration(); String key = ensemble + ":" + port + ":" + znode; String ensemble2 = null; ZKConfig.ZKClusterKey zkClusterKey = ZKConfig.transformClusterKey(key); if (multiplePortSupport) { ensemble2 = ZKConfig.standardizeZKQuorumServerString(ensemble, Integer.toString(port)); assertEquals(ensemble2, zkClusterKey.getQuorumString()); } else { assertEquals(ensemble, zkClusterKey.getQuorumString()); } assertEquals(port, zkClusterKey.getClientPort()); assertEquals(znode, zkClusterKey.getZnodeParent()); conf = HBaseConfiguration.createClusterConf(conf, key); assertEquals(zkClusterKey.getQuorumString(), conf.get(HConstants.ZOOKEEPER_QUORUM)); assertEquals(zkClusterKey.getClientPort(), conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, -1)); assertEquals(zkClusterKey.getZnodeParent(), conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT)); String reconstructedKey = ZKConfig.getZooKeeperClusterKey(conf); if (multiplePortSupport) { String key2 = ensemble2 + ":" + port + ":" + znode; assertEquals(key2, reconstructedKey); } else { assertEquals(key, reconstructedKey); } }
@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 = ZKConfig.getZooKeeperClusterKey(conf, "test"); assertTrue(!clusterKey.contains("\t") && !clusterKey.contains("\n")); assertEquals("localhost:3333:hbase,test", clusterKey); }