@Test
public void testMergeByIntWritableKeyWithSequenceFileInputFormat() throws Exception {
HashMap<IntWritable, Text> inputData1 = new HashMap<IntWritable, Text>();
inputData1.put(new IntWritable(1), new Text("Macon Kent,6269 Aenean St.,1-247-399-1051,08253"));
inputData1.put(new IntWritable(2), new Text("Dale Zamora,521-7792 Mauris Rd.,1-214-625-6970,90510"));
inputData1.put(new IntWritable(3), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
createSequenceFileInHdfs(inputData1, "/input1", "testFile1.seq");
HashMap<IntWritable, Text> inputData2 = new HashMap<IntWritable, Text>();
inputData2.put(new IntWritable(1), new Text("Macaulay Jackson,5435 Dui. Avenue,1-770-395-6446,31584"));
inputData2.put(new IntWritable(2), new Text("Timon Leonard,716 Ac Ave,1-857-935-3882,62240"));
inputData2.put(new IntWritable(4), new Text("Charles Wood,525-9709 In Rd.,1-370-528-4758,62714"));
createSequenceFileInHdfs(inputData2, "/input2", "testFile2.seq");
String[] args = new String[] {
"-newPath", "/input1",
"-oldPath", "/input2",
"-mergeBy", "key",
"-outputPath", "output",
"-inputFormat", "org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat",
"-inputKeyClassName", "org.apache.hadoop.io.IntWritable",
"-inputValueClassName", "org.apache.hadoop.io.Text" };
MergeJob job=runMergeJobs(args);
assertEquals(3,job.getTotalRecordsNew());
assertEquals(3,job.getTotalRecordsOld());
assertEquals(0,job.getBadRecords());
assertEquals(4,job.getOutput());
FileSystem outputFS = getFileSystem();
Path outputPath = new Path(outputFS.getHomeDirectory(), "output/part-r-00000");
Configuration conf = new Configuration();
SequenceFile.Reader reader = new SequenceFile.Reader(outputFS, outputPath, conf);
Writable writableKey = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable writableValue = (Writable)
ReflectionUtils.newInstance(reader.getValueClass(), conf);
List<IntWritable> expectedOutput = new ArrayList<IntWritable>();
expectedOutput.add(new IntWritable(1));
expectedOutput.add(new IntWritable(2));
expectedOutput.add(new IntWritable(3));
expectedOutput.add(new IntWritable(4));
int count = 0;
while (reader.next(writableKey, writableValue)) {
logger.debug("key and value is: " + writableKey + ", " + writableValue);
assertTrue("Matched output " + writableKey , expectedOutput.contains(writableKey));
count++;