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

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

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

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.


Field Summary
protected  K1 inputKey
          Deprecated. 
protected  List<Pair<K1,V1>> inputs
           
protected  V1 inputVal
          Deprecated. 
static org.apache.commons.logging.Log LOG
           
protected  org.apache.hadoop.fs.Path mapInputPath
           
protected  org.apache.hadoop.mrunit.internal.output.MockOutputCreator<K2,V2> mockOutputCreator
           
 
Fields inherited from class org.apache.hadoop.mrunit.TestDriver
counterWrapper, expectedEnumCounters, expectedOutputs, expectedStringCounters
 
Constructor Summary
MapDriverBase()
           
 
Method Summary
 void addAll(List<Pair<K1,V1>> inputs)
          Adds list of inputs to send to the mapper
 void addInput(K1 key, V1 val)
          Adds an input to send to the mapper
 void addInput(Pair<K1,V1> input)
          Adds an input to send to the mapper
 void clearInput()
          Clears the list of inputs to send to the mapper
 K1 getInputKey()
          Deprecated. 
 V1 getInputValue()
          Deprecated. 
 org.apache.hadoop.fs.Path getMapInputPath()
           
protected  void preRunChecks(Object mapper)
          Handle inputKey and inputVal for backwards compatibility.
protected  void printPreTestDebugLog()
          Overridable hook for printing pre-test debug information
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 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)
          Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #setInput(), #addInput(), and #addAll()
 void setInputValue(V1 val)
          Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #setInput(), #addInput(), and #addAll()
 void setMapInputPath(org.apache.hadoop.fs.Path mapInputPath)
           
 T withAll(List<Pair<K1,V1>> inputRecords)
          Identical to addAll() but returns self for fluent programming style
 T withInput(K1 key, V1 val)
          Identical to setInput() but returns self for fluent programming style
 T withInput(Pair<K1,V1> inputRecord)
          Identical to setInput() but returns self for fluent programming style
 T withInputFromString(String input)
          Deprecated. No replacement due to lack of type safety and incompatibility with non Text Writables
 T withInputKey(K1 key)
          Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #withInput() and #withAll()
 T withInputValue(V1 val)
          Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #withInput() and #withAll()
 T withMapInputPath(org.apache.hadoop.fs.Path mapInputPath)
           
 
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, toString, wait, wait, wait
 

Field Detail

LOG

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

inputs

protected List<Pair<K1,V1>> inputs

mapInputPath

protected org.apache.hadoop.fs.Path mapInputPath

inputKey

@Deprecated
protected K1 inputKey
Deprecated. 

inputVal

@Deprecated
protected V1 inputVal
Deprecated. 

mockOutputCreator

protected final org.apache.hadoop.mrunit.internal.output.MockOutputCreator<K2,V2> mockOutputCreator
Constructor Detail

MapDriverBase

public MapDriverBase()
Method Detail

setInputKey

@Deprecated
public void setInputKey(K1 key)
Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #setInput(), #addInput(), and #addAll()

Sets the input key to send to the mapper

Parameters:
key -

getInputKey

@Deprecated
public K1 getInputKey()
Deprecated. 


setInputValue

@Deprecated
public void setInputValue(V1 val)
Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #setInput(), #addInput(), and #addAll()

Sets the input value to send to the mapper

Parameters:
val -

getInputValue

@Deprecated
public V1 getInputValue()
Deprecated. 


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

addInput

public void addInput(K1 key,
                     V1 val)
Adds an input to send to the mapper

Parameters:
key -
val -

addInput

public void addInput(Pair<K1,V1> input)
Adds an input to send to the mapper

Parameters:
input - a (K, V) pair

addAll

public void addAll(List<Pair<K1,V1>> inputs)
Adds list of inputs to send to the mapper

Parameters:
inputs - list of (K, V) pairs

clearInput

public void clearInput()
Clears the list of inputs to send to 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".

withInputKey

@Deprecated
public T withInputKey(K1 key)
Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #withInput() and #withAll()

Identical to setInputKey() but with fluent programming style

Returns:
this

withInputValue

@Deprecated
public T withInputValue(V1 val)
Deprecated. MRUNIT-64. Moved to list implementation to support multiple input (k, v)*. Replaced by #withInput() and #withAll()

Identical to setInputValue() but with fluent programming style

Parameters:
val -
Returns:
this

withInput

public T withInput(K1 key,
                   V1 val)
Identical to setInput() but returns self for fluent programming style

Returns:
this

withInput

public T withInput(Pair<K1,V1> inputRecord)
Identical to setInput() but returns self for fluent programming style

Parameters:
inputRecord -
Returns:
this

withInputFromString

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

Identical to setInputFromString, but with a fluent programming style

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

withAll

public T withAll(List<Pair<K1,V1>> inputRecords)
Identical to addAll() but returns self for fluent programming style

Parameters:
inputRecords -
Returns:
this

getMapInputPath

public org.apache.hadoop.fs.Path getMapInputPath()
Returns:
the path passed to the mapper InputSplit

setMapInputPath

public void setMapInputPath(org.apache.hadoop.fs.Path mapInputPath)
Parameters:
mapInputPath - Path which is to be passed to the mappers InputSplit

withMapInputPath

public final T withMapInputPath(org.apache.hadoop.fs.Path mapInputPath)
Parameters:
mapInputPath - The Path object which will be given to the mapper
Returns:

preRunChecks

protected void preRunChecks(Object mapper)
Handle inputKey and inputVal for backwards compatibility.


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

printPreTestDebugLog

protected void printPreTestDebugLog()
Description copied from class: TestDriver
Overridable hook for printing pre-test debug information

Overrides:
printPreTestDebugLog in class TestDriver<K1,V1,K2,V2,T extends MapDriverBase<K1,V1,K2,V2,T>>


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