コード例 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestTotalOrderBinarySearch()
        {
            TotalOrderPartitioner <Text, NullWritable> partitioner = new TotalOrderPartitioner
                                                                     <Text, NullWritable>();
            Configuration conf = new Configuration();
            Path          p    = TestTotalOrderPartitioner.WritePartitionFile <Text>("totalorderbinarysearch"
                                                                                     , conf, splitStrings);

            conf.SetBoolean(TotalOrderPartitioner.NaturalOrder, false);
            conf.SetClass(MRJobConfig.MapOutputKeyClass, typeof(Text), typeof(object));
            try
            {
                partitioner.SetConf(conf);
                NullWritable nw = NullWritable.Get();
                foreach (TestTotalOrderPartitioner.Check <Text> chk in testStrings)
                {
                    NUnit.Framework.Assert.AreEqual(chk.data.ToString(), chk.part, partitioner.GetPartition
                                                        (chk.data, nw, splitStrings.Length + 1));
                }
            }
            finally
            {
                p.GetFileSystem(conf).Delete(p, true);
            }
        }
コード例 #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestTotalOrderCustomComparator()
        {
            TotalOrderPartitioner <Text, NullWritable> partitioner = new TotalOrderPartitioner
                                                                     <Text, NullWritable>();
            Configuration conf = new Configuration();

            Text[] revSplitStrings = Arrays.CopyOf(splitStrings, splitStrings.Length);
            Arrays.Sort(revSplitStrings, new TestTotalOrderPartitioner.ReverseStringComparator
                            ());
            Path p = TestTotalOrderPartitioner.WritePartitionFile <Text>("totalordercustomcomparator"
                                                                         , conf, revSplitStrings);

            conf.SetBoolean(TotalOrderPartitioner.NaturalOrder, false);
            conf.SetClass(MRJobConfig.MapOutputKeyClass, typeof(Text), typeof(object));
            conf.SetClass(MRJobConfig.KeyComparator, typeof(TestTotalOrderPartitioner.ReverseStringComparator
                                                            ), typeof(RawComparator));
            AList <TestTotalOrderPartitioner.Check <Text> > revCheck = new AList <TestTotalOrderPartitioner.Check
                                                                                  <Text> >();

            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("aaaaa"), 9));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("aaabb"), 9));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("aabbb"), 9));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("aaaaa"), 9));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("babbb"), 8));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("baabb"), 8));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("yai"), 1));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("yak"), 1));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("z"), 0));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("ddngo"), 4));
            revCheck.AddItem(new TestTotalOrderPartitioner.Check <Text>(new Text("hi"), 3));
            try
            {
                partitioner.SetConf(conf);
                NullWritable nw = NullWritable.Get();
                foreach (TestTotalOrderPartitioner.Check <Text> chk in revCheck)
                {
                    NUnit.Framework.Assert.AreEqual(chk.data.ToString(), chk.part, partitioner.GetPartition
                                                        (chk.data, nw, splitStrings.Length + 1));
                }
            }
            finally
            {
                p.GetFileSystem(conf).Delete(p, true);
            }
        }