mrunit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1369676 - in /mrunit/trunk/src: main/java/org/apache/hadoop/mrunit/ main/java/org/apache/hadoop/mrunit/internal/mapred/ main/java/org/apache/hadoop/mrunit/mapreduce/ test/java/org/apache/hadoop/mrunit/ test/java/org/apache/hadoop/mrunit/in...
Date Sun, 05 Aug 2012 20:38:28 GMT
Author: brock
Date: Sun Aug  5 20:38:27 2012
New Revision: 1369676

URL: http://svn.apache.org/viewvc?rev=1369676&view=rev
Log:
MRUNIT-125: reduce duplicate code related to fluent methods with generics

Modified:
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriverBase.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriverBase.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/PipelineMapReduceDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockInputSplit.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockReporter.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestConfigureClose.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestCounters.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestExample.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestPipelineMapReduceDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockOutputCollector.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockReporter.java

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriver.java Sun Aug  5 20:38:27 2012
@@ -25,7 +25,6 @@ import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapred.Counters;
 import org.apache.hadoop.mapred.InputFormat;
 import org.apache.hadoop.mapred.JobConf;
@@ -45,8 +44,7 @@ import org.apache.hadoop.util.Reflection
  * the harness will deliver the input to the Mapper and will check its outputs
  * against the expected results.
  */
