Source:
<code>public void testCachedConnections() throws Exception { final String tableName = generateUniqueName(); final String index1Name = generateUniqueName(); final Connection conn = DriverManager.getConnection(getUrl()); final HBaseAdmin admin = getUtility().getHBaseAdmin(); final MiniHBaseCluster cluster = getUtility().getHBaseCluster(); final HRegionServer regionServer = cluster.getRegionServer(0); Configuration conf = admin.getConfiguration(); final int noOfOrgs = 20; final AtomicBoolean flag = new AtomicBoolean(); flag.set(false); String createTableSql = "CREATE TABLE " + tableName + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('" + ORG_PREFIX + "-" + noOfOrgs / 2 + "')"; conn.createStatement().execute(createTableSql); conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)"); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName)); final HRegionInfo regionInfo = regions.get(0); writeToTable(tableName, conn, noOfOrgs); <START> Thread.sleep(1000); <END> int beforeRegionCloseCount = getActiveConnections(regionServer, conf); int regionsCount = admin.getOnlineRegions(regionServer.getServerName()).size(); admin.unassign(regionInfo.getEncodedNameAsBytes(), true); while(!(admin.getOnlineRegions(regionServer.getServerName()).size() < regionsCount)); int afterRegionCloseCount = getActiveConnections(regionServer, conf); assertTrue("Cached connections not closed when region closes: ", afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0); }</code><technical_language>This is guaranteed work. Is alternative</technical_language>

Target:
public void testCachedConnections() throws Exception { final String tableName = generateUniqueName(); final String index1Name = generateUniqueName(); final Connection conn = DriverManager.getConnection(getUrl()); final HBaseAdmin admin = getUtility().getHBaseAdmin(); final MiniHBaseCluster cluster = getUtility().getHBaseCluster(); final HRegionServer regionServer = cluster.getRegionServer(0); Configuration conf = admin.getConfiguration(); final int noOfOrgs = 20; final AtomicBoolean flag = new AtomicBoolean(); flag.set(false); String createTableSql = "CREATE TABLE " + tableName + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('" + ORG_PREFIX + "-" + noOfOrgs / 2 + "')"; conn.createStatement().execute(createTableSql); conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)"); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName)); final HRegionInfo regionInfo = regions.get(0); writeToTable(tableName, conn, noOfOrgs); int beforeRegionCloseCount = getActiveConnections(regionServer, conf); int regionsCount = admin.getOnlineRegions(regionServer.getServerName()).size(); admin.unassign(regionInfo.getEncodedNameAsBytes(), true); while(!(admin.getOnlineRegions(regionServer.getServerName()).size() < regionsCount)); int afterRegionCloseCount = getActiveConnections(regionServer, conf); assertTrue("Cached connections not closed when region closes: ", afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0); }