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

Switch to Plain View
Hadoop, mail # user - Re: Errors about MRunit


+
姚吉龙 2013-04-20, 14:14
Copy link to this message
-
Re: Errors about MRunit
姚吉龙 2013-04-21, 02:52
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)
 at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
 at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
 at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Any body help to figure out these?
I am going crazy
BRs
Geelong

2013/4/21 Rishi Yadav <[EMAIL PROTECTED]>

+
Jagat Singh 2013-04-21, 02:39