diff --git src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 66d808f..3986e9f 100644 --- src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -558,7 +558,10 @@ public class HBaseTestingUtility { while (s.next() != null) { continue; } + s.close(); + t.close(); LOG.info("Minicluster is up"); + //getHBaseAdmin(); return this.hbaseCluster; } @@ -577,6 +580,8 @@ public class HBaseTestingUtility { // do nothing } LOG.info("HBase has been restarted"); + s.close(); + t.close(); } /** @@ -699,8 +704,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 +725,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 +754,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 +795,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 +822,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 +852,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 +866,7 @@ public class HBaseTestingUtility { HBaseAdmin admin = new HBaseAdmin(getConfiguration()); admin.disableTable(tableName); admin.deleteTable(tableName); + admin.close(); } /** @@ -867,6 +884,7 @@ public class HBaseTestingUtility { table.delete(del); } resScan = table.getScanner(scan); + resScan.close(); return table; } @@ -1056,11 +1074,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 +1115,8 @@ public class HBaseTestingUtility { LOG.info("createMultiRegionsInMeta: inserted " + hri.toString()); newRegions.add(hri); } + + meta.close(); return newRegions; } @@ -1111,6 +1136,7 @@ public class HBaseTestingUtility { rows.add(result.getRow()); } s.close(); + t.close(); return rows; } @@ -1134,6 +1160,7 @@ public class HBaseTestingUtility { } } s.close(); + t.close(); return rows; } @@ -1261,7 +1288,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 +1332,7 @@ public class HBaseTestingUtility { public void closeRegion(byte[] regionName) throws IOException { HBaseAdmin admin = getHBaseAdmin(); admin.closeRegion(regionName, null); + admin.close(); } /** @@ -1403,6 +1431,7 @@ public class HBaseTestingUtility { System.currentTimeMillis() - startWait < timeoutMillis); Thread.sleep(200); } + admin.close(); } /** @@ -1540,6 +1569,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..7a085f2 100644 --- src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -221,6 +221,7 @@ public class TestAdmin { ok = false; } assertTrue(ok); + ht.close(); } @Test @@ -270,6 +271,9 @@ public class TestAdmin { ok = false; } assertTrue(ok); + + ht1.close(); + ht2.close(); } @Test @@ -277,7 +281,7 @@ public class TestAdmin { HTableDescriptor [] tables = admin.listTables(); int numTables = tables.length; TEST_UTIL.createTable(Bytes.toBytes("testCreateTable"), - HConstants.CATALOG_FAMILY); + HConstants.CATALOG_FAMILY).close(); tables = this.admin.listTables(); assertEquals(numTables + 1, tables.length); } @@ -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 @@ -319,7 +324,7 @@ public class TestAdmin { "hbase.online.schema.update.enable", true); HTableDescriptor [] tables = admin.listTables(); int numTables = tables.length; - TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); + TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); tables = this.admin.listTables(); assertEquals(numTables + 1, tables.length); @@ -407,7 +412,7 @@ public class TestAdmin { "hbase.online.schema.update.enable", false); HTableDescriptor[] tables = admin.listTables(); int numTables = tables.length; - TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); + TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); tables = this.admin.listTables(); assertEquals(numTables + 1, tables.length); @@ -565,6 +570,7 @@ public class TestAdmin { assertTrue(hri.getEndKey() == null || hri.getEndKey().length == 0); verifyRoundRobinDistribution(ht, expectedRegions); + ht.close(); // Now test using start/end with a number of regions @@ -584,8 +590,8 @@ public class TestAdmin { admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); admin.createTable(desc, startKey, endKey, expectedRegions); - ht = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); - regions = ht.getRegionsInfo(); + HTable ht2 = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); + regions = ht2.getRegionsInfo(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), expectedRegions, regions.size()); @@ -623,7 +629,8 @@ public class TestAdmin { assertTrue(Bytes.equals(hri.getStartKey(), new byte [] {9,9,9,9,9,9,9,9,9,9})); assertTrue(hri.getEndKey() == null || hri.getEndKey().length == 0); - verifyRoundRobinDistribution(ht, expectedRegions); + verifyRoundRobinDistribution(ht2, expectedRegions); + ht2.close(); // Try once more with something that divides into something infinite @@ -639,14 +646,17 @@ public class TestAdmin { admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); admin.createTable(desc, startKey, endKey, expectedRegions); - ht = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); - regions = ht.getRegionsInfo(); + + HTable ht3 = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); + regions = ht3.getRegionsInfo(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), expectedRegions, regions.size()); System.err.println("Found " + regions.size() + " regions"); - verifyRoundRobinDistribution(ht, expectedRegions); + verifyRoundRobinDistribution(ht3, expectedRegions); + ht3.close(); + // Try an invalid case where there are duplicate split keys splitKeys = new byte [][] { @@ -659,14 +669,15 @@ 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()); + HBaseAdmin ladmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); try { - admin.createTable(desc, splitKeys); + ladmin.createTable(desc, splitKeys); assertTrue("Should not be able to create this table because of " + "duplicate split keys", false); } catch(IllegalArgumentException iae) { // Expected } + ladmin.close(); } @Test @@ -900,6 +911,7 @@ public class TestAdmin { } } finally { TEST_UTIL.deleteTable(tableName); + table.close(); } } @@ -920,7 +932,7 @@ public class TestAdmin { @Test public void testEnableDisableAddColumnDeleteColumn() throws Exception { byte [] tableName = Bytes.toBytes("testMasterAdmin"); - TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); + TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); this.admin.disableTable(tableName); try { new HTable(TEST_UTIL.getConfiguration(), tableName); @@ -1011,7 +1023,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 +1045,7 @@ public class TestAdmin { HBaseAdmin hbaseadmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); hbaseadmin.createTable(new HTableDescriptor(name), startKey, endKey, expectedRegions); + hbaseadmin.close(); } /** @@ -1048,6 +1061,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 +1103,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,7 +1115,7 @@ public class TestAdmin { public void testTableNotEnabledExceptionWithATable() throws IOException { final byte [] name = Bytes.toBytes( "testTableNotEnabledExceptionWithATable"); - TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); + TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close(); this.admin.disableTable(name); this.admin.disableTable(name); } @@ -1114,8 +1128,12 @@ 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); + try { this.admin.enableTable(name); + }finally { + t.close(); + } } /** @@ -1131,7 +1149,7 @@ public class TestAdmin { public void testShouldCloseTheRegionBasedOnTheEncodedRegionName() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1152,7 +1170,7 @@ public class TestAdmin { @Test public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1174,7 +1192,7 @@ public class TestAdmin { @Test public void testCloseRegionThatFetchesTheHRIFromMeta() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion2"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1204,7 +1222,7 @@ public class TestAdmin { @Test public void testCloseRegionWhenServerNameIsNull() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion3"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1228,7 +1246,7 @@ public class TestAdmin { @Test public void testCloseRegionWhenServerNameIsEmpty() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegionWhenServerNameIsEmpty"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1251,7 +1269,7 @@ public class TestAdmin { @Test public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion4"); - HBaseAdmin admin = createTable(TABLENAME); + createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1284,6 +1302,14 @@ public class TestAdmin { return admin; } + private void createTableWithDefaultConf(byte[] TABLENAME) throws IOException { + HTableDescriptor htd = new HTableDescriptor(TABLENAME); + HColumnDescriptor hcd = new HColumnDescriptor("value"); + htd.addFamily(hcd); + + admin.createTable(htd, null); + } + @Test public void testHundredsOfTable() 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); @@ -1419,7 +1444,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 +1470,8 @@ public class TestAdmin { } } } + + table.close(); return regionServer; } 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