void checkFormat(Job job) throws Exception { TaskAttemptContext attemptContext = new TaskAttemptContext(job.getConfiguration(), new TaskAttemptID("123", 0, false, 1, 2)); MyClassMessagePackBase64LineInputFormat format = new MyClassMessagePackBase64LineInputFormat(); FileInputFormat.setInputPaths(job, workDir); List<InputSplit> splits = format.getSplits(job); for (int j = 0; j < splits.size(); j++) { RecordReader<LongWritable, MyClassWritable> reader = format.createRecordReader(splits.get(j), attemptContext); reader.initialize(splits.get(j), attemptContext); int count = 0; try { while (reader.nextKeyValue()) { LongWritable key = reader.getCurrentKey(); MyClassWritable val = reader.getCurrentValue(); MyClass mc = val.get(); assertEquals(mc.v, count); assertEquals(mc.s, Integer.toString(count)); count++; } } finally { reader.close(); } } }
public int run(String args[]) throws Exception { Configuration conf = getConf(); /* creates a new job with given job name */ Job job = Job.getInstance(conf, "Mat_vect_mul"); job.setJarByClass(Mat_vect_mul.class); /* adds input-vector file to the cache */ DistributedCache.addCacheFile(new Path(args[1]).toUri(), job.getConfiguration()); /* set the key class and value class for the job output */ job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); /* set mapper and reducer for the job */ job.setMapperClass(Map1.class); job.setReducerClass(Reduce1.class); /* set the input foramt and output format for the job */ job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); /* add path to the list of inputs for the map-reduce job */ FileInputFormat.addInputPath(job, new Path(args[0])); /* set path of the output diretcory for the map-reduce job*/ FileOutputFormat.setOutputPath(job, new Path(args[2])); /* Submit the job, then poll for progress until the job is complete */ boolean succ = job.waitForCompletion(true); if (!succ) { System.out.println("Job failed, exiting"); return -1; } return 0; }