Index: src/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 676035) +++ src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -60,6 +60,9 @@ * Used by {@link HTable} and {@link HBaseAdmin} */ public class HConnectionManager implements HConstants { + + private static boolean acceptingRequests = true; + /* * Private. Not instantiable. */ @@ -80,13 +83,16 @@ * @return HConnection object for the instance specified by the configuration */ public static HConnection getConnection(HBaseConfiguration conf) { - TableServers connection; - synchronized (HBASE_INSTANCES) { - String instanceName = conf.get(HBASE_DIR); - connection = HBASE_INSTANCES.get(instanceName); - if (connection == null) { - connection = new TableServers(conf); - HBASE_INSTANCES.put(instanceName, connection); + TableServers connection = null; + if(acceptingRequests) { + + synchronized (HBASE_INSTANCES) { + String instanceName = conf.get(HBASE_DIR); + connection = HBASE_INSTANCES.get(instanceName); + if (connection == null) { + connection = new TableServers(conf); + HBASE_INSTANCES.put(instanceName, connection); + } } } return connection; @@ -97,8 +103,10 @@ * @param conf */ public static void deleteConnectionInfo(HBaseConfiguration conf) { - synchronized (HBASE_INSTANCES) { - HBASE_INSTANCES.remove(conf.get(HBASE_DIR)); + if(acceptingRequests) { + synchronized (HBASE_INSTANCES) { + HBASE_INSTANCES.remove(conf.get(HBASE_DIR)); + } } } @@ -106,10 +114,31 @@ * Clear the static map of connection info. */ public static void deleteConnectionInfo() { - synchronized (HBASE_INSTANCES) { - HBASE_INSTANCES.clear(); + if(acceptingRequests) { + synchronized (HBASE_INSTANCES) { + HBASE_INSTANCES.clear(); + } } } + + /** + * Method only used for testing purposes. + * Deletes connection informations and makes that no other + * request is accepted. + */ + public static void closeConnectionsForTests() { + deleteConnectionInfo(); + acceptingRequests = false; + } + + /** + * Method only used for testing purposes. + * HCM now accepts connections again. This is required in tests + * that have many test* methods since HCM is static. + */ + public static void openConnectionsForTests() { + acceptingRequests = true; + } /* Encapsulates finding the servers for an HBase instance */ Index: src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java =================================================================== --- src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java (revision 676035) +++ src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java (working copy) @@ -103,6 +103,7 @@ @Override protected void setUp() throws Exception { try { + HConnectionManager.openConnectionsForTests(); if (startDfs) { // start up the dfs dfsCluster = new MiniDFSCluster(conf, 2, true, (String[])null); @@ -145,7 +146,7 @@ protected void tearDown() throws Exception { super.tearDown(); try { - HConnectionManager.deleteConnectionInfo(conf); + HConnectionManager.closeConnectionsForTests(); if (this.cluster != null) { try { this.cluster.shutdown();