我想單元測試使用MRUnit的Mapper程序(來自Hadoop:權威指南,第153頁,部分:使用MRUnit編寫單元測試:Mapper)。我使用的IntelliJ IDEA,它是示出了方法的誤差MRUnit測試用於測試hadoop映射程序錯誤
new org.apache.hadoop.mrunit.MapDriver<>().withMapper(myMapper)
該錯誤消息表示, withMapper(org.apache.hadoop.mapreduce.Mapper)在MapDriver不能被應用到(complexmapreduce.MaxTempMapper )
MaxTempMapper被聲明爲org.apache.hadoop.mapreduce.Mapper 一個子類,所以我真的不知道這裏有什麼問題。
以下是完整映射器和單元測試類
MaxTempMapper
package complexmapreduce;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class MaxTempMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private static final int MISSING = 9999;
private NDCRecordParser myParser = new NDCRecordParser();
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
myParser.parse(value);
if (myParser.isValidTemperature()) {
context.write(new Text(myParser.getYear()), new IntWritable(myParser.getMaxTemperature()));
}
}
}
MaxTempUnitTest
package complexmapreduce;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.junit.Test;
import java.io.IOException;
public class MaxTempSingleLineUnitTest {
@Test
public void testMaxTempMapper() throws IOException {
Text value = new Text("0029029070999991901010106004+64333+023450FM-12+000599999V0202701N015919999999N0000001N9-00781+99999102001ADDGF108991999999999999999999");
LongWritable key = new LongWritable(0);
MaxTempMapper myMapper = new MaxTempMapper();
new org.apache.hadoop.mrunit.mapreduce.MapDriver<>()
.withMapper(myMapper) // <<<===Error here
.withInput(key, value)
.withOutput(new Text("1901"),
new IntWritable(0210))
.runTest();
}
}
注:已經嘗試過解決方案here,但沒有運氣。
這裏是的IntelliJ
這沒有什麼區別......仍然有相同的錯誤。我添加了原始帖子的截圖。 –
您使用的是哪個版本的Java? –
使用Java 8.我確保支持註釋,並使用正確的hadoop2 API(org.apache.hadoop.mrunit.mapreduce.MapDriver而不是org.apache.hadoop.mrunit.mapred.MapDriver)。編譯該程序會給我以下錯誤。 錯誤:(14,25)java:找不到符號 symbol:class MaxTempMapper location:package complexmapreduce –