mrunit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1369090 - in /mrunit/trunk/src: main/java/org/apache/hadoop/mrunit/ main/java/org/apache/hadoop/mrunit/internal/counters/ main/java/org/apache/hadoop/mrunit/mapreduce/ test/java/org/apache/hadoop/mrunit/
Date Fri, 03 Aug 2012 16:29:09 GMT
Author: brock
Date: Fri Aug  3 16:29:08 2012
New Revision: 1369090

URL: http://svn.apache.org/viewvc?rev=1369090&view=rev
Log:
MRUNIT-64: Multiple Input Key, Value Pairs should be supported (2)

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/ReduceDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/ReduceDriverBase.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/counters/CounterWrapper.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
    mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapReduceDriver.java
    mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestReduceDriver.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=1369090&r1=1369089&r2=1369090&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 Fri Aug  3 16:29:08
2012
@@ -39,13 +39,11 @@ import org.apache.hadoop.mrunit.types.Pa
 import org.apache.hadoop.util.ReflectionUtils;
 
 /**
- * Harness that allows you to test a Mapper instance. You provide the input key
- * and value that should be sent to the Mapper, and outputs you expect to be
+ * Harness that allows you to test a Mapper instance. You provide the input
+ * (k, v)* pairs that should be sent to the Mapper, and outputs you expect to be
  * sent by the Mapper to the collector for those inputs. By calling runTest(),
  * the harness will deliver the input to the Mapper and will check its outputs
- * against the expected results. This is designed to handle a single (k, v) ->
- * (k, v)* case from the Mapper, representing a single unit test. Multiple input
- * (k, v) pairs should go in separate unit tests.
+ * against the expected results.
  */
 @SuppressWarnings("deprecation")
 public class MapDriver<K1, V1, K2, V2> extends MapDriverBase<K1, V1, K2, V2>
{
@@ -115,7 +113,11 @@ public class MapDriver<K1, V1, K2, V2> e
    * Identical to setInputKey() but with fluent programming style
    * 
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #withInput()} and
+   *             {@link #withAll()}
    */
+  @Deprecated
   public MapDriver<K1, V1, K2, V2> withInputKey(final K1 key) {
     setInputKey(key);
     return this;
@@ -126,7 +128,11 @@ public class MapDriver<K1, V1, K2, V2> e
    * 
    * @param val
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #withInput()} and
+   *             {@link #withAll()}
    */
+  @Deprecated
   public MapDriver<K1, V1, K2, V2> withInputValue(final V1 val) {
     setInputValue(val);
     return this;
@@ -154,6 +160,17 @@ public class MapDriver<K1, V1, K2, V2> e
   }
 
   /**
+   * Identical to addAll() but returns self for fluent programming style
+   * 
+   * @param inputRecords
+   * @return this
+   */
+  public MapDriver<K1, V1, K2, V2> withAll(final List<Pair<K1, V1>> inputRecords)
{
+    addAll(inputRecords);
+    return this;
+  }
+  
+  /**
    * Works like addOutput(), but returns self for fluent style
    * 
    * @param outputRecord
@@ -175,6 +192,18 @@ public class MapDriver<K1, V1, K2, V2> e
   }
 
   /**
+   * Functions like addAllOutput() but returns self for fluent programming style
+   * 
+   * @param outputRecords
+   * @return this
+   */
+  public MapDriver<K1, V1, K2, V2> withAllOutput(
+      final List<Pair<K2, V2>> outputRecords) {
+    addAllOutput(outputRecords);
+    return this;
+  }
+  
+  /**
    * Identical to setInputFromString, but with a fluent programming style
    * 
    * @param input
@@ -240,9 +269,15 @@ public class MapDriver<K1, V1, K2, V2> e
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    if (inputKey == null || inputVal == null) {
+    // 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");
     }
@@ -256,7 +291,10 @@ public class MapDriver<K1, V1, K2, V2> e
 
     ReflectionUtils.setConf(myMapper, new JobConf(getConfiguration()));
 
-    myMapper.map(inputKey, inputVal, outputCollectable, reporter);
+    for (Pair<K1, V1> kv : inputs) {
+      myMapper.map(kv.getFirst(), kv.getSecond(), outputCollectable, reporter);
+    }
+
     myMapper.close();
     return outputCollectable.getOutputs();
   }

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=1369090&r1=1369089&r2=1369090&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 Fri Aug  3 16:29:08
2012
@@ -49,6 +49,9 @@ public abstract class MapDriverBase<K1, 
    * Sets the input key to send to the mapper
    * 
    * @param key
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void setInputKey(final K1 key) {
@@ -63,6 +66,9 @@ public abstract class MapDriverBase<K1, 
    * Sets the input value to send to the mapper
    * 
    * @param val
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void setInputValue(final V1 val) {

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=1369090&r1=1369089&r2=1369090&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 Fri Aug  3 16:29:08
2012
@@ -216,6 +216,31 @@ public class MapReduceDriver<K1, V1, K2,
   }
 
   /**
+   * 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
@@ -298,27 +323,32 @@ public class MapReduceDriver<K1, V1, K2,
 
       final List<Pair<OUTKEY, OUTVAL>> reduceOutputs = new ArrayList<Pair<OUTKEY,
OUTVAL>>();
 
-      for (final Pair<K2, List<V2>> input : inputs) {
-        final K2 inputKey = input.getFirst();
-        final List<V2> inputValues = input.getSecond();
-        final StringBuilder sb = new StringBuilder();
-        formatValueList(inputValues, sb);
-        LOG.debug("Reducing input (" + inputKey.toString() + ", "
-            + sb.toString() + ")");
+      if (!inputs.isEmpty()) {
+        if (LOG.isDebugEnabled()) {
+          final StringBuilder sb = new StringBuilder();
+          for (Pair<K2, List<V2>> input : inputs) {
+            formatValueList(input.getSecond(), sb);
+            LOG.debug("Reducing input (" + input.getFirst() + ", " + sb + ")");
+            sb.delete(0, sb.length());
+          }
+        }
 
         final ReduceDriver<K2, V2, OUTKEY, OUTVAL> reduceDriver = ReduceDriver
             .newReduceDriver(reducer).withCounters(getCounters())
-            .withConfiguration(configuration).withInputKey(inputKey)
-            .withInputValues(inputValues);
+            .withConfiguration(configuration).withAll(inputs);
+
         if (getOutputCopyingOrInputFormatConfiguration() != null) {
           reduceDriver
               .withOutputCopyingOrInputFormatConfiguration(getOutputCopyingOrInputFormatConfiguration());
         }
+
         if (outputFormatClass != null) {
           reduceDriver.withOutputFormat(outputFormatClass, inputFormatClass);
         }
+
         reduceOutputs.addAll(reduceDriver.run());
       }
+
       return reduceOutputs;
     }
   }
@@ -338,13 +368,10 @@ public class MapReduceDriver<K1, V1, K2,
     List<Pair<K2, V2>> mapOutputs = new ArrayList<Pair<K2, V2>>();
 
     // run map component
-    for (final Pair<K1, V1> input : inputList) {
-      LOG.debug("Mapping input " + input.toString() + ")");
-
-      mapOutputs.addAll(MapDriver.newMapDriver(myMapper)
-          .withConfiguration(configuration).withCounters(getCounters())
-          .withInput(input).withMapInputPath(getMapInputPath()).run());
-    }
+    LOG.debug("Starting map phase with mapper: " + myMapper);
+    mapOutputs.addAll(MapDriver.newMapDriver(myMapper)
+        .withCounters(getCounters()).withConfiguration(configuration)
+        .withAll(inputList).withMapInputPath(getMapInputPath()).run());
 
     if (myCombiner != null) {
       // User has specified a combiner. Run this and replace the mapper outputs

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=1369090&r1=1369089&r2=1369090&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 Fri Aug  3 16:29:08
2012
@@ -43,9 +43,7 @@ import org.apache.hadoop.util.Reflection
  * sent to the Reducer (as if they came from a Mapper), and outputs you expect
  * to be sent by the Reducer to the collector. By calling runTest(), the harness
  * will deliver the input to the Reducer and will check its outputs against the
- * expected results. This is designed to handle a single (k, v*) -> (k, v)* case
- * from the Reducer, representing a single unit test. Multiple input (k, v*)
- * sets should go in separate unit tests.
+ * expected results.
  */
 @SuppressWarnings("deprecation")
 public class ReduceDriver<K1, V1, K2, V2> extends
@@ -120,7 +118,11 @@ public class ReduceDriver<K1, V1, K2, V2
    * Identical to setInputKey() but with fluent programming style
    * 
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
+  @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputKey(final K1 key) {
     setInputKey(key);
     return this;
@@ -131,7 +133,11 @@ public class ReduceDriver<K1, V1, K2, V2
    * 
    * @param val
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
+  @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputValue(final V1 val) {
     addInputValue(val);
     return this;
@@ -142,7 +148,11 @@ public class ReduceDriver<K1, V1, K2, V2
    * 
    * @param values
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
+  @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputValues(final List<V1> values)
{
     addInputValues(values);
     return this;
@@ -160,6 +170,29 @@ public class ReduceDriver<K1, V1, K2, V2
   }
 
   /**
+   * Identical to addInput() but returns self for fluent programming style
+   * 
+   * @param input
+   * @return this
+   */
+  public ReduceDriver<K1, V1, K2, V2> withInput(final Pair<K1, List<V1>>
input) {
+    addInput(input);
+    return this;
+  }
+
+  /**
+   * Identical to addAll() but returns self for fluent programming style
+   * 
+   * @param inputs
+   * @return this
+   */
+  public ReduceDriver<K1, V1, K2, V2> withAll(
+      final List<Pair<K1, List<V1>>> inputs) {
+    addAll(inputs);
+    return this;
+  }
+  
+  /**
    * Works like addOutput(), but returns self for fluent style
    * 
    * @param outputRecord
@@ -185,6 +218,18 @@ public class ReduceDriver<K1, V1, K2, V2
   }
 
   /**
+   * Works like addAllOutput(), but returns self for fluent style
+   * 
+   * @param outputRecord
+   * @return this
+   */
+  public ReduceDriver<K1, V1, K2, V2> withAllOutput(
+      final List<Pair<K2, V2>> outputRecords) {
+    addAllOutput(outputRecords);
+    return this;
+  }
+  
+  /**
    * Identical to setInput, but with a fluent programming style
    * 
    * @param input
@@ -250,9 +295,16 @@ public class ReduceDriver<K1, V1, K2, V2
 
   @Override
   public List<Pair<K2, V2>> run() throws IOException {
-    if (inputKey == null || getInputValues().isEmpty()) {
+    // 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");
     }
@@ -266,8 +318,11 @@ public class ReduceDriver<K1, V1, K2, V2
 
     ReflectionUtils.setConf(myReducer, new JobConf(getConfiguration()));
 
-    myReducer.reduce(inputKey, getInputValues().iterator(), outputCollectable,
-        reporter);
+    for (Pair<K1, List<V1>> kv : inputs) {
+      myReducer.reduce(kv.getFirst(), kv.getSecond().iterator(),
+          outputCollectable, reporter);
+    }
+    
     myReducer.close();
     return outputCollectable.getOutputs();
   }

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=1369090&r1=1369089&r2=1369090&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 Fri Aug  3 16:29:08
2012
@@ -52,6 +52,8 @@ public abstract class ReduceDriverBase<K
    * Returns a list of values.
    * 
    * @return List of values
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #getInputValues(Object)}
    */
   @Deprecated
   public List<V1> getInputValues() {
@@ -59,8 +61,26 @@ public abstract class ReduceDriverBase<K
   }
 
   /**
+   * Returns a list of values for the given key
+   * 
+   * @param key
+   * @return List for the given key, or null if key does not exist
+   */
+  public List<V1> getInputValues(final K1 key) {
+    for (Pair<K1, List<V1>> p : inputs) {
+      if (p.getFirst().equals(key)) {
+        return p.getSecond();
+      }
+    }
+    return null;
+  }
+  
+  /**
    * Sets the input key to send to the Reducer
    * 
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void setInputKey(final K1 key) {
@@ -71,6 +91,9 @@ public abstract class ReduceDriverBase<K
    * adds an input value to send to the reducer
    * 
    * @param val
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void addInputValue(final V1 val) {
@@ -81,6 +104,9 @@ public abstract class ReduceDriverBase<K
    * Sets the input values to send to the reducer; overwrites existing ones
    * 
    * @param values
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void setInputValues(final List<V1> values) {
@@ -92,6 +118,9 @@ public abstract class ReduceDriverBase<K
    * Adds a set of input values to send to the reducer
    * 
    * @param values
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #setInput()},
+   *             {@link #addInput()}, and {@link #addAll()}
    */
   @Deprecated
   public void addInputValues(final List<V1> values) {

Modified: mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/counters/CounterWrapper.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/counters/CounterWrapper.java?rev=1369090&r1=1369089&r2=1369090&view=diff
==============================================================================
--- mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/counters/CounterWrapper.java
(original)
+++ mrunit/trunk/src/main/java/org/apache/hadoop/mrunit/internal/counters/CounterWrapper.java
Fri Aug  3 16:29:08 2012
@@ -91,7 +91,7 @@ public class CounterWrapper {
     }
   }
 
-  public Collection<String> getGroupNames() {
+  public Iterable<String> getGroupNames() {
     if (mapred != null) {
       return mapred.getGroupNames();
     } else {
@@ -104,7 +104,7 @@ public class CounterWrapper {
    */
   public Collection<Pair<String, String>> findCounterValues() {
     final Collection<Pair<String, String>> counters = new LinkedList<Pair<String,
String>>();
-    final Collection<String> groupNames = getGroupNames();
+    final Iterable<String> groupNames = getGroupNames();
     if (mapred != null) {
       for (String groupName : groupNames) {
         final Group group = mapred.getGroup(groupName);

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=1369090&r1=1369089&r2=1369090&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 Fri Aug 
3 16:29:08 2012
@@ -117,6 +117,9 @@ extends MapDriverBase<K1, V1, K2, V2> im
    * Identical to setInputKey() but with fluent programming style
    * 
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #withInput()} and
+   *             {@link #withAll()}
    */
   @Deprecated
   public MapDriver<K1, V1, K2, V2> withInputKey(final K1 key) {
@@ -129,6 +132,9 @@ extends MapDriverBase<K1, V1, K2, V2> im
    * 
    * @param val
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v)*. Replaced by {@link #withInput()} and
+   *             {@link #withAll()}
    */
   @Deprecated
   public MapDriver<K1, V1, K2, V2> withInputValue(final V1 val) {
@@ -252,7 +258,7 @@ extends MapDriverBase<K1, V1, K2, V2> im
       setInput(inputKey, inputVal);
     }
 
-    if (inputs == null || inputs.size() == 0) {
+    if (inputs == null || inputs.isEmpty()) {
       throw new IllegalStateException("No input was provided");
     }
    	

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=1369090&r1=1369089&r2=1369090&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 Fri Aug
 3 16:29:08 2012
@@ -121,6 +121,9 @@ public class ReduceDriver<K1, V1, K2, V2
    * Identical to setInputKey() but with fluent programming style
    * 
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
   @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputKey(final K1 key) {
@@ -133,6 +136,9 @@ public class ReduceDriver<K1, V1, K2, V2
    * 
    * @param val
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
   @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputValue(final V1 val) {
@@ -145,6 +151,9 @@ public class ReduceDriver<K1, V1, K2, V2
    * 
    * @param values
    * @return this
+   * @deprecated MRUNIT-64. Moved to list implementation to support multiple
+   *             input (k, v*)*. Replaced by {@link #withInput(Object, List)},
+   *             {@link #withAll(List)}, and {@link #withInput(Pair)}
    */
   @Deprecated
   public ReduceDriver<K1, V1, K2, V2> withInputValues(final List<V1> values)
{
@@ -278,7 +287,7 @@ public class ReduceDriver<K1, V1, K2, V2
       addInput(inputKey, getInputValues());
     }
     
-    if (inputs.isEmpty()) {
+    if (inputs == null || inputs.isEmpty()) {
       throw new IllegalStateException("No input was provided");
     }
     

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapDriver.java?rev=1369090&r1=1369089&r2=1369090&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapDriver.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestMapDriver.java Fri Aug  3 16:29:08
2012
@@ -191,6 +191,19 @@ public class TestMapDriver {
   }
   
   @Test
+  public void testAddAll() throws IOException {
+    final List<Pair<Text, Text>> inputs = new ArrayList<Pair<Text, Text>>();
+    inputs.add(new Pair<Text, Text>(new Text("foo"), new Text("bar")));
+    inputs.add(new Pair<Text, Text>(new Text("foo"), new Text("bar")));
+
+    final List<Pair<Text, Text>> outputs = new ArrayList<Pair<Text, Text>>();
+    outputs.add(new Pair<Text, Text>(new Text("foo"), new Text("bar")));
+    outputs.add(new Pair<Text, Text>(new Text("foo"), new Text("bar")));
+
+    driver.withAll(inputs).withAllOutput(outputs).runTest();
+  }
+  
+  @Test
   public void testUnexpectedOutput() throws IOException {
     thrown
         .expectAssertionErrorMessage("1 Error(s): (Received unexpected output (foo, bar)
at position 1.)");

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=1369090&r1=1369089&r2=1369090&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 Fri Aug 
3 16:29:08 2012
@@ -124,6 +124,20 @@ public class TestMapReduceDriver {
   }
 
   @Test
+  public void testAddAll() throws IOException {
+    final List<Pair<Text, LongWritable>> inputs = new ArrayList<Pair<Text,
LongWritable>>();
+    inputs.add(new Pair<Text, LongWritable>(new Text("foo"), new LongWritable(FOO_IN_A)));
+    inputs.add(new Pair<Text, LongWritable>(new Text("foo"), new LongWritable(FOO_IN_B)));
+    inputs.add(new Pair<Text, LongWritable>(new Text("bar"), new LongWritable(BAR_IN)));
+
+    final List<Pair<Text, LongWritable>> outputs = new ArrayList<Pair<Text,
LongWritable>>();
+    outputs.add(new Pair<Text, LongWritable>(new Text("bar"), new LongWritable(BAR_IN)));
+    outputs.add(new Pair<Text, LongWritable>(new Text("foo"), new LongWritable(FOO_OUT)));
+
+    driver.withAll(inputs).withAllOutput(outputs).runTest();
+  }
+  
+  @Test
   public void testTestRun3OrderInsensitive() throws IOException {
     driver.withInput(new Text("foo"), new LongWritable(FOO_IN_A))
         .withInput(new Text("bar"), new LongWritable(BAR_IN))

Modified: mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestReduceDriver.java
URL: http://svn.apache.org/viewvc/mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestReduceDriver.java?rev=1369090&r1=1369089&r2=1369090&view=diff
==============================================================================
--- mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestReduceDriver.java (original)
+++ mrunit/trunk/src/test/java/org/apache/hadoop/mrunit/TestReduceDriver.java Fri Aug  3 16:29:08
2012
@@ -244,6 +244,22 @@ public class TestReduceDriver {
   }
 
   @Test
+  public void testAddAll() throws IOException {
+    final List<LongWritable> vals = new ArrayList<LongWritable>();
+    vals.add(new LongWritable(IN_A));
+    vals.add(new LongWritable(IN_B));
+
+    final List<Pair<Text, List<LongWritable>>> inputs = new ArrayList<Pair<Text,
List<LongWritable>>>();
+    inputs.add(new Pair<Text, List<LongWritable>>(new Text("foo"), vals));
+
+    final List<Pair<Text, LongWritable>> expected = new ArrayList<Pair<Text,
LongWritable>>();
+    expected.add(new Pair<Text, LongWritable>(new Text("foo"),
+        new LongWritable(OUT_VAL)));
+
+    driver.withAll(inputs).withAllOutput(expected).runTest();
+  }
+  
+  @Test
   public void testNoInput() throws IOException {
     driver = ReduceDriver.newReduceDriver();
     thrown.expectMessage(IllegalStateException.class, "No input was provided");



Mime
View raw message