AvroKeyValue<CharSequence, Integer> secondInputRecord
= new AvroKeyValue<CharSequence, Integer>(new GenericData.Record(keyValueSchema));
secondInputRecord.setKey("second");
secondInputRecord.setValue(2);
final SeekableInput avroFileInput = new SeekableFileInput(
AvroFiles.createFile(new File(mTempDir.getRoot(), "myInputFile.avro"), keyValueSchema,
firstInputRecord.get(), secondInputRecord.get()));
// Create the record reader over the avro input file.
RecordReader<AvroKey<CharSequence>, AvroValue<Integer>> recordReader
= new AvroKeyValueRecordReader<CharSequence, Integer>(
Schema.create(Schema.Type.STRING), Schema.create(Schema.Type.INT)) {
@Override
protected SeekableInput createSeekableInput(Configuration conf, Path path)
throws IOException {
return avroFileInput;
}
};
// Set up the job configuration.
Configuration conf = new Configuration();
// Create a mock input split for this record reader.
FileSplit inputSplit = createMock(FileSplit.class);
expect(inputSplit.getPath()).andReturn(new Path("/path/to/an/avro/file")).anyTimes();
expect(inputSplit.getStart()).andReturn(0L).anyTimes();
expect(inputSplit.getLength()).andReturn(avroFileInput.length()).anyTimes();
// Create a mock task attempt context for this record reader.
TaskAttemptContext context = createMock(TaskAttemptContext.class);
expect(context.getConfiguration()).andReturn(conf).anyTimes();