use of org.apache.hadoop.mapreduce.task.JobContextImpl in project jena by apache.
the class AbstractNodeTupleInputFormatTests method testSplitInputs.
protected final void testSplitInputs(Configuration config, File[] inputs, int expectedSplits, int expectedTuples) throws IOException, InterruptedException {
// Set up fake job
InputFormat<LongWritable, T> inputFormat = this.getInputFormat();
Job job = Job.getInstance(config);
job.setInputFormatClass(inputFormat.getClass());
for (File input : inputs) {
this.addInputPath(input, job.getConfiguration(), job);
}
JobContext context = new JobContextImpl(job.getConfiguration(), job.getJobID());
Assert.assertEquals(inputs.length, FileInputFormat.getInputPaths(context).length);
// Check splits
List<InputSplit> splits = inputFormat.getSplits(context);
Assert.assertEquals(expectedSplits, splits.size());
// Check tuples
int count = 0;
for (InputSplit split : splits) {
// Validate split
Assert.assertTrue(this.isValidSplit(split, config));
// Read split
TaskAttemptContext taskContext = new TaskAttemptContextImpl(job.getConfiguration(), new TaskAttemptID());
RecordReader<LongWritable, T> reader = inputFormat.createRecordReader(split, taskContext);
reader.initialize(split, taskContext);
count += this.countTuples(reader);
}
Assert.assertEquals(expectedTuples, count);
}
use of org.apache.hadoop.mapreduce.task.JobContextImpl in project jena by apache.
the class AbstractNodeTupleInputFormatTests method testMultipleInputs.
/**
* Runs a multiple input test
*
* @param inputs
* Inputs
* @param expectedSplits
* Number of splits expected
* @param expectedTuples
* Number of tuples expected
* @throws IOException
* @throws InterruptedException
*/
protected final void testMultipleInputs(File[] inputs, int expectedSplits, int expectedTuples) throws IOException, InterruptedException {
// Prepare configuration and inputs
Configuration config = this.prepareConfiguration();
// Set up fake job
InputFormat<LongWritable, T> inputFormat = this.getInputFormat();
Job job = Job.getInstance(config);
job.setInputFormatClass(inputFormat.getClass());
for (File input : inputs) {
this.addInputPath(input, job.getConfiguration(), job);
}
JobContext context = new JobContextImpl(job.getConfiguration(), job.getJobID());
Assert.assertEquals(inputs.length, FileInputFormat.getInputPaths(context).length);
NLineInputFormat.setNumLinesPerSplit(job, expectedTuples);
// Check splits
List<InputSplit> splits = inputFormat.getSplits(context);
Assert.assertEquals(expectedSplits, splits.size());
// Check tuples
int count = 0;
for (InputSplit split : splits) {
TaskAttemptContext taskContext = new TaskAttemptContextImpl(job.getConfiguration(), new TaskAttemptID());
RecordReader<LongWritable, T> reader = inputFormat.createRecordReader(split, taskContext);
reader.initialize(split, taskContext);
count += this.countTuples(reader);
}
Assert.assertEquals(expectedTuples, count);
}
Aggregations