IndexInstancesMapper extends Mapper<Text, VectorWritable, IntWritable, VectorWritable> { @Override protected void map(Text labelText, VectorWritable instance, Context ctx) throws IOException, InterruptedException { String label = SLASH.split(labelText.toString())[1]; if (labelIndex.containsKey(label)) { ctx.write(new IntWritable(labelIndex.get(label)), instance); } else { ctx.getCounter(Counter.SKIPPED_INSTANCES).increment(1); } }    }
@Test public void index() throws Exception { ctx.write(new IntWritable(0), instance); EasyMock.replay(ctx); IndexInstancesMapper indexInstances = new IndexInstancesMapper(); setField(indexInstances, "labelIndex", labelIndex); indexInstances.map(new Text("/bird/"), instance, ctx); EasyMock.verify(ctx); }
@Test public void skip() throws Exception { Counter skippedInstances = EasyMock.createMock(Counter.class); EasyMock.expect(ctx.getCounter(IndexInstancesMapper.Counter.SKIPPED_INSTANCES)).andReturn(skippedInstances); skippedInstances.increment(1); EasyMock.replay(ctx, skippedInstances); IndexInstancesMapper indexInstances = new IndexInstancesMapper(); setField(indexInstances, "labelIndex", labelIndex); indexInstances.map(new Text("/fish/"), instance, ctx); EasyMock.verify(ctx, skippedInstances); }