Created
November 16, 2011 11:06
-
-
Save DNNX/1369840 to your computer and use it in GitHub Desktop.
How to test Hadoop Mappers with and without MRUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void shouldMapDocument() throws IOException, InterruptedException { | |
new MapDriver(new DocumentMapper()) | |
.withInput(createDocumentForTest()) | |
.withOutput(expected0) | |
.withOutput(expected1) | |
.runTest(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void shouldMapDocument() throws IOException, InterruptedException { | |
final List<Symbol> mapOutput = new ArrayList<Symbol>(); // this is a closure | |
Document input = createDocumentForTest(); | |
DocumentMapperTest.Context context = new Context( | |
new Configuration(), | |
new TaskAttemptID(), | |
null, // <- oh, nulls. holy boilerplate! | |
null, | |
null, | |
null, | |
null | |
) { | |
public void write(Text key, Symbol symbol) // look! I'm a wannabe-javascript function. | |
{ | |
mapOutput .add(symbol); // <- here we use this closure | |
} | |
}; | |
DocumentMapperTest mapper = new DocumentMapperTest(); | |
mapper.map(new Text("Q123"), input, context); | |
assertEquals(2, mapOutput .size()); | |
assertEquals(expected0, mapOutput.get(0)); | |
assertEquals(expected1, mapOutput.get(1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment