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

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

public abstract class ReduceDriverBase<K1,V1,K2,V2>
extends TestDriver<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. 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.


Nested Class Summary
protected static class ReduceDriverBase.ValueClassInstanceReuseList<T>
           
 
Field Summary
protected  K1 inputKey
           
 
Fields inherited from class org.apache.hadoop.mrunit.TestDriver
configuration, counterWrapper, expectedEnumCounters, expectedOutputs, expectedStringCounters, LOG
 
Constructor Summary
ReduceDriverBase()
           
 
Method Summary
 void addInputValue(V1 val)
          adds an input value to send to the reducer
 void addInputValues(List<V1> values)
          Adds a set of input values to send to the reducer
 void addOutput(K2 key, V2 val)
          Adds an output (k, v) pair we expect from the Reducer
 void addOutput(Pair<K2,V2> outputRecord)
          Adds an output (k, v) pair we expect from the Reducer
 void addOutputFromString(String output)
          Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables
 List<V1> getInputValues()
          Returns a list which when iterated over, returns the same instance of the value each time with different contents similar to how Hadoop currently works with Writables.
abstract  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 runTest(boolean orderMatters)
          Runs the test and validates the results
 void setInput(K1 key, List<V1> values)
          Sets the input to send to the reducer
 void setInputFromString(String input)
          Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables
 void setInputKey(K1 key)
          Sets the input key to send to the Reducer
 void setInputValues(List<V1> values)
          Sets the input values to send to the reducer; overwrites existing ones
 
Methods inherited from class org.apache.hadoop.mrunit.TestDriver
formatValueList, getConfiguration, getExpectedEnumCounters, getExpectedOutputs, getExpectedStringCounters, parseCommaDelimitedList, parseTabbedPair, resetExpectedCounters, resetOutput, runTest, setConfiguration, validate, validate, withCounter, withCounter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputKey

protected K1 inputKey
Constructor Detail

ReduceDriverBase

public ReduceDriverBase()
Method Detail

getInputValues

public List<V1> getInputValues()
Returns a list which when iterated over, returns the same instance of the value each time with different contents similar to how Hadoop currently works with Writables.

Returns:
List of values

setInputKey

public void setInputKey(K1 key)
Sets the input key to send to the Reducer


addInputValue

public void addInputValue(V1 val)
adds an input value to send to the reducer

Parameters:
val -

setInputValues

public void setInputValues(List<V1> values)
Sets the input values to send to the reducer; overwrites existing ones

Parameters:
values -

addInputValues

public void addInputValues(List<V1> values)
Adds a set of input values to send to the reducer

Parameters:
values -

setInput

public void setInput(K1 key,
                     List<V1> values)
Sets the input to send to the reducer

Parameters:
key -
values -

addOutput

public void addOutput(Pair<K2,V2> outputRecord)
Adds an output (k, v) pair we expect from the Reducer

Parameters:
outputRecord - The (k, v) pair to add

addOutput

public void addOutput(K2 key,
                      V2 val)
Adds an output (k, v) pair we expect from the Reducer

Parameters:
key - The key part of a (k, v) pair to add
val - The val part of a (k, v) pair to add

setInputFromString

@Deprecated
public void setInputFromString(String input)
Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables

Expects an input of the form "key \t val, val, val..." Forces the Reducer input types to Text.

Parameters:
input - A string of the form "key \t val,val,val". Trims any whitespace.

addOutputFromString

@Deprecated
public void addOutputFromString(String output)
Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables

Expects an input of the form "key \t val" Forces the Reducer output types to Text.

Parameters:
output - A string of the form "key \t val". Trims any whitespace.

run

public abstract 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 TestDriver<K1,V1,K2,V2>
Returns:
the list of (k, v) pairs returned as output from the test
Throws:
IOException

runTest

public void runTest(boolean orderMatters)
Description copied from class: TestDriver
Runs the test and validates the results

Specified by:
runTest in class TestDriver<K1,V1,K2,V2>
Parameters:
orderMatters - Whether or not output ordering is important


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