コード例 #1
0
        public void throw_exception_if_index_entries_not_descending_during_ptable_get_latest_entry(byte version,
                                                                                                   bool skipIndexVerify)
        {
            string ptableFileName = ConstructPTable(version);

            CorruptPTableFile(ptableFileName, version, "zeroOutMiddleEntries");
            //loading with a depth of 1 should load only 2 midpoints (first and last index entry)
            PTable     pTable = PTable.FromFile(ptableFileName, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, 1, skipIndexVerify);
            IndexEntry entry;

            Assert.Throws <MaybeCorruptIndexException>(() =>
                                                       pTable.TryGetLatestEntry(GetOriginalHash(numIndexEntries / 2, version), out entry));
            pTable.Dispose();
        }
コード例 #2
0
        public void throw_exception_if_index_entries_not_descending_during_ptable_get_one_value_2(byte version,
                                                                                                  bool skipIndexVerify)
        {
            string ptableFileName = ConstructPTable(version);

            CorruptPTableFile(ptableFileName, version, "maxOutMiddleEntries");
            //loading with a depth of 1 should load only 2 midpoints (first and last index entry)
            PTable pTable = PTable.FromFile(ptableFileName, 1, skipIndexVerify);
            long   position;

            Assert.Throws <MaybeCorruptIndexException>(() =>
                                                       pTable.TryGetOneValue(GetOriginalHash(numIndexEntries / 2, version), 1, out position));
            pTable.Dispose();
        }
コード例 #3
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            var header = new PTableHeader(1);

            using (var f = File.Open(Filename, FileMode.OpenOrCreate)) {
                f.Seek(0, SeekOrigin.Begin);
                var bytes = header.AsByteArray();
                f.Write(bytes, 0, bytes.Length);
                var size = (long)(uint.MaxValue + 10000000L) * (long)PTable.IndexEntrySize + PTableHeader.Size + PTable.MD5Size;
                Console.WriteLine("allocating file " + Filename + " size is " + size);
                f.SetLength(size);
                Console.WriteLine("file allocated");
            }
            _ptable = PTable.FromFile(Filename, 22);
        }
コード例 #4
0
        public void setup()
        {
            _filename       = Path.GetRandomFileName();
            _copiedfilename = Path.GetRandomFileName();
            var mtable = new HashListMemTable(maxSize: 2000);

            mtable.Add(0x0101, 0x0001, 0x0001);
            mtable.Add(0x0105, 0x0001, 0x0002);
            _table = PTable.FromMemtable(mtable, _filename);
            File.Copy(_filename, _copiedfilename);
            _table.MarkForDestruction();
            using (var f = new FileStream(_copiedfilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Seek(130, SeekOrigin.Begin);
                f.WriteByte(0x22);
            }
            _table = PTable.FromFile(_copiedfilename);
        }
コード例 #5
0
        public void Setup()
        {
            _filename       = GetTempFilePath();
            _copiedfilename = GetTempFilePath();

            var mtable = new HashListMemTable(maxSize: 10);

            mtable.Add(0x0101, 0x0001, 0x0001);
            mtable.Add(0x0105, 0x0001, 0x0002);
            _table = PTable.FromMemtable(mtable, _filename);
            _table.Dispose();
            File.Copy(_filename, _copiedfilename);
            using (var f = new FileStream(_copiedfilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Seek(22, SeekOrigin.Begin);
                f.WriteByte(0x22);
            }
            _table = PTable.FromFile(_copiedfilename, 16);
        }
コード例 #6
0
        public void same_midpoints_are_loaded_when_enabling_or_disabling_index_verification()
        {
            for (int depth = 2; depth <= 20; depth++)
            {
                var ptableWithMD5Verification = PTable.FromFile(_copiedfilename, depth, false);
                var ptableWithoutVerification = PTable.FromFile(_copiedfilename, depth, true);
                var midPoints1 = ptableWithMD5Verification.GetMidPoints();
                var midPoints2 = ptableWithoutVerification.GetMidPoints();

                Assert.AreEqual(midPoints1.Length, midPoints2.Length);
                for (var i = 0; i < midPoints1.Length; i++)
                {
                    Assert.AreEqual(midPoints1[i].ItemIndex, midPoints2[i].ItemIndex);
                    Assert.AreEqual(midPoints1[i].Key.Stream, midPoints2[i].Key.Stream);
                    Assert.AreEqual(midPoints1[i].Key.Version, midPoints2[i].Key.Version);
                }

                ptableWithMD5Verification.Dispose();
                ptableWithoutVerification.Dispose();
            }
        }
コード例 #7
0
        public void the_hash_is_invalid()
        {
            var exc = Assert.Throws <CorruptIndexException>(() => PTable.FromFile(_copiedfilename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, 16, false));

            Assert.IsInstanceOf <HashValidationException>(exc.InnerException);
        }
コード例 #8
0
        public void the_invalid_file_exception_is_thrown()
        {
            var exc = Assert.Throws <CorruptIndexException>(() => PTable.FromFile(Filename, 16, false));

            Assert.IsInstanceOf <InvalidFileException>(exc.InnerException);
        }
コード例 #9
0
 public void no_error_if_index_verification_disabled()
 {
     Assert.DoesNotThrow(
         () => _table = PTable.FromFile(_copiedfilename, 16, true)
         );
 }
コード例 #10
0
        public void the_hash_is_invalid()
        {
            var exc = Assert.Throws <CorruptIndexException>(() => _table = PTable.FromFile(_copiedfilename, 16, false));

            Assert.IsInstanceOf <HashValidationException>(exc.InnerException);
        }
コード例 #11
0
 public void no_error_if_index_verification_disabled()
 {
     Assert.DoesNotThrow(
         () => _table = PTable.FromFile(_copiedfilename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, 16, true)
         );
 }
        public void the_invalid_file_exception_is_thrown()
        {
            var exc = Assert.Throws <CorruptIndexException>(() => PTable.FromFile(Filename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, 16, false));

            Assert.IsInstanceOf <InvalidFileException>(exc.InnerException);
        }