diff --git src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 868e8cf..de3e132 100644 --- src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -62,6 +62,7 @@ import org.apache.hadoop.hbase.io.hfile.ChecksumUtil; import org.apache.hadoop.hbase.io.hfile.Compression; import org.apache.hadoop.hbase.io.hfile.Compression.Algorithm; import org.apache.hadoop.hbase.io.hfile.HFile; +import org.apache.hadoop.hbase.mapreduce.MapreduceTestingShim; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.regionserver.HRegion; @@ -1439,8 +1440,14 @@ public class HBaseTestingUtility { mrCluster = new MiniMRCluster(0, 0, servers, FileSystem.get(conf).getUri().toString(), 1, null, null, null, new JobConf(conf)); - mrCluster.getJobTrackerRunner().getJobTracker().getConf().set("mapred.local.dir", + + JobConf jobConf = MapreduceTestingShim.getJobConf(mrCluster); + if (jobConf == null) { + jobConf = mrCluster.createJobConf(); + } + jobConf.set("mapred.local.dir", conf.get("mapred.local.dir")); //Hadoop MiniMR overwrites this while it should not + LOG.info("Mini mapreduce cluster started"); JobConf mrClusterJobConf = mrCluster.createJobConf(); c.set("mapred.job.tracker", mrClusterJobConf.get("mapred.job.tracker")); diff --git src/test/java/org/apache/hadoop/hbase/mapreduce/MapreduceTestingShim.java src/test/java/org/apache/hadoop/hbase/mapreduce/MapreduceTestingShim.java index 76de6a3..7432792 100644 --- src/test/java/org/apache/hadoop/hbase/mapreduce/MapreduceTestingShim.java +++ src/test/java/org/apache/hadoop/hbase/mapreduce/MapreduceTestingShim.java @@ -19,9 +19,12 @@ package org.apache.hadoop.hbase.mapreduce; import java.io.IOException; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.MiniMRCluster; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.mapreduce.JobID; @@ -29,11 +32,12 @@ import org.apache.hadoop.mapreduce.JobID; /** * This class provides shims for HBase to interact with the Hadoop 1.0.x and the * Hadoop 0.23.x series. - * + * * NOTE: No testing done against 0.22.x, or 0.21.x. */ abstract public class MapreduceTestingShim { private static MapreduceTestingShim instance; + private static Class[] emptyParam = new Class[] {}; static { try { @@ -49,11 +53,17 @@ abstract public class MapreduceTestingShim { abstract public JobContext newJobContext(Configuration jobConf) throws IOException; + abstract public JobConf obtainJobConf(MiniMRCluster cluster); + public static JobContext createJobContext(Configuration jobConf) throws IOException { return instance.newJobContext(jobConf); } + public static JobConf getJobConf(MiniMRCluster cluster) { + return instance.obtainJobConf(cluster); + } + private static class MapreduceV1Shim extends MapreduceTestingShim { public JobContext newJobContext(Configuration jobConf) throws IOException { // Implementing: @@ -68,6 +78,22 @@ abstract public class MapreduceTestingShim { "Failed to instantiate new JobContext(jobConf, new JobID())", e); } } + public JobConf obtainJobConf(MiniMRCluster cluster) { + if (cluster == null) return null; + try { + Object runner = cluster.getJobTrackerRunner(); + Method meth = runner.getClass().getDeclaredMethod("getJobTracker", emptyParam); + Object tracker = meth.invoke(runner, new Object []{}); + Method m = tracker.getClass().getDeclaredMethod("getConf", emptyParam); + return (JobConf) m.invoke(tracker, new Object []{}); + } catch (NoSuchMethodException nsme) { + return null; + } catch (InvocationTargetException ite) { + return null; + } catch (IllegalAccessException iae) { + return null; + } + } }; private static class MapreduceV2Shim extends MapreduceTestingShim { @@ -83,6 +109,18 @@ abstract public class MapreduceTestingShim { "Failed to return from Job.getInstance(jobConf)"); } } + public JobConf obtainJobConf(MiniMRCluster cluster) { + try { + Method meth = MiniMRCluster.class.getMethod("getJobTrackerConf", emptyParam); + return (JobConf) meth.invoke(cluster, new Object []{}); + } catch (NoSuchMethodException nsme) { + return null; + } catch (InvocationTargetException ite) { + return null; + } catch (IllegalAccessException iae) { + return null; + } + } }; }