Java – Hadoop unit tests with mock context

Hadoop unit tests with mock context… here is a solution to the problem.

Hadoop unit tests with mock context

I’m trying to write unit tests for a hadoop job. The problem is that the mapper uses the Context parameter passed to it to determine which file it is reading at that time. It makes the following call:

String inputFile = ((FileSplit) context.getInputSplit()).getPath().toString();

However, when writing unit tests for the mapper using MRUnit, I can’t seem to find any way to emulate this Context object. Even MapDriver doesn’t seem to have the option to set the new Context object. Is there any way to write unit tests for this mapper class?

Solution

Related Problems and Solutions