Ejemplo n.º 1
0
        public virtual void TestCustomOffsets()
        {
            Configuration    conf = new Configuration();
            BinaryComparable key1 = new BytesWritable(new byte[] { 1, 2, 3, 4, 5 });
            BinaryComparable key2 = new BytesWritable(new byte[] { 6, 2, 3, 7, 8 });

            BinaryPartitioner.SetOffsets(conf, 1, -3);
            BinaryPartitioner <object> partitioner = ReflectionUtils.NewInstance <BinaryPartitioner
                                                                                  >(conf);
            int partition1 = partitioner.GetPartition(key1, null, 10);
            int partition2 = partitioner.GetPartition(key2, null, 10);

            NUnit.Framework.Assert.AreEqual(partition1, partition2);
            BinaryPartitioner.SetOffsets(conf, 1, 2);
            partitioner = ReflectionUtils.NewInstance <BinaryPartitioner>(conf);
            partition1  = partitioner.GetPartition(key1, null, 10);
            partition2  = partitioner.GetPartition(key2, null, 10);
            NUnit.Framework.Assert.AreEqual(partition1, partition2);
            BinaryPartitioner.SetOffsets(conf, -4, -3);
            partitioner = ReflectionUtils.NewInstance <BinaryPartitioner>(conf);
            partition1  = partitioner.GetPartition(key1, null, 10);
            partition2  = partitioner.GetPartition(key2, null, 10);
            NUnit.Framework.Assert.AreEqual(partition1, partition2);
        }