Advertisement
Guest User

ff

a guest
Nov 26th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. package com.mcba.hadoop.test;
  2.  
  3. import com.mcba.formation.hadoop.maxtemperature.MaxTemperatureMapper;
  4. import com.mcba.formation.hadoop.maxtemperature.MaxTemperatureReducer;
  5. import org.apache.hadoop.io.IntWritable;
  6. import org.apache.hadoop.io.LongWritable;
  7. import org.apache.hadoop.io.Text;
  8. import org.apache.hadoop.mrunit.mapreduce.MapDriver;
  9. import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
  10. import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13.  
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. public class MaxTemperatureMRUnitTest {
  18.  
  19.     MapDriver<LongWritable, Text, Text, IntWritable> mapDriver;
  20.     ReduceDriver<Text, IntWritable, Text, IntWritable> reduceDriver;
  21.     MapReduceDriver<LongWritable, Text, Text, IntWritable, Text, IntWritable> mapReduceDriver;
  22.     Text textTest = new Text("0043011990999991950051518004+68750+023550FM-12+038299999V0203201N00261220001CN9999999N9-00111+99999999999");
  23.  
  24.  
  25.     //@Rule
  26.     //public ExpectedException exception = ExpectedException.none();
  27.  
  28.     @Before
  29.     public void setUp() {
  30.         MaxTemperatureMapper mapper = new MaxTemperatureMapper();
  31.         MaxTemperatureReducer reducer = new MaxTemperatureReducer();
  32.         mapDriver = MapDriver.newMapDriver(mapper);
  33.         reduceDriver = ReduceDriver.newReduceDriver(reducer);
  34.         mapReduceDriver = MapReduceDriver.newMapReduceDriver(mapper, reducer);
  35.     }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.     @Test
  43.     public void testMapperSuccess() throws IOException, InterruptedException {
  44.        
  45.         mapDriver.withInput(new LongWritable(1l),
  46.         textTest)
  47.         .withOutput(new Text("1950"), new IntWritable(-11))
  48.         .runTest();
  49.     }
  50.  
  51.  
  52.  
  53.  
  54.     @Test (expected = AssertionError.class)
  55.     public void testMapperFail() throws IOException, InterruptedException {
  56.  
  57.         //si on n'as pas d'exception le test echoue
  58.         mapDriver.withInput(new LongWritable(1l),textTest)
  59.                 .withOutput(new Text("1951"), new IntWritable(-11))
  60.                 .runTest();
  61.     }  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.     @Test
  74.     public void testReducerSuccess() throws Exception{
  75.         List<IntWritable> values = new ArrayList<IntWritable>();
  76.         values.add(new IntWritable(11));
  77.         values.add(new IntWritable(10));
  78.         values.add(new IntWritable(189));
  79.        
  80.         reduceDriver.withInput(new Text("1950"), values)
  81.         .withOutput(new Text("1950"), new IntWritable(189))
  82.         .runTest();
  83.     }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     @Test (expected = AssertionError.class)
  92.     public void testReducerFail() throws Exception{
  93.         List<IntWritable> values = new ArrayList<IntWritable>();
  94.         values.add(new IntWritable(11));
  95.         values.add(new IntWritable(10));
  96.         values.add(new IntWritable(189));
  97.        
  98.         reduceDriver.withInput(new Text("1950"), values);
  99.         reduceDriver.withOutput(new Text("1950"), new IntWritable(11));
  100.         //exception.expectMessage("Missing expected output (1950, 11) at position 0, got (1950, 189)");
  101.        
  102.         reduceDriver.runTest();
  103.     }
  104.    
  105.    
  106.    
  107.     @Test
  108.     public void testMapReduceSuccess() throws Exception{
  109.         mapReduceDriver.withInput(new LongWritable(1l),
  110.                 textTest).withOutput(new Text("1950"), new IntWritable(-11)).runTest();
  111.     }
  112.  
  113.     @Test (expected = AssertionError.class)
  114.     public void testMapReduceFailed() throws Exception{
  115.          //exception.expect(AssertionError.class);
  116.         mapReduceDriver.withInput(new LongWritable(1l),
  117.                 textTest).withOutput(new Text("1950"), new IntWritable(-189)).runTest();
  118.     }
  119.    
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement