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

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

public abstract class MapDriverBase<K1,V1,K2,V2>
extends TestDriver<K1,V1,K2,V2>

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 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.


Field Summary
protected  K1 inputKey
           
protected  V1 inputVal
           
static org.apache.commons.logging.Log LOG
           
 
Fields inherited from class org.apache.hadoop.mrunit.TestDriver
configuration, counterWrapper, expectedEnumCounters, expectedOutputs, expectedStringCounters
 
Constructor Summary
MapDriverBase()
           
 
Method Summary
 void addOutput(K2 key, V2 val)
          Adds a (k, v) pair we expect as output from the mapper
 void addOutput(Pair<K2,V2> outputRecord)
          Adds an output (k, v) pair we expect from the Mapper
 void addOutputFromString(String output)
          Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables
 K1 getInputKey()
           
 V1 getInputValue()
           
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, V1 val)
          Sets the input to send to the mapper
 void setInput(Pair<K1,V1> inputRecord)
          Sets the input to send to the mapper
 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 mapper
 void setInputValue(V1 val)
          Sets the input value to send to the mapper
 
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

LOG

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

inputKey

protected K1 inputKey

inputVal

protected V1 inputVal
Constructor Detail

MapDriverBase

public MapDriverBase()
Method Detail

setInputKey

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

Parameters:
key -

getInputKey

public K1 getInputKey()

setInputValue

public void setInputValue(V1 val)
Sets the input value to send to the mapper

Parameters:
val -

getInputValue

public V1 getInputValue()

setInput

public void setInput(K1 key,
                     V1 val)
Sets the input to send to the mapper


setInput

public void setInput(Pair<K1,V1> inputRecord)
Sets the input to send to the mapper

Parameters:
inputRecord - a (key, val) pair

addOutput

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

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

addOutput

public void addOutput(K2 key,
                      V2 val)
Adds a (k, v) pair we expect as output from the mapper


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" Forces the Mapper input types to Text.

Parameters:
input - A string of the form "key \t val".

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 Mapper 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.