-@SuppressWarnings("deprecation")
-public class MapDriver<K1, V1, K2, V2> extends MapDriverBase<K1, V1, K2, V2> {
+public class MapDriver<K1, V1, K2, V2> extends MapDriverBase<K1, V1, K2, V2, MapDriver<K1, V1, K2, V2>> {
 
   public static final Log LOG = LogFactory.getLog(MapDriver.class);
 
@@ -269,18 +267,7 @@ public class MapDriver<K1, V1, K2, V2> e
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    // handle inputKey and inputVal for backwards compatibility
-    if (inputKey != null && inputVal != null) {
-      setInput(inputKey, inputVal);
-    }
-
-    if (inputs == null || inputs.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-
-    if (myMapper == null) {
-      throw new IllegalStateException("No Mapper class was provided");
-    }
+    preRunChecks(myMapper);
 
     final OutputCollectable<K2, V2> outputCollectable = mockOutputCreator
         .createOutputCollectable(getConfiguration(),
@@ -305,26 +292,6 @@ public class MapDriver<K1, V1, K2, V2> e
   }
 
   /**
-   * @param configuration
-   *          The configuration object that will given to the mapper associated
-   *          with the driver
-   * @return this object for fluent coding
-   */
-  public MapDriver<K1, V1, K2, V2> withConfiguration(
-      final Configuration configuration) {
-    setConfiguration(configuration);
-    return this;
-  }
-  /**
-   * @param mapInputPath
-   *       The Path object which will be given to the mapper
-   * @return
-   */
-  public MapDriver<K1, V1, K2, V2> withMapInputPath(Path mapInputPath) {
-    setMapInputPath(mapInputPath);
-    return this;
-  }
-  /**
    * Returns a new MapDriver without having to specify the generic types on the
    * right hand side of the object create statement.
    * 

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriverBase.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriverBase.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriverBase.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapDriverBase.java Sun Aug  5 20:38:27 2012
@@ -23,7 +23,10 @@ import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mrunit.internal.output.MockOutputCreator;
 import org.apache.hadoop.mrunit.types.Pair;
 
 /**
@@ -33,8 +36,8 @@ import org.apache.hadoop.mrunit.types.Pa
  * the harness will deliver the input to the Mapper and will check its outputs
  * against the expected results.
  */
-public abstract class MapDriverBase<K1, V1, K2, V2> extends
-    TestDriver<K1, V1, K2, V2> {
+public abstract class MapDriverBase<K1, V1, K2, V2, T extends MapDriverBase<K1, V1, K2, V2, T>>
+    extends TestDriver<K1, V1, K2, V2, T> {
 
   public static final Log LOG = LogFactory.getLog(MapDriverBase.class);
 
@@ -44,6 +47,8 @@ public abstract class MapDriverBase<K1, 
   protected K1 inputKey;
   @Deprecated
   protected V1 inputVal;
+  
+  protected final MockOutputCreator<K2, V2> mockOutputCreator = new MockOutputCreator<K2, V2>();
 
   /**
    * Sets the input key to send to the mapper
@@ -201,6 +206,171 @@ public abstract class MapDriverBase<K1, 
   public void addOutputFromString(final String output) {
     addOutput((Pair<K2, V2>) parseTabbedPair(output));
   }
+  
+  @SuppressWarnings("unchecked")
+  private T thisAsMapDriver() {
+    return (T) this;
+  }
+  
+  /**
+   * Identical to setInputKey() but with fluent programming style
+   * 
+   * @return this
+   */
+  public T withInputKey(final K1 key) {
+    setInputKey(key);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Identical to setInputValue() but with fluent programming style
+   * 
+   * @param val
+   * @return this
+   */
+  public T withInputValue(final V1 val) {
+    setInputValue(val);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Identical to setInput() but returns self for fluent programming style
+   * 
+   * @return this
+   */
+  public T withInput(final K1 key, final V1 val) {
+    setInput(key, val);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Identical to setInput() but returns self for fluent programming style
+   * 
+   * @param inputRecord
+   * @return this
+   */
+  public T withInput(final Pair<K1, V1> inputRecord) {
+    setInput(inputRecord);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Works like addOutput(), but returns self for fluent style
+   * 
+   * @param outputRecord
+   * @return this
+   */
+  public T withOutput(final Pair<K2, V2> outputRecord) {
+    addOutput(outputRecord);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Functions like addOutput() but returns self for fluent programming style
+   * 
+   * @return this
+   */
+  public T withOutput(final K2 key, final V2 val) {
+    addOutput(key, val);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Identical to setInputFromString, but with a fluent programming style
+   * 
+   * @param input
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withInputFromString(final String input) {
+    setInputFromString(input);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Identical to addOutputFromString, but with a fluent programming style
+   * 
+   * @param output
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withOutputFromString(final String output) {
+    addOutputFromString(output);
+    return thisAsMapDriver();
+  }
+
+  public T withOutputCopyingOrInputFormatConfiguration(
+      Configuration configuration) {
+    setOutputCopyingOrInputFormatConfiguration(configuration);
+    return thisAsMapDriver();
+  }
+  
+  /**
+   * Identical to addAll() but returns self for fluent programming style
+   * 
+   * @param inputRecords
+   * @return this
+   */
+  public T withAll(final List<Pair<K1, V1>> inputRecords) {
+    addAll(inputRecords);
+    return thisAsMapDriver();
+  }
+
+  /**
+   * Functions like addAllOutput() but returns self for fluent programming style
+   * 
+   * @param outputRecords
+   * @return this
+   */
+  public T withAllOutput(
+      final List<Pair<K2, V2>> outputRecords) {
+    addAllOutput(outputRecords);
+    return thisAsMapDriver();
+  }
+  
+  /**
+   * @param configuration
+   *          The configuration object that will given to the mapper associated
+   *          with the driver
+   * @return this object for fluent coding
+   */
+  public T withConfiguration(
+      final Configuration configuration) {
+    setConfiguration(configuration);
+    return thisAsMapDriver();
+  }
+  /**
+   * @param mapInputPath
+   *       The Path object which will be given to the mapper
+   * @return
+   */
+  public T withMapInputPath(Path mapInputPath) {
+    setMapInputPath(mapInputPath);
+    return thisAsMapDriver();
+  }
+  
+  /**
+   * Handle inputKey and inputVal for backwards compatibility.
+   */
+  protected void preRunChecks(Object mapper) {
+    if (inputKey != null && inputVal != null) {
+      setInput(inputKey, inputVal);
+    }
+
+    if (inputs == null || inputs.isEmpty()) {
+      throw new IllegalStateException("No input was provided");
+    }
+
+    if (mapper == null) {
+      throw new IllegalStateException("No Mapper class was provided");
+    }
+  }
 
   @Override
   public abstract List<Pair<K2, V2>> run() throws IOException;

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -26,7 +26,6 @@ import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.RawComparator;
 import org.apache.hadoop.mapred.Counters;
 import org.apache.hadoop.mapred.InputFormat;
@@ -49,9 +48,9 @@ import org.apache.hadoop.mrunit.types.Pa
  * If a combiner is specified, then it will be run exactly once after the Mapper
  * and before the Reducer.
  */
-@SuppressWarnings({ "deprecation" })
-public class MapReduceDriver<K1, V1, K2, V2, K3, V3> extends
-    MapReduceDriverBase<K1, V1, K2, V2, K3, V3> {
+public class MapReduceDriver<K1, V1, K2, V2, K3, V3>
+    extends
+    MapReduceDriverBase<K1, V1, K2, V2, K3, V3, MapReduceDriver<K1, V1, K2, V2, K3, V3>> {
 
   public static final Log LOG = LogFactory.getLog(MapReduceDriver.class);
 
@@ -355,15 +354,7 @@ public class MapReduceDriver<K1, V1, K2,
 
   @Override
   public List<Pair<K3, V3>> run() throws IOException {
-    if (inputList.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-    if (myMapper == null) {
-      throw new IllegalStateException("No Mapper class was provided");
-    }
-    if (myReducer == null) {
-      throw new IllegalStateException("No Reducer class was provided");
-    }
+    preRunChecks(myMapper, myReducer);
 
     List<Pair<K2, V2>> mapOutputs = new ArrayList<Pair<K2, V2>>();
 
@@ -393,28 +384,6 @@ public class MapReduceDriver<K1, V1, K2,
   }
 
   /**
-   * @param configuration
-   *          The configuration object that will given to the mapper and reducer
-   *          associated with the driver
-   * @return this driver object for fluent coding
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withConfiguration(
-      final Configuration configuration) {
-    setConfiguration(configuration);
-    return this;
-  }
-  
-  /**
-   * @param mapInputPath
-   *       The Path object which will be given to the mapper
-   * @return
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withMapInputPath(Path mapInputPath) {
-    setMapInputPath(mapInputPath);
-    return this;
-  }
-
-  /**
    * Identical to {@link #setKeyGroupingComparator(RawComparator)}, but with a
    * fluent programming style
    * 
@@ -442,26 +411,6 @@ public class MapReduceDriver<K1, V1, K2,
     return this;
   }
 
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withCounter(final Enum<?> e,
-      final long expectedValue) {
-    super.withCounter(e, expectedValue);
-    return this;
-  }
-
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withCounter(final String g,
-      final String n, final long e) {
-    super.withCounter(g, n, e);
-    return this;
-  }
-  
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withStrictCounterChecking() {
-    super.withStrictCounterChecking();
-    return this;
-  }
-
   /**
    * Returns a new MapReduceDriver without having to specify the generic types
    * on the right hand side of the object create statement.

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriverBase.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriverBase.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriverBase.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/MapReduceDriverBase.java Sun Aug  5 20:38:27 2012
@@ -28,9 +28,9 @@ import java.util.Map.Entry;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.RawComparator;
-import org.apache.hadoop.io.WritableComparable;
-import org.apache.hadoop.io.WritableComparator;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mrunit.types.Pair;
@@ -46,9 +46,8 @@ import org.apache.hadoop.util.Reflection
  * designed to handle a single (k, v)* -> (k, v)* case from the Mapper/Reducer
  * pair, representing a single unit test.
  */
-
-public abstract class MapReduceDriverBase<K1, V1, K2, V2, K3, V3> extends
-    TestDriver<K1, V1, K3, V3> {
+public abstract class MapReduceDriverBase<K1, V1, K2, V2, K3, V3, T extends MapReduceDriverBase<K1, V1, K2, V2, K3, V3, T>>
+    extends TestDriver<K1, V1, K3, V3, T> {
 
   public static final Log LOG = LogFactory.getLog(MapReduceDriverBase.class);
 
@@ -153,7 +152,160 @@ public abstract class MapReduceDriverBas
   public void addOutputFromString(final String output) {
     addOutput((Pair<K3, V3>) parseTabbedPair(output));
   }
+  
+  @SuppressWarnings("unchecked")
+  private T thisAsMapReduceDriver() {
+    return (T) this;
+  }
+  
+  /**
+   * Identical to addInput() but returns self for fluent programming style
+   * 
+   * @param key
+   * @param val
+   * @return this
+   */
+  public T withInput(final K1 key,
+      final V1 val) {
+    addInput(key, val);
+    return thisAsMapReduceDriver();
+  }
+
+  /**
+   * Identical to addInput() but returns self for fluent programming style
+   * 
+   * @param input
+   *          The (k, v) pair to add
+   * @return this
+   */
+  public T withInput(
+      final Pair<K1, V1> input) {
+    addInput(input);
+    return thisAsMapReduceDriver();
+  }
 
+  /**
+   * Works like addOutput(), but returns self for fluent style
+   * 
+   * @param outputRecord
+   * @return this
+   */
+  public T withOutput(
+      final Pair<K3, V3> outputRecord) {
+    addOutput(outputRecord);
+    return thisAsMapReduceDriver();
+  }
+
+  /**
+   * Functions like addOutput() but returns self for fluent programming style
+   * 
+   * @param key
+   * @param val
+   * @return this
+   */
+  public T withOutput(final K3 key,
+      final V3 val) {
+    addOutput(key, val);
+    return thisAsMapReduceDriver();
+  }
+
+  /**
+   * Identical to addInputFromString, but with a fluent programming style
+   * 
+   * @param input
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withInputFromString(
+      final String input) {
+    addInputFromString(input);
+    return thisAsMapReduceDriver();
+  }
+
+  /**
+   * Identical to addOutputFromString, but with a fluent programming style
+   * 
+   * @param output
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withOutputFromString(
+      final String output) {
+    addOutputFromString(output);
+    return thisAsMapReduceDriver();
+  }
+
+  public T withOutputCopyingOrInputFormatConfiguration(
+      Configuration configuration) {
+    setOutputCopyingOrInputFormatConfiguration(configuration);
+    return thisAsMapReduceDriver();
+  }
+  
+  /**
+   * Identical to addAll() but returns self for fluent programming style
+   * 
+   * @param inputs
+   *          List of (k, v) pairs to add
+   * @return this
+   */
+  public T withAll(
+      final List<Pair<K1, V1>> inputs) {
+    addAll(inputs);
+    return thisAsMapReduceDriver();
+  }
+  
+  /**
+   * Works like addAllOutput(), but returns self for fluent style
+   * 
+   * @param outputRecords
+   * @return this
+   */
+  public T withAllOutput(
+      final List<Pair<K3, V3>> outputRecords) {
+    addAllOutput(outputRecords);
+    return thisAsMapReduceDriver();
+  }
+  
+  /**
+   * @param configuration
+   *          The configuration object that will given to the mapper and reducer
+   *          associated with the driver
+   * @return this driver object for fluent coding
+   */
+  public T withConfiguration(
+      final Configuration configuration) {
+    setConfiguration(configuration);
+    return thisAsMapReduceDriver();
+  }
+  
+  /**
+   * @param mapInputPath
+   *       The Path object which will be given to the mapper
+   * @return
+   */
+  public T withMapInputPath(Path mapInputPath) {
+    setMapInputPath(mapInputPath);
+    return thisAsMapReduceDriver();
+  }
+
+  protected void preRunChecks(Object mapper, Object reducer) {
+    if (inputList.isEmpty()) {
+      throw new IllegalStateException("No input was provided");
+    }
+    if (mapper == null) {
+      throw new IllegalStateException("No Mapper class was provided");
+    }
+    if (reducer == null) {
+      throw new IllegalStateException("No Reducer class was provided");
+    }
+  }
+  
   @Override
   public abstract List<Pair<K3, V3>> run() throws IOException;
 

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/PipelineMapReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/PipelineMapReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/PipelineMapReduceDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/PipelineMapReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -52,9 +52,9 @@ import org.apache.hadoop.mrunit.types.Pa
  * to the first Mapper. (K2, V2) refer to the types associated with the final
  * Reducer's output. No intermediate types are specified.
  */
-@SuppressWarnings({ "deprecation", "rawtypes" })
+@SuppressWarnings("rawtypes")
 public class PipelineMapReduceDriver<K1, V1, K2, V2> extends
-    TestDriver<K1, V1, K2, V2> {
+    TestDriver<K1, V1, K2, V2, PipelineMapReduceDriver<K1, V1, K2, V2>> {
 
   public static final Log LOG = LogFactory
       .getLog(PipelineMapReduceDriver.class);
@@ -278,26 +278,6 @@ public class PipelineMapReduceDriver<K1,
     return this;
   }
 
-  @Override
-  public PipelineMapReduceDriver<K1, V1, K2, V2> withCounter(final Enum<?> e,
-      final long expectedValue) {
-    super.withCounter(e, expectedValue);
-    return this;
-  }
-
-  @Override
-  public PipelineMapReduceDriver<K1, V1, K2, V2> withCounter(final String g,
-      final String n, final long e) {
-    super.withCounter(g, n, e);
-    return this;
-  }
-  
-  @Override
-  public PipelineMapReduceDriver<K1, V1, K2, V2> withStrictCounterChecking() {
-    super.withStrictCounterChecking();
-    return this;
-  }
-
   /**
    * Expects an input of the form "key \t val" Forces the Reducer output types
    * to Text.

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -32,7 +32,6 @@ import org.apache.hadoop.mapred.OutputFo
 import org.apache.hadoop.mapred.Reducer;
 import org.apache.hadoop.mrunit.internal.counters.CounterWrapper;
 import org.apache.hadoop.mrunit.internal.mapred.MockReporter;
-import org.apache.hadoop.mrunit.internal.output.MockOutputCreator;
 import org.apache.hadoop.mrunit.internal.output.OutputCollectable;
 import org.apache.hadoop.mrunit.types.Pair;
 import org.apache.hadoop.util.ReflectionUtils;
@@ -45,17 +44,14 @@ import org.apache.hadoop.util.Reflection
  * will deliver the input to the Reducer and will check its outputs against the
  * expected results.
  */
-@SuppressWarnings("deprecation")
 public class ReduceDriver<K1, V1, K2, V2> extends
-    ReduceDriverBase<K1, V1, K2, V2> {
+    ReduceDriverBase<K1, V1, K2, V2, ReduceDriver<K1, V1, K2, V2>> {
 
   public static final Log LOG = LogFactory.getLog(ReduceDriver.class);
 
   private Reducer<K1, V1, K2, V2> myReducer;
   private Counters counters;
 
-  private final MockOutputCreator<K2, V2> mockOutputCreator = new MockOutputCreator<K2, V2>();
-
   public ReduceDriver(final Reducer<K1, V1, K2, V2> r) {
     this();
     setReducer(r);
@@ -295,19 +291,7 @@ public class ReduceDriver<K1, V1, K2, V2
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    // handle inputKey and inputValues for backwards compatibility
-    if (inputKey != null && !getInputValues().isEmpty()) {
-      clearInput();
-      addInput(inputKey, getInputValues());
-    }
-
-    if (inputs == null || inputs.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-    
-    if (myReducer == null) {
-      throw new IllegalStateException("No Reducer class was provided");
-    }
+    preRunChecks(myReducer);
 
     final OutputCollectable<K2, V2> outputCollectable = mockOutputCreator
         .createOutputCollectable(getConfiguration(),

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java Sun Aug  5 20:38:27 2012
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mrunit.internal.io.Serialization;
+import org.apache.hadoop.mrunit.internal.output.MockOutputCreator;
 import org.apache.hadoop.mrunit.types.Pair;
 
 /**
@@ -35,14 +36,16 @@ import org.apache.hadoop.mrunit.types.Pa
  * will deliver the input to the Reducer and will check its outputs against the
  * expected results. 
  */
-public abstract class ReduceDriverBase<K1, V1, K2, V2> extends
-    TestDriver<K1, V1, K2, V2> {
+public abstract class ReduceDriverBase<K1, V1, K2, V2, T extends ReduceDriverBase<K1, V1, K2, V2, T>>
+    extends TestDriver<K1, V1, K2, V2, T> {
 
   protected List<Pair<K1, List<V1>>> inputs = new ArrayList<Pair<K1, List<V1>>>();
   @Deprecated
   protected K1 inputKey;
   @Deprecated
   private final List<V1> inputValues;
+  
+  protected final MockOutputCreator<K2, V2> mockOutputCreator = new MockOutputCreator<K2, V2>();
 
   public ReduceDriverBase() {
     inputValues = new ArrayList<V1>();
@@ -256,6 +259,169 @@ public abstract class ReduceDriverBase<K
   public void addOutputFromString(final String output) {
     addOutput((Pair<K2, V2>) parseTabbedPair(output));
   }
+  
+  @SuppressWarnings("unchecked")
+  private T thisAsReduceDriver() {
+    return (T) this;
+  }
+  
+  /**
+   * Identical to setInputKey() but with fluent programming style
+   * 
+   * @return this
+   */
+  public T withInputKey(final K1 key) {
+    setInputKey(key);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to addInputValue() but with fluent programming style
+   * 
+   * @param val
+   * @return this
+   */
+  public T withInputValue(final V1 val) {
+    addInputValue(val);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to addInputValues() but with fluent programming style
+   * 
+   * @param values
+   * @return this
+   */
+  public T withInputValues(final List<V1> values) {
+    addInputValues(values);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to setInput() but returns self for fluent programming style
+   * 
+   * @return this
+   */
+  public T withInput(final K1 key,
+      final List<V1> values) {
+    setInput(key, values);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Works like addOutput(), but returns self for fluent style
+   * 
+   * @param outputRecord
+   * @return this
+   */
+  public T withOutput(final Pair<K2, V2> outputRecord) {
+    addOutput(outputRecord);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Works like addOutput(), but returns self for fluent style
+   * 
+   * @param key
+   *          The key part of a (k, v) pair to add
+   * @param val
+   *          The val part of a (k, v) pair to add
+   * @return this
+   */
+  public T withOutput(final K2 key, final V2 val) {
+    addOutput(key, val);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to setInput, but with a fluent programming style
+   * 
+   * @param input
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withInputFromString(final String input) {
+    setInputFromString(input);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to addOutput, but with a fluent programming style
+   * 
+   * @param output
+   *          A string of the form "key \t val". Trims any whitespace.
+   * @return this
+   * @deprecated No replacement due to lack of type safety and incompatibility
+   *             with non Text Writables
+   */
+  @Deprecated
+  public T withOutputFromString(final String output) {
+    addOutputFromString(output);
+    return thisAsReduceDriver();
+  }
+
+  public T withOutputCopyingOrInputFormatConfiguration(
+      Configuration configuration) {
+    setOutputCopyingOrInputFormatConfiguration(configuration);
+    return thisAsReduceDriver();
+  }
+  
+  /**
+   * Identical to addInput() but returns self for fluent programming style
+   * 
+   * @param input
+   * @return this
+   */
+  public T withInput(final Pair<K1, List<V1>> input) {
+    addInput(input);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Identical to addAll() but returns self for fluent programming style
+   * 
+   * @param inputs
+   * @return this
+   */
+  public T withAll(
+      final List<Pair<K1, List<V1>>> inputs) {
+    addAll(inputs);
+    return thisAsReduceDriver();
+  }
+
+  /**
+   * Works like addAllOutput(), but returns self for fluent style
+   * 
+   * @param outputRecord
+   * @return this
+   */
+  public T withAllOutput(
+      final List<Pair<K2, V2>> outputRecords) {
+    addAllOutput(outputRecords);
+    return thisAsReduceDriver();
+  }
+  
+
+  /**
+   * Handle inputKey and inputValues for backwards compatibility.
+   */
+  protected void preRunChecks(Object reducer) {
+    if (inputKey != null && !getInputValues().isEmpty()) {
+      clearInput();
+      addInput(inputKey, getInputValues());
+    }
+
+    if (inputs == null || inputs.isEmpty()) {
+      throw new IllegalStateException("No input was provided");
+    }
+    
+    if (reducer == null) {
+      throw new IllegalStateException("No Reducer class was provided");
+    }
+  }
 
   @Override
   public abstract List<Pair<K2, V2>> run() throws IOException;

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/TestDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/TestDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/TestDriver.java Sun Aug  5 20:38:27 2012
@@ -36,7 +36,7 @@ import org.apache.hadoop.mrunit.internal
 import org.apache.hadoop.mrunit.internal.io.Serialization;
 import org.apache.hadoop.mrunit.types.Pair;
 
-public abstract class TestDriver<K1, V1, K2, V2> {
+public abstract class TestDriver<K1, V1, K2, V2, T extends TestDriver<K1, V1, K2, V2, T>> {
 
   public static final Log LOG = LogFactory.getLog(TestDriver.class);
 
@@ -98,6 +98,11 @@ public abstract class TestDriver<K1, V1,
     expectedEnumCounters.clear();
     expectedStringCounters.clear();
   }
+  
+  @SuppressWarnings("unchecked")
+  private T thisAsTestDriver() {
+    return (T) this;
+  }
 
   /**
    * Register expected enumeration based counter value
@@ -108,10 +113,10 @@ public abstract class TestDriver<K1, V1,
    *          Expected value
    * @return
    */
-  public TestDriver<K1, V1, K2, V2> withCounter(final Enum<?> e,
+  public T withCounter(final Enum<?> e,
       final long expectedValue) {
     expectedEnumCounters.add(new Pair<Enum<?>, Long>(e, expectedValue));
-    return this;
+    return thisAsTestDriver();
   }
 
   /**
@@ -125,11 +130,11 @@ public abstract class TestDriver<K1, V1,
    *          Expected value
    * @return
    */
-  public TestDriver<K1, V1, K2, V2> withCounter(final String group,
+  public T withCounter(final String group,
       final String name, final long expectedValue) {
     expectedStringCounters.add(new Pair<Pair<String, String>, Long>(
         new Pair<String, String>(group, name), expectedValue));
-    return this;
+    return thisAsTestDriver();
   }
 
   /**
@@ -140,9 +145,9 @@ public abstract class TestDriver<K1, V1,
    * This mode allows you to ensure that no unexpected counters has been
    * declared.
    */
-  public TestDriver<K1, V1, K2, V2> withStrictCounterChecking() {
+  public T withStrictCounterChecking() {
     strictCountersChecking = true;
-    return this;
+    return thisAsTestDriver();
   }
 
   /**
@@ -282,12 +287,12 @@ public abstract class TestDriver<K1, V1,
     return outList;
   }
 
-  protected <T> T copy(T object) {
+  protected <E> E copy(E object) {
     return serialization.copyWithConf(object, configuration);
   }
 
-  protected <S, T> Pair<S, T> copyPair(S first, T second) {
-    return new Pair<S, T>(copy(first), copy(second));
+  protected <S, E> Pair<S, E> copyPair(S first, E second) {
+    return new Pair<S, E>(copy(first), copy(second));
   }
 
   /**

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockInputSplit.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockInputSplit.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockInputSplit.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockInputSplit.java Sun Aug  5 20:38:27 2012
@@ -29,7 +29,6 @@ import org.apache.hadoop.mapred.InputSpl
  * A fake InputSplit object to be returned by our MockReporter to the user
  * class.
  */
-@SuppressWarnings("deprecation")
 class MockInputSplit extends FileSplit implements InputSplit {
 
   public MockInputSplit(Path mockPath) {

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockReporter.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockReporter.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockReporter.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/mapred/MockReporter.java Sun Aug  5 20:38:27 2012
@@ -23,7 +23,6 @@ import org.apache.hadoop.mapred.Counters
 import org.apache.hadoop.mapred.InputSplit;
 import org.apache.hadoop.mapred.Reporter;
 
-@SuppressWarnings("deprecation")
 public class MockReporter implements Reporter {
 
   private final MockInputSplit inputSplit;

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java Sun Aug  5 20:38:27 2012
@@ -18,7 +18,7 @@
 
 package org.apache.hadoop.mrunit.mapreduce;
 
-import static org.apache.hadoop.mrunit.internal.util.ArgumentChecker.*;
+import static org.apache.hadoop.mrunit.internal.util.ArgumentChecker.returnNonNull;
 
 import java.io.IOException;
 import java.util.List;
@@ -26,7 +26,6 @@ import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.Counters;
 import org.apache.hadoop.mapreduce.InputFormat;
 import org.apache.hadoop.mapreduce.Mapper;
@@ -35,7 +34,6 @@ import org.apache.hadoop.mrunit.MapDrive
 import org.apache.hadoop.mrunit.internal.counters.CounterWrapper;
 import org.apache.hadoop.mrunit.internal.mapreduce.ContextDriver;
 import org.apache.hadoop.mrunit.internal.mapreduce.MockMapContextWrapper;
-import org.apache.hadoop.mrunit.internal.output.MockOutputCreator;
 import org.apache.hadoop.mrunit.types.Pair;
 
 /**
@@ -46,14 +44,13 @@ import org.apache.hadoop.mrunit.types.Pa
  * against the expected results.
  */
 public class MapDriver<K1, V1, K2, V2> 
-extends MapDriverBase<K1, V1, K2, V2> implements ContextDriver {
-
+extends MapDriverBase<K1, V1, K2, V2, MapDriver<K1, V1, K2, V2> > implements ContextDriver {
+  
   public static final Log LOG = LogFactory.getLog(MapDriver.class);
 
   private Mapper<K1, V1, K2, V2> myMapper;
   private Counters counters;
 
-  private final MockOutputCreator<K2, V2> mockOutputCreator = new MockOutputCreator<K2, V2>();
   private final MockMapContextWrapper<K1, V1, K2, V2> wrapper = new MockMapContextWrapper<K1, V1, K2, V2>(
       inputs, mockOutputCreator,  this);
 
@@ -253,18 +250,7 @@ extends MapDriverBase<K1, V1, K2, V2> im
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    // handle inputKey and inputVal for backwards compatibility
-    if (inputKey != null && inputVal != null) {
-      setInput(inputKey, inputVal);
-    }
-
-    if (inputs == null || inputs.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-   	
-    if (myMapper == null) {
-      throw new IllegalStateException("No Mapper class was provided");
-    }        
+    preRunChecks(myMapper);
 
     try {
       myMapper.run(wrapper.getMockContext());
@@ -278,36 +264,6 @@ extends MapDriverBase<K1, V1, K2, V2> im
   public String toString() {
     return "MapDriver (0.20+) (" + myMapper + ")";
   }
-
-  /**
-   * @param configuration
-   *          The configuration object that will given to the mapper associated
-   *          with the driver
-   * @return this object for fluent coding
-   */
-  public MapDriver<K1, V1, K2, V2> withConfiguration(
-      final Configuration configuration) {
-    setConfiguration(configuration);
-    return this;
-  }
-  
-  /**
-   * @param mapInputPath
-   *       The Path object which will be given to the mapper
-   * @return this object for fluent coding
-   */
-  public MapDriver<K1, V1, K2, V2> withMapInputPath(Path mapInputPath) {
-    setMapInputPath(mapInputPath);
-    return this;
-  }
-
-
-  @Override
-  public MapDriver<K1, V1, K2, V2> withCounter(final Enum<?> e,
-      final long expectedValue) {
-    super.withCounter(e, expectedValue);
-    return this;
-  }
   
   /**
    * <p>Obtain Context object for furthering mocking with Mockito.
@@ -337,19 +293,6 @@ extends MapDriverBase<K1, V1, K2, V2> im
     return wrapper.getMockContext();
   }
 
-  @Override
-  public MapDriver<K1, V1, K2, V2> withCounter(final String g, final String n,
-      final long expectedValue) {
-    super.withCounter(g, n, expectedValue);
-    return this;
-  }
-  
-  @Override
-  public MapDriver<K1, V1, K2, V2> withStrictCounterChecking() {
-    super.withStrictCounterChecking();
-    return this;
-  }
-
   /**
    * Returns a new MapDriver without having to specify the generic types on the
    * right hand side of the object create statement.

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -17,7 +17,7 @@
  */
 package org.apache.hadoop.mrunit.mapreduce;
 
-import static org.apache.hadoop.mrunit.internal.util.ArgumentChecker.*;
+import static org.apache.hadoop.mrunit.internal.util.ArgumentChecker.returnNonNull;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -25,8 +25,6 @@ import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.RawComparator;
 import org.apache.hadoop.mapreduce.Counters;
 import org.apache.hadoop.mapreduce.InputFormat;
@@ -49,7 +47,7 @@ import org.apache.hadoop.mrunit.types.Pa
  */
 
 public class MapReduceDriver<K1, V1, K2, V2, K3, V3> extends
-    MapReduceDriverBase<K1, V1, K2, V2, K3, V3> {
+    MapReduceDriverBase<K1, V1, K2, V2, K3, V3, MapReduceDriver<K1, V1, K2, V2, K3, V3>> {
 
   public static final Log LOG = LogFactory.getLog(MapReduceDriver.class);
 
@@ -187,120 +185,6 @@ public class MapReduceDriver<K1, V1, K2,
     return this;
   }
 
-  /**
-   * Identical to addInput() but returns self for fluent programming style
-   * 
-   * @param key
-   * @param val
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withInput(final K1 key,
-      final V1 val) {
-    addInput(key, val);
-    return this;
-  }
-
-  /**
-   * Identical to addInput() but returns self for fluent programming style
-   * 
-   * @param input
-   *          The (k, v) pair to add
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withInput(
-      final Pair<K1, V1> input) {
-    addInput(input);
-    return this;
-  }
-
-  /**
-   * Identical to addAll() but returns self for fluent programming style
-   * 
-   * @param inputs
-   *          List of (k, v) pairs to add
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withAll(
-      final List<Pair<K1, V1>> inputs) {
-    addAll(inputs);
-    return this;
-  }
-  
-  /**
-   * Works like addAllOutput(), but returns self for fluent style
-   * 
-   * @param outputRecords
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withAllOutput(
-      final List<Pair<K3, V3>> outputRecords) {
-    addAllOutput(outputRecords);
-    return this;
-  }
-  
-  /**
-   * Works like addOutput(), but returns self for fluent style
-   * 
-   * @param outputRecord
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withOutput(
-      final Pair<K3, V3> outputRecord) {
-    addOutput(outputRecord);
-    return this;
-  }
-
-  /**
-   * Functions like addOutput() but returns self for fluent programming style
-   * 
-   * @param key
-   * @param val
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withOutput(final K3 key,
-      final V3 val) {
-    addOutput(key, val);
-    return this;
-  }
-
-  /**
-   * Identical to addInputFromString, but with a fluent programming style
-   * 
-   * @param input
-   *          A string of the form "key \t val". Trims any whitespace.
-   * @return this
-   * @deprecated No replacement due to lack of type safety and incompatibility
-   *             with non Text Writables
-   */
-  @Deprecated
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withInputFromString(
-      final String input) {
-    addInputFromString(input);
-    return this;
-  }
-
-  /**
-   * Identical to addOutputFromString, but with a fluent programming style
-   * 
-   * @param output
-   *          A string of the form "key \t val". Trims any whitespace.
-   * @return this
-   * @deprecated No replacement due to lack of type safety and incompatibility
-   *             with non Text Writables
-   */
-  @Deprecated
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withOutputFromString(
-      final String output) {
-    addOutputFromString(output);
-    return this;
-  }
-
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withOutputCopyingOrInputFormatConfiguration(
-      Configuration configuration) {
-    setOutputCopyingOrInputFormatConfiguration(configuration);
-    return this;
-  }
-
   @SuppressWarnings("rawtypes")
   public MapReduceDriver<K1, V1, K2, V2, K3, V3> withOutputFormat(
       final Class<? extends OutputFormat> outputFormatClass,
@@ -353,15 +237,7 @@ public class MapReduceDriver<K1, V1, K2,
 
   @Override
   public List<Pair<K3, V3>> run() throws IOException {
-    if (inputList.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-    if (myMapper == null) {
-      throw new IllegalStateException("No Mapper class was provided");
-    }
-    if (myReducer == null) {
-      throw new IllegalStateException("No Reducer class was provided");
-    }
+    preRunChecks(myMapper,myReducer);
 
     List<Pair<K2, V2>> mapOutputs = new ArrayList<Pair<K2, V2>>();
 
@@ -391,28 +267,6 @@ public class MapReduceDriver<K1, V1, K2,
   }
 
   /**
-   * @param configuration
-   *          The configuration object that will given to the mapper and reducer
-   *          associated with the driver
-   * @return this driver object for fluent coding
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withConfiguration(
-      final Configuration configuration) {
-    setConfiguration(configuration);
-    return this;
-  }
-  
-  /**
-   * @param mapInputPath
-   *       The Path object which will be given to the mapper
-   * @return this
-   */
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withMapInputPath(Path mapInputPath) {
-    setMapInputPath(mapInputPath);
-    return this;
-  }
-  
-  /**
    * Identical to {@link #setKeyGroupingComparator(RawComparator)}, but with a
    * fluent programming style
    * 
@@ -440,26 +294,6 @@ public class MapReduceDriver<K1, V1, K2,
     return this;
   }
 
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withCounter(final Enum<?> e,
-      final long expectedValue) {
-    super.withCounter(e, expectedValue);
-    return this;
-  }
-
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withCounter(final String g,
-      final String n, final long e) {
-    super.withCounter(g, n, e);
-    return this;
-  }
-  
-  @Override
-  public MapReduceDriver<K1, V1, K2, V2, K3, V3> withStrictCounterChecking() {
-    super.withStrictCounterChecking();
-    return this;
-  }
-
   /**
    * Returns a new MapReduceDriver without having to specify the generic types
    * on the right hand side of the object create statement.

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java (original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -34,7 +34,6 @@ import org.apache.hadoop.mrunit.ReduceDr
 import org.apache.hadoop.mrunit.internal.counters.CounterWrapper;
 import org.apache.hadoop.mrunit.internal.mapreduce.ContextDriver;
 import org.apache.hadoop.mrunit.internal.mapreduce.MockReduceContextWrapper;
-import org.apache.hadoop.mrunit.internal.output.MockOutputCreator;
 import org.apache.hadoop.mrunit.types.Pair;
 
 /**
@@ -46,14 +45,14 @@ import org.apache.hadoop.mrunit.types.Pa
  * expected results.
  */
 public class ReduceDriver<K1, V1, K2, V2> extends
-    ReduceDriverBase<K1, V1, K2, V2> implements ContextDriver {
+    ReduceDriverBase<K1, V1, K2, V2, ReduceDriver<K1, V1, K2, V2>> implements
+    ContextDriver {
 
   public static final Log LOG = LogFactory.getLog(ReduceDriver.class);
 
   private Reducer<K1, V1, K2, V2> myReducer;
   private Counters counters;
 
-  private final MockOutputCreator<K2, V2> mockOutputCreator = new MockOutputCreator<K2, V2>();
   private final MockReduceContextWrapper<K1, V1, K2, V2> wrapper = new MockReduceContextWrapper<K1, V1, K2, V2>(
       inputs, mockOutputCreator, this);
 
@@ -281,19 +280,7 @@ public class ReduceDriver<K1, V1, K2, V2
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    // handle inputKey and inputValues for backwards compatibility
-    if (inputKey != null && !getInputValues().isEmpty()) {
-      clearInput();
-      addInput(inputKey, getInputValues());
-    }
-    
-    if (inputs == null || inputs.isEmpty()) {
-      throw new IllegalStateException("No input was provided");
-    }
-    
-    if (myReducer == null) {
-      throw new IllegalStateException("No Reducer class was provided");
-    }
+    preRunChecks(myReducer);
 
     try {
       myReducer.run(wrapper.getMockContext());
@@ -320,26 +307,6 @@ public class ReduceDriver<K1, V1, K2, V2
     return this;
   }
 
-  @Override
-  public ReduceDriver<K1, V1, K2, V2> withCounter(final Enum<?> e,
-      final long expectedValue) {
-    super.withCounter(e, expectedValue);
-    return this;
-  }
-
-  @Override
-  public ReduceDriver<K1, V1, K2, V2> withCounter(final String g,
-      final String n, final long e) {
-    super.withCounter(g, n, e);
-    return this;
-  }
-  
-  @Override
-  public ReduceDriver<K1, V1, K2, V2> withStrictCounterChecking() {
-    super.withStrictCounterChecking();
-    return this;
-  }
-  
   /**
    * <p>Obtain Context object for furthering mocking with Mockito.
    * For example, causing write() to throw an exception:</p>

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestConfigureClose.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestConfigureClose.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestConfigureClose.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestConfigureClose.java Sun Aug  5 20:38:27 2012
@@ -31,7 +31,6 @@ import org.apache.hadoop.mapred.Reducer;
 import org.apache.hadoop.mapred.Reporter;
 import org.junit.Test;
 
-@SuppressWarnings("deprecation")
 public class TestConfigureClose {
 
   @Test
@@ -63,6 +62,7 @@ public class TestConfigureClose {
   }
 
   @Test
+  @SuppressWarnings("deprecation")
   public void testReducerConfigureClose() throws IOException {
     final AtomicBoolean configureWasCalled = new AtomicBoolean(false);
     final AtomicBoolean closeWasCalled = new AtomicBoolean(false);

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestCounters.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestCounters.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestCounters.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestCounters.java Sun Aug  5 20:38:27 2012
@@ -33,7 +33,6 @@ import org.junit.Test;
 /**
  * Test counters usage in various drivers.
  */
-@SuppressWarnings("deprecation")
 public class TestCounters {
 
   private static final String GROUP = "GROUP";
@@ -79,6 +78,7 @@ public class TestCounters {
   }
 
   @Test
+  @SuppressWarnings("deprecation")
   public void testReducer() throws IOException {
     final Reducer<Text, Text, Text, Text> reducer = new CounterReducer();
     final ReduceDriver<Text, Text, Text, Text> driver = ReduceDriver

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestExample.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestExample.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestExample.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestExample.java Sun Aug  5 20:38:27 2012
@@ -31,7 +31,6 @@ import org.junit.Test;
  * 
  * This example is reproduced in the overview for the MRUnit javadoc.
  */
-@SuppressWarnings("deprecation")
 public class TestExample {
 
   private Mapper<Text, Text, Text, Text> mapper;

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -52,7 +52,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-@SuppressWarnings("deprecation")
 public class TestMapReduceDriver {
 
   private static final int FOO_IN_A = 42;
@@ -650,8 +649,9 @@ public class TestMapReduceDriver {
 
   @Test
   public void testUseOfWritableRegisteredComparator() throws IOException {
-    MapReduceDriver<TestWritable,Text,TestWritable,Text,TestWritable,Text> driver 
-      = MapReduceDriver.newMapReduceDriver(new IdentityMapper(), new IdentityReducer());
+    MapReduceDriver<TestWritable, Text, TestWritable, Text, TestWritable, Text> driver = MapReduceDriver
+        .newMapReduceDriver(new IdentityMapper<TestWritable, Text>(),
+            new IdentityReducer<TestWritable, Text>());
     driver.withInput(new TestWritable("A1"), new Text("A1"))
       .withInput(new TestWritable("A2"), new Text("A2"))
       .withInput(new TestWritable("A3"), new Text("A3"))

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestPipelineMapReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestPipelineMapReduceDriver.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestPipelineMapReduceDriver.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestPipelineMapReduceDriver.java Sun Aug  5 20:38:27 2012
@@ -35,7 +35,7 @@ import org.apache.hadoop.mrunit.types.Pa
 import org.junit.Rule;
 import org.junit.Test;
 
-@SuppressWarnings({"deprecation", "rawtypes"})
+@SuppressWarnings("rawtypes")
 public class TestPipelineMapReduceDriver {
 
   private static final int FOO_IN_A = 42;

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockOutputCollector.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockOutputCollector.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockOutputCollector.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockOutputCollector.java Sun Aug  5 20:38:27 2012
@@ -27,7 +27,6 @@ import org.apache.hadoop.mapred.Reporter
 import org.apache.hadoop.mrunit.MapDriver;
 import org.junit.Test;
 
-@SuppressWarnings("deprecation")
 public class TestMockOutputCollector {
 
   /**

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockReporter.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockReporter.java?rev=1369676&r1=1369675&r2=1369676&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockReporter.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/internal/mapred/TestMockReporter.java Sun Aug  5 20:38:27 2012
@@ -26,7 +26,6 @@ import org.apache.hadoop.mrunit.internal
 import org.junit.Rule;
 import org.junit.Test;
 
-@SuppressWarnings("deprecation")
 public class TestMockReporter {
 
   @Rule



Mime
View raw message