??Mapreduce??????е??????
???????????? ???????[ 2014/11/24 14:02:46 ] ??????????????? ??????? ????
?????????????????е????????????????job?????????????????е???????????????????????????????????????????????????????????????map??reduce???????в????
????tomwhite???頂hadoop????????????????Mockito???е?????????????????????????????????wordcount???е???????(???????????????????????ο?????????????????)??
package org.apache.hadoop.examples;
/* author zhouhh
* date:2012.8.7
*/
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.io.*;
import org.junit.*;
public class WordCountTest {
@Test
public void testWordCountMap() throws IOException?? InterruptedException
{
WordCount w = new WordCount();
WordCount.TokenizerMapper mapper = new WordCount.TokenizerMapper();
Text value = new Text("a b c b a a");
@SuppressWarnings("unchecked")
WordCount.TokenizerMapper.Context context = mock(WordCount.TokenizerMapper.Context.class);
mapper.map(null?? value?? context);
verify(context??times(3)).write(new Text("a")?? new IntWritable(1));
verify(context).write(new Text("c")?? new IntWritable(1));
//verify(context).write(new Text("cc")?? new IntWritable(1));
}
@Test
public void testWordCountReduce() throws IOException?? InterruptedException
{
WordCount.IntSumReducer reducer = new WordCount.IntSumReducer();
WordCount.IntSumReducer.Context context = mock(WordCount.IntSumReducer.Context.class);
Text key = new Text("a");
List values = new ArrayList();
values.add(new IntWritable(1));
values.add(new IntWritable(1));
reducer.reduce(key?? values?? context);
verify(context).write(new Text("a")?? new IntWritable(2));
}
public static void main(String[] args) {
// try {
// WordCountTest t = new WordCountTest();
//
// //t.testWordCountMap();
// t.testWordCountReduce();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}
????verify(context)??????ε?д????????д??????verify(contex??times(n))??飬?????????
???????????????????run as JUnit Test????????????????????
???????????????hadoop1.0.3?????в????????Mockito???hadoop??lib????????????mockito-all-1.8.5.jar
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11