public void the_file_gets_created_and_can_be_read()
        {
            var indexEntrySize = PTable.IndexEntryV4Size;

            if (_ptableVersion == PTableVersions.IndexV1)
            {
                indexEntrySize = PTable.IndexEntryV1Size;
            }
            else if (_ptableVersion == PTableVersions.IndexV2)
            {
                indexEntrySize = PTable.IndexEntryV2Size;
            }
            else if (_ptableVersion == PTableVersions.IndexV3)
            {
                indexEntrySize = PTable.IndexEntryV3Size;
            }

            var table = new HashListMemTable(_ptableVersion, maxSize: 10);

            table.Add(0x010100000000, 0x0001, 0x0001);
            table.Add(0x010500000000, 0x0001, 0x0002);
            table.Add(0x010200000000, 0x0001, 0x0003);
            table.Add(0x010200000000, 0x0002, 0x0003);
            using (var sstable = PTable.FromMemtable(table, Filename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault,
                                                     skipIndexVerify: _skipIndexVerify,
                                                     useBloomFilter: true)) {
                var fileinfo        = new FileInfo(Filename);
                var midpointsCached = PTable.GetRequiredMidpointCountCached(4, _ptableVersion);
                Assert.AreEqual(
                    PTableHeader.Size + 4 * indexEntrySize + midpointsCached * indexEntrySize +
                    PTableFooter.GetSize(_ptableVersion) + PTable.MD5Size, fileinfo.Length);
                var items = sstable.IterateAllInOrder().ToList();
                Assert.AreEqual(GetHash(0x010500000000), items[0].Stream);
                Assert.AreEqual(0x0001, items[0].Version);
                Assert.AreEqual(GetHash(0x010200000000), items[1].Stream);
                Assert.AreEqual(0x0002, items[1].Version);
                Assert.AreEqual(GetHash(0x010200000000), items[2].Stream);
                Assert.AreEqual(0x0001, items[2].Version);
                Assert.AreEqual(GetHash(0x010100000000), items[3].Stream);
                Assert.AreEqual(0x0001, items[3].Version);

                var stream = (ulong)0x010200000000;
                Assert.True(sstable.TryGetLatestEntry(stream, out var entry));
                Assert.AreEqual(GetHash(stream), entry.Stream);
                Assert.AreEqual(0x0002, entry.Version);
                Assert.AreEqual(0x0003, entry.Position);
            }
        }
Exemple #2
0
        public void midpoints_are_cached_in_ptable_footer()
        {
            var numIndexEntries   = 14;
            var requiredMidpoints = PTable.GetRequiredMidpointCountCached(numIndexEntries, PTableVersions.IndexV4);

            var newTableFileCopy = GetTempFilePath();

            File.Copy(_newtableFile, newTableFileCopy);
            using (var filestream = File.Open(newTableFileCopy, FileMode.Open, FileAccess.Read))
            {
                var footerSize = PTableFooter.GetSize(PTableVersions.IndexV4);
                Assert.AreEqual(filestream.Length, PTableHeader.Size + numIndexEntries * PTable.IndexEntryV4Size + requiredMidpoints * PTable.IndexEntryV4Size + footerSize + PTable.MD5Size);
                filestream.Seek(PTableHeader.Size + numIndexEntries * PTable.IndexEntryV4Size + requiredMidpoints * PTable.IndexEntryV4Size, SeekOrigin.Begin);

                var ptableFooter = PTableFooter.FromStream(filestream);
                Assert.AreEqual(FileType.PTableFile, ptableFooter.FileType);
                Assert.AreEqual(PTableVersions.IndexV4, ptableFooter.Version);
                Assert.AreEqual(requiredMidpoints, ptableFooter.NumMidpointsCached);
            }
        }
Exemple #3
0
        public void the_file_gets_created()
        {
            var indexEntrySize = PTable.IndexEntryV4Size;

            if (_ptableVersion == PTableVersions.IndexV1)
            {
                indexEntrySize = PTable.IndexEntryV1Size;
            }
            else if (_ptableVersion == PTableVersions.IndexV2)
            {
                indexEntrySize = PTable.IndexEntryV2Size;
            }
            else if (_ptableVersion == PTableVersions.IndexV3)
            {
                indexEntrySize = PTable.IndexEntryV3Size;
            }

            var table = new HashListMemTable(_ptableVersion, maxSize: 10);

            table.Add(0x010100000000, 0x0001, 0x0001);
            table.Add(0x010500000000, 0x0001, 0x0002);
            table.Add(0x010200000000, 0x0001, 0x0003);
            table.Add(0x010200000000, 0x0002, 0x0003);
            using (var sstable = PTable.FromMemtable(table, Filename, skipIndexVerify: _skipIndexVerify)) {
                var fileinfo        = new FileInfo(Filename);
                var midpointsCached = PTable.GetRequiredMidpointCountCached(4, _ptableVersion);
                Assert.AreEqual(
                    PTableHeader.Size + 4 * indexEntrySize + midpointsCached * indexEntrySize +
                    PTableFooter.GetSize(_ptableVersion) + PTable.MD5Size, fileinfo.Length);
                var items = sstable.IterateAllInOrder().ToList();
                Assert.AreEqual(GetHash(0x010500000000), items[0].Stream);
                Assert.AreEqual(0x0001, items[0].Version);
                Assert.AreEqual(GetHash(0x010200000000), items[1].Stream);
                Assert.AreEqual(0x0002, items[1].Version);
                Assert.AreEqual(GetHash(0x010200000000), items[2].Stream);
                Assert.AreEqual(0x0001, items[2].Version);
                Assert.AreEqual(GetHash(0x010100000000), items[3].Stream);
                Assert.AreEqual(0x0001, items[3].Version);
            }
        }