HBASE-5053 HCM Tests leak connections (N Keywal)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1215314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f016b62fd
commit
0c5abfccd7
|
@ -276,6 +276,9 @@ public class HConnectionManager {
|
||||||
} else if (stopProxy) {
|
} else if (stopProxy) {
|
||||||
connection.stopProxyOnClose(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "HConnectionKey{" +
|
||||||
|
"properties=" + properties +
|
||||||
|
", username='" + username + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encapsulates connection to zookeeper and regionservers.*/
|
/* Encapsulates connection to zookeeper and regionservers.*/
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -33,6 +34,7 @@ import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HostConfiguration;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -112,14 +114,8 @@ public class TestHCM {
|
||||||
getHConnectionManagerCacheSize());
|
getHConnectionManagerCacheSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getHConnectionManagerCacheSize()
|
private static int getHConnectionManagerCacheSize(){
|
||||||
throws SecurityException, NoSuchFieldException,
|
return HConnectionTestingUtility.getConnectionCount();
|
||||||
IllegalArgumentException, IllegalAccessException {
|
|
||||||
Field cacheField =
|
|
||||||
HConnectionManager.class.getDeclaredField("HBASE_INSTANCES");
|
|
||||||
cacheField.setAccessible(true);
|
|
||||||
Map<?, ?> cache = (Map<?, ?>) cacheField.get(null);
|
|
||||||
return cache.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,12 +183,12 @@ public class TestHCM {
|
||||||
// go above zk connections, we just fall into cycle where we are failing
|
// 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.
|
// to set up a session and test runs for a long time.
|
||||||
int maxConnections = Math.min(zkmaxconnections - 1, 20);
|
int maxConnections = Math.min(zkmaxconnections - 1, 20);
|
||||||
List<HConnection> connections = new ArrayList<HConnection>();
|
List<HConnection> connections = new ArrayList<HConnection>(maxConnections);
|
||||||
HConnection previousConnection = null;
|
HConnection previousConnection = null;
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < maxConnections; i++) {
|
for (int i = 0; i < maxConnections; i++) {
|
||||||
// set random key to differentiate the connection from previous ones
|
// 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("some_key", String.valueOf(_randy.nextInt()));
|
||||||
configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
|
configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
|
||||||
String.valueOf(_randy.nextInt()));
|
String.valueOf(_randy.nextInt()));
|
||||||
|
@ -214,6 +210,7 @@ public class TestHCM {
|
||||||
LOG.info("The current HConnectionManager#HBASE_INSTANCES cache size is: "
|
LOG.info("The current HConnectionManager#HBASE_INSTANCES cache size is: "
|
||||||
+ getHConnectionManagerCacheSize());
|
+ getHConnectionManagerCacheSize());
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
|
connections.add(currentConnection);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
for (HConnection c: connections) {
|
for (HConnection c: connections) {
|
||||||
|
@ -225,11 +222,13 @@ public class TestHCM {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClosing() throws Exception {
|
public void testClosing() throws Exception {
|
||||||
Configuration configuration = TEST_UTIL.getConfiguration();
|
Configuration configuration =
|
||||||
|
new Configuration(TEST_UTIL.getConfiguration());
|
||||||
configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
|
configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
|
||||||
String.valueOf(_randy.nextInt()));
|
String.valueOf(_randy.nextInt()));
|
||||||
|
|
||||||
HConnection c1 = HConnectionManager.createConnection(configuration);
|
HConnection c1 = HConnectionManager.createConnection(configuration);
|
||||||
|
// We create two connections with the same key.
|
||||||
HConnection c2 = HConnectionManager.createConnection(configuration);
|
HConnection c2 = HConnectionManager.createConnection(configuration);
|
||||||
|
|
||||||
HConnection c3 = HConnectionManager.getConnection(configuration);
|
HConnection c3 = HConnectionManager.getConnection(configuration);
|
||||||
|
@ -247,9 +246,14 @@ public class TestHCM {
|
||||||
c3.close();
|
c3.close();
|
||||||
assertTrue(c3.isClosed());
|
assertTrue(c3.isClosed());
|
||||||
// c3 was removed from the cache
|
// c3 was removed from the cache
|
||||||
assertTrue(HConnectionManager.getConnection(configuration) != c3);
|
HConnection c5 = HConnectionManager.getConnection(configuration);
|
||||||
|
assertTrue(c5 != c3);
|
||||||
|
|
||||||
assertFalse(c2.isClosed());
|
assertFalse(c2.isClosed());
|
||||||
|
c2.close();
|
||||||
|
assertTrue(c2.isClosed());
|
||||||
|
c5.close();
|
||||||
|
assertTrue(c5.isClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue