hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r925558 - in /hadoop/mapreduce/trunk: ./ src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/ src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/ src/contrib/...
Date Sat, 20 Mar 2010 06:30:27 GMT
Author: cdouglas
Date: Sat Mar 20 06:30:27 2010
New Revision: 925558

URL: http://svn.apache.org/viewvc?rev=925558&view=rev
Log:
MAPREDUCE-1569. Pass configuration through mocked contexts in MRUnit. Contributed by Chris
White

Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/TestDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockMapContext.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockReduceContext.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapReduceDriver.java
    hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestReduceDriver.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Sat Mar 20 06:30:27 2010
@@ -223,6 +223,9 @@ Trunk (unreleased changes)
     MAPREDUCE-1460. Oracle support in DataDrivenDBInputFormat.
     (Aaron Kimball via tomwhite)
 
+    MAPREDUCE-1569. Pass configuration through mocked contexts in MRUnit.
+    (Chris White via cdouglas)
+
   OPTIMIZATIONS
 
     MAPREDUCE-270. Fix the tasktracker to optionally send an out-of-band

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/TestDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/TestDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/TestDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/TestDriver.java
Sat Mar 20 06:30:27 2010
@@ -24,6 +24,7 @@ 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.io.Text;
 import org.apache.hadoop.mrunit.types.Pair;
 
@@ -32,9 +33,12 @@ public abstract class TestDriver<K1, V1,
   public static final Log LOG = LogFactory.getLog(TestDriver.class);
 
   protected List<Pair<K2, V2>> expectedOutputs;
+  
+  protected Configuration configuration;
 
   public TestDriver() {
     expectedOutputs = new ArrayList<Pair<K2, V2>>();
+    configuration = new Configuration();
   }
 
   /**
@@ -242,4 +246,19 @@ public abstract class TestDriver<K1, V1,
     sb.append(")");
   }
 
+  /** 
+   * @return The configuration object that will given to the mapper and/or 
+   *         reducer associated with the driver (new API only)
+   */
+  public Configuration getConfiguration() {
+    return configuration;
+  }
+  
+  /**
+   * @param configuration The configuration object that will given to the 
+   *        mapper and/or reducer associated with the driver (new API only)
+   */
+  public void setConfiguration(Configuration configuration) {
+    this.configuration = configuration;
+  }
 }

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapDriver.java
Sat Mar 20 06:30:27 2010
@@ -25,6 +25,7 @@ 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.mapreduce.Counters;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.lib.map.WrappedMapper;
@@ -193,7 +194,7 @@ public class MapDriver<K1, V1, K2, V2> e
 
     try {
       MockMapContext<K1, V1, K2, V2> context =
-        new MockMapContext<K1, V1, K2, V2>(inputs, getCounters());
+        new MockMapContext<K1, V1, K2, V2>(configuration, inputs, getCounters());
 
       myMapper.run(new WrappedMapper<K1, V1, K2, V2>().getMapContext(context));
       return context.getOutputs();
@@ -206,5 +207,15 @@ public class MapDriver<K1, V1, K2, V2> e
   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(Configuration configuration) {
+    setConfiguration(configuration);
+	  return this;
+  }
 }
 

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/MapReduceDriver.java
Sat Mar 20 06:30:27 2010
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Counters;
 import org.apache.hadoop.mapreduce.Mapper;
@@ -202,7 +203,7 @@ public class MapReduceDriver<K1, V1, K2,
       LOG.debug("Mapping input " + input.toString() + ")");
 
       mapOutputs.addAll(new MapDriver<K1, V1, K2, V2>(myMapper).withInput(
-              input).withCounters(getCounters()).run());
+              input).withCounters(getCounters()).withConfiguration(configuration).run());
     }
 
     List<Pair<K2, List<V2>>> reduceInputs = shuffle(mapOutputs);
@@ -217,7 +218,7 @@ public class MapReduceDriver<K1, V1, K2,
           + sb.toString() + ")");
 
       reduceOutputs.addAll(new ReduceDriver<K2, V2, K3, V3>(myReducer)
-              .withCounters(getCounters())
+              .withCounters(getCounters()).withConfiguration(configuration)
               .withInputKey(inputKey).withInputValues(inputValues).run());
     }
 
@@ -228,4 +229,15 @@ public class MapReduceDriver<K1, V1, K2,
   public String toString() {
     return "MapReduceDriver (0.20+) (" + myMapper + ", " + myReducer + ")";
   }
