Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual TFile.Reader.Location Locate(TFile.Reader.Scanner scanner, byte[]
                                               key)
 {
     if (scanner.SeekTo(key) == true)
     {
         return(scanner.currentLocation);
     }
     return(scanner.endLocation);
 }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
0
 /// <exception cref="System.IO.IOException"/>
 private void CheckBlockIndex(int recordIndex, int blockIndexExpected)
 {
     TFile.Reader reader = new TFile.Reader(fs.Open(path), fs.GetFileStatus(path).GetLen
                                                (), conf);
     TFile.Reader.Scanner scanner = reader.CreateScanner();
     scanner.SeekTo(Runtime.GetBytesForString(ComposeSortedKey(Key, recordIndex
                                                               )));
     Assert.Equal(blockIndexExpected, scanner.currentLocation.GetBlockIndex
                      ());
     scanner.Close();
     reader.Close();
 }
Exemplo n.º 5
0
 public virtual void TestFailureNegativeLength_3()
 {
     if (skip)
     {
         return;
     }
     WriteRecords(3);
     TFile.Reader reader = new TFile.Reader(fs.Open(path), fs.GetFileStatus(path).GetLen
                                                (), conf);
     TFile.Reader.Scanner scanner = reader.CreateScanner();
     try
     {
         // test negative array offset
         try
         {
             scanner.SeekTo(Runtime.GetBytesForString("keyY"), -1, 4);
             NUnit.Framework.Assert.Fail("Failed to handle negative offset.");
         }
         catch (Exception)
         {
         }
         // noop, expecting exceptions
         // test negative array length
         try
         {
             scanner.SeekTo(Runtime.GetBytesForString("keyY"), 0, -2);
             NUnit.Framework.Assert.Fail("Failed to handle negative key length.");
         }
         catch (Exception)
         {
         }
     }
     finally
     {
         // noop, expecting exceptions
         reader.Close();
         scanner.Close();
     }
 }