From 228ebc64d853cca75f7071d1d53bbeaca3da4b03 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 28 Nov 2011 18:22:18 +0000 Subject: [PATCH] HBASE-4877 TestHCM failing sporadically on jenkins and always for me on an ubuntu machine git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1207491 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + .../apache/hadoop/hbase/client/TestHCM.java | 61 ++++++++++++------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 90fee6407f7..3afd03f8389 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -447,6 +447,8 @@ Release 0.92.0 - Unreleased HBASE-4739 Master dying while going to close a region can leave it in transition forever (Gao Jinchao) HBASE-4855 SplitLogManager hangs on cluster restart due to batch.installed doubly counted + HBASE-4877 TestHCM failing sporadically on jenkins and always for me on an + ubuntu machine TESTS HBASE-4450 test for number of blocks read: to serve as baseline for expected diff --git a/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java b/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index 4847ab445b8..692e606df92 100644 --- a/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ b/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -178,31 +178,46 @@ public class TestHCM { */ @Test public void testConnectionUniqueness() throws Exception { + int zkmaxconnections = TEST_UTIL.getConfiguration(). + getInt(HConstants.ZOOKEEPER_MAX_CLIENT_CNXNS, + HConstants.DEFAULT_ZOOKEPER_MAX_CLIENT_CNXNS); + // Test up to a max that is < the maximum number of zk connections. If we + // 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 connections = new ArrayList(); HConnection previousConnection = null; - for (int i = 0; i < HConnectionManager.MAX_CACHED_HBASE_INSTANCES + 10; i++) { - // set random key to differentiate the connection from previous ones - Configuration configuration = TEST_UTIL.getConfiguration(); - configuration.set("some_key", String.valueOf(_randy.nextInt())); - configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID, - String.valueOf(_randy.nextInt())); - LOG.info("The hash code of the current configuration is: " - + configuration.hashCode()); - HConnection currentConnection = HConnectionManager - .getConnection(configuration); - if (previousConnection != null) { - assertTrue("Got the same connection even though its key changed!", - previousConnection != currentConnection); - } - // change the configuration, so that it is no longer reachable from the - // client's perspective. However, since its part of the LRU doubly linked - // list, it will eventually get thrown out, at which time it should also - // close the corresponding {@link HConnection}. - configuration.set("other_key", String.valueOf(_randy.nextInt())); + try { + for (int i = 0; i < maxConnections; i++) { + // set random key to differentiate the connection from previous ones + Configuration configuration = TEST_UTIL.getConfiguration(); + configuration.set("some_key", String.valueOf(_randy.nextInt())); + configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID, + String.valueOf(_randy.nextInt())); + LOG.info("The hash code of the current configuration is: " + + configuration.hashCode()); + HConnection currentConnection = + HConnectionManager.getConnection(configuration); + if (previousConnection != null) { + assertTrue("Got the same connection even though its key changed!", + previousConnection != currentConnection); + } + // change the configuration, so that it is no longer reachable from the + // client's perspective. However, since its part of the LRU doubly linked + // list, it will eventually get thrown out, at which time it should also + // close the corresponding {@link HConnection}. + configuration.set("other_key", String.valueOf(_randy.nextInt())); - previousConnection = currentConnection; - LOG.info("The current HConnectionManager#HBASE_INSTANCES cache size is: " - + getHConnectionManagerCacheSize()); - Thread.sleep(50); + previousConnection = currentConnection; + LOG.info("The current HConnectionManager#HBASE_INSTANCES cache size is: " + + getHConnectionManagerCacheSize()); + Thread.sleep(50); + } + } finally { + for (HConnection c: connections) { + // Clean up connections made so we don't interfere w/ subsequent tests. + HConnectionManager.deleteConnection(c.getConfiguration(), true); + } } }