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

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

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


Field Summary
protected  org.apache.hadoop.conf.Configuration configuration
           
protected  CounterWrapper counterWrapper
           
protected  List<Pair<Enum,Long>> expectedEnumCounters
           
protected  List<Pair<K2,V2>> expectedOutputs
           
protected  List<Pair<Pair<String,String>,Long>> expectedStringCounters
           
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
TestDriver()
           
 
Method Summary
protected static void formatValueList(List<?> values, StringBuilder sb)
           
 org.apache.hadoop.conf.Configuration getConfiguration()
           
 List<Pair<Enum,Long>> getExpectedEnumCounters()
           
 List<Pair<K2,V2>> getExpectedOutputs()
           
 List<Pair<Pair<String,String>,Long>> getExpectedStringCounters()
           
protected static List<org.apache.hadoop.io.Text> parseCommaDelimitedList(String commaDelimList)
          Split "val,val,val,val..." into a List of Text(val) objects.
static Pair<org.apache.hadoop.io.Text,org.apache.hadoop.io.Text> parseTabbedPair(String tabSeparatedPair)
          Split "key \t val" into Pair(Text(key), Text(val))
 void resetExpectedCounters()
          Clears the list of expected counters from this driver
 void resetOutput()
          Clears the list of outputs expected from this driver
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()
          Runs the test and validates the results
abstract  void runTest(boolean orderMatters)
          Runs the test and validates the results
 void setConfiguration(org.apache.hadoop.conf.Configuration configuration)
           
protected  void validate(CounterWrapper counterWrapper)
          Check that passed counter do contain all expected counters with proper values.
protected  void validate(List<Pair<K2,V2>> outputs, boolean orderMatters)
          check the outputs against the expected inputs in record
 TestDriver<K1,V1,K2,V2> withCounter(Enum e, long expectedValue)
          Register expected enumeration based counter value
 TestDriver<K1,V1,K2,V2> withCounter(String group, String name, long expectedValue)
          Register expected name based counter value
 
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

expectedOutputs

protected List<Pair<K2,V2>> expectedOutputs

expectedEnumCounters

protected List<Pair<Enum,Long>> expectedEnumCounters

expectedStringCounters

protected List<Pair<Pair<String,String>,Long>> expectedStringCounters

configuration

protected org.apache.hadoop.conf.Configuration configuration

counterWrapper

protected CounterWrapper counterWrapper
Constructor Detail

TestDriver

public TestDriver()
Method Detail

getExpectedOutputs

public List<Pair<K2,V2>> getExpectedOutputs()
Returns:
the list of (k, v) pairs expected as output from this driver

resetOutput

public void resetOutput()
Clears the list of outputs expected from this driver


getExpectedEnumCounters

public List<Pair<Enum,Long>> getExpectedEnumCounters()
Returns:
expected counters from this driver

getExpectedStringCounters

public List<Pair<Pair<String,String>,Long>> getExpectedStringCounters()
Returns:
expected counters from this driver

resetExpectedCounters

public void resetExpectedCounters()
Clears the list of expected counters from this driver


withCounter

public TestDriver<K1,V1,K2,V2> withCounter(Enum e,
                                           long expectedValue)
Register expected enumeration based counter value

Parameters:
e - Enumeration based counter
expectedValue - Expected value
Returns:

withCounter

public TestDriver<K1,V1,K2,V2> withCounter(String group,
                                           String name,
                                           long expectedValue)
Register expected name based counter value

Parameters:
group - Counter group
name - Counter name
expectedValue - Expected value
Returns:

run

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

Returns:
the list of (k, v) pairs returned as output from the test
Throws:
IOException

runTest

public void runTest()
Runs the test and validates the results


runTest

public abstract void runTest(boolean orderMatters)
Runs the test and validates the results

Parameters:
orderMatters - Whether or not output ordering is important

parseTabbedPair

public static Pair<org.apache.hadoop.io.Text,org.apache.hadoop.io.Text> parseTabbedPair(String tabSeparatedPair)
Split "key \t val" into Pair(Text(key), Text(val))

Parameters:
tabSeparatedPair -
Returns:

parseCommaDelimitedList

protected static List<org.apache.hadoop.io.Text> parseCommaDelimitedList(String commaDelimList)
Split "val,val,val,val..." into a List of Text(val) objects.

Parameters:
commaDelimList - A list of values separated by commas

validate

protected void validate(List<Pair<K2,V2>> outputs,
                        boolean orderMatters)
check the outputs against the expected inputs in record

Parameters:
outputs - The actual output (k, v) pairs
orderMatters - Whether or not output ordering is important when validating test result

validate

protected void validate(CounterWrapper counterWrapper)
Check that passed counter do contain all expected counters with proper values.

Parameters:
counterWrapper -

formatValueList

protected static void formatValueList(List<?> values,
                                      StringBuilder sb)

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()
Returns:
The configuration object that will given to the mapper and/or reducer associated with the driver (new API only)

setConfiguration

public void setConfiguration(org.apache.hadoop.conf.Configuration configuration)
Parameters:
configuration - The configuration object that will given to the mapper and/or reducer associated with the driver (new API only)


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