diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index a006a9bdc4c..8c406664598 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -481,6 +481,42 @@ public class HBaseTestingUtility { createDirAndSetProperty("mapred_local", "mapred.local.dir"); createDirAndSetProperty("mapred_system", "mapred.system.dir"); createDirAndSetProperty("mapred_temp", "mapred.temp.dir"); + enableShortCircuit(); + + } + + + /** + * Get the HBase setting for dfs.client.read.shortcircuit from the conf or a system property. + * This allows to specify this parameter on the command line. + * If not set, default is true. + */ + public boolean isReadShortCircuitOn(){ + final String propName = "hbase.tests.use.shortcircuit.reads"; + String readOnProp = System.getProperty(propName); + if (readOnProp != null){ + return Boolean.parseBoolean(readOnProp); + } else { + return conf.getBoolean(propName, true); + } + } + + /** Enable the short circuit read, unless configured differently. + * Set both HBase and HDFS settings, including skipping the hdfs checksum checks. + */ + private void enableShortCircuit() { + if (isReadShortCircuitOn()) { + String curUser = System.getProperty("user.name"); + LOG.info("read short circuit is ON for user " + curUser); + // read short circuit, for hdfs + conf.set("dfs.block.local-path-access.user", curUser); + // read short circuit, for hbase + conf.setBoolean("dfs.client.read.shortcircuit", true); + // Skip checking checksum, for the hdfs client and the datanode + conf.setBoolean("dfs.client.read.shortcircuit.skip.checksum", true); + } else { + LOG.info("read short circuit is OFF"); + } } private String createDirAndSetProperty(final String relPath, String property) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java index 2f8b59aa7b7..c67dad1d940 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java @@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.io.hfile.HFileScanner; import org.apache.hadoop.hbase.io.hfile.NoOpDataBlockEncoder; import org.apache.hadoop.hbase.regionserver.StoreFile.BloomType; import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Assume; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -163,6 +164,10 @@ public class TestFSErrorsExposed { */ @Test(timeout=5 * 60 * 1000) public void testFullSystemBubblesFSErrors() throws Exception { + // We won't have an error if the datanode is not there if we use short circuit + // it's a known 'feature'. + Assume.assumeTrue(!util.isReadShortCircuitOn()); + try { // We set it not to run or it will trigger server shutdown while sync'ing // because all the datanodes are bad