public virtual void TestFailureNegativeLength_2()
 {
     if (skip)
     {
         return;
     }
     CloseOutput();
     TFile.Reader reader = new TFile.Reader(fs.Open(path), fs.GetFileStatus(path).GetLen
                                                (), conf);
     TFile.Reader.Scanner scanner = reader.CreateScanner();
     try
     {
         scanner.LowerBound(Runtime.GetBytesForString("keyX"), 0, -1);
         NUnit.Framework.Assert.Fail("Error on handling negative length.");
     }
     catch (Exception)
     {
     }
     finally
     {
         // noop, expecting exceptions
         scanner.Close();
         reader.Close();
     }
     CloseOutput();
 }
示例#2
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void TestFailureSeek()
 {
     TFile.Reader reader = new TFile.Reader(fs.Open(path), fs.GetFileStatus(path).GetLen
                                                (), conf);
     TFile.Reader.Scanner scanner = reader.CreateScanner();
     try
     {
         // can't find ceil
         try
         {
             scanner.LowerBound(Runtime.GetBytesForString("keyN"));
             NUnit.Framework.Assert.Fail("Cannot search in a unsorted TFile!");
         }
         catch (Exception)
         {
         }
         finally
         {
         }
         // noop, expecting excetions
         // can't find higher
         try
         {
             scanner.UpperBound(Runtime.GetBytesForString("keyA"));
             NUnit.Framework.Assert.Fail("Cannot search higher in a unsorted TFile!");
         }
         catch (Exception)
         {
         }
         finally
         {
         }
         // noop, expecting excetions
         // can't seek
         try
         {
             scanner.SeekTo(Runtime.GetBytesForString("keyM"));
             NUnit.Framework.Assert.Fail("Cannot search a unsorted TFile!");
         }
         catch (Exception)
         {
         }
         finally
         {
         }
     }
     finally
     {
         // noop, expecting excetions
         scanner.Close();
         reader.Close();
     }
 }
示例#3
0
        /// <summary>test none codecs</summary>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void BasicWithSomeCodec(string codec)
        {
            Path ncTFile            = new Path(Root, "basic.tfile");
            FSDataOutputStream fout = CreateFSOutput(ncTFile);

            TFile.Writer writer = new TFile.Writer(fout, minBlockSize, codec, "memcmp", conf);
            WriteRecords(writer);
            fout.Close();
            FSDataInputStream fin = fs.Open(ncTFile);

            TFile.Reader reader = new TFile.Reader(fs.Open(ncTFile), fs.GetFileStatus(ncTFile
                                                                                      ).GetLen(), conf);
            TFile.Reader.Scanner scanner = reader.CreateScanner();
            ReadAllRecords(scanner);
            scanner.SeekTo(GetSomeKey(50));
            Assert.True("location lookup failed", scanner.SeekTo(GetSomeKey
                                                                     (50)));
            // read the key and see if it matches
            byte[] readKey = ReadKey(scanner);
            Assert.True("seeked key does not match", Arrays.Equals(GetSomeKey
                                                                       (50), readKey));
            scanner.SeekTo(new byte[0]);
            byte[] val1 = ReadValue(scanner);
            scanner.SeekTo(new byte[0]);
            byte[] val2 = ReadValue(scanner);
            Assert.True(Arrays.Equals(val1, val2));
            // check for lowerBound
            scanner.LowerBound(GetSomeKey(50));
            Assert.True("locaton lookup failed", scanner.currentLocation.CompareTo
                            (reader.End()) < 0);
            readKey = ReadKey(scanner);
            Assert.True("seeked key does not match", Arrays.Equals(readKey,
                                                                   GetSomeKey(50)));
            // check for upper bound
            scanner.UpperBound(GetSomeKey(50));
            Assert.True("location lookup failed", scanner.currentLocation.CompareTo
                            (reader.End()) < 0);
            readKey = ReadKey(scanner);
            Assert.True("seeked key does not match", Arrays.Equals(readKey,
                                                                   GetSomeKey(51)));
            scanner.Close();
            // test for a range of scanner
            scanner = reader.CreateScannerByKey(GetSomeKey(10), GetSomeKey(60));
            ReadAndCheckbytes(scanner, 10, 50);
            NUnit.Framework.Assert.IsFalse(scanner.Advance());
            scanner.Close();
            reader.Close();
            fin.Close();
            fs.Delete(ncTFile, true);
        }
示例#4
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void SeekTFile()
        {
            int  miss               = 0;
            long totalBytes         = 0;
            FSDataInputStream fsdis = fs.Open(path);

            TFile.Reader reader = new TFile.Reader(fsdis, fs.GetFileStatus(path).GetLen(), conf
                                                   );
            KeySampler kSampler = new KeySampler(rng, reader.GetFirstKey(), reader.GetLastKey
                                                     (), keyLenGen);

            TFile.Reader.Scanner scanner = reader.CreateScanner();
            BytesWritable        key     = new BytesWritable();
            BytesWritable        val     = new BytesWritable();

            timer.Reset();
            timer.Start();
            for (int i = 0; i < options.seekCount; ++i)
            {
                kSampler.Next(key);
                scanner.LowerBound(key.Get(), 0, key.GetSize());
                if (!scanner.AtEnd())
                {
                    scanner.Entry().Get(key, val);
                    totalBytes += key.GetSize();
                    totalBytes += val.GetSize();
                }
                else
                {
                    ++miss;
                }
            }
            timer.Stop();
            double duration = (double)timer.Read() / 1000;

            // in us.
            System.Console.Out.Printf("time: %s...avg seek: %s...%d hit...%d miss...avg I/O size: %.2fKB\n"
                                      , timer.ToString(), NanoTimer.NanoTimeToString(timer.Read() / options.seekCount)
                                      , options.seekCount - miss, miss, (double)totalBytes / 1024 / (options.seekCount
                                                                                                     - miss));
        }