1

当我为 MapReduce 运行单元测试时,我遇到了以下异常。我已经导入了所有可能的 jar。我不确定我哪里出错了。我已经包含了我在下面导入的 jar 的屏幕截图。

我正在测试一个简单的代码:

import java.io.IOException;

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.mapreduce.Mapper;
import org.apache.hadoop.mrunit.mapreduce.*;
import org.junit.Test;


public class TestExample extends TestCase {

        public static class maptest extends Mapper<LongWritable, Text, Text, IntWritable>{
            Text day=new Text();

            public void map(LongWritable key,Text value,Context ct)throws IOException,InterruptedException
            {
                String[] line=value.toString().split(",");
                int val=Integer.parseInt(line[0]);
                day.set(line[1]);
                ct.write(day,new IntWritable(val));

            }
        }
         MapDriver<LongWritable, Text, Text, IntWritable> mapDriver;

  public void setUp() {
   new maptest();
    mapDriver = MapDriver.newMapDriver( new maptest());
  }

  @Test
  public void testMapper() {
    try {
        mapDriver.withInput(new LongWritable(), new Text("1,sunday,abhay,holiday"))
                .withOutput(new Text("sunday"), new IntWritable(1))
                .runTest();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
  }
}

我得到了以下例外:

java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
    at org.apache.hadoop.fs.Path.normalizePath(Path.java:237)
    at org.apache.hadoop.fs.Path.initialize(Path.java:203)
    at org.apache.hadoop.fs.Path.<init>(Path.java:172)
    at org.apache.hadoop.mrunit.MapDriverBase.<init>(MapDriverBase.java:45)
    at org.apache.hadoop.mrunit.mapreduce.MapDriver.<init>(MapDriver.java:73)
    at org.apache.hadoop.mrunit.mapreduce.MapDriver.<init>(MapDriver.java:69)
    at org.apache.hadoop.mrunit.mapreduce.MapDriver.newMapDriver(MapDriver.java:221)
    at TestExample.setUp(TestExample.java:35)
    at junit.framework.TestCase.runBare(TestCase.java:139)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:252)
    at junit.framework.TestSuite.run(TestSuite.java:247)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    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)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 22 more

已导入 Jar 文件--单击此处

4

0 回答 0