HBASE-10292. TestRegionServerCoprocessorExceptionWithAbort fails occasionally

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1556586 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2014-01-08 17:50:43 +00:00
parent b6a875e83a
commit 1e04340c83
2 changed files with 42 additions and 34 deletions

View File

@ -49,9 +49,7 @@ import static org.junit.Assert.*;
public class TestRegionServerCoprocessorExceptionWithAbort {
static final Log LOG = LogFactory.getLog(TestRegionServerCoprocessorExceptionWithAbort.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] ROW = Bytes.toBytes("aaa");
private static final TableName TABLE_NAME =
TableName.valueOf("observed_table");
private static final TableName TABLE_NAME = TableName.valueOf("observed_table");
@BeforeClass
public static void setupBeforeClass() throws Exception {
@ -83,30 +81,51 @@ public class TestRegionServerCoprocessorExceptionWithAbort {
// Note which regionServer will abort (after put is attempted).
final HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
Put put = new Put(ROW);
put.add(TEST_FAMILY, ROW, ROW);
Assert.assertFalse("The region server should be available", regionServer.isAborted());
boolean threwIOE = false;
try {
LOG.info("Running put " + put);
final byte[] ROW = Bytes.toBytes("aaa");
Put put = new Put(ROW);
put.add(TEST_FAMILY, ROW, ROW);
table.put(put);
fail("The put should have failed, as the coprocessor is buggy");
} catch (IOException ignored) {
// Expected.
table.flushCommits();
} catch (IOException e) {
threwIOE = true;
} finally {
assertTrue("The regionserver should have thrown an exception", threwIOE);
}
Assert.assertTrue("The region server should have aborted", regionServer.isAborted());
// Wait 10 seconds for the regionserver to abort: expected result is that
// it will abort.
boolean aborted = false;
for (int i = 0; i < 10; i++) {
aborted = regionServer.isAborted();
if (aborted) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
fail("InterruptedException while waiting for regionserver " +
"zk node to be deleted.");
}
}
Assert.assertTrue("The region server should have aborted", aborted);
table.close();
}
public static class BuggyRegionObserver extends SimpleRegionObserver {
@SuppressWarnings("null")
@Override
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
final Put put, final WALEdit edit,
final Durability durability) {
TableName tableName =
c.getEnvironment().getRegion().getRegionInfo().getTable();
if (TABLE_NAME.equals(tableName) && Bytes.equals(put.getRow(), ROW)) {
throw new NullPointerException("Buggy coprocessor: " + put);
String tableName =
c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString();
if (tableName.equals("observed_table")) {
// Trigger a NPE to fail the coprocessor
Integer i = null;
i = i + 1;
}
}
}

View File

@ -25,7 +25,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.util.Bytes;
@ -55,6 +54,7 @@ public class TestRegionServerCoprocessorExceptionWithRemove {
String tableName =
c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString();
if (tableName.equals("observed_table")) {
// Trigger a NPE to fail the coprocessor
Integer i = null;
i = i + 1;
}
@ -100,33 +100,22 @@ public class TestRegionServerCoprocessorExceptionWithRemove {
HRegionServer regionServer =
TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
// same logic as {@link TestMasterCoprocessorExceptionWithRemove},
// but exception will be RetriesExhaustedWithDetailException rather
// than DoNotRetryIOException. The latter exception is what the RegionServer
// will have actually thrown, but the client will wrap this in a
// RetriesExhaustedWithDetailException.
// We will verify that "DoNotRetryIOException" appears in the text of the
// the exception's detailMessage.
boolean threwDNRE = false;
boolean threwIOE = false;
try {
final byte[] ROW = Bytes.toBytes("aaa");
Put put = new Put(ROW);
put.add(TEST_FAMILY, ROW, ROW);
table.put(put);
} catch (RetriesExhaustedWithDetailsException e) {
// below, could call instead :
// startsWith("Failed 1 action: DoNotRetryIOException.")
// But that might be too brittle if client-side
// DoNotRetryIOException-handler changes its message.
assertTrue(e.getMessage().contains("DoNotRetryIOException"));
threwDNRE = true;
table.flushCommits();
} catch (IOException e) {
threwIOE = true;
} finally {
assertTrue(threwDNRE);
assertTrue("The regionserver should have thrown an exception", threwIOE);
}
// Wait 3 seconds for the regionserver to abort: expected result is that
// Wait 10 seconds for the regionserver to abort: expected result is that
// it will survive and not abort.
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 10; i++) {
assertFalse(regionServer.isAborted());
try {
Thread.sleep(1000);