Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HDFS >> mail # user >> Re: Errors about MRunit


Copy link to this message
-
Re: Errors about MRunit
Can you please confirm if you are not mixing old and new mapreduce API
On Sun, Apr 21, 2013 at 12:52 PM, 姚吉龙 <[EMAIL PROTECTED]> wrote:

> Thanks
> But I am confused about the MRunit. How to use MRunit without maven
> I am just following the tutorial:
> https://cwiki.apache.org/confluence/display/MRUNIT/MRUnit+Tutorial
>
> My test code  is below, the maper and reducer is in another project linked
> in my testing project
>
>
>
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.List;
> import junit.framework.TestCase;
> import org.apache.hadoop.io.IntWritable;
> import org.apache.hadoop.io.LongWritable;
> import org.apache.hadoop.io.Text;
> import org.apache.hadoop.mapred.lib.IdentityMapper;
> import org.apache.hadoop.mapred.Mapper;
> import org.apache.hadoop.mrunit.mapreduce.MapDriver;
> import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
> import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
> import org.apache.hadoop.mrunit.types.Pair;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
>
> public class UnitTest extends TestCase{
>   MapDriver<Object, Text, Text, Text> mapDriver;
>   ReduceDriver<Text, Text, Text, Text> reduceDriver;
>   MapReduceDriver<Object, Text, Text, Text, Text, Text> mapReduceDriver;
>    @Before
>   public void setUp() {
> carTest.FirstMapper mapper = new carTest.FirstMapper();
>  carTest.FirstReducer reducer = new carTest.FirstReducer();
>     mapDriver = MapDriver.newMapDriver(mapper);;
>     reduceDriver = ReduceDriver.newReduceDriver(reducer);
>     mapReduceDriver = MapReduceDriver.newMapReduceDriver(mapper, reducer);
>   }
>   @Test
>   public void testMapper() throws IOException {
>     mapDriver.withInput(new Object(), new Text(
>
>  "199397,32100000000000000800000120110131014195,321000000000000008,20110131170958,00,,苏K16423,2,,34.00,,,,460,,,K33,02,,1710048437180058,476096"));
>     mapDriver.withOutput(new Text("苏K16423"), new
> Text("321000000000000008"));
>     mapDriver.runTest();
>
>  //"199397","32100000000000000800000120110131014195","321000000000000008","20110131170958","00","","苏K16423","2","","34.00","","","","460","","","K33","02","","1710048437180058","476096"
>
>   }
>   @Test
>   public void testReducer() throws IOException {
>     List<Text> values = new ArrayList<Text>();
>     values.add(new
> Text("199397,32100000000000000800000120110131014195,321000000000000005,20110131172000,00,,苏K16423,2,,34.00,,,,460,,,K33,02,,1710048437180058,476096"));
>   //  values.add(new Text("1"));
>     reduceDriver.withInput(new Text("6"), values);
>     reduceDriver.withOutput(new Text("6"), new Text("2"));
>     reduceDriver.runTest();
>   }
>
>
>   }
>
> While, always failed to pass
> [image: 内嵌图片 1]
> Here is the trace
>
> java.lang.IncompatibleClassChangeError: Found class
> org.apache.hadoop.mapreduce.TaskInputOutputContext, but interface was
> expected
> at
> org.apache.hadoop.mrunit.mapreduce.mock.MockContextWrapper.createCommon(MockContextWrapper.java:53)
>  at
> org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper.create(MockMapContextWrapper.java:70)
> at
> org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper.<init>(MockMapContextWrapper.java:62)
>  at org.apache.hadoop.mrunit.mapreduce.MapDriver.run(MapDriver.java:217)
> at org.apache.hadoop.mrunit.MapDriverBase.runTest(MapDriverBase.java:150)
>  at org.apache.hadoop.mrunit.TestDriver.runTest(TestDriver.java:137)
> at UnitTest.testMapper(UnitTest.java:37)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
>  at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
>  at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)