mrunit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Ziemba (JIRA)" <j...@apache.org>
Subject [jira] [Created] (MRUNIT-224) Custom Comparators are not used for results written to MultipleOutputs
Date Thu, 20 Aug 2015 22:51:47 GMT
Dan Ziemba created MRUNIT-224:
---------------------------------

             Summary: 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


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)

Mime
View raw message