hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1215314 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/client/HConnectionManager.java test/java/org/apache/hadoop/hbase/client/TestHCM.java
Date Fri, 16 Dec 2011 22:05:02 GMT
Author: tedyu
Date: Fri Dec 16 22:05:02 2011
New Revision: 1215314

URL: http://svn.apache.org/viewvc?rev=1215314&view=rev
Log:
HBASE-5053 HCM Tests leak connections (N Keywal)

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1215314&r1=1215313&r2=1215314&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Fri Dec
16 22:05:02 2011
@@ -276,6 +276,9 @@ public class HConnectionManager {
         } else if (stopProxy) {
           connection.stopProxyOnClose(stopProxy);
         }
+      }else {
+        LOG.error("Connection not found in the list, can't delete it "+
+          "(connection key="+connectionKey+"). May be the key was modified?");
       }
     }
   }
@@ -470,6 +473,14 @@ public class HConnectionManager {
       }
       return true;
     }
+
+    @Override
+    public String toString() {
+      return "HConnectionKey{" +
+        "properties=" + properties +
+        ", username='" + username + '\'' +
+        '}';
+    }
   }
 
   /* Encapsulates connection to zookeeper and regionservers.*/

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java?rev=1215314&r1=1215313&r2=1215314&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java Fri Dec 16 22:05:02
2011
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertEquals;
 
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -33,6 +34,7 @@ import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 
+import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -112,14 +114,8 @@ public class TestHCM {
       getHConnectionManagerCacheSize());
   }
 
-  private static int getHConnectionManagerCacheSize()
-  throws SecurityException, NoSuchFieldException,
-  IllegalArgumentException, IllegalAccessException {
-    Field cacheField =
-      HConnectionManager.class.getDeclaredField("HBASE_INSTANCES");
-    cacheField.setAccessible(true);
-    Map<?, ?> cache = (Map<?, ?>) cacheField.get(null);
-    return cache.size();
+  private static int getHConnectionManagerCacheSize(){
+    return HConnectionTestingUtility.getConnectionCount();
   }
 
   /**
@@ -187,12 +183,12 @@ public class TestHCM {
     // go above zk connections, we just fall into cycle where we are failing
     // to set up a session and test runs for a long time.
     int maxConnections = Math.min(zkmaxconnections - 1, 20);
-    List<HConnection> connections = new ArrayList<HConnection>();
+    List<HConnection> connections = new ArrayList<HConnection>(maxConnections);
     HConnection previousConnection = null;
     try {
       for (int i = 0; i < maxConnections; i++) {
         // set random key to differentiate the connection from previous ones
-        Configuration configuration = TEST_UTIL.getConfiguration();
+        Configuration configuration = new Configuration(TEST_UTIL.getConfiguration());
         configuration.set("some_key", String.valueOf(_randy.nextInt()));
         configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
             String.valueOf(_randy.nextInt()));
@@ -214,6 +210,7 @@ public class TestHCM {
         LOG.info("The current HConnectionManager#HBASE_INSTANCES cache size is: "
             + getHConnectionManagerCacheSize());
         Thread.sleep(50);
+        connections.add(currentConnection);
       }
     } finally {
       for (HConnection c: connections) {
@@ -225,11 +222,13 @@ public class TestHCM {
 
   @Test
   public void testClosing() throws Exception {
-    Configuration configuration = TEST_UTIL.getConfiguration();
+    Configuration configuration =
+      new Configuration(TEST_UTIL.getConfiguration());
     configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
         String.valueOf(_randy.nextInt()));
 
     HConnection c1 = HConnectionManager.createConnection(configuration);
+    // We create two connections with the same key.
     HConnection c2 = HConnectionManager.createConnection(configuration);
 
     HConnection c3 = HConnectionManager.getConnection(configuration);
@@ -247,9 +246,14 @@ public class TestHCM {
     c3.close();
     assertTrue(c3.isClosed());
     // c3 was removed from the cache
-    assertTrue(HConnectionManager.getConnection(configuration) != c3);
+    HConnection c5 = HConnectionManager.getConnection(configuration);
+    assertTrue(c5 != c3);
 
     assertFalse(c2.isClosed());
+    c2.close();
+    assertTrue(c2.isClosed());
+    c5.close();
+    assertTrue(c5.isClosed());
   }
 
   /**



Mime
View raw message