import
import
import
import
org.apache.hadoop.io.LongWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mrunit.mapreduce.MapDriver;
org.junit.Test;
public class MyMapperTest {
@Test
public void processesValidRecord() throws Exception {
Text value = new Text();
value.set("201001 1003
abc");
TextPair textPair = new TextPair();
textPair.setKey1(new Text("1003"));
textPair.setKey2(new Text("1"));
Text outValue = new Text("201001" + "\t" + "abc");
new MapDriver<LongWritable, Text, TextPair, Text>()
.withMapper(new MyMapper())
.withInput(new LongWritable(0), value)
.withOutput(textPair, outValue).runTest();
}
}
这个是对MyMapper中有关data.info部分的测试,这里刚开始的时候,在写
TextPair类的时候,并没有覆写
@Override
public int hashCode() {
// TODO Auto-generated method stub
return Integer.parseInt(this.getKey1().toString()) * 157
+ Integer.parseInt(this.getKey2().toString());
}
@Override
public boolean equals(Object obj) {
TextPair o = (TextPair) obj;
return this.getKey1().equals(o.key1) && this.getKey2().equals(o.key2);
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.getKey1().toString() + "\t" + this.getKey2().toString();
}
上面这3个方法,导致怎么测试都不能成功,即使结果完全一样也没有通过
测试,后来,覆写之后就成功了。
import
import
import
org.apache.hadoop.io.LongWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mrunit.mapreduce.MapDriver;
org.junit.Test;
public class MyMapperTest {
@Test
public void processesValidRecord() throws Exception {
Text value = new Text();
value.set("201001 1003
abc");
TextPair textPair = new TextPair();
textPair.setKey1(new Text("1003"));
textPair.setKey2(new Text("1"));
Text outValue = new Text("201001" + "\t" + "abc");
new MapDriver<LongWritable, Text, TextPair, Text>()
.withMapper(new MyMapper())
.withInput(new LongWritable(0), value)
.withOutput(textPair, outValue).runTest();
}
}
这个是对MyMapper中有关data.info部分的测试,这里刚开始的时候,在写
TextPair类的时候,并没有覆写
@Override
public int hashCode() {
// TODO Auto-generated method stub
return Integer.parseInt(this.getKey1().toString()) * 157
+ Integer.parseInt(this.getKey2().toString());
}
@Override
public boolean equals(Object obj) {
TextPair o = (TextPair) obj;
return this.getKey1().equals(o.key1) && this.getKey2().equals(o.key2);
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.getKey1().toString() + "\t" + this.getKey2().toString();
}
上面这3个方法,导致怎么测试都不能成功,即使结果完全一样也没有通过
测试,后来,覆写之后就成功了。