use of org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO.SerializableSplit in project beam by apache.
the class HadoopFormatIOReadTest method testReadDisplayData.
/**
* This test validates functionality of {@link
* HadoopInputFormatBoundedSource#populateDisplayData(DisplayData.Builder)}
* populateDisplayData(DisplayData.Builder)}.
*/
@Test
public void testReadDisplayData() {
HadoopInputFormatBoundedSource<Text, Employee> boundedSource = new HadoopInputFormatBoundedSource<>(serConf, WritableCoder.of(Text.class), AvroCoder.of(Employee.class), // No key translation required.
null, // No value translation required.
null, new SerializableSplit(), false, false);
DisplayData displayData = DisplayData.from(boundedSource);
assertThat(displayData, hasDisplayItem("mapreduce.job.inputformat.class", serConf.get().get("mapreduce.job.inputformat.class")));
assertThat(displayData, hasDisplayItem("key.class", serConf.get().get("key.class")));
assertThat(displayData, hasDisplayItem("value.class", serConf.get().get("value.class")));
}
use of org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO.SerializableSplit in project beam by apache.
the class HadoopFormatIOReadTest method testReadIfCreateRecordReaderFails.
/**
* This test validates behavior of {@link HadoopInputFormatBoundedSource} if RecordReader object
* creation fails.
*/
@Test
public void testReadIfCreateRecordReaderFails() throws Exception {
thrown.expect(Exception.class);
thrown.expectMessage("Exception in creating RecordReader");
InputFormat<Text, Employee> mockInputFormat = Mockito.mock(EmployeeInputFormat.class);
Mockito.when(mockInputFormat.createRecordReader(Mockito.any(InputSplit.class), Mockito.any(TaskAttemptContext.class))).thenThrow(new IOException("Exception in creating RecordReader"));
HadoopInputFormatBoundedSource<Text, Employee> boundedSource = new HadoopInputFormatBoundedSource<>(serConf, WritableCoder.of(Text.class), AvroCoder.of(Employee.class), // No key translation required.
null, // No value translation required.
null, new SerializableSplit(), false, false);
boundedSource.setInputFormatObj(mockInputFormat);
SourceTestUtils.readFromSource(boundedSource, p.getOptions());
}
use of org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO.SerializableSplit in project beam by apache.
the class HadoopFormatIOReadTest method testGetFractionConsumedForBadProgressValue.
/**
* This test validates the method getFractionConsumed()- when a bad progress value is returned by
* the inputformat.
*/
@Test
public void testGetFractionConsumedForBadProgressValue() throws Exception {
InputFormat<Text, Employee> mockInputFormat = Mockito.mock(EmployeeInputFormat.class);
EmployeeRecordReader mockReader = Mockito.mock(EmployeeRecordReader.class);
Mockito.when(mockInputFormat.createRecordReader(Mockito.any(), Mockito.any())).thenReturn(mockReader);
Mockito.when(mockReader.nextKeyValue()).thenReturn(true);
// Set to a bad value , not in range of 0 to 1
Mockito.when(mockReader.getProgress()).thenReturn(2.0F);
InputSplit mockInputSplit = Mockito.mock(NewObjectsEmployeeInputSplit.class);
HadoopInputFormatBoundedSource<Text, Employee> boundedSource = new HadoopInputFormatBoundedSource<>(serConf, WritableCoder.of(Text.class), AvroCoder.of(Employee.class), // No key translation required.
null, // No value translation required.
null, new SerializableSplit(mockInputSplit), false, false);
boundedSource.setInputFormatObj(mockInputFormat);
BoundedReader<KV<Text, Employee>> reader = boundedSource.createReader(p.getOptions());
assertEquals(Double.valueOf(0), reader.getFractionConsumed());
boolean start = reader.start();
assertTrue(start);
if (start) {
boolean advance = reader.advance();
assertEquals(null, reader.getFractionConsumed());
assertTrue(advance);
if (advance) {
advance = reader.advance();
assertEquals(null, reader.getFractionConsumed());
}
}
// Validate if getFractionConsumed() returns null after few number of reads as getProgress
// returns invalid value '2' which is not in the range of 0 to 1.
assertEquals(null, reader.getFractionConsumed());
reader.close();
}
use of org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO.SerializableSplit in project beam by apache.
the class HadoopFormatIOReadTest method testReadWithNullCreateRecordReader.
/**
* This test validates behavior of HadoopInputFormatSource if {@link
* InputFormat#createRecordReader(InputSplit, TaskAttemptContext)} createRecordReader(InputSplit,
* TaskAttemptContext)} of InputFormat returns null.
*/
@Test
public void testReadWithNullCreateRecordReader() throws Exception {
InputFormat<Text, Employee> mockInputFormat = Mockito.mock(EmployeeInputFormat.class);
thrown.expect(IOException.class);
thrown.expectMessage(String.format("Null RecordReader object returned by %s", mockInputFormat.getClass()));
Mockito.when(mockInputFormat.createRecordReader(Mockito.any(InputSplit.class), Mockito.any(TaskAttemptContext.class))).thenReturn(null);
HadoopInputFormatBoundedSource<Text, Employee> boundedSource = new HadoopInputFormatBoundedSource<>(serConf, WritableCoder.of(Text.class), AvroCoder.of(Employee.class), // No key translation required.
null, // No value translation required.
null, new SerializableSplit(), false, false);
boundedSource.setInputFormatObj(mockInputFormat);
SourceTestUtils.readFromSource(boundedSource, p.getOptions());
}
use of org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO.SerializableSplit in project beam by apache.
the class HadoopFormatIOReadTest method testReadersStartWhenZeroRecords.
/**
* This test validates behavior of {@link
* HadoopInputFormatBoundedSource.HadoopInputFormatReader#start() start()} method if InputFormat's
* {@link InputFormat#getSplits(JobContext)} getSplits(JobContext)} returns InputSplitList having
* zero records.
*/
@Test
public void testReadersStartWhenZeroRecords() throws Exception {
InputFormat mockInputFormat = Mockito.mock(EmployeeInputFormat.class);
EmployeeRecordReader mockReader = Mockito.mock(EmployeeRecordReader.class);
Mockito.when(mockInputFormat.createRecordReader(Mockito.any(), Mockito.any())).thenReturn(mockReader);
Mockito.when(mockReader.nextKeyValue()).thenReturn(false);
InputSplit mockInputSplit = Mockito.mock(NewObjectsEmployeeInputSplit.class);
HadoopInputFormatBoundedSource<Text, Employee> boundedSource = new HadoopInputFormatBoundedSource<>(serConf, WritableCoder.of(Text.class), AvroCoder.of(Employee.class), // No key translation required.
null, // No value translation required.
null, new SerializableSplit(mockInputSplit), false, false);
boundedSource.setInputFormatObj(mockInputFormat);
BoundedReader<KV<Text, Employee>> reader = boundedSource.createReader(p.getOptions());
assertFalse(reader.start());
assertEquals(Double.valueOf(1), reader.getFractionConsumed());
reader.close();
}
Aggregations