You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mrunit.apache.org by "Dan Ziemba (JIRA)" <ji...@apache.org> on 2015/08/23 09:01:45 UTC

[jira] [Updated] (MRUNIT-224) Custom Comparators are not used for results written to MultipleOutputs

     [ https://issues.apache.org/jira/browse/MRUNIT-224?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Ziemba updated MRUNIT-224:
------------------------------
    Attachment: 0001-MRUNIT-224-Key-and-Value-Comparators-not-effective-w.patch

I've made an attempt at fixing this myself.  Patch is attached: [^0001-MRUNIT-224-Key-and-Value-Comparators-not-effective-w.patch]

> Custom Comparators are not used for results written to MultipleOutputs
> ----------------------------------------------------------------------
>
>                 Key: MRUNIT-224
>                 URL: https://issues.apache.org/jira/browse/MRUNIT-224
>             Project: MRUnit
>          Issue Type: Bug
>    Affects Versions: 1.1.0
>            Reporter: Dan Ziemba
>         Attachments: 0001-MRUNIT-224-Key-and-Value-Comparators-not-effective-w.patch
>
>
> TestDriver's setValueComparator method has no effect when testing for data written to MultipleOutputs.  setKeyComparator probably doesn't work either.  See the example unit test below:
> {code:java}
> package test;
> import org.apache.hadoop.io.LongWritable;
> import org.apache.hadoop.io.Text;
> import org.apache.hadoop.mapreduce.Mapper;
> import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
> import org.apache.hadoop.mrunit.mapreduce.MapDriver;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.powermock.core.classloader.annotations.PrepareForTest;
> import org.powermock.modules.junit4.PowerMockRunner;
> import java.io.IOException;
> import java.util.Comparator;
> @RunWith(PowerMockRunner.class)
> @PrepareForTest(MosComparatorTest.MosMapper.class)
> public class MosComparatorTest {
>     private class NormalMapper extends Mapper<LongWritable, Text, LongWritable, Text> {
>         @Override
>         protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
>             context.write(key, new Text("testValueOut"));
>         }
>     }
>     public class MosMapper extends Mapper<LongWritable, Text, LongWritable, Text> {
>         private MultipleOutputs<LongWritable, Text> mos;
>         @Override
>         protected void setup(Context context) throws IOException, InterruptedException {
>             mos = new MultipleOutputs<>(context);
>         }
>         @Override
>         protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
>             mos.write("testOut", key, new Text("testValueOut"));
>         }
>         @Override
>         protected void cleanup(Context context) throws IOException, InterruptedException {
>             mos.close();
>         }
>     }
>     @Test
>     public void testNormal() throws Exception {
>         MapDriver<LongWritable, Text, LongWritable, Text> driver = MapDriver.newMapDriver(new NormalMapper());
>         driver.withInput(new LongWritable(123), new Text("testValueIn"))
>                 .withOutput(new LongWritable(123), new Text("testValueOut"))
>                 .runTest();
>     }
>     @Test
>     public void testNormalValueComparator() throws Exception {
>         MapDriver<LongWritable, Text, LongWritable, Text> driver = MapDriver.newMapDriver(new NormalMapper());
>         driver.setValueComparator(new Comparator<Text>() {
>             @Override
>             public int compare(Text o1, Text o2) {
>                 // Everything matches
>                 return 0;
>             }
>         });
>         driver.withInput(new LongWritable(123), new Text("testValueIn"))
>                 .withOutput(new LongWritable(123), new Text("this doesn't matter"))
>                 .runTest();
>     }
>     @Test
>     public void testMos() throws Exception {
>         MapDriver<LongWritable, Text, LongWritable, Text> driver = MapDriver.newMapDriver(new MosMapper());
>         driver.withInput(new LongWritable(123), new Text("testValueIn"))
>                 .withMultiOutput("testOut", new LongWritable(123), new Text("testValueOut"))
>                 .runTest();
>     }
>     /**
>      * This test fails.  It should pass because of the custom value Comparator.
>      * <p/>
>      * <pre>java.lang.AssertionError: 1 Error(s): (Expected output (123, this shouldn't matter) for namedOutput 'testOut' at position 0, but found (123, testValueOut))</pre>
>      */
>     @Test
>     public void testMosValueComparator() throws Exception {
>         MapDriver<LongWritable, Text, LongWritable, Text> driver = MapDriver.newMapDriver(new MosMapper());
>         driver.setValueComparator(new Comparator<Text>() {
>             @Override
>             public int compare(Text o1, Text o2) {
>                 // Everything matches
>                 return 0;
>             }
>         });
>         driver.withInput(new LongWritable(123), new Text("testValueIn"))
>                 .withMultiOutput("testOut", new LongWritable(123), new Text("this shouldn't matter"))
>                 .runTest();
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)