You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 19:44:50 UTC

svn commit: r1181969 - /hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java

Author: nspiegelberg
Date: Tue Oct 11 17:44:49 2011
New Revision: 1181969

URL: http://svn.apache.org/viewvc?rev=1181969&view=rev
Log:
Fix TestCloseRegionRetry unit test.

Summary:
This unit test used HBaseTestingUtility.createMultiRegions which used to cause
issues since it would create regions in .meta without the regions
actually being served by any region server. Also, added a configuration
option which speeds the execution of this unit test. Now it takes just
over 1 min.

Test Plan: 1) Run the unit test 100 times.

Reviewers: kannan, liyintang

Reviewed By: kannan

CC: hbase@lists, , pritam, kannan

Differential Revision: 313072

Task ID: 677331

Modified:
    hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java

Modified: hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java?rev=1181969&r1=1181968&r2=1181969&view=diff
==============================================================================
--- hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java (original)
+++ hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionCloseRetry.java Tue Oct 11 17:44:49 2011
@@ -6,12 +6,16 @@ package org.apache.hadoop.hbase.regionse
 import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.server.datanode.DataNode;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerAddress;
@@ -39,12 +43,16 @@ import org.junit.Test;
  */
 public class TestHRegionCloseRetry {
   final Log LOG = LogFactory.getLog(getClass());
-  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+  private static final Configuration conf = HBaseConfiguration.create();
+  private static HBaseTestingUtility TEST_UTIL = null;
   private static byte[][] FAMILIES = { Bytes.toBytes("f1"),
       Bytes.toBytes("f2"), Bytes.toBytes("f3"), Bytes.toBytes("f4") };
 
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
+    // Helps the unit test to exit quicker.
+    conf.setInt("dfs.client.block.recovery.retries", 0);
+    TEST_UTIL = new HBaseTestingUtility(conf);
     TEST_UTIL.startMiniCluster(3);
   }
 
@@ -58,22 +66,33 @@ public class TestHRegionCloseRetry {
 
     // Build some data.
     byte[] tableName = Bytes.toBytes("testCloseHRegionRetry");
-    TEST_UTIL.createTable(tableName, FAMILIES);
-    HTable table = new HTable(tableName);
+    HTable table = TEST_UTIL.createTable(tableName, FAMILIES);
     for (int i = 0; i < FAMILIES.length; i++) {
       byte[] columnFamily = FAMILIES[i];
-      TEST_UTIL.createMultiRegions(table, columnFamily);
       TEST_UTIL.loadTable(table, columnFamily);
     }
 
     // Pick a regionserver.
+    HRegionServer server = null;
+    HRegionInfo regionInfo = null;
     Configuration conf = TEST_UTIL.getConfiguration();
-    HRegionServer server = TEST_UTIL.getHBaseCluster().getRegionServer(0);
+    for (int i = 0; i < 3; i++) {
+      server = TEST_UTIL.getHBaseCluster().getRegionServer(i);
+
+      // Some initialiation relevant to zk.
+      HRegion[] region = server.getOnlineRegionsAsArray();
+      for (int j = 0; j < region.length; j++) {
+        if (!region[j].getRegionInfo().isRootRegion()
+            && !region[j].getRegionInfo().isMetaRegion()) {
+          regionInfo = region[j].getRegionInfo();
+          break;
+        }
+      }
+      if (regionInfo != null)
+        break;
+    }
+    assertNotNull(regionInfo);
 
-    // Some initializtion relevant to zk.
-    HRegion[] region = server.getOnlineRegionsAsArray();
-    assertTrue(region.length != 0);
-    HRegionInfo regionInfo = region[0].getRegionInfo();
     ZooKeeperWrapper zkWrapper = ZooKeeperWrapper.getInstance(conf, server
         .getHServerInfo().getServerName());
     String regionZNode = zkWrapper.getZNode(
@@ -82,16 +101,13 @@ public class TestHRegionCloseRetry {
     // Ensure region is online before closing.
     assertNotNull(server.getOnlineRegion(regionInfo.getRegionName()));
 
-    TEST_UTIL.getDFSCluster().shutdownDataNodes();
+    TEST_UTIL.getDFSCluster().shutdownNameNode();
     try {
       server.closeRegion(regionInfo, true);
     } catch (IOException e) {
       LOG.warn(e);
-      TEST_UTIL.getDFSCluster().startDataNodes(conf, 3, true, null, null);
-      TEST_UTIL.getDFSCluster().waitClusterUp();
-      LOG.info("New DFS Cluster up");
-      // Close region should fail since filesystem wad down. The region should
-      // be in the state "CLOSING"
+      TEST_UTIL.getDFSCluster().restartNameNode();
+
       Stat stat = new Stat();
       assertTrue(zkWrapper.exists(regionZNode, false));
       byte[] data = zkWrapper.readZNode(regionZNode, stat);
@@ -109,6 +125,7 @@ public class TestHRegionCloseRetry {
       // Verify region is closed.
       assertNull(server.getOnlineRegion(regionInfo.getRegionName()));
       assertEquals(HBaseEventType.RS2ZK_REGION_CLOSED, rsData.getHbEvent());
+      LOG.info("Test completed successfully");
       return;
     }
     fail("Close of region did not fail, even though filesystem was down");