You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2013/07/13 00:04:05 UTC

svn commit: r1502709 - /hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java

Author: enis
Date: Fri Jul 12 22:04:05 2013
New Revision: 1502709

URL: http://svn.apache.org/r1502709
Log:
HBASE-8914 [0.94] TestRegionServerCoprocessorExceptionWithAbort is flaky

Modified:
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java?rev=1502709&r1=1502708&r2=1502709&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java Fri Jul 12 22:04:05 2013
@@ -1,5 +1,4 @@
 /*
- * Copyright 2011 The Apache Software Foundation
  *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,27 +19,28 @@
 
 package org.apache.hadoop.hbase.coprocessor;
 
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 
+import junit.framework.Assert;
+
 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.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MediumTests;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import static org.junit.Assert.*;
-
 /**
  * Tests unhandled exceptions thrown by coprocessors running on a regionserver..
  * Expected result is that the regionserver will abort with an informative
@@ -49,49 +49,18 @@ import static org.junit.Assert.*;
  */
 @Category(MediumTests.class)
 public class TestRegionServerCoprocessorExceptionWithAbort {
-  static final Log LOG = LogFactory.getLog(TestRegionObserverInterface.class);
-
-  private class zkwAbortable implements Abortable {
-    @Override
-    public void abort(String why, Throwable e) {
-      throw new RuntimeException("Fatal ZK rs tracker error, why=", e);
-    }
-    @Override
-    public boolean isAborted() {
-      return false;
-    }
-  };
-
-  private class RSTracker extends ZooKeeperNodeTracker {
-    public boolean regionZKNodeWasDeleted = false;
-    public String rsNode;
-    private Thread mainThread;
-
-    public RSTracker(ZooKeeperWatcher zkw, String rsNode, Thread mainThread) {
-      super(zkw, rsNode, new zkwAbortable());
-      this.rsNode = rsNode;
-      this.mainThread = mainThread;
-    }
-
-    @Override
-    public synchronized void nodeDeleted(String path) {
-      if (path.equals(rsNode)) {
-        regionZKNodeWasDeleted = true;
-        mainThread.interrupt();
-      }
-    }
-  }
-  private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
-  static final int timeout = 30000;
+  static final Log LOG = LogFactory.getLog(TestRegionServerCoprocessorExceptionWithAbort.class);
+  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+  private static final String TABLE_NAME = "observed_table";
 
   @BeforeClass
   public static void setupBeforeClass() throws Exception {
     // set configure to indicate which cp should be loaded
     Configuration conf = TEST_UTIL.getConfiguration();
-    conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
-        BuggyRegionObserver.class.getName());
+    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);  // Let's fail fast.
+    conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, BuggyRegionObserver.class.getName());
     conf.set("hbase.coprocessor.abortonerror", "true");
-    TEST_UTIL.startMiniCluster(2);
+    TEST_UTIL.startMiniCluster(3);
   }
 
   @AfterClass
@@ -101,11 +70,11 @@ public class TestRegionServerCoprocessor
 
   @Test
   public void testExceptionFromCoprocessorDuringPut()
-      throws IOException {
+    throws IOException, InterruptedException {
     // When we try to write to TEST_TABLE, the buggy coprocessor will
     // cause a NullPointerException, which will cause the regionserver (which
     // hosts the region we attempted to write to) to abort.
-    byte[] TEST_TABLE = Bytes.toBytes("observed_table");
+    byte[] TEST_TABLE = Bytes.toBytes(TABLE_NAME);
     byte[] TEST_FAMILY = Bytes.toBytes("aaa");
 
     HTable table = TEST_UTIL.createTable(TEST_TABLE, TEST_FAMILY);
@@ -113,47 +82,20 @@ public class TestRegionServerCoprocessor
     TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
 
     // Note which regionServer will abort (after put is attempted).
-    final HRegionServer regionServer =
-        TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
+    final HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
 
-    // add watch so we can know when this regionserver aborted.
-    ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
-        "unittest", new zkwAbortable());
-
-    RSTracker rsTracker = new RSTracker(zkw,
-        "/hbase/rs/"+regionServer.getServerName(), Thread.currentThread());
-    rsTracker.start();
-    zkw.registerListener(rsTracker);
+    final byte[] ROW = Bytes.toBytes("aaa");
+    Put put = new Put(ROW);
+    put.add(TEST_FAMILY, ROW, ROW);
 
-    boolean caughtInterruption = false;
+    Assert.assertFalse("The region server should be available", regionServer.isAborted());
     try {
-      final byte[] ROW = Bytes.toBytes("aaa");
-      Put put = new Put(ROW);
-      put.add(TEST_FAMILY, ROW, ROW);
       table.put(put);
-    } catch (IOException e) {
-      // Depending on exact timing of the threads involved, zkw's interruption
-      // might be caught here ...
-      if (e.getCause().getClass().equals(InterruptedException.class)) {
-	LOG.debug("caught interruption here (during put()).");
-        caughtInterruption = true;
-      } else {
-        fail("put() failed: " + e);
-      }
-    }
-    if (caughtInterruption == false) {
-      try {
-        Thread.sleep(timeout);
-        fail("RegionServer did not abort within 30 seconds.");
-      } catch (InterruptedException e) {
-        // .. or it might be caught here.
-	LOG.debug("caught interruption here (during sleep()).");
-        caughtInterruption = true;
-      }
+      fail("The put should have failed, as the coprocessor is buggy");
+    } catch (IOException ignored) {
+      // Expected.
     }
-    assertTrue("Main thread caught interruption.",caughtInterruption);
-    assertTrue("RegionServer aborted on coprocessor exception, as expected.",
-        rsTracker.regionZKNodeWasDeleted);
+    Assert.assertTrue("The region server should have aborted", regionServer.isAborted());
     table.close();
   }
 
@@ -162,11 +104,9 @@ public class TestRegionServerCoprocessor
     public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
                        final Put put, final WALEdit edit,
                        final boolean writeToWAL) {
-      String tableName =
-          c.getEnvironment().getRegion().getRegionInfo().getTableNameAsString();
-      if (tableName.equals("observed_table")) {
-        Integer i = null;
-        i = i + 1;
+      String tableName = c.getEnvironment().getRegion().getRegionInfo().getTableNameAsString();
+      if (TABLE_NAME.equals(tableName)) {
+        throw new NullPointerException("Buggy coprocessor");
       }
     }
   }