+  
+  /** 
+   * @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(
+      Configuration configuration) {
+    setConfiguration(configuration);
+    return this;
+  }
 }

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/ReduceDriver.java
Sat Mar 20 06:30:27 2010
@@ -25,6 +25,7 @@ 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.mapreduce.Counters;
 import org.apache.hadoop.mapreduce.Reducer;
 import org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer;
@@ -198,7 +199,7 @@ public class ReduceDriver<K1, V1, K2, V2
 
     try {
       MockReduceContext<K1, V1, K2, V2> context = 
-        new MockReduceContext<K1, V1, K2, V2>(inputs, getCounters());
+        new MockReduceContext<K1, V1, K2, V2>(configuration, inputs, getCounters());
       myReducer.run(new WrappedReducer<K1, V1, K2, V2>().getReducerContext(context));
       return context.getOutputs();
     } catch (InterruptedException ie) {
@@ -210,5 +211,16 @@ public class ReduceDriver<K1, V1, K2, V2
   public String toString() {
     return "ReduceDriver (0.20+) (" + myReducer + ")";
   }
+  
+  /** 
+   * @param configuration The configuration object that will given to the 
+   *        reducer associated with the driver
+   * @return this object for fluent coding
+   */
+  public ReduceDriver<K1, V1, K2, V2> withConfiguration(
+      Configuration configuration) {
+    setConfiguration(configuration);
+    return this;
+  }
 }
 

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockMapContext.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockMapContext.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockMapContext.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockMapContext.java
Sat Mar 20 06:30:27 2010
@@ -38,15 +38,37 @@ public class MockMapContext<KEYIN, VALUE
   private Pair<KEYIN, VALUEIN> curInput;
   private MockOutputCollector<KEYOUT, VALUEOUT> output;
   
-  public MockMapContext(final List<Pair<KEYIN, VALUEIN>> in, 
+  /**
+   * Create a new instance with the passed configuration, map key/value input 
+   * pairs and counters
+   * 
+   * @param configuration Configuration for the mapper
+   * @param in input key/value pairs for the mapper
+   * @param counters pre-initialized counter values
+   */
+  public MockMapContext(final Configuration configuration,
+                        final List<Pair<KEYIN, VALUEIN>> in, 
                         final Counters counters) {
-    super(new Configuration(),
+    super(configuration,
         new TaskAttemptID("mrunit-jt", 0, TaskType.MAP, 0, 0),
         null, null, new MockOutputCommitter(), new MockReporter(counters), null);
     this.inputIter = in.iterator();
     this.output = new MockOutputCollector<KEYOUT, VALUEOUT>();
   }
-
+  
+  /**
+   * Create a new instance with the passed map key/value input pairs and
+   * counters. A new {@link Configuration} object will be created and used
+   * to configure the mapper
+   * 
+   * @param in input key/value pairs for the mapper
+   * @param counters pre-initialized counter values
+   */
+  public MockMapContext(final List<Pair<KEYIN, VALUEIN>> in, 
+          final Counters counters) {
+    this(new Configuration(), in, counters);  
+  }
+  
   @Override
   public InputSplit getInputSplit() {
     return new MockInputSplit();

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockReduceContext.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockReduceContext.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockReduceContext.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/java/org/apache/hadoop/mrunit/mapreduce/mock/MockReduceContext.java
Sat Mar 20 06:30:27 2010
@@ -42,10 +42,22 @@ public class MockReduceContext <KEYIN, V
 
   private MockOutputCollector<KEYOUT, VALUEOUT> output;
 
-  public MockReduceContext(final List<Pair<KEYIN, List<VALUEIN>>> in, 
+  /**
+   * Create a new instance with the passed configuration, reducer key/values input 
+   * pairs and counters
+   * 
+   * @param configuration Configuration for the mapper
+   * @param in input key/value pairs for the mapper
+   * @param counters pre-initialized counter values
+   * 
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public MockReduceContext(Configuration configuration, 
+                           final List<Pair<KEYIN, List<VALUEIN>>> in, 
                            final Counters counters) 
   throws IOException, InterruptedException {
-    super(new Configuration(),
+    super(configuration,
           new TaskAttemptID("mrunit-jt", 0, TaskType.REDUCE, 0, 0),
           new MockRawKeyValueIterator(), null, null, null,
           new MockOutputCommitter(), new MockReporter(counters), null,
@@ -53,7 +65,20 @@ public class MockReduceContext <KEYIN, V
     this.inputIter = in.iterator();
     this.output = new MockOutputCollector<KEYOUT, VALUEOUT>();
   }
-
+  
+  /**
+   * Create a new instance with the passed reducer key/values input pairs and
+   * counters. A new {@link Configuration} object will be created and used
+   * to configure the reducer
+   * 
+   * @param in input key/values pairs for the reducer
+   * @param counters pre-initialized counter values
+   */
+  public MockReduceContext(final List<Pair<KEYIN, List<VALUEIN>>> in, 
+          final Counters counters) 
+  throws IOException, InterruptedException {
+    this(new Configuration(), in, counters);
+  }
 
   /**
    * A private iterable/iterator implementation that wraps around the 

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapDriver.java
Sat Mar 20 06:30:27 2010
@@ -24,8 +24,11 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.NullWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mrunit.types.Pair;
@@ -181,6 +184,32 @@ public class TestMapDriver extends TestC
       // expected.
     }
   }
-
+  
+  @Test
+  public void testConfiguration() {
+	  Configuration conf = new Configuration();
+	  conf.set("TestKey", "TestValue");
+	  MapDriver<NullWritable, NullWritable, NullWritable, NullWritable> confDriver 
+	      = new MapDriver<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  ConfigurationMapper<NullWritable, NullWritable, NullWritable, NullWritable> mapper

+	      = new ConfigurationMapper<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  confDriver.withMapper(mapper).withConfiguration(conf).
+	      withInput(NullWritable.get(),NullWritable.get()).
+	      withOutput(NullWritable.get(),NullWritable.get()).runTest();
+	  assertEquals(mapper.setupConfiguration.get("TestKey"), "TestValue");
+  }
+
+  /**
+   * Test mapper which stores the configuration object it was passed during its setup method
+   */
+  public static class ConfigurationMapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> extends
Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
+	public Configuration setupConfiguration;
+	
+	@Override
+	protected void setup(Context context) throws IOException,
+			InterruptedException {
+		setupConfiguration = context.getConfiguration();
+	}
+  }
 }
 

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapReduceDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapReduceDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapReduceDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestMapReduceDriver.java
Sat Mar 20 06:30:27 2010
@@ -21,15 +21,20 @@ import static org.apache.hadoop.mrunit.t
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.NullWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.Reducer;
 import org.apache.hadoop.mapreduce.lib.reduce.LongSumReducer;
+import org.apache.hadoop.mrunit.mapreduce.TestMapDriver.ConfigurationMapper;
+import org.apache.hadoop.mrunit.mapreduce.TestReduceDriver.ConfigurationReducer;
 import org.apache.hadoop.mrunit.types.Pair;
 import org.junit.Before;
 import org.junit.Test;
@@ -230,6 +235,26 @@ public class TestMapReduceDriver extends
 
     assertListEquals(expected, outputs);
   }
+  
+  @Test
+  public void testConfiguration() {
+	  Configuration conf = new Configuration();
+	  conf.set("TestKey", "TestValue");
+	  
+	  MapReduceDriver<NullWritable, NullWritable, NullWritable, NullWritable, NullWritable,
NullWritable> confDriver 
+	      = new MapReduceDriver<NullWritable, NullWritable, NullWritable, NullWritable, NullWritable,
NullWritable>();
+	  
+	  ConfigurationMapper<NullWritable, NullWritable, NullWritable, NullWritable> mapper

+	      = new ConfigurationMapper<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  ConfigurationReducer<NullWritable, NullWritable, NullWritable, NullWritable> reducer

+      = new ConfigurationReducer<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  
+	  confDriver.withMapper(mapper).withReducer(reducer).withConfiguration(conf).
+	      withInput(NullWritable.get(),NullWritable.get()).
+	      withOutput(NullWritable.get(),NullWritable.get()).runTest();
+	  assertEquals(mapper.setupConfiguration.get("TestKey"), "TestValue");
+	  assertEquals(reducer.setupConfiguration.get("TestKey"), "TestValue");	  
+  }
 
 }
 

