hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-13040 Possible failure of TestHMasterRPCException (Zhang Duo)
Date Tue, 17 Feb 2015 20:10:34 GMT
Repository: hbase
Updated Branches:
  refs/heads/master ca25a6a87 -> 54d70e61b


HBASE-13040 Possible failure of TestHMasterRPCException (Zhang Duo)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/54d70e61
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/54d70e61
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/54d70e61

Branch: refs/heads/master
Commit: 54d70e61bf06109ec8f129fb6b21461aa51d20d0
Parents: ca25a6a
Author: stack <stack@apache.org>
Authored: Tue Feb 17 12:10:18 2015 -0800
Committer: stack <stack@apache.org>
Committed: Tue Feb 17 12:10:18 2015 -0800

----------------------------------------------------------------------
 .../hbase/master/TestHMasterRPCException.java   | 113 +++++++++++--------
 1 file changed, 68 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/54d70e61/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
index 2419918..37d6940 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
@@ -19,15 +19,18 @@
 
 package org.apache.hadoop.hbase.master;
 
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-import java.net.SocketTimeoutException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.*;
 import org.apache.hadoop.hbase.CoordinatedStateManager;
 import org.apache.hadoop.hbase.CoordinatedStateManagerFactory;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.ipc.RpcClient;
 import org.apache.hadoop.hbase.ipc.RpcClientFactory;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@@ -36,60 +39,80 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRe
 import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.testclassification.MasterTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.zookeeper.KeeperException;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import com.google.protobuf.BlockingRpcChannel;
 import com.google.protobuf.ServiceException;
 
-@Category({MasterTests.class, MediumTests.class})
+@Category({ MasterTests.class, MediumTests.class })
 public class TestHMasterRPCException {
 
-  @Test
-  public void testRPCException() throws Exception {
-    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
-    TEST_UTIL.startMiniZKCluster();
-    Configuration conf = TEST_UTIL.getConfiguration();
+  private static final Log LOG = LogFactory.getLog(TestHMasterRPCException.class);
+
+  private final HBaseTestingUtility testUtil = HBaseTestingUtility.createLocalHTU();
+
+  private HMaster master;
+
+  private RpcClient rpcClient;
+
+  @Before
+  public void setUp() throws Exception {
+    Configuration conf = testUtil.getConfiguration();
     conf.set(HConstants.MASTER_PORT, "0");
+    conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
+    testUtil.startMiniZKCluster();
+
     CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
-    HMaster hm = new HMaster(conf, cp);
-    ServerName sm = hm.getServerName();
-    RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
-    try {
-      int i = 0;
-      //retry the RPC a few times; we have seen SocketTimeoutExceptions if we
-      //try to connect too soon. Retry on SocketTimeoutException.
-      while (i < 20) {
-        try {
-          BlockingRpcChannel channel =
-            rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
-          MasterProtos.MasterService.BlockingInterface stub =
+    ZooKeeperWatcher watcher = testUtil.getZooKeeperWatcher();
+    ZKUtil.createWithParents(watcher, watcher.getMasterAddressZNode(), Bytes.toBytes("fake:123"));
+    master = new HMaster(conf, cp);
+    rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
+  }
+
+  @After
+  public void tearDown() throws IOException {
+    if (rpcClient != null) {
+      rpcClient.close();
+    }
+    if (master != null) {
+      master.stopMaster();
+    }
+    testUtil.shutdownMiniZKCluster();
+  }
+
+  @Test
+  public void testRPCException() throws IOException, InterruptedException, KeeperException
{
+    ServerName sm = master.getServerName();
+    boolean fakeZNodeDelete = false;
+    for (int i = 0; i < 20; i++) {
+      try {
+        BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(),
0);
+        MasterProtos.MasterService.BlockingInterface stub =
             MasterProtos.MasterService.newBlockingStub(channel);
-          stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
-          fail();
-        } catch (ServiceException ex) {
-          IOException ie = ProtobufUtil.getRemoteException(ex);
-          if (!(ie instanceof SocketTimeoutException)) {
-            if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
-                "ServerNotRunningYetException: Server is not running yet")) {
-              // Done.  Got the exception we wanted.
-              System.out.println("Expected exception: " + ie.getMessage());
-              return;
-            } else {
-              throw ex;
-            }
-          } else {
-            System.err.println("Got SocketTimeoutException. Will retry. ");
-          }
-        } catch (Throwable t) {
-          fail("Unexpected throwable: " + t);
+        assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance())
+            .getIsMasterRunning());
+        return;
+      } catch (ServiceException ex) {
+        IOException ie = ProtobufUtil.getRemoteException(ex);
+        // No SocketTimeoutException here. RpcServer is already started after the construction
of
+        // HMaster.
+        assertTrue(ie.getMessage().startsWith(
+          "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running
yet"));
+        LOG.info("Expected exception: ", ie);
+        if (!fakeZNodeDelete) {
+          testUtil.getZooKeeperWatcher().getRecoverableZooKeeper()
+              .delete(testUtil.getZooKeeperWatcher().getMasterAddressZNode(), -1);
+          fakeZNodeDelete = true;
         }
-        Thread.sleep(100);
-        i++;
       }
-      fail();
-    } finally {
-      rpcClient.close();
+      Thread.sleep(1000);
     }
   }
-}
\ No newline at end of file
+}


Mime
View raw message