1

I have been searching in mrunit documentation but hasnt been able to find it so far.. How do i pass configuration parameters in my mrunit.

So for example, if i take the wordcount example.

Lets say, in my driver code I am setting this parameter...

conf.set("delimiter",args[2])

And in my mapper code I am calling this as:

String delimiter = conf.get("delimiter");
String [] tokens = value.toString().split(delimiter);
for (String token:tokens)
   context.write(token,one);

How do I set up this configuration parameter.

I have been looking into this example: https://github.com/wpm/Hadoop-Word-Count/blob/master/src/test/java/wpmcn/hadoop/WordCountTest.java

Thanks

frazman
  • 32,081
  • 75
  • 184
  • 269

2 Answers2

2

Use MapDriver.withConfiguration

 Configuration conf = new Configuration();
 conf.set("delimiter", someValue);
 myMapDriver.withConfiguration(conf);
John B
  • 32,493
  • 6
  • 77
  • 98
1

I had similar problem and I solved it as given in below code.

mapDriver.withInput(key, value);
mapDriver.getConfiguration().set("my.config.param", "my.config.param.value");
.....
.....
mapDriver.run();

Please note that mapDriver.getContext().getConfiguration may not work in this case, because the context object is a mocked object in the API.

Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53