public void when_indexmap_file_is_garbage()
        {
            File.WriteAllText(_indexMapFileName, "alkfjasd;lkf\nasdfasdf\n");

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            _filename  = GetTempFilePath();
            _mergeFile = GetTempFilePath();

            _map = IndexMapTestFactory.FromFile(_filename, maxTablesPerLevel: 2);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 1, 0);

            _result = _map.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), skipIndexVerify: _skipIndexVerify),
                123, 321, (streamId, hash) => hash, _ => true, _ => new System.Tuple <string, bool>("", true),
                new GuidFilenameProvider(PathName), _ptableVersion, _maxAutoMergeIndexLevel, 0,
                skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());
            _result = _result.MergedMap.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), skipIndexVerify: _skipIndexVerify),
                100, 400, (streamId, hash) => hash, _ => true, _ => new System.Tuple <string, bool>("", true),
                new FakeFilenameProvider(_mergeFile), _ptableVersion, _maxAutoMergeIndexLevel, 0,
                skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());
        }
        public void when_indexmap_file_exists_but_is_empty()
        {
            File.WriteAllText(_indexMapFileName, "");

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
Esempio n. 4
0
        public void saved_file_could_be_read_correctly_and_without_errors()
        {
            var map = IndexMapTestFactory.FromFile(_filename);

            Assert.AreEqual(-1, map.PrepareCheckpoint);
            Assert.AreEqual(-1, map.CommitCheckpoint);
        }
Esempio n. 5
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            _filename = GetFilePathFor("indexfile");
            _map      = IndexMapTestFactory.FromFile(_filename);
            _map.SaveToFile(_filename);
        }
