org.apache.hadoop.mrunit
Class ReduceDriver<K1,V1,K2,V2>

java.lang.Object
  extended by org.apache.hadoop.mrunit.TestDriver<K1,V1,K2,V2,T>
      extended by org.apache.hadoop.mrunit.ReduceDriverBase<K1,V1,K2,V2,ReduceDriver<K1,V1,K2,V2>>
          extended by org.apache.hadoop.mrunit.ReduceDriver<K1,V1,K2,V2>

public class ReduceDriver<K1,V1,K2,V2>
extends ReduceDriverBase<K1,V1,K2,V2,ReduceDriver<K1,V1,K2,V2>>

Harness that allows you to test a Reducer instance. You provide a key and a set of intermediate values for that key that represent inputs that should be 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.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.hadoop.mrunit.ReduceDriverBase
ReduceDriverBase.ValueClassInstanceReuseList<T>
 
Field Summary
static org.apache.commons.logging.Log LOG
           
 
Fields inherited from class org.apache.hadoop.mrunit.ReduceDriverBase
inputKey, inputs, mockOutputCreator
 
Fields inherited from class org.apache.hadoop.mrunit.TestDriver
counterWrapper, expectedEnumCounters, expectedOutputs, expectedStringCounters
 
Constructor Summary
ReduceDriver()
           
ReduceDriver(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)
           
 
Method Summary
 org.apache.hadoop.mapred.Counters getCounters()
           
 org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> getReducer()
           
static
<K1,V1,K2,V2>
ReduceDriver<K1,V1,K2,V2>
newReduceDriver()
          Returns a new ReduceDriver without having to specify the generic types on the right hand side of the object create statement.
static
<K1,V1,K2,V2>
ReduceDriver<K1,V1,K2,V2>
newReduceDriver(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> reducer)
          Returns a new ReduceDriver without having to specify the generic types on the right hand side of the object create statement.
 List<Pair<K2,V2>> run()
          Runs the test but returns the result set instead of validating it (ignores any addOutput(), etc calls made before this)
 void setCounters(org.apache.hadoop.mapred.Counters ctrs)
          Sets the counters object to use for this test.
 void setReducer(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)
          Sets the reducer object to use for this test
 String toString()
           
 ReduceDriver<K1,V1,K2,V2> withCounters(org.apache.hadoop.mapred.Counters ctrs)
          Sets the counters to use and returns self for fluent style
 ReduceDriver<K1,V1,K2,V2> withOutputFormat(Class<? extends org.apache.hadoop.mapred.OutputFormat> outputFormatClass, Class<? extends org.apache.hadoop.mapred.InputFormat> inputFormatClass)
          Configure Reducer to output with a real OutputFormat.
 ReduceDriver<K1,V1,K2,V2> withReducer(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)
          Identical to setReducer(), but with fluent programming style
 
Methods inherited from class org.apache.hadoop.mrunit.ReduceDriverBase
addAll, addInput, addInput, addInputValue, addInputValues, clearInput, getInputValues, getInputValues, preRunChecks, printPreTestDebugLog, setInput, setInputFromString, setInputKey, setInputValues, withAll, withInput, withInput, withInputFromString, withInputKey, withInputValue, withInputValues
 
Methods inherited from class org.apache.hadoop.mrunit.TestDriver
addAllOutput, addCacheArchive, addCacheArchive, addCacheFile, addCacheFile, addOutput, addOutput, addOutputFromString, cleanupDistributedCache, copy, copyPair, formatValueList, getConfiguration, getExpectedEnumCounters, getExpectedOutputs, getExpectedStringCounters, getOutputSerializationConfiguration, initDistributedCache, parseCommaDelimitedList, parseTabbedPair, resetExpectedCounters, resetOutput, run, runTest, runTest, setCacheArchives, setCacheFiles, setConfiguration, setOutputSerializationConfiguration, thisAsTestDriver, validate, validate, withAllOutput, withCacheArchive, withCacheArchive, withCacheFile, withCacheFile, withConfiguration, withCounter, withCounter, withOutput, withOutput, withOutputFromString, withOutputSerializationConfiguration, withStrictCounterChecking
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG
Constructor Detail

ReduceDriver

public ReduceDriver(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)

ReduceDriver

public ReduceDriver()
Method Detail

getCounters

public org.apache.hadoop.mapred.Counters getCounters()
Returns:
the counters used in this test

setCounters

public void setCounters(org.apache.hadoop.mapred.Counters ctrs)
Sets the counters object to use for this test.

Parameters:
ctrs - The counters object to use.

withCounters

public ReduceDriver<K1,V1,K2,V2> withCounters(org.apache.hadoop.mapred.Counters ctrs)
Sets the counters to use and returns self for fluent style


setReducer

public void setReducer(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)
Sets the reducer object to use for this test

Parameters:
r - The reducer object to use

withReducer

public ReduceDriver<K1,V1,K2,V2> withReducer(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> r)
Identical to setReducer(), but with fluent programming style

Parameters:
r - The Reducer to use
Returns:
this

getReducer

public org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> getReducer()

withOutputFormat

public ReduceDriver<K1,V1,K2,V2> withOutputFormat(Class<? extends org.apache.hadoop.mapred.OutputFormat> outputFormatClass,
                                                  Class<? extends org.apache.hadoop.mapred.InputFormat> inputFormatClass)
Configure Reducer to output with a real OutputFormat. Set InputFormat to read output back in for use with run* methods

Parameters:
outputFormatClass -
inputFormatClass -
Returns:
this for fluent style

run

public List<Pair<K2,V2>> run()
                      throws IOException
Description copied from class: TestDriver
Runs the test but returns the result set instead of validating it (ignores any addOutput(), etc calls made before this)

Specified by:
run in class ReduceDriverBase<K1,V1,K2,V2,ReduceDriver<K1,V1,K2,V2>>
Returns:
the list of (k, v) pairs returned as output from the test
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

newReduceDriver

public static <K1,V1,K2,V2> ReduceDriver<K1,V1,K2,V2> newReduceDriver()
Returns a new ReduceDriver without having to specify the generic types on the right hand side of the object create statement.

Returns:
new ReduceDriver

newReduceDriver

public static <K1,V1,K2,V2> ReduceDriver<K1,V1,K2,V2> newReduceDriver(org.apache.hadoop.mapred.Reducer<K1,V1,K2,V2> reducer)
Returns a new ReduceDriver without having to specify the generic types on the right hand side of the object create statement.

Parameters:
reducer - passed to ReduceDriver constructor
Returns:
new ReduceDriver


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.