diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index ed2a453..71a3dea 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -561,41 +561,42 @@ public class HBaseTestingUtility { * @return zk cluster started. */ public MiniZooKeeperCluster startMiniZKCluster(int zooKeeperServerNum) - throws Exception { - setupClusterTestDir(); - return startMiniZKCluster(clusterTestDir, zooKeeperServerNum); - } - - private MiniZooKeeperCluster startMiniZKCluster(final File dir) - throws Exception { - return startMiniZKCluster(dir,1); + throws Exception { + MiniZooKeeperCluster mzkc = new MiniZooKeeperCluster(this.getConfiguration()); + final int defPort = this.conf.getInt("test.hbase.zookeeper.property.clientPort", 0); + if (defPort > 0){ + // If there is a port in the config file, we use it. + mzkc.setDefaultClientPort(defPort); + } + return startMiniZKCluster(mzkc, zooKeeperServerNum); } /** - * Start a mini ZK cluster. If the property "test.hbase.zookeeper.property.clientPort" is set - * the port mentionned is used as the default port for ZooKeeper. + * Call if you want to set up a minizookeepercluster but you want to create the instance yourself so you + * can set config on it other than the default before it is started. + * The passed mzkc instance should not be running. + * @param mzkc + * @param zooKeeperServerNum + * @see #startMiniZKCluster() if you want zk + dfs + hbase mini cluster. + * @throws Exception + * @see #shutdownMiniZKCluster() + * @return zk cluster started. */ - private MiniZooKeeperCluster startMiniZKCluster(final File dir, - int zooKeeperServerNum) + public MiniZooKeeperCluster startMiniZKCluster(final MiniZooKeeperCluster mzkc, int zooKeeperServerNum) throws Exception { + setupClusterTestDir(); if (this.zkCluster != null) { - throw new IOException("Cluster already running at " + dir); + throw new IOException("Cluster already running at " + this.clusterTestDir); } this.passedZkCluster = false; - this.zkCluster = new MiniZooKeeperCluster(this.getConfiguration()); - final int defPort = this.conf.getInt("test.hbase.zookeeper.property.clientPort", 0); - if (defPort > 0){ - // If there is a port in the config file, we use it. - this.zkCluster.setDefaultClientPort(defPort); - } - int clientPort = this.zkCluster.startup(dir,zooKeeperServerNum); - this.conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, - Integer.toString(clientPort)); + this.zkCluster = mzkc; + int clientPort = this.zkCluster.startup(this.clusterTestDir, zooKeeperServerNum); + this.conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(clientPort)); return this.zkCluster; } /** - * Shuts down zk cluster created by call to {@link #startMiniZKCluster(File)} + * Shuts down zk cluster created by call to startMiniZKCluster. * or does nothing. * @throws IOException * @see #startMiniZKCluster() @@ -699,7 +700,7 @@ public class HBaseTestingUtility { // Start up a zk cluster. if (this.zkCluster == null) { - startMiniZKCluster(clusterTestDir); + startMiniZKCluster(); } // Start the MiniHBaseCluster