/// <exception cref="System.Exception"/> protected internal virtual void _testMOWithJavaSerialization(bool withCounters) { string input = "a\nb\nc\nd\ne\nc\nd\ne"; Configuration conf = CreateJobConf(); conf.Set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization," + "org.apache.hadoop.io.serializer.WritableSerialization"); Job job = MapReduceTestUtil.CreateJob(conf, InDir, OutDir, 2, 1, input); job.SetJobName("mo"); MultipleOutputs.AddNamedOutput(job, Text, typeof(TextOutputFormat), typeof(long), typeof(string)); MultipleOutputs.SetCountersEnabled(job, withCounters); job.SetSortComparatorClass(typeof(JavaSerializationComparator)); job.SetMapOutputKeyClass(typeof(long)); job.SetMapOutputValueClass(typeof(string)); job.SetOutputKeyClass(typeof(long)); job.SetOutputValueClass(typeof(string)); job.SetMapperClass(typeof(TestMRMultipleOutputs.MOJavaSerDeMap)); job.SetReducerClass(typeof(TestMRMultipleOutputs.MOJavaSerDeReduce)); job.WaitForCompletion(true); // assert number of named output part files int namedOutputCount = 0; int valueBasedOutputCount = 0; FileSystem fs = OutDir.GetFileSystem(conf); FileStatus[] statuses = fs.ListStatus(OutDir); foreach (FileStatus status in statuses) { string fileName = status.GetPath().GetName(); if (fileName.Equals("text-m-00000") || fileName.Equals("text-m-00001") || fileName .Equals("text-r-00000")) { namedOutputCount++; } else { if (fileName.Equals("a-r-00000") || fileName.Equals("b-r-00000") || fileName.Equals ("c-r-00000") || fileName.Equals("d-r-00000") || fileName.Equals("e-r-00000")) { valueBasedOutputCount++; } } } NUnit.Framework.Assert.AreEqual(3, namedOutputCount); NUnit.Framework.Assert.AreEqual(5, valueBasedOutputCount); // assert TextOutputFormat files correctness BufferedReader reader = new BufferedReader(new InputStreamReader(fs.Open(new Path (FileOutputFormat.GetOutputPath(job), "text-r-00000")))); int count = 0; string line = reader.ReadLine(); while (line != null) { NUnit.Framework.Assert.IsTrue(line.EndsWith(Text)); line = reader.ReadLine(); count++; } reader.Close(); NUnit.Framework.Assert.IsFalse(count == 0); if (withCounters) { CounterGroup counters = job.GetCounters().GetGroup(typeof(MultipleOutputs).FullName ); NUnit.Framework.Assert.AreEqual(6, counters.Size()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter(Text).GetValue()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter("a").GetValue()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter("b").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("c").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("d").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("e").GetValue()); } }
/// <exception cref="System.Exception"/> protected internal virtual void _testMultipleOutputs(bool withCounters) { string input = "a\nb\nc\nd\ne\nc\nd\ne"; Configuration conf = CreateJobConf(); Job job = MapReduceTestUtil.CreateJob(conf, InDir, OutDir, 2, 1, input); job.SetJobName("mo"); MultipleOutputs.AddNamedOutput(job, Text, typeof(TextOutputFormat), typeof(LongWritable ), typeof(Text)); MultipleOutputs.AddNamedOutput(job, Sequence, typeof(SequenceFileOutputFormat), typeof( IntWritable), typeof(Text)); MultipleOutputs.SetCountersEnabled(job, withCounters); job.SetMapperClass(typeof(TestMRMultipleOutputs.MOMap)); job.SetReducerClass(typeof(TestMRMultipleOutputs.MOReduce)); job.WaitForCompletion(true); // assert number of named output part files int namedOutputCount = 0; int valueBasedOutputCount = 0; FileSystem fs = OutDir.GetFileSystem(conf); FileStatus[] statuses = fs.ListStatus(OutDir); foreach (FileStatus status in statuses) { string fileName = status.GetPath().GetName(); if (fileName.Equals("text-m-00000") || fileName.Equals("text-m-00001") || fileName .Equals("text-r-00000") || fileName.Equals("sequence_A-m-00000") || fileName.Equals ("sequence_A-m-00001") || fileName.Equals("sequence_B-m-00000") || fileName.Equals ("sequence_B-m-00001") || fileName.Equals("sequence_B-r-00000") || fileName.Equals ("sequence_C-r-00000")) { namedOutputCount++; } else { if (fileName.Equals("a-r-00000") || fileName.Equals("b-r-00000") || fileName.Equals ("c-r-00000") || fileName.Equals("d-r-00000") || fileName.Equals("e-r-00000")) { valueBasedOutputCount++; } } } NUnit.Framework.Assert.AreEqual(9, namedOutputCount); NUnit.Framework.Assert.AreEqual(5, valueBasedOutputCount); // assert TextOutputFormat files correctness BufferedReader reader = new BufferedReader(new InputStreamReader(fs.Open(new Path (FileOutputFormat.GetOutputPath(job), "text-r-00000")))); int count = 0; string line = reader.ReadLine(); while (line != null) { NUnit.Framework.Assert.IsTrue(line.EndsWith(Text)); line = reader.ReadLine(); count++; } reader.Close(); NUnit.Framework.Assert.IsFalse(count == 0); // assert SequenceOutputFormat files correctness SequenceFile.Reader seqReader = new SequenceFile.Reader(fs, new Path(FileOutputFormat .GetOutputPath(job), "sequence_B-r-00000"), conf); NUnit.Framework.Assert.AreEqual(typeof(IntWritable), seqReader.GetKeyClass()); NUnit.Framework.Assert.AreEqual(typeof(Text), seqReader.GetValueClass()); count = 0; IntWritable key = new IntWritable(); Text value = new Text(); while (seqReader.Next(key, value)) { NUnit.Framework.Assert.AreEqual(Sequence, value.ToString()); count++; } seqReader.Close(); NUnit.Framework.Assert.IsFalse(count == 0); if (withCounters) { CounterGroup counters = job.GetCounters().GetGroup(typeof(MultipleOutputs).FullName ); NUnit.Framework.Assert.AreEqual(9, counters.Size()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter(Text).GetValue()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter(Sequence + "_A").GetValue ()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter(Sequence + "_B").GetValue ()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter(Sequence + "_C").GetValue ()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter("a").GetValue()); NUnit.Framework.Assert.AreEqual(2, counters.FindCounter("b").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("c").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("d").GetValue()); NUnit.Framework.Assert.AreEqual(4, counters.FindCounter("e").GetValue()); } }