HBASE-4974 Remove some resources leaks on the tests
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1212688 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e608b3979
commit
d855d71ba8
|
@ -569,7 +569,10 @@ public class HBaseTestingUtility {
|
|||
while (s.next() != null) {
|
||||
continue;
|
||||
}
|
||||
s.close();
|
||||
t.close();
|
||||
LOG.info("Minicluster is up");
|
||||
//getHBaseAdmin();
|
||||
return this.hbaseCluster;
|
||||
}
|
||||
|
||||
|
@ -588,6 +591,8 @@ public class HBaseTestingUtility {
|
|||
// do nothing
|
||||
}
|
||||
LOG.info("HBase has been restarted");
|
||||
s.close();
|
||||
t.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -710,8 +715,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);
|
||||
}
|
||||
|
||||
|
@ -730,7 +736,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);
|
||||
}
|
||||
|
||||
|
@ -757,7 +765,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);
|
||||
}
|
||||
|
||||
|
@ -796,7 +806,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);
|
||||
}
|
||||
|
||||
|
@ -821,7 +833,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);
|
||||
}
|
||||
|
||||
|
@ -849,7 +863,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);
|
||||
}
|
||||
|
||||
|
@ -861,6 +877,7 @@ public class HBaseTestingUtility {
|
|||
HBaseAdmin admin = new HBaseAdmin(getConfiguration());
|
||||
admin.disableTable(tableName);
|
||||
admin.deleteTable(tableName);
|
||||
admin.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -878,6 +895,7 @@ public class HBaseTestingUtility {
|
|||
table.delete(del);
|
||||
}
|
||||
resScan = table.getScanner(scan);
|
||||
resScan.close();
|
||||
return table;
|
||||
}
|
||||
|
||||
|
@ -1067,11 +1085,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;
|
||||
}
|
||||
|
||||
|
@ -1103,6 +1126,8 @@ public class HBaseTestingUtility {
|
|||
LOG.info("createMultiRegionsInMeta: inserted " + hri.toString());
|
||||
newRegions.add(hri);
|
||||
}
|
||||
|
||||
meta.close();
|
||||
return newRegions;
|
||||
}
|
||||
|
||||
|
@ -1122,6 +1147,7 @@ public class HBaseTestingUtility {
|
|||
rows.add(result.getRow());
|
||||
}
|
||||
s.close();
|
||||
t.close();
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -1145,6 +1171,7 @@ public class HBaseTestingUtility {
|
|||
}
|
||||
}
|
||||
s.close();
|
||||
t.close();
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1299,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1316,6 +1343,7 @@ public class HBaseTestingUtility {
|
|||
public void closeRegion(byte[] regionName) throws IOException {
|
||||
HBaseAdmin admin = getHBaseAdmin();
|
||||
admin.closeRegion(regionName, null);
|
||||
admin.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1414,6 +1442,7 @@ public class HBaseTestingUtility {
|
|||
System.currentTimeMillis() - startWait < timeoutMillis);
|
||||
Thread.sleep(200);
|
||||
}
|
||||
admin.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1551,6 +1580,7 @@ public class HBaseTestingUtility {
|
|||
result.clear();
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<HRegionInfo> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -199,7 +199,9 @@ public class TestScannersWithFilters {
|
|||
table.delete(d);
|
||||
}
|
||||
numRows -= 2;
|
||||
table.close();
|
||||
}
|
||||
admin.close();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
Loading…
Reference in New Issue