You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by fhueske <gi...@git.apache.org> on 2016/03/22 11:51:57 UTC

[GitHub] flink pull request: [FLINK-2444] add tests for HadoopInputFormats

Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1628#discussion_r56966658
  
    --- Diff: flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java ---
    @@ -20,22 +20,137 @@
     
     import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
     import org.apache.flink.api.common.typeinfo.TypeInformation;
    +import org.apache.flink.api.java.hadoop.mapreduce.wrapper.HadoopInputSplit;
     import org.apache.flink.api.java.tuple.Tuple2;
     import org.apache.flink.api.java.typeutils.TupleTypeInfo;
    -import org.apache.flink.api.java.hadoop.mapreduce.HadoopInputFormat;
    -import org.apache.hadoop.mapreduce.InputSplit;
    -import org.apache.hadoop.mapreduce.Job;
    -import org.apache.hadoop.mapreduce.RecordReader;
    -import org.apache.hadoop.mapreduce.TaskAttemptContext;
    +import org.apache.hadoop.conf.Configurable;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.mapreduce.*;
     import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    +import org.junit.Rule;
     import org.junit.Test;
    +import org.junit.rules.ExpectedException;
     
     import java.io.IOException;
    +import java.util.List;
     
    -import static org.junit.Assert.fail;
    +import static org.hamcrest.CoreMatchers.equalTo;
    +import static org.hamcrest.core.Is.is;
    +import static org.junit.Assert.assertThat;
    +import static org.mockito.Mockito.*;
     
     public class HadoopInputFormatTest {
     
    +	@Rule
    +	public final ExpectedException exception = ExpectedException.none();
    +
    +	@Test
    +	public void testConfigure() throws Exception {
    +
    +		ConfigurableDummyInputFormat inputFormat = mock(ConfigurableDummyInputFormat.class);
    +
    +		HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
    +		hadoopInputFormat.configure(new org.apache.flink.configuration.Configuration());
    +
    +		verify(inputFormat, times(1)).setConf(any(Configuration.class));
    +	}
    +
    +	@Test
    +	public void testCreateInputSplits() throws Exception {
    +		DummyInputFormat inputFormat = mock(DummyInputFormat.class);
    +
    +		HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
    +		hadoopInputFormat.createInputSplits(2);
    +
    +		verify(inputFormat, times(1)).getSplits(any(JobContext.class));
    +	}
    +
    +	@Test
    +	public void testOpen() throws Exception {
    +		DummyInputFormat inputFormat = mock(DummyInputFormat.class);
    +		when(inputFormat.createRecordReader(any(InputSplit.class), any(TaskAttemptContext.class))).thenReturn(new DummyRecordReader());
    +		HadoopInputSplit inputSplit = mock(HadoopInputSplit.class);
    +
    +		HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
    +		hadoopInputFormat.open(inputSplit);
    +
    +		verify(inputFormat, timeout(1)).createRecordReader(any(InputSplit.class), any(TaskAttemptContext.class));
    --- End diff --
    
    should be `times(1)` instead of `timeout(1)`, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---