Esempio n. 6
0
 public void allow_prepare_checkpoint_equal_to_minus_one_if_no_ptables_are_in_index()
 {
     CreateArtificialIndexMapFile(_indexMapFileName, -1, 0, null);
     Assert.DoesNotThrow(() => {
         var indexMap = IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2);
         indexMap.InOrder().ToList().ForEach(x => x.Dispose());
     });
 }
        public void when_ptable_line_is_missing_one_number()
        {
            var lines = File.ReadAllLines(_indexMapFileName);

            File.WriteAllLines(_indexMapFileName, new[] { lines[0], lines[1], string.Format("0,{0}", _ptableFileName) });

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void when_indexmap_file_does_not_have_md5_checksum()
        {
            var lines = File.ReadAllLines(_indexMapFileName);

            File.WriteAllLines(_indexMapFileName, lines.Skip(1));

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void when_ptable_line_is_missing_filename()
        {
            var lines = File.ReadAllLines(_indexMapFileName);

            File.WriteAllLines(_indexMapFileName, new[] { lines[0], lines[1], "0,0" });

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
Esempio n. 10
0
        public void saved_file_could_be_read_correctly_and_without_errors()
        {
            var map = IndexMapTestFactory.FromFile(_filename, maxAutoMergeLevel: _maxAutoMergeIndexLevel);

            map.InOrder().ToList().ForEach(x => x.Dispose());

            Assert.AreEqual(7, map.PrepareCheckpoint);
            Assert.AreEqual(11, map.CommitCheckpoint);
        }
        public void when_indexmap_file_does_not_have_latest_commit_position()
        {
            var lines = File.ReadAllLines(_indexMapFileName);

            File.WriteAllLines(_indexMapFileName, lines.Where((x, i) => i != 1));

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void should_initialize_auto_merge_level_correctly()
        {
            var map = IndexMapTestFactory.FromFile(_filename, loadPTables: false, maxAutoMergeLevel: 4);

            var v2File = GetFilePathFor("v1tov2");

            map.SaveToFile(v2File);
            Assert.AreEqual(V2FileContents, File.ReadAllText(v2File));
        }
        public void when_ptable_file_is_deleted()
        {
            _ptable.MarkForDestruction();
            _ptable = null;
            File.Delete(_ptableFileName);

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
Esempio n. 14
0
        public override void Setup()
        {
            base.Setup();
            AddTables(5);
            _map.Dispose(TimeSpan.FromMilliseconds(100));
            var filename = GetFilePathFor("indexmap");

            _result.MergedMap.SaveToFile(filename);
            _result.MergedMap.Dispose(TimeSpan.FromMilliseconds(5));
            _map = IndexMapTestFactory.FromFile(filename, maxAutoMergeLevel: 1);
        }
        public void when_indexmap_md5_checksum_is_corrupted()
        {
            using (var fs = File.Open(_indexMapFileName, FileMode.Open)) {
                var b = (byte)fs.ReadByte();
                b          ^= 1;        // swap single bit
                fs.Position = 0;
                fs.WriteByte(b);
            }

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void can_reduce_max_auto_merge_to_lower_than_map_value()
        {
            IndexMap map = null;

            Assert.DoesNotThrow(() => map = IndexMapTestFactory.FromFile(_filename, maxAutoMergeLevel: 3));
            var newIndexFile = GetFilePathFor("indexfile2");

            map?.SaveToFile(newIndexFile);
            var lines = File.ReadAllLines(newIndexFile);

            Assert.AreEqual(lines[3], "3");
        }
        public void when_ptable_type_is_corrupted()
        {
            _ptable.Dispose();
            _ptable = null;

            using (var fs = File.Open(_ptableFileName, FileMode.Open)) {
                fs.Seek(0, SeekOrigin.Begin);
                fs.WriteByte(123);
            }

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void when_checkpoints_pair_is_corrupted()
        {
            using (var fs = File.Open(_indexMapFileName, FileMode.Open)) {
                fs.Position = 34;
                var b = (byte)fs.ReadByte();
                b          ^= 1;
                fs.Position = 34;
                fs.WriteByte(b);
            }

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
Esempio n. 19
0
        public override async Task SetUp()
        {
            await base.SetUp();

            _indexMapFileName = GetFilePathFor("index.map");
            _ptableFileName   = GetFilePathFor("ptable");

            _emptyIndexMap = IndexMapTestFactory.FromFile(_indexMapFileName);

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

            memTable.Add(0, 1, 2);
            _ptable = PTable.FromMemtable(memTable, _ptableFileName, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault);
        }
        public override void SetUp()
        {
            base.SetUp();

            _indexMapFileName = GetFilePathFor("index.map");
            _ptableFileName   = GetFilePathFor("ptable");

            _emptyIndexMap = IndexMapTestFactory.FromFile(_indexMapFileName);

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

            memTable.Add(0, 1, 2);
            _ptable = PTable.FromMemtable(memTable, _ptableFileName);
        }
        public void when_ptable_data_is_corrupted()
        {
            _ptable.Dispose();
            _ptable = null;

            using (var fs = File.Open(_ptableFileName, FileMode.Open)) {
                fs.Position = new Random().Next(PTableHeader.Size, (int)fs.Length);
                var b = (byte)fs.ReadByte();
                b           ^= 1;
                fs.Position -= 1;
                fs.WriteByte(b);
            }

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
        public void when_ptable_hash_is_corrupted()
        {
            _ptable.Dispose();
            _ptable = null;

            using (var fs = File.Open(_ptableFileName, FileMode.Open)) {
                fs.Seek(-PTable.MD5Size, SeekOrigin.End);
                var b = (byte)fs.ReadByte();
                b ^= 1;
                fs.Seek(-PTable.MD5Size, SeekOrigin.End);
                fs.WriteByte(b);
            }

            Assert.Throws <CorruptIndexException>(() =>
                                                  IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2));
        }
Esempio n. 23
0
        public void should_merge_levels_above_max_level()
        {
            AddTables(201);             //gives 1 level 0, 1 level 3 and 6 level 5s
            Assert.AreEqual(8, _result.MergedMap.InOrder().Count());
            var filename = GetFilePathFor("changemaxlevel");

            _result.MergedMap.SaveToFile(filename);
            _result.MergedMap.Dispose(TimeSpan.FromMilliseconds(100));
            _map.Dispose(TimeSpan.FromMilliseconds(100));
            _map    = IndexMapTestFactory.FromFile(filename, maxAutoMergeLevel: 3);
            _result = _map.TryManualMerge(
                UpgradeHash, ExistsAt,
                RecordExistsAt, _fileNameProvider, _ptableVersion,
                skipIndexVerify: _skipIndexVerify);
            Assert.AreEqual(2, _result.MergedMap.InOrder().Count());
        }
Esempio n. 24
0
        public override async Task TestFixtureSetUp()
        {
            await base.TestFixtureSetUp();

            _mergeFile = GetTempFilePath();
            _filename  = GetTempFilePath();

            _map = IndexMapTestFactory.FromFile(_filename, maxTablesPerLevel: 4);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 1, 0);

            _result = _map.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify), 1, 2,
                (streamId, hash) => hash,
                _ => true,
                _ => new System.Tuple <string, bool>("", true),
                new GuidFilenameProvider(PathName),
                _ptableVersion,
                _maxAutoMergeIndexLevel,
                0,
                skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());

            _result = _result.MergedMap.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify), 3, 4,
                (streamId, hash) => hash,
                _ => true, _ => new System.Tuple <string, bool>("", true), new GuidFilenameProvider(PathName),
                _ptableVersion, _maxAutoMergeIndexLevel, 0, skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());

            _result = _result.MergedMap.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify), 4, 5,
                (streamId, hash) => hash,
                _ => true, _ => new System.Tuple <string, bool>("", true), new GuidFilenameProvider(PathName),
                _ptableVersion, _maxAutoMergeIndexLevel, 0, skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());

            _result = _result.MergedMap.AddPTable(
                PTable.FromMemtable(memtable, GetTempFilePath(), Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify), 0, 1,
                (streamId, hash) => hash,
                _ => true, _ => new System.Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile),
                _ptableVersion, _maxAutoMergeIndexLevel, 0, skipIndexVerify: _skipIndexVerify);
            _result.ToDelete.ForEach(x => x.MarkForDestruction());
        }