Modified: hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestReduceDriver.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestReduceDriver.java?rev=925558&r1=925557&r2=925558&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestReduceDriver.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mrunit/src/test/org/apache/hadoop/mrunit/mapreduce/TestReduceDriver.java
Sat Mar 20 06:30:27 2010
@@ -23,14 +23,20 @@ import static org.apache.hadoop.mrunit.t
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.NullWritable;
 import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.hadoop.mapreduce.Mapper.Context;
 import org.apache.hadoop.mapreduce.lib.reduce.LongSumReducer;
+import org.apache.hadoop.mrunit.mapreduce.TestMapDriver.ConfigurationMapper;
 import org.apache.hadoop.mrunit.types.Pair;
 import org.junit.Before;
 import org.junit.Test;
@@ -261,5 +267,32 @@ public class TestReduceDriver extends Te
         .withOutput(new Text("foo"), new LongWritable(4))
         .runTest();
   }
+  
+  @Test
+  public void testConfiguration() {
+	  Configuration conf = new Configuration();
+	  conf.set("TestKey", "TestValue");
+	  ReduceDriver<NullWritable, NullWritable, NullWritable, NullWritable> confDriver

+	      = new ReduceDriver<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  ConfigurationReducer<NullWritable, NullWritable, NullWritable, NullWritable> reducer

+	      = new ConfigurationReducer<NullWritable, NullWritable, NullWritable, NullWritable>();
+	  confDriver.withReducer(reducer).withConfiguration(conf).
+	      withInput(NullWritable.get(),Arrays.asList(NullWritable.get())).
+	      withOutput(NullWritable.get(),NullWritable.get()).runTest();
+	  assertEquals(reducer.setupConfiguration.get("TestKey"), "TestValue");
+  }
+
+  /**
+   * Test reducer which stores the configuration object it was passed during its setup method
+   */
+  public static class ConfigurationReducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> extends
Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
+	public Configuration setupConfiguration;
+	
+	@Override
+	protected void setup(Context context) throws IOException,
+			InterruptedException {
+		setupConfiguration = context.getConfiguration();
+	}
+  }
 }
 



Mime
View raw message