diff --git src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 66d808f..5b7e7ac 100644 --- src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -699,8 +699,9 @@ public class HBaseTestingUtility { HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); desc.addFamily(hcd); } - (new HBaseAdmin(getConfiguration())).createTable(desc, startKey, - endKey, numRegions); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc, startKey, endKey, numRegions); + admin.close(); return new HTable(getConfiguration(), tableName); } @@ -719,7 +720,9 @@ public class HBaseTestingUtility { for(byte[] family : families) { desc.addFamily(new HColumnDescriptor(family)); } - getHBaseAdmin().createTable(desc); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc); + admin.close(); return new HTable(c, tableName); } @@ -746,7 +749,9 @@ public class HBaseTestingUtility { HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); desc.addFamily(hcd); } - getHBaseAdmin().createTable(desc); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc); + admin.close(); return new HTable(c, tableName); } @@ -785,7 +790,9 @@ public class HBaseTestingUtility { HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); desc.addFamily(hcd); } - getHBaseAdmin().createTable(desc); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc); + admin.close(); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -810,7 +817,9 @@ public class HBaseTestingUtility { HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); desc.addFamily(hcd); } - getHBaseAdmin().createTable(desc); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc); + admin.close(); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -838,7 +847,9 @@ public class HBaseTestingUtility { desc.addFamily(hcd); i++; } - getHBaseAdmin().createTable(desc); + HBaseAdmin admin = getHBaseAdmin(); + admin.createTable(desc); + admin.close(); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -850,6 +861,7 @@ public class HBaseTestingUtility { HBaseAdmin admin = new HBaseAdmin(getConfiguration()); admin.disableTable(tableName); admin.deleteTable(tableName); + admin.close(); } /** @@ -867,6 +879,7 @@ public class HBaseTestingUtility { table.delete(del); } resScan = table.getScanner(scan); + resScan.close(); return table; } @@ -1056,11 +1069,16 @@ public class HBaseTestingUtility { HConnection conn = table.getConnection(); conn.clearRegionCache(); // assign all the new regions IF table is enabled. - if (getHBaseAdmin().isTableEnabled(table.getTableName())) { + HBaseAdmin admin = getHBaseAdmin(); + if (admin.isTableEnabled(table.getTableName())) { for(HRegionInfo hri : newRegions) { hbaseCluster.getMaster().assignRegion(hri); } } + + admin.close(); + meta.close(); + return count; } @@ -1092,6 +1110,8 @@ public class HBaseTestingUtility { LOG.info("createMultiRegionsInMeta: inserted " + hri.toString()); newRegions.add(hri); } + + meta.close(); return newRegions; } @@ -1111,6 +1131,7 @@ public class HBaseTestingUtility { rows.add(result.getRow()); } s.close(); + t.close(); return rows; } @@ -1134,6 +1155,7 @@ public class HBaseTestingUtility { } } s.close(); + t.close(); return rows; } @@ -1261,7 +1283,7 @@ public class HBaseTestingUtility { Thread.sleep(sleep); if (checkStatus) { - new HTable(new Configuration(conf), HConstants.META_TABLE_NAME); + new HTable(new Configuration(conf), HConstants.META_TABLE_NAME).close(); } } @@ -1305,6 +1327,7 @@ public class HBaseTestingUtility { public void closeRegion(byte[] regionName) throws IOException { HBaseAdmin admin = getHBaseAdmin(); admin.closeRegion(regionName, null); + admin.close(); } /** @@ -1403,6 +1426,7 @@ public class HBaseTestingUtility { System.currentTimeMillis() - startWait < timeoutMillis); Thread.sleep(200); } + admin.close(); } /** @@ -1540,6 +1564,7 @@ public class HBaseTestingUtility { result.clear(); } } + scanner.close(); return result; } diff --git src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index c0b0922..c08d6f2 100644 --- src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -270,16 +270,20 @@ public class TestAdmin { ok = false; } assertTrue(ok); + + ht1.close(); + ht2.close(); } @Test public void testCreateTable() throws IOException { HTableDescriptor [] tables = admin.listTables(); int numTables = tables.length; - TEST_UTIL.createTable(Bytes.toBytes("testCreateTable"), + HTable t = TEST_UTIL.createTable(Bytes.toBytes("testCreateTable"), HConstants.CATALOG_FAMILY); tables = this.admin.listTables(); assertEquals(numTables + 1, tables.length); + t.close(); } @Test @@ -295,6 +299,7 @@ public class TestAdmin { HTable table = new HTable(TEST_UTIL.getConfiguration(), "myTestTable"); HTableDescriptor confirmedHtd = table.getTableDescriptor(); assertEquals(htd.compareTo(confirmedHtd), 0); + table.close(); } @Test @@ -581,7 +586,6 @@ public class TestAdmin { desc = new HTableDescriptor(TABLE_2); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); admin.createTable(desc, startKey, endKey, expectedRegions); ht = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); @@ -636,7 +640,7 @@ public class TestAdmin { desc = new HTableDescriptor(TABLE_3); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + admin.createTable(desc, startKey, endKey, expectedRegions); ht = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); @@ -659,7 +663,7 @@ public class TestAdmin { byte [] TABLE_4 = Bytes.add(tableName, Bytes.toBytes("_4")); desc = new HTableDescriptor(TABLE_4); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + try { admin.createTable(desc, splitKeys); assertTrue("Should not be able to create this table because of " + @@ -675,9 +679,10 @@ public class TestAdmin { boolean exist = false; exist = this.admin.tableExists(table); assertEquals(false, exist); - TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY); + HTable t = TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY); exist = this.admin.tableExists(table); assertEquals(true, exist); + t.close(); } /** @@ -900,6 +905,7 @@ public class TestAdmin { } } finally { TEST_UTIL.deleteTable(tableName); + table.close(); } } @@ -920,7 +926,7 @@ public class TestAdmin { @Test public void testEnableDisableAddColumnDeleteColumn() throws Exception { byte [] tableName = Bytes.toBytes("testMasterAdmin"); - TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); + HTable t = TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); this.admin.disableTable(tableName); try { new HTable(TEST_UTIL.getConfiguration(), tableName); @@ -936,6 +942,7 @@ public class TestAdmin { } this.admin.disableTable(tableName); this.admin.deleteTable(tableName); + t.close(); } @Test @@ -1011,7 +1018,7 @@ public class TestAdmin { admin.createTable(new HTableDescriptor(name + "SOMEUPPERCASE")); admin.createTable(new HTableDescriptor(name)); // Before fix, below would fail throwing a NoServerForRegionException. - new HTable(TEST_UTIL.getConfiguration(), name); + new HTable(TEST_UTIL.getConfiguration(), name).close(); } /*** @@ -1033,6 +1040,8 @@ public class TestAdmin { HBaseAdmin hbaseadmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); hbaseadmin.createTable(new HTableDescriptor(name), startKey, endKey, expectedRegions); + + hbaseadmin.close(); } /** @@ -1048,6 +1057,7 @@ public class TestAdmin { Put put = new Put(value); put.add(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value); table.put(put); + table.close(); } /** @@ -1089,7 +1099,7 @@ public class TestAdmin { @Test (expected=TableExistsException.class) public void testTableExistsExceptionWithATable() throws IOException { final byte [] name = Bytes.toBytes("testTableExistsExceptionWithATable"); - TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); + TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close(); TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); } @@ -1101,9 +1111,13 @@ public class TestAdmin { public void testTableNotEnabledExceptionWithATable() throws IOException { final byte [] name = Bytes.toBytes( "testTableNotEnabledExceptionWithATable"); - TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); - this.admin.disableTable(name); + HTable t = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); this.admin.disableTable(name); + try { + this.admin.disableTable(name); + }finally { + t.close(); + } } /** @@ -1114,8 +1128,9 @@ public class TestAdmin { public void testTableNotDisabledExceptionWithATable() throws IOException { final byte [] name = Bytes.toBytes( "testTableNotDisabledExceptionWithATable"); - TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); + HTable t = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); this.admin.enableTable(name); + t.close(); } /** @@ -1127,11 +1142,12 @@ public class TestAdmin { new HTable(TEST_UTIL.getConfiguration(), "testTableNotFoundExceptionWithoutAnyTables"); } + @Test public void testShouldCloseTheRegionBasedOnTheEncodedRegionName() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion"); - HBaseAdmin admin = createTable(TABLENAME); + HBaseAdmin ladmin = createTable(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1139,7 +1155,7 @@ public class TestAdmin { for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { info = regionInfo; - admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), rs + ladmin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), rs .getServerName().getServerName()); } } @@ -1147,12 +1163,14 @@ public class TestAdmin { onlineRegions = rs.getOnlineRegions(); assertFalse("The region should not be present in online regions list.", onlineRegions.contains(info)); + + ladmin.close(); } @Test public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); - HBaseAdmin admin = createTable(TABLENAME); + HBaseAdmin ladmin = createTable(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1161,7 +1179,7 @@ public class TestAdmin { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion1")) { info = regionInfo; - admin.closeRegionWithEncodedRegionName("sample", rs.getServerName() + ladmin.closeRegionWithEncodedRegionName("sample", rs.getServerName() .getServerName()); } } @@ -1169,6 +1187,8 @@ public class TestAdmin { onlineRegions = rs.getOnlineRegions(); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); + + ladmin.close(); } @Test @@ -1199,12 +1219,14 @@ public class TestAdmin { assertFalse("The region should not be present in online regions list.", isInList); + + admin.close(); } @Test public void testCloseRegionWhenServerNameIsNull() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion3"); - HBaseAdmin admin = createTable(TABLENAME); + HBaseAdmin ladmin = createTable(TABLENAME); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1214,7 +1236,7 @@ public class TestAdmin { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString() .contains("TestHBACloseRegion3")) { - admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), + ladmin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), null); } } @@ -1222,6 +1244,7 @@ public class TestAdmin { fail("The test should throw exception if the servername passed is null."); } catch (IllegalArgumentException e) { } + ladmin.close(); } @@ -1246,6 +1269,7 @@ public class TestAdmin { fail("The test should throw exception if the servername passed is empty."); } catch (IllegalArgumentException e) { } + admin.close(); } @Test @@ -1269,6 +1293,8 @@ public class TestAdmin { onlineRegions = rs.getOnlineRegions(); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); + + admin.close(); } private HBaseAdmin createTable(byte[] TABLENAME) throws IOException { @@ -1332,7 +1358,6 @@ public class TestAdmin { HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); admin.createTable(desc, startKey, endKey, expectedRegions); List RegionInfos = admin.getTableRegions(tableName); @@ -1340,7 +1365,6 @@ public class TestAdmin { assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + RegionInfos.size(), expectedRegions, RegionInfos.size()); - } @Test @@ -1419,7 +1443,8 @@ public class TestAdmin { private HRegionServer startAndWriteData(String tableName, byte[] value) throws IOException { // When the META table can be opened, the region servers are running - new HTable(TEST_UTIL.getConfiguration(), HConstants.META_TABLE_NAME); + new HTable( + TEST_UTIL.getConfiguration(), HConstants.META_TABLE_NAME).close(); HRegionServer regionServer = TEST_UTIL.getHBaseCluster() .getRegionServerThreads().get(0).getRegionServer(); @@ -1444,6 +1469,9 @@ public class TestAdmin { } } } + + admin.close(); + return regionServer; } diff --git src/test/java/org/apache/diff --git src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java index d1024ee..0ece0bd 100644 --- src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java +++ src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java @@ -202,14 +202,16 @@ public class TestCatalogJanitor { return false; } + private boolean stopped = false; + @Override public void stop(String why) { - //no-op + stopped = true; } @Override public boolean isStopped() { - return false; + return stopped; } @Override @@ -458,6 +460,9 @@ public class TestCatalogJanitor { // Super parent should get cleaned up now both splita and splitb are gone. assertTrue(janitor.cleanParent(parent, regions.get(parent))); + + services.stop("test finished"); + janitor.join(); } private String setRootDirAndCleanIt(final HBaseTestingUtility htu, diff --git src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java index 9b7666e..07915ed 100644 --- src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java +++ src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java @@ -199,7 +199,9 @@ public class TestScannersWithFilters { table.delete(d); } numRows -= 2; + table.close(); } + admin.close(); } @AfterClass