Esempio n. 25
0
        public override async Task SetUp()
        {
            await base.SetUp();

            _indexMapFileName = GetFilePathFor("index.map");
            _ptableFileName   = GetFilePathFor("ptable");

            var indexMap = IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2, maxAutoMergeLevel: _maxAutoMergeIndexLevel);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 0, 0);
            memtable.Add(1, 1, 100);
            _ptable = PTable.FromMemtable(memtable, _ptableFileName, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify);

            indexMap = indexMap.AddAndMergePTable(_ptable, 0, 0, (streamId, hash) => hash, _ => true,
                                                  _ => new Tuple <string, bool>("", true), new GuidFilenameProvider(PathName), _ptableVersion, 0, skipIndexVerify: _skipIndexVerify).MergedMap;
            indexMap.SaveToFile(_indexMapFileName);
        }
Esempio n. 26
0
        public override async Task TestFixtureSetUp()
        {
            await base.TestFixtureSetUp();

            _filename  = GetTempFilePath();
            _tablename = GetTempFilePath();
            _mergeFile = GetFilePathFor("mergefile");

            _map = IndexMapTestFactory.FromFile(_filename, maxAutoMergeLevel: _maxAutoMergeIndexLevel);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 1, 0);
            var table = PTable.FromMemtable(memtable, _tablename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, skipIndexVerify: _skipIndexVerify);

            _result = _map.AddAndMergePTable(table, 7, 11, (streamId, hash) => hash, _ => true,
                                             _ => new System.Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion, 0, skipIndexVerify: _skipIndexVerify);
            table.MarkForDestruction();
        }
