public abstract class TestDriver<K,V,T extends TestDriver<K,V,T>> extends Object
Modifier and Type | Field and Description |
---|---|
protected org.apache.hadoop.mrunit.internal.counters.CounterWrapper |
counterWrapper |
protected List<Pair<Enum<?>,Long>> |
expectedEnumCounters |
protected Map<String,List<Pair<?,?>>> |
expectedMultipleOutputs |
protected List<Pair<K,V>> |
expectedOutputs |
protected Map<String,List<Pair<?,?>>> |
expectedPathOutputs |
protected List<Pair<Pair<String,String>,Long>> |
expectedStringCounters |
static org.apache.commons.logging.Log |
LOG |
protected org.apache.hadoop.mrunit.internal.output.MockMultipleOutputs |
mos |
Constructor and Description |
---|
TestDriver() |
Modifier and Type | Method and Description |
---|---|
void |
addAllOutput(List<Pair<K,V>> outputRecords)
Adds output (k, v)* pairs we expect
|
void |
addCacheArchive(String path)
Adds an archive to be put on the distributed cache.
|
void |
addCacheArchive(URI uri)
Adds an archive to be put on the distributed cache.
|
void |
addCacheFile(String path)
Adds a file to be put on the distributed cache.
|
void |
addCacheFile(URI uri)
Adds a file to be put on the distributed cache.
|
<K,V> void |
addMultiOutput(String namedOutput,
K key,
V val)
add a (k, v) pair we expect as Multiple output
|
<K,V> void |
addMultiOutput(String namedOutput,
Pair<K,V> outputRecord)
Adds an output (k, v) pair we expect as Multiple output
|
void |
addOutput(K key,
V val)
Adds a (k, v) pair we expect as output
|
void |
addOutput(Pair<K,V> outputRecord)
Adds an output (k, v) pair we expect
|
void |
addOutputFromString(String output)
Deprecated.
No replacement due to lack of type safety and incompatibility
with non Text Writables
|
protected void |
cleanupDistributedCache()
Cleans up the distributed cache test by deleting the temporary directory
and any extracted cache archives contained within
|
protected <E> E |
copy(E object) |
protected <S,E> Pair<S,E> |
copyPair(S first,
E second) |
protected boolean |
driverReused()
Check to see if this driver is being reused
|
protected static <KEYIN,VALUEIN> |
formatPairList(List<Pair<KEYIN,VALUEIN>> pairs,
StringBuilder sb) |
static void |
formatValueList(List<?> values,
StringBuilder sb) |
org.apache.hadoop.conf.Configuration |
getConfiguration() |
List<Pair<Enum<?>,Long>> |
getExpectedEnumCounters() |
List<Pair<K,V>> |
getExpectedOutputs() |
List<Pair<Pair<String,String>,Long>> |
getExpectedStringCounters() |
Comparator<K> |
getKeyComparator() |
org.apache.hadoop.conf.Configuration |
getOutputSerializationConfiguration()
Get the
Configuration to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat. |
Comparator<V> |
getValueComparator() |
protected void |
initDistributedCache()
Initialises the test distributed cache if required.
|
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))
|
protected void |
printPreTestDebugLog()
Overridable hook for printing pre-test debug information
|
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<K,V>> |
run()
Runs the test but returns the result set instead of validating it (ignores
any addOutput(), etc calls made before this)
|
List<Pair<K,V>> |
run(boolean validateCounters)
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
|
void |
runTest(boolean orderMatters)
Runs the test and validates the results
|
void |
setCacheArchives(URI[] archives)
Set the list of archives to put on the distributed cache
|
void |
setCacheFiles(URI[] files)
Set the list of files to put on the distributed cache
|
void |
setConfiguration(org.apache.hadoop.conf.Configuration configuration)
Deprecated.
Use getConfiguration() to set configuration items as opposed to
overriding the entire configuration object as it's used
internally.
|
void |
setKeyComparator(Comparator<K> keyComparator)
Set the output key comparator
|
void |
setOutputSerializationConfiguration(org.apache.hadoop.conf.Configuration configuration)
Set the
Configuration to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat. |
protected void |
setUsedOnceStatus()
Set to true when run() is called to prevent driver reuse
|
void |
setValueComparator(Comparator<V> valueComparator)
Set the output value comparator
|
protected T |
thisAsTestDriver() |
protected void |
validate(org.apache.hadoop.mrunit.internal.counters.CounterWrapper counterWrapper)
Check counters.
|
protected void |
validate(List<Pair<K,V>> outputs,
boolean orderMatters)
check the outputs against the expected inputs in record
|
protected void |
validate(org.apache.hadoop.mrunit.internal.output.MockMultipleOutputs mos) |
protected void |
validateOutputList(String name,
org.apache.hadoop.mrunit.internal.util.Errors errors,
Map<String,List<Pair<?,?>>> actuals,
Map<String,List<Pair<?,?>>> expects)
Check Multiple Outputs.
|
T |
withAllOutput(List<Pair<K,V>> outputRecords)
Functions like addAllOutput() but returns self for fluent programming style
|
T |
withCacheArchive(String archive)
Adds an archive to be put on the distributed cache.
|
T |
withCacheArchive(URI archive)
Adds an archive to be put on the distributed cache.
|
T |
withCacheFile(String file)
Adds a file to be put on the distributed cache.
|
T |
withCacheFile(URI file)
Adds a file to be put on the distributed cache.
|
T |
withConfiguration(org.apache.hadoop.conf.Configuration configuration)
Deprecated.
Use getConfiguration() to set configuration items as opposed to
overriding the entire configuration object as it's used
internally.
|
T |
withCounter(Enum<?> e,
long expectedValue)
Register expected enumeration based counter value
|
T |
withCounter(String group,
String name,
long expectedValue)
Register expected name based counter value
|
<K extends Comparable,V extends Comparable> |
withMultiOutput(String namedOutput,
K key,
V value)
works like addMultiOutput() but returns self for fluent programming style
|
<K,V> T |
withMultiOutput(String namedOutput,
Pair<K,V> outputRecord)
Works like addMultiOutput(), but returns self for fluent programming style
|
T |
withOutput(K key,
V val)
Works like addOutput() but returns self for fluent programming style
|
T |
withOutput(Pair<K,V> outputRecord)
Works like addOutput(), but returns self for fluent style
|
T |
withOutputFromString(String output)
Deprecated.
No replacement due to lack of type safety and incompatibility
with non Text Writables
|
T |
withOutputSerializationConfiguration(org.apache.hadoop.conf.Configuration configuration)
Set the
Configuration to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat. |
<K,V> T |
withPathOutput(K key,
V value,
String path) |
<K,V> T |
withPathOutput(Pair<K,V> outputRecord,
String path) |
T |
withStrictCounterChecking()
Change counter checking.
|
public static final org.apache.commons.logging.Log LOG
protected org.apache.hadoop.mrunit.internal.counters.CounterWrapper counterWrapper
protected org.apache.hadoop.mrunit.internal.output.MockMultipleOutputs mos
protected boolean driverReused()
protected void setUsedOnceStatus()
public void addAllOutput(List<Pair<K,V>> outputRecords)
outputRecords
- The (k, v)* pairs to addpublic T withAllOutput(List<Pair<K,V>> outputRecords)
outputRecords
- public void addOutput(Pair<K,V> outputRecord)
outputRecord
- The (k, v) pair to addpublic void addOutput(K key, V val)
key
- the keyval
- the valuepublic T withOutput(Pair<K,V> outputRecord)
outputRecord
- public T withOutput(K key, V val)
@Deprecated public void addOutputFromString(String output)
output
- A string of the form "key \t val". Trims any whitespace.@Deprecated public T withOutputFromString(String output)
output
- A string of the form "key \t val". Trims any whitespace.public List<Pair<K,V>> getExpectedOutputs()
public void resetOutput()
public List<Pair<Enum<?>,Long>> getExpectedEnumCounters()
public List<Pair<Pair<String,String>,Long>> getExpectedStringCounters()
public void resetExpectedCounters()
protected T thisAsTestDriver()
public T withCounter(Enum<?> e, long expectedValue)
e
- Enumeration based counterexpectedValue
- Expected valuepublic T withCounter(String group, String name, long expectedValue)
group
- Counter groupname
- Counter nameexpectedValue
- Expected valuepublic T withStrictCounterChecking()
public org.apache.hadoop.conf.Configuration getConfiguration()
public Comparator<K> getKeyComparator()
public Comparator<V> getValueComparator()
@Deprecated public void setConfiguration(org.apache.hadoop.conf.Configuration configuration)
configuration
- The configuration object that will given to the mapper and/or
reducer associated with the driver. This method should only be
called directly after the constructor as the internal state of the
driver depends on the configuration object@Deprecated public T withConfiguration(org.apache.hadoop.conf.Configuration configuration)
configuration
- The configuration object that will given to the mapper associated
with the driver. This method should only be called directly after
the constructor as the internal state of the driver depends on the
configuration objectpublic org.apache.hadoop.conf.Configuration getOutputSerializationConfiguration()
Configuration
to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat.public void setOutputSerializationConfiguration(org.apache.hadoop.conf.Configuration configuration)
Configuration
to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat. When this configuration is not set, MRUnit will use the
configuration set with withConfiguration(Configuration)
or
setConfiguration(Configuration)
configuration
- public T withOutputSerializationConfiguration(org.apache.hadoop.conf.Configuration configuration)
Configuration
to use when copying output for use with run*
methods or for the InputFormat when reading output back in when setting a
real OutputFormat. When this configuration is not set, MRUnit will use the
configuration set with withConfiguration(Configuration)
or
setConfiguration(Configuration)
configuration
- public void addCacheFile(String path)
path
- path to the filepublic void addCacheFile(URI uri)
uri
- uri of the filepublic void setCacheFiles(URI[] files)
files
- list of URIspublic void setKeyComparator(Comparator<K> keyComparator)
keyComparator
- the key comparatorpublic void setValueComparator(Comparator<V> valueComparator)
valueComparator
- the value comparatorpublic void addCacheArchive(String path)
path
- path to the archivepublic void addCacheArchive(URI uri)
uri
- uri of the archivepublic void setCacheArchives(URI[] archives)
archives
- list of URIspublic T withCacheFile(String file)
file
- path to the filepublic T withCacheFile(URI file)
file
- uri of the filepublic T withCacheArchive(String archive)
archive
- path to the archivepublic T withCacheArchive(URI archive)
archive
- uri of the archivepublic List<Pair<K,V>> run(boolean validateCounters) throws IOException
validateCounters
- whether to run automatic counter validationIOException
protected void initDistributedCache() throws IOException
IOException
protected void cleanupDistributedCache() throws IOException
IOException
- if the local fs handle cannot be retrievedpublic abstract List<Pair<K,V>> run() throws IOException
IOException
public void runTest() throws IOException
IOException
public void runTest(boolean orderMatters) throws IOException
orderMatters
- Whether or not output ordering is importantIOException
protected void printPreTestDebugLog()
public static Pair<org.apache.hadoop.io.Text,org.apache.hadoop.io.Text> parseTabbedPair(String tabSeparatedPair)
tabSeparatedPair
- protected static List<org.apache.hadoop.io.Text> parseCommaDelimitedList(String commaDelimList)
commaDelimList
- A list of values separated by commasprotected <E> E copy(E object)
protected <S,E> Pair<S,E> copyPair(S first, E second)
protected void validate(List<Pair<K,V>> outputs, boolean orderMatters)
outputs
- The actual output (k, v) pairsorderMatters
- Whether or not output ordering is important when validating test
resultprotected void validate(org.apache.hadoop.mrunit.internal.counters.CounterWrapper counterWrapper)
protected void validateOutputList(String name, org.apache.hadoop.mrunit.internal.util.Errors errors, Map<String,List<Pair<?,?>>> actuals, Map<String,List<Pair<?,?>>> expects)
protected void validate(org.apache.hadoop.mrunit.internal.output.MockMultipleOutputs mos)
public static void formatValueList(List<?> values, StringBuilder sb)
protected static <KEYIN,VALUEIN> void formatPairList(List<Pair<KEYIN,VALUEIN>> pairs, StringBuilder sb)
public <K,V> void addMultiOutput(String namedOutput, Pair<K,V> outputRecord)
namedOutput
- outputRecord
- public <K,V> void addMultiOutput(String namedOutput, K key, V val)
namedOutput
- key
- val
- public <K extends Comparable,V extends Comparable> T withMultiOutput(String namedOutput, K key, V value)
namedOutput
- key
- value
- public <K,V> T withMultiOutput(String namedOutput, Pair<K,V> outputRecord)
namedOutput
- outputRecord
- Copyright © 2014 The Apache Software Foundation. All Rights Reserved.