Index: hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (revision 1505128) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (working copy) @@ -928,6 +928,15 @@ * @throws IOException */ public void shutdownMiniHBaseCluster() throws IOException { + shutdownMiniHBaseCluster(true); + } + + /** + * Shutdown HBase mini cluster. Does not shutdown zk or dfs if running. + * @param staleConnection + * @throws IOException + */ + public void shutdownMiniHBaseCluster(boolean staleConnection) throws IOException { if (hbaseAdmin != null) { hbaseAdmin.close(); hbaseAdmin = null; @@ -942,7 +951,7 @@ conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1); conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1); if (this.hbaseCluster != null) { - this.hbaseCluster.shutdown(); + this.hbaseCluster.shutdown(staleConnection); // Wait till hbase is down before going on to shutdown zk. this.hbaseCluster.waitUntilShutDown(); this.hbaseCluster = null; Index: hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java (revision 1505128) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java (working copy) @@ -231,6 +231,12 @@ public abstract void shutdown() throws IOException; /** + * Shut down the HBase cluster + * @param staleConnection + */ + public abstract void shutdown(boolean staleConnection) throws IOException; + + /** * Restores the cluster to it's initial state if this is a real cluster, * otherwise does nothing. */ Index: hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (revision 1505128) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (working copy) @@ -504,10 +504,19 @@ * @throws IOException */ public void shutdown() throws IOException { + shutdown(true); + } + + /** + * Shut down the mini HBase cluster + * @param staleConnection + * @throws IOException + */ + public void shutdown(boolean staleConnection) throws IOException { if (this.hbaseCluster != null) { this.hbaseCluster.shutdown(); } - HConnectionManager.deleteAllConnections(); + HConnectionManager.deleteAllConnections(staleConnection); } @Override Index: hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java (revision 1505128) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java (working copy) @@ -49,7 +49,7 @@ // enabling and shutdown the peer admin.enablePeer("2"); - utility2.shutdownMiniHBaseCluster(); + utility2.shutdownMiniHBaseCluster(false); byte[] rowkey = Bytes.toBytes("disable inactive peer"); Put put = new Put(rowkey); Index: hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java =================================================================== --- hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java (revision 1505128) +++ hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java (working copy) @@ -220,6 +220,11 @@ } @Override + public void shutdown(boolean staleConnection) throws IOException { + throw new RuntimeException("Not implemented yet"); + } + + @Override public boolean isDistributedCluster() { return true; } Index: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1505128) +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -318,19 +318,31 @@ } /** - * Delete information for all connections. + * Delete information for all connections. Close or not the connection, depending on the + * staleConnection boolean and the ref count. By default, you should use it with + * staleConnection to true. */ - public static void deleteAllConnections() { + public static void deleteAllConnections(boolean staleConnection) { synchronized (CONNECTION_INSTANCES) { Set connectionKeys = new HashSet(); connectionKeys.addAll(CONNECTION_INSTANCES.keySet()); for (HConnectionKey connectionKey : connectionKeys) { - deleteConnection(connectionKey, false); + deleteConnection(connectionKey, staleConnection); } CONNECTION_INSTANCES.clear(); } } + /** + * Delete information for all connections.. + * @Deprecated kept for backward compatibility, but the behavior is broken. HBASE-8983 + */ + @Deprecated + public static void deleteAllConnections() { + deleteAllConnections(false); + } + + private static void deleteConnection(HConnection connection, boolean staleConnection) { synchronized (CONNECTION_INSTANCES) { for (Entry e: CONNECTION_INSTANCES.entrySet()) { @@ -353,7 +365,7 @@ } } else { LOG.error("Connection not found in the list, can't delete it "+ - "(connection key=" + connectionKey + "). May be the key was modified?"); + "(connection key=" + connectionKey + "). May be the key was modified?", new Exception()); } } }