Esempio n. 27
0
        public override void SetUp()
        {
            base.SetUp();

            _filename  = GetFilePathFor("indexfile");
            _tablename = GetTempFilePath();
            _mergeFile = GetFilePathFor("outfile");

            _map = IndexMapTestFactory.FromFile(_filename, maxTablesPerLevel: 4);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 2, 123);
            var table = PTable.FromMemtable(memtable, _tablename);

            _result = _map.AddPTable(table, 0, 0, (streamId, hash) => hash, _ => true,
                                     _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                     _maxAutoMergeIndexLevel, 0);
            _result = _result.MergedMap.AddPTable(table, 0, 0, (streamId, hash) => hash, _ => true,
                                                  _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                                  _maxAutoMergeIndexLevel, 0);
            _result = _result.MergedMap.AddPTable(table, 0, 0, (streamId, hash) => hash, _ => true,
                                                  _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                                  _maxAutoMergeIndexLevel, 0);
            var merged = _result.MergedMap.AddPTable(table, 0, 0, (streamId, hash) => hash, _ => true,
                                                     _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                                     _maxAutoMergeIndexLevel, 0);

            _result = merged.MergedMap.AddPTable(table, 0, 0, (streamId, hash) => hash, _ => true,
                                                 _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                                 _maxAutoMergeIndexLevel, 0);
            _result = _result.MergedMap.AddPTable(table, 7, 11, (streamId, hash) => hash, _ => true,
                                                  _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                                  _maxAutoMergeIndexLevel, 0);
            _result.MergedMap.SaveToFile(_filename);

            table.Dispose();

            merged.MergedMap.InOrder().ToList().ForEach(x => x.Dispose());
            merged.ToDelete.ForEach(x => x.Dispose());

            _result.MergedMap.InOrder().ToList().ForEach(x => x.Dispose());
            _result.ToDelete.ForEach(x => x.Dispose());
        }
Esempio n. 28
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            _filename  = GetTempFilePath();
            _tablename = GetTempFilePath();
            _mergeFile = GetFilePathFor("mergefile");

            _map = IndexMapTestFactory.FromFile(_filename);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 1, 0);
            var table = PTable.FromMemtable(memtable, _tablename, skipIndexVerify: _skipIndexVerify);

            _result = _map.AddPTable(table, 7, 11, (streamId, hash) => hash, _ => true,
                                     _ => new System.Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion,
                                     _maxAutoMergeIndexLevel, 0, skipIndexVerify: _skipIndexVerify);
            table.MarkForDestruction();
        }
        public override void SetUp()
        {
            base.SetUp();

            _indexMapFileName = GetFilePathFor("index.map");
            _ptableFileName   = GetFilePathFor("ptable");

            var indexMap = IndexMapTestFactory.FromFile(_indexMapFileName, maxTablesPerLevel: 2);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 0, 0);
            memtable.Add(1, 1, 100);
            _ptable = PTable.FromMemtable(memtable, _ptableFileName, skipIndexVerify: _skipIndexVerify);

            indexMap = indexMap.AddPTable(_ptable, 0, 0, (streamId, hash) => hash, _ => true,
                                          _ => new Tuple <string, bool>("", true), new GuidFilenameProvider(PathName), _ptableVersion,
                                          _maxAutoMergeIndexLevel, 0, skipIndexVerify: _skipIndexVerify).MergedMap;
            indexMap.SaveToFile(_indexMapFileName);
        }
        public override async Task TestFixtureSetUp()
        {
            await base.TestFixtureSetUp();

            _filename  = GetFilePathFor("indexfile");
            _tablename = GetTempFilePath();
            _mergeFile = GetFilePathFor("outputfile");

            _map = IndexMapTestFactory.FromFile(_filename, maxAutoMergeLevel: _maxAutoMergeIndexLevel);
            var memtable = new HashListMemTable(_ptableVersion, maxSize: 10);

            memtable.Add(0, 2, 7);
            var table = PTable.FromMemtable(memtable, _tablename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault);

            _result = _map.AddAndMergePTable(table, 7, 11, (streamId, hash) => hash, _ => true,
                                             _ => new Tuple <string, bool>("", true), new FakeFilenameProvider(_mergeFile), _ptableVersion, 0);
            _result.MergedMap.SaveToFile(_filename);
            _result.ToDelete.ForEach(x => x.Dispose());
            _result.MergedMap.InOrder().ToList().ForEach(x => x.Dispose());
            table.Dispose();
        }