Exemplo n.º 1
0
        public virtual void TestReaderGetClosest()
        {
            string TestMethodKey = "testReaderWithWrongKeyClass.mapfile";

            MapFile.Writer writer = null;
            MapFile.Reader reader = null;
            try
            {
                writer = CreateWriter(TestMethodKey, typeof(IntWritable), typeof(Text));
                for (int i = 0; i < 10; i++)
                {
                    writer.Append(new IntWritable(i), new Text("value" + i));
                }
                writer.Close();
                reader = CreateReader(TestMethodKey, typeof(Text));
                reader.GetClosest(new Text("2"), new Text(string.Empty));
                NUnit.Framework.Assert.Fail("no excepted exception in testReaderWithWrongKeyClass !!!"
                                            );
            }
            catch (IOException)
            {
            }
            finally
            {
                /* Should be thrown to pass the test */
                IOUtils.Cleanup(null, writer, reader);
            }
        }
Exemplo n.º 2
0
        public virtual void TestGetClosestOnCurrentApi()
        {
            string TestPrefix = "testGetClosestOnCurrentApi.mapfile";

            MapFile.Writer writer = null;
            MapFile.Reader reader = null;
            try
            {
                writer = CreateWriter(TestPrefix, typeof(Text), typeof(Text));
                int FirstKey = 1;
                // Test keys: 11,21,31,...,91
                for (int i = FirstKey; i < 100; i += 10)
                {
                    Text t = new Text(Extensions.ToString(i));
                    writer.Append(t, t);
                }
                writer.Close();
                reader = CreateReader(TestPrefix, typeof(Text));
                Text key   = new Text("55");
                Text value = new Text();
                // Test get closest with step forward
                Text closest = (Text)reader.GetClosest(key, value);
                Assert.Equal(new Text("61"), closest);
                // Test get closest with step back
                closest = (Text)reader.GetClosest(key, value, true);
                Assert.Equal(new Text("51"), closest);
                // Test get closest when we pass explicit key
                Text explicitKey = new Text("21");
                closest = (Text)reader.GetClosest(explicitKey, value);
                Assert.Equal(new Text("21"), explicitKey);
                // Test what happens at boundaries. Assert if searching a key that is
                // less than first key in the mapfile, that the first key is returned.
                key     = new Text("00");
                closest = (Text)reader.GetClosest(key, value);
                Assert.Equal(FirstKey, System.Convert.ToInt32(closest.ToString
                                                                  ()));
                // Assert that null is returned if key is > last entry in mapfile.
                key     = new Text("92");
                closest = (Text)reader.GetClosest(key, value);
                NUnit.Framework.Assert.IsNull("Not null key in testGetClosestWithNewCode", closest
                                              );
                // If we were looking for the key before, we should get the last key
                closest = (Text)reader.GetClosest(key, value, true);
                Assert.Equal(new Text("91"), closest);
            }
            finally
            {
                IOUtils.Cleanup(null, writer, reader);
            }
        }
Exemplo n.º 3
0
        public virtual void TestGetClosest()
        {
            // Write a mapfile of simple data: keys are
            Path       dirName          = new Path(TestDir, "testGetClosest.mapfile");
            FileSystem fs               = FileSystem.GetLocal(conf);
            Path       qualifiedDirName = fs.MakeQualified(dirName);

            // Make an index entry for every third insertion.
            MapFile.Writer.SetIndexInterval(conf, 3);
            MapFile.Writer writer = null;
            MapFile.Reader reader = null;
            try
            {
                writer = new MapFile.Writer(conf, fs, qualifiedDirName.ToString(), typeof(Text),
                                            typeof(Text));
                // Assert that the index interval is 1
                Assert.Equal(3, writer.GetIndexInterval());
                // Add entries up to 100 in intervals of ten.
                int FirstKey = 10;
                for (int i = FirstKey; i < 100; i += 10)
                {
                    string iStr = Extensions.ToString(i);
                    Text   t    = new Text(Runtime.Substring("00", iStr.Length) + iStr);
                    writer.Append(t, t);
                }
                writer.Close();
                // Now do getClosest on created mapfile.
                reader = new MapFile.Reader(qualifiedDirName, conf);
                Text key     = new Text("55");
                Text value   = new Text();
                Text closest = (Text)reader.GetClosest(key, value);
                // Assert that closest after 55 is 60
                Assert.Equal(new Text("60"), closest);
                // Get closest that falls before the passed key: 50
                closest = (Text)reader.GetClosest(key, value, true);
                Assert.Equal(new Text("50"), closest);
                // Test get closest when we pass explicit key
                Text Twenty = new Text("20");
                closest = (Text)reader.GetClosest(Twenty, value);
                Assert.Equal(Twenty, closest);
                closest = (Text)reader.GetClosest(Twenty, value, true);
                Assert.Equal(Twenty, closest);
                // Test what happens at boundaries. Assert if searching a key that is
                // less than first key in the mapfile, that the first key is returned.
                key     = new Text("00");
                closest = (Text)reader.GetClosest(key, value);
                Assert.Equal(FirstKey, System.Convert.ToInt32(closest.ToString
                                                                  ()));
                // If we're looking for the first key before, and we pass in a key before
                // the first key in the file, we should get null
                closest = (Text)reader.GetClosest(key, value, true);
                NUnit.Framework.Assert.IsNull(closest);
                // Assert that null is returned if key is > last entry in mapfile.
                key     = new Text("99");
                closest = (Text)reader.GetClosest(key, value);
                NUnit.Framework.Assert.IsNull(closest);
                // If we were looking for the key before, we should get the last key
                closest = (Text)reader.GetClosest(key, value, true);
                Assert.Equal(new Text("90"), closest);
            }
            finally
            {
                IOUtils.Cleanup(null, writer, reader);
            }
        }