Import Java.io.ioexception;import Java.util.arraylist;import java.util.list;import Org.apache.hadoop.io.intwritable;import Org.apache.hadoop.io.longwritable;import Org.apache.hadoop.io.Text; Import Org.apache.hadoop.mrunit.mapreduce.mapdriver;import Org.apache.hadoop.mrunit.types.pair;import Org.junit.test;public class Wordcountest {@SuppressWarnings ({"Rawtypes","unchecked"}) @Test public void Test () throws IOException {//fail ("not yet implemented");Text value = new text ("Hello World Hello Hadoop"); List<pair<text, intwritable>> outputs = new Arraylist<pair<text, intwritable>>(); Outputs.add (New Pair (New Text ("Hello"), New Intwritable (1))); Outputs.add (New Pair (New Text (" World"), New Intwritable (1))); Outputs.add (New Pair (New Text ("Hello"), New Intwritable (1))); Outputs.add (New Pair (New Text ("Hadoop"), New Intwritable (1))); //temperature ^^ ^^ ^New Mapdriver<object, text, text, intwritable>(). Withmapper (New Wordcount.tokenizermapper ()). Withinput (New longwritable (0), value). Withalloutput (outputs). Runtest (); }}
In the sixth chapter of the authoritative guide to Hadoop, there is a detailed example of this, which can be referenced to fulfill your needs, and if more understanding is needed, you can look at the Testdriver class to meet your needs and changes.
When simulating a small cluster test, you need to extend clustermapreducetestcase this class, and you can refer to the examples in the Hadoop authoritative guide.
It is recommended that you write your own unit tests when you develop mapreduce, which further guarantees the quality of the data and makes writing mrunit a standard for writing mapreduce programs.
Mrunit for WordCount Demo