You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2011/12/10 00:35:02 UTC

svn commit: r1212691 - in /hbase/branches/0.92: ./ src/test/java/org/apache/hadoop/hbase/ src/test/java/org/apache/hadoop/hbase/client/ src/test/java/org/apache/hadoop/hbase/master/ src/test/java/org/apache/hadoop/hbase/rest/

Author: stack
Date: Fri Dec  9 23:35:02 2011
New Revision: 1212691

URL: http://svn.apache.org/viewvc?rev=1212691&view=rev
Log:
HBASE-4974 Remove some resources leaks on the tests

Modified:
    hbase/branches/0.92/CHANGES.txt
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java

Modified: hbase/branches/0.92/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/CHANGES.txt?rev=1212691&r1=1212690&r2=1212691&view=diff
==============================================================================
--- hbase/branches/0.92/CHANGES.txt (original)
+++ hbase/branches/0.92/CHANGES.txt Fri Dec  9 23:35:02 2011
@@ -472,6 +472,7 @@ Release 0.92.0 - Unreleased
    HBASE-4969  tautology in HRegionInfo.readFields (Prakash Khemani)
    HBASE-4994  TestHeapSize broke in trunk
    HBASE-4995  Increase zk maxClientCnxns to give us some head room
+   HBASE-4974  Remove some resources leaks on the tests (nkeywal)
 
   TESTS
    HBASE-4492  TestRollingRestart fails intermittently

Modified: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=1212691&r1=1212690&r2=1212691&view=diff
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (original)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java Fri Dec  9 23:35:02 2011
@@ -527,7 +527,10 @@ public class HBaseTestingUtility {
     while (s.next() != null) {
       continue;
     }
+    s.close();
+    t.close();
     LOG.info("Minicluster is up");
+    //getHBaseAdmin();
     return this.hbaseCluster;
   }
 
@@ -546,6 +549,8 @@ public class HBaseTestingUtility {
       // do nothing
     }
     LOG.info("HBase has been restarted");
+    s.close();
+    t.close();
   }
 
   /**
@@ -669,7 +674,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);
   }
 
@@ -696,7 +703,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);
   }
 
@@ -735,7 +744,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);
   }
 
@@ -760,7 +771,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);
   }
 
@@ -788,7 +801,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);
   }
 
@@ -800,6 +815,7 @@ public class HBaseTestingUtility {
     HBaseAdmin admin = new HBaseAdmin(getConfiguration());
     admin.disableTable(tableName);
     admin.deleteTable(tableName);
+    admin.close();
   }
 
   /**
@@ -817,6 +833,7 @@ public class HBaseTestingUtility {
       table.delete(del);
     }
     resScan = table.getScanner(scan);
+    resScan.close();
     return table;
   }
 
@@ -1006,11 +1023,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;
   }
 
@@ -1042,6 +1064,8 @@ public class HBaseTestingUtility {
       LOG.info("createMultiRegionsInMeta: inserted " + hri.toString());
       newRegions.add(hri);
     }
+
+    meta.close();
     return newRegions;
   }
 
@@ -1061,6 +1085,7 @@ public class HBaseTestingUtility {
       rows.add(result.getRow());
     }
     s.close();
+    t.close();
     return rows;
   }
 
@@ -1084,6 +1109,7 @@ public class HBaseTestingUtility {
       }
     }
     s.close();
+    t.close();
     return rows;
   }
 
@@ -1211,7 +1237,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();
     }
   }
 
@@ -1255,6 +1281,7 @@ public class HBaseTestingUtility {
   public void closeRegion(byte[] regionName) throws IOException {
     HBaseAdmin admin = getHBaseAdmin();
     admin.closeRegion(regionName, null);
+    admin.close();
   }
 
   /**
@@ -1345,6 +1372,7 @@ public class HBaseTestingUtility {
           System.currentTimeMillis() - startWait < timeoutMillis);
       Thread.sleep(200);
     }
+    admin.close();
   }
 
   /**
@@ -1482,6 +1510,7 @@ public class HBaseTestingUtility {
         result.clear();
       }
     }
+    scanner.close();
     return result;
   }
 

Modified: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1212691&r1=1212690&r2=1212691&view=diff
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Fri Dec  9 23:35:02 2011
@@ -232,6 +232,7 @@ public class TestAdmin {
       ok = false;
     }
     assertTrue(ok);
+    ht.close();
   }
 
   @Test
@@ -281,6 +282,9 @@ public class TestAdmin {
       ok = false;
     }
     assertTrue(ok);
+
+    ht1.close();
+    ht2.close();
   }
 
   @Test
@@ -288,7 +292,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);
   }
@@ -306,6 +310,7 @@ public class TestAdmin {
     HTable table = new HTable(TEST_UTIL.getConfiguration(), "myTestTable");
     HTableDescriptor confirmedHtd = table.getTableDescriptor();
     assertEquals(htd.compareTo(confirmedHtd), 0);
+    table.close();
   }
 
   @Test
@@ -330,7 +335,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);
 
@@ -418,7 +423,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);
 
@@ -576,6 +581,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
 
@@ -595,8 +601,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());
@@ -634,7 +640,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
 
@@ -650,14 +657,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 [][] {
@@ -670,14 +680,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
@@ -856,6 +867,7 @@ public class TestAdmin {
       }
     } finally {
       TEST_UTIL.deleteTable(tableName);
+      table.close();
     }
   }
 
@@ -876,7 +888,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);
@@ -967,7 +979,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();
   }
 
   /***
@@ -989,6 +1001,7 @@ public class TestAdmin {
     HBaseAdmin hbaseadmin = new HBaseAdmin(TEST_UTIL.getConfiguration());
     hbaseadmin.createTable(new HTableDescriptor(name), startKey, endKey,
       expectedRegions);
+    hbaseadmin.close();
   }
 
   /**
@@ -1004,6 +1017,7 @@ public class TestAdmin {
     Put put = new Put(value);
     put.add(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value);
     table.put(put);
+    table.close();
   }
 
   /**
@@ -1045,7 +1059,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);
   }
 
@@ -1057,7 +1071,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);
   }
@@ -1070,8 +1084,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();
+    }
   }
 
   /**
@@ -1087,7 +1105,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);
@@ -1108,7 +1126,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);
@@ -1130,7 +1148,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);
@@ -1160,7 +1178,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);
 
@@ -1184,7 +1202,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);
 
@@ -1207,7 +1225,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);
@@ -1240,6 +1258,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{
@@ -1288,7 +1314,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);
@@ -1375,7 +1400,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();
 
@@ -1400,6 +1426,8 @@ public class TestAdmin {
         }
       }
     }
+
+    table.close();
     return regionServer;
   }
   

Modified: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java?rev=1212691&r1=1212690&r2=1212691&view=diff
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java (original)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java Fri Dec  9 23:35:02 2011
@@ -207,14 +207,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
@@ -455,6 +457,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,

Modified: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java?rev=1212691&r1=1212690&r2=1212691&view=diff
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java (original)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java Fri Dec  9 23:35:02 2011
@@ -201,7 +201,9 @@ public class TestScannersWithFilters {
         table.delete(d);
       }
       numRows -= 2;
+      table.close();
     }
+    admin.close();
   }
 
   @AfterClass