Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BF44E900C for ; Sat, 26 Nov 2011 15:46:41 +0000 (UTC) Received: (qmail 26177 invoked by uid 500); 26 Nov 2011 15:46:41 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 26128 invoked by uid 500); 26 Nov 2011 15:46:40 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 26121 invoked by uid 99); 26 Nov 2011 15:46:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Nov 2011 15:46:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Nov 2011 15:46:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3747D2388993 for ; Sat, 26 Nov 2011 15:46:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1206462 - /hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java Date: Sat, 26 Nov 2011 15:46:19 -0000 To: commits@hbase.apache.org From: tedyu@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111126154619.3747D2388993@eris.apache.org> Author: tedyu Date: Sat Nov 26 15:46:18 2011 New Revision: 1206462 URL: http://svn.apache.org/viewvc?rev=1206462&view=rev Log: HBASE-4832 TestRegionServerCoprocessorExceptionWithAbort fails if the region server stops too fast Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java?rev=1206462&r1=1206461&r2=1206462&view=diff ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java (original) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java Sat Nov 26 15:46:18 2011 @@ -22,6 +22,8 @@ package org.apache.hadoop.hbase.coproces import java.io.IOException; +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.client.HTable; @@ -29,6 +31,9 @@ import org.apache.hadoop.hbase.client.Pu 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.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -44,7 +49,40 @@ 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; @BeforeClass public static void setupBeforeClass() throws Exception { @@ -61,7 +99,7 @@ public class TestRegionServerCoprocessor TEST_UTIL.shutdownMiniCluster(); } - @Test(timeout=30000) + @Test public void testExceptionFromCoprocessorDuringPut() throws IOException { // When we try to write to TEST_TABLE, the buggy coprocessor will @@ -75,35 +113,50 @@ public class TestRegionServerCoprocessor TEST_UTIL.createMultiRegions(table, TEST_FAMILY)); // Note which regionServer will abort (after put is attempted). - HRegionServer regionServer = + 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); + + boolean caughtInterruption = false; try { final byte[] ROW = Bytes.toBytes("aaa"); Put put = new Put(ROW); put.add(TEST_FAMILY, ROW, ROW); table.put(put); } catch (IOException e) { - fail("put() failed: " + e); - } - // Wait up to 30 seconds for regionserver to abort. - boolean regionServerAborted = false; - for (int i = 0; i < 30; i++) { - if (regionServer.isAborted()) { - regionServerAborted = true; - break; + // 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(1000); + Thread.sleep(timeout); + fail("RegionServer did not abort within 30 seconds."); } catch (InterruptedException e) { - fail("InterruptedException while waiting for regionserver " + - "zk node to be deleted."); + // .. or it might be caught here. + LOG.debug("caught interruption here (during sleep())."); + caughtInterruption = true; } } + assertTrue("Main thread caught interruption.",caughtInterruption); assertTrue("RegionServer aborted on coprocessor exception, as expected.", - regionServerAborted); + rsTracker.regionZKNodeWasDeleted); } - public static class BuggyRegionObserver extends SimpleRegionObserver { + public static class BuggyRegionObserver extends SimpleRegionObserver { @Override public void prePut(final ObserverContext c, final Put put, final WALEdit edit,