Hadoop Mrunit throughing exceptions

151 views Asked by At

I am getting the following exceptions when I am running unit tests for MapReduce. I have imported every possible jar. I am not sure where I went wrong. I have Included the screenshot of jars I imported below.

I was testing a simple code:

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();
    }
  }
}

And I got following exceptions:

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 Files Imported--Click here

0

There are 0 answers