我是hadoop的新手,我正在學習haddop權威指南。我正在使用MRunit進行單元測試,但在進行reduce任務測試時,我正面臨編譯錯誤。面對編譯錯誤Hadoop Junit測試
下面是我的降低的java文件:MaxTemperatureReducer.java
package org.priya.mapred.mapred;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
//import org.apache.hadoop.mapred.MRBench.Reduce;
import org.apache.hadoop.mapreduce.Reducer;
public class MaxTemperatureReducer extends Reducer<Text, IntWritable , Text, IntWritable> {
public void reduce(Text key,Iterator<IntWritable> values, Context context) throws InterruptedException ,IOException
{
int maxValue = Integer.MIN_VALUE;
while(values.hasNext())
{
IntWritable value =values.next();
if(maxValue >= value.get())
{
maxValue= value.get();
}
}
context.write(key, new IntWritable(maxValue));
}
}
下面是我的JUnit進行測試文件:MaxTemperatureReducerTest.java
package org.priya.mapred.mapred;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
//import org.apache.hadoop.mrunit.ReduceDriver;
import org.apache.hadoop.mrunit.ReduceDriver;
//import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
public class MaxTemperatureReducerTest {
@Test
public void reducerTestValid()
{
ArrayList<IntWritable> listOfValues = new ArrayList<IntWritable>();
listOfValues.add(new IntWritable(20));
listOfValues.add(new IntWritable(30));
listOfValues.add(new IntWritable(40));
listOfValues.add(new IntWritable(60));
new ReduceDriver<Text ,IntWritable , Text, IntWritable>()
.withReducer(new MaxTemperatureReducer())
.withInput(new Text("1950"),listOfValues)
.withOutput(new Text("1950"), new IntWritable(60));
}
}
而我傳遞reduceclass即新MaxTemperatureReducer的一個實例( )給我的reducerdriver使用,withReducer()方法的驅動類。我正在收到編譯錯誤。
The method withReducer(Reducer<Text,IntWritable,Text,IntWritable>) in the type ReduceDriver<Text,IntWritable,Text,IntWritable> is not applicable for the arguments (MaxTemperatureReducer)
請幫我,我可以看到MaxTemperatureMapper類擴展了減速類,我不能understatnd爲什麼withReducer()方法不接受MaxTemperatureReducer實例。
感謝, Priyaranjan
感謝venkat,我改爲org.apache.hadoop.mapred.Reducer,它工作正常。 – priyaranjan