MapperInfoHandler extends AnnotationHandlerBase { @SuppressWarnings("rawtypes") public void configureOutputKeyValue(Job job, Class<? extends Mapper> mapperClass, MapperInfo map, boolean isMapOnly) { MaraAnnotationUtil util = MaraAnnotationUtil.INSTANCE; Type[] params = util.getGenericTypeParams(mapperClass, Mapper.class); int length = 4; int keyIdx = 2; int valueIdx = 3; if (params != null && params.length == 2) { length = 2; keyIdx = 0; valueIdx = 1; } if (map != null && map.output().key() != void.class) { job.setMapOutputKeyClass(map.output().key()); if (isMapOnly) { job.setOutputKeyClass(map.output().key()); } } else if (params != null && params.length == length){ job.setMapOutputKeyClass((Class<?>)params[keyIdx]); if (isMapOnly) { job.setOutputKeyClass((Class<?>)params[keyIdx]); } } if (map != null && map.output().value() != void.class) { job.setMapOutputValueClass(map.output().value()); if (isMapOnly) { job.setOutputValueClass(map.output().value()); } } else if (params != null && params.length == length){ job.setMapOutputValueClass((Class<?>)params[valueIdx]); if (isMapOnly) { job.setOutputValueClass((Class<?>)params[valueIdx]); } } }  @Override boolean accept(Annotation annotation); @Override @SuppressWarnings("rawtypes") void process(Annotation annotation, Job job, Object target); @SuppressWarnings("rawtypes") void configureOutputKeyValue(Job job, Class<? extends Mapper> mapperClass, 
			MapperInfo map, boolean isMapOnly);  }
@Test public void testConfigureMapperIntText() { handler.configureOutputKeyValue(job, TestMapperIntText.class, null, false); verify(job).setMapOutputKeyClass(IntWritable.class); verify(job).setMapOutputValueClass(Text.class); verify(job, never()).setOutputKeyClass(IntWritable.class); verify(job, never()).setOutputValueClass(IntWritable.class); }
@Test public void testConfigureMapperTableMapper_MapOnly() { handler.configureOutputKeyValue(job, TestTableMapper.class, null, true); verify(job, times(1)).setMapOutputKeyClass(Text.class); verify(job, times(1)).setMapOutputValueClass(NullWritable.class); verify(job).setOutputKeyClass(Text.class); verify(job).setOutputValueClass(NullWritable.class); }
@Test public void testConfigureMapperIntText_MapOnly() { handler.configureOutputKeyValue(job, TestMapperIntText.class, null, true); verify(job).setOutputKeyClass(IntWritable.class); verify(job).setOutputValueClass(Text.class); }
@Test public void testConfigureMapperLongText() { handler.configureOutputKeyValue(job, TestMapperLongText.class, null, false); verify(job).setMapOutputKeyClass(LongWritable.class); verify(job).setMapOutputValueClass(Text.class); verify(job, never()).setOutputKeyClass(LongWritable.class); verify(job, never()).setOutputValueClass(Text.class); }
@Test public void testConfigureMapperLongText_MapOnly() { handler.configureOutputKeyValue(job, TestMapperLongText.class, null, true); verify(job).setOutputKeyClass(LongWritable.class); verify(job).setOutputValueClass(Text.class); }
@Test public void testConfigureMapperTextText() { handler.configureOutputKeyValue(job, TestMapperTextText.class, null, false); verify(job).setMapOutputKeyClass(Text.class); verify(job).setMapOutputValueClass(NullWritable.class); verify(job, never()).setOutputKeyClass(Text.class); verify(job, never()).setOutputValueClass(NullWritable.class); }
@Test public void testConfigureMapperTextText_MapOnly() { handler.configureOutputKeyValue(job, TestMapperTextText.class, null, true); verify(job).setMapOutputKeyClass(Text.class); verify(job).setMapOutputValueClass(NullWritable.class); verify(job).setOutputKeyClass(Text.class); verify(job).setOutputValueClass(NullWritable.class); }
@Test public void testConfigureMapperSubclassing() { handler.configureOutputKeyValue(job, TestMapperSubclassTest.class, null, false); verify(job).setMapOutputKeyClass(Text.class); verify(job).setMapOutputValueClass(NullWritable.class); verify(job, never()).setOutputKeyClass(Text.class); verify(job, never()).setOutputValueClass(NullWritable.class); }
@Test public void testConfigureMapperSubclassing_MapOnly() { handler.configureOutputKeyValue(job, TestMapperSubclassTest.class, null, true); verify(job).setMapOutputKeyClass(Text.class); verify(job).setMapOutputValueClass(NullWritable.class); verify(job).setOutputKeyClass(Text.class); verify(job).setOutputValueClass(NullWritable.class); }
@Test public void testConfigureMapperNoGenerics() { handler.configureOutputKeyValue(job, TestMapperNoGenericsTest.class, null, false); verify(job, never()).setMapOutputKeyClass(any(Class.class)); verify(job, never()).setMapOutputValueClass(any(Class.class)); }
@Test public void testConfigureMapperTableMapper() { handler.configureOutputKeyValue(job, TestTableMapper.class, null, false); verify(job, times(1)).setMapOutputKeyClass(Text.class); verify(job, times(1)).setMapOutputValueClass(NullWritable.class); verify(job, never()).setOutputKeyClass(Text.class); verify(job, never()).setOutputValueClass(NullWritable.class); }