Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mcba.hadoop.test;
- import com.mcba.formation.hadoop.maxtemperature.MaxTemperatureMapper;
- import com.mcba.formation.hadoop.maxtemperature.MaxTemperatureReducer;
- import org.apache.hadoop.io.IntWritable;
- import org.apache.hadoop.io.LongWritable;
- import org.apache.hadoop.io.Text;
- import org.apache.hadoop.mrunit.mapreduce.MapDriver;
- import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
- import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
- import org.junit.Before;
- import org.junit.Test;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- public class MaxTemperatureMRUnitTest {
- MapDriver<LongWritable, Text, Text, IntWritable> mapDriver;
- ReduceDriver<Text, IntWritable, Text, IntWritable> reduceDriver;
- MapReduceDriver<LongWritable, Text, Text, IntWritable, Text, IntWritable> mapReduceDriver;
- Text textTest = new Text("0043011990999991950051518004+68750+023550FM-12+038299999V0203201N00261220001CN9999999N9-00111+99999999999");
- //@Rule
- //public ExpectedException exception = ExpectedException.none();
- @Before
- public void setUp() {
- MaxTemperatureMapper mapper = new MaxTemperatureMapper();
- MaxTemperatureReducer reducer = new MaxTemperatureReducer();
- mapDriver = MapDriver.newMapDriver(mapper);
- reduceDriver = ReduceDriver.newReduceDriver(reducer);
- mapReduceDriver = MapReduceDriver.newMapReduceDriver(mapper, reducer);
- }
- @Test
- public void testMapperSuccess() throws IOException, InterruptedException {
- mapDriver.withInput(new LongWritable(1l),
- textTest)
- .withOutput(new Text("1950"), new IntWritable(-11))
- .runTest();
- }
- @Test (expected = AssertionError.class)
- public void testMapperFail() throws IOException, InterruptedException {
- //si on n'as pas d'exception le test echoue
- mapDriver.withInput(new LongWritable(1l),textTest)
- .withOutput(new Text("1951"), new IntWritable(-11))
- .runTest();
- }
- @Test
- public void testReducerSuccess() throws Exception{
- List<IntWritable> values = new ArrayList<IntWritable>();
- values.add(new IntWritable(11));
- values.add(new IntWritable(10));
- values.add(new IntWritable(189));
- reduceDriver.withInput(new Text("1950"), values)
- .withOutput(new Text("1950"), new IntWritable(189))
- .runTest();
- }
- @Test (expected = AssertionError.class)
- public void testReducerFail() throws Exception{
- List<IntWritable> values = new ArrayList<IntWritable>();
- values.add(new IntWritable(11));
- values.add(new IntWritable(10));
- values.add(new IntWritable(189));
- reduceDriver.withInput(new Text("1950"), values);
- reduceDriver.withOutput(new Text("1950"), new IntWritable(11));
- //exception.expectMessage("Missing expected output (1950, 11) at position 0, got (1950, 189)");
- reduceDriver.runTest();
- }
- @Test
- public void testMapReduceSuccess() throws Exception{
- mapReduceDriver.withInput(new LongWritable(1l),
- textTest).withOutput(new Text("1950"), new IntWritable(-11)).runTest();
- }
- @Test (expected = AssertionError.class)
- public void testMapReduceFailed() throws Exception{
- //exception.expect(AssertionError.class);
- mapReduceDriver.withInput(new LongWritable(1l),
- textTest).withOutput(new Text("1950"), new IntWritable(-189)).runTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement