Beispiel #1
0
        public void MoreFileSegmentation()
        {
            TestFileCollection testFileCollection = new TestFileCollection();

            for (int i = 0; i < 10; i++)
            {
                testFileCollection.Add(new TestFile());
                testFileCollection[i].Append(
                    Enumerable.Range(1, 1000).Select(j => $"{i}. file and this is line number {j.ToString("00000000")}").ToArray());
            }

            var refresher = new Subject <Unit>();
            var segmenter = new FileSegmenter(testFileCollection.Select(t => t.Info.WatchFile(refresher)).Merge(), 1000);
            FileSegmentCollection result = null;

            using (var indexer = segmenter.Segments.Subscribe(segment => result = segment))
            {
                result.Should().NotBeNull();
                var current     = new FileSegmentCollection(result);
                int depthOfLink = 0;
                while (current != null)
                {
                    depthOfLink++;
                    current = current.Link;
                }
                depthOfLink.Should().Be(10);
                result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Head);
                result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Tail);

                testFileCollection.ForEach(t => t.Delete());
            }

            testFileCollection.ForEach(t => t.Delete());
        }
Beispiel #2
0
        public void SearchInTailedFilesAndScrollIntoTheEnds()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                    files[i].Append(Enumerable.Range(1, 10).Select(j => $"{i}. files {j}. row").ToArray());
                }


                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => int.Parse(str.Split('.')[0]) % 2 != 0);

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();
                    var lines         = fileSearchResult.ReadLines(new ScrollRequest(20, 30)).Select(line => line.Text);
                    var expectedLines = Enumerable.Range(7, 3).Select(i =>
                    {
                        return(i % 2 != 0 ? Enumerable.Range(1, 10).Select(j => $"{i}. files {j}. row") : null);
                    })
                                        .Where(t => t != null)
                                        .SelectMany(t => t).ToArray();

                    lines.ShouldAllBeEquivalentTo(expectedLines);
                }
            }
        }
Beispiel #3
0
        public void SearchInTenTailedFiles()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                    files[i].Append(Enumerable.Range(1, 100).Select(j => $"{(i + 1)}. files {j} row").ToArray());
                }
                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => str.Contains("files 9 row"));

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();
                    int matches = 0;
                    while (fileSearchResult != null)
                    {
                        matches         += fileSearchResult.Count;
                        fileSearchResult = fileSearchResult.Previous as FileSearchResult;
                    }
                    matches.Should().Be(10);
                }
            }
        }
Beispiel #4
0
        public void SearchOnDataWhenTailedFilesArePopulated()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                }
                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => str.Contains("9"));

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    for (int i = 0; i < 10; i++)
                    {
                        files[i].Append(Enumerable.Range(1, 100).Select(j => j.ToString()).ToArray());
                    }
                    pulse.Once();
                    pulse.Once();
                    while (fileSearchResult != null)
                    {
                        fileSearchResult.Matches.Length.Should().NotBe(0);
                        fileSearchResult = fileSearchResult.Previous as FileSearchResult;
                    }
                }
            }
        }
        public void CanReadIndiciesBack_LargeTailedFilesTail()
        {
            var pulse     = new Subject <Unit>();
            var scheduler = new TestScheduler();

            using (var testFiles = new TestFileCollection())
            {
                for (int i = 0; i < 3; i++)
                {
                    testFiles.Add(new TestFile());
                    testFiles[i].Append(
                        Enumerable.Range(1, 10000)
                        .Select(j => $"{i + 1}. file and this is line number {j.ToString("00000000")}")
                        .ToArray());
                }

                IndexCollection result = null;
                var             index  = testFiles.Select(t => t.Info.WatchFile(pulse))
                                         .Merge()
                                         .WithSegments()
                                         .Index(1000, scheduler);

                using (index.Subscribe(indicies => result = indicies as IndexCollection))
                {
                    pulse.Once();
                    scheduler.AdvanceBy(1);
                    var tail         = result.ReadLines(new ScrollRequest(10));
                    var tailText     = tail.Select(l => l.Text).ToArray();
                    var tailExpected =
                        Enumerable.Range(1, 10).Select(i => $"1. file and this is line number {i.ToString("00000000")}");
                    tailText.ShouldAllBeEquivalentTo(tailExpected);
                }
            }
        }
Beispiel #6
0
        public void SearchInTailedFilesAndAfterAppendOneLineIntoOneFileAndSrollBegins()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                    files[i].Append(Enumerable.Range(1, 10).Select(j => $"{i}. files {j}. row").ToArray());
                }


                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => int.Parse(str.Split('.')[0]) % 2 != 0);

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();
                    files[0].Append("1. file added new row");
                    pulse.Once();
                    while (fileSearchResult?.Next != null)
                    {
                        fileSearchResult = fileSearchResult?.Next as FileSearchResult;
                    }
                    var lines         = fileSearchResult.ReadLines(new ScrollRequest(20, 0)).Select(line => line.Text);
                    var expectedLines = Enumerable.Range(1, 3).Select(i =>
                    {
                        return(i % 2 != 0 ? Enumerable.Range(1, 10).Select(j => $"{i}. files {j}. row") : null);
                    })
                                        .Where(t => t != null)
                                        .SelectMany(t => t).ToList();
                    expectedLines.RemoveAt(expectedLines.Count - 1);
                    expectedLines =
                        new[] { new[] { "1. file added new row" }, expectedLines.ToArray() }.SelectMany(t => t).ToList();
                    lines.ShouldAllBeEquivalentTo(expectedLines.ToArray());
                }
            }
        }
Beispiel #7
0
        public void EmptyTailedFiles()
        {
            var pulse     = new Subject <Unit>();
            var scheduler = new TestScheduler();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                }
                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => str.Contains("9"), scheduler);

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    scheduler.AdvanceByMilliSeconds(250);
                    pulse.Once();
                    var segments          = 0;
                    var segmentsCompleted = 0;
                    var isSearchCompleted = true;
                    var count             = 0;
                    while (fileSearchResult != null)
                    {
                        segments          += fileSearchResult.Segments;
                        segmentsCompleted += fileSearchResult.SegmentsCompleted;
                        isSearchCompleted  = isSearchCompleted && fileSearchResult.IsSearching;
                        count             += fileSearchResult.Count;
                        fileSearchResult   = fileSearchResult.Previous as FileSearchResult;
                    }

                    segments.Should().Be(10);
                    segmentsCompleted.Should().Be(0);
                    isSearchCompleted.Should().Be(false);
                    count.Should().Be(0);
                }
            }
        }
Beispiel #8
0
        public void WillContinuallyTailInTailedFilesWithTwoFileModified()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                    files[i].Append(Enumerable.Range(1, 100).Select(j => $"{(i + 1)}. files {j} row").ToArray());
                }
                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => str.Contains("files 9 row"));

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();

                    files[7].Append("8. files 9 row");
                    files[9].Append("10. files 9 row");

                    pulse.Once();

                    int matches           = 0;
                    var _fileSearchResult = fileSearchResult;
                    while (_fileSearchResult?.Next != null)
                    {
                        _fileSearchResult = _fileSearchResult.Next as FileSearchResult;
                    }
                    while (_fileSearchResult != null)
                    {
                        matches          += _fileSearchResult.Count;
                        _fileSearchResult = _fileSearchResult.Previous as FileSearchResult;
                    }
                    matches.Should().Be(12);
                }
            }
        }
        public void CanReadIndiciesBack_SmallTailedFilesMid()
        {
            var pulse = new Subject <Unit>();

            using (var testFiles = new TestFileCollection())
            {
                for (int i = 0; i < 3; i++)
                {
                    testFiles.Add(new TestFile());
                    testFiles[i].Append(
                        Enumerable.Range(1, 5)
                        .Select(j => $"{i + 1}. file and this is line number {j.ToString("00000000")}")
                        .ToArray());
                }

                IndexCollection result = null;
                var             index  = testFiles.Select(t => t.Info.WatchFile(pulse))
                                         .Merge()
                                         .WithSegments()
                                         .Index();

                using (index.Subscribe(indicies => result = indicies as IndexCollection))
                {
                    pulse.Once();

                    var mid         = result.ReadLines(new ScrollRequest(10, 2));
                    var midText     = mid.Select(l => l.Text).ToArray();
                    var midExpected = new[]
                    {
                        Enumerable.Range(3, 3).Select(i => $"3. file and this is line number {i.ToString("00000000")}"),
                        Enumerable.Range(1, 5).Select(i => $"2. file and this is line number {i.ToString("00000000")}"),
                        Enumerable.Range(1, 2).Select(i => $"1. file and this is line number {i.ToString("00000000")}"),
                    }.SelectMany(t => t);
                    midText.ShouldAllBeEquivalentTo(midExpected);
                }
            }
        }
Beispiel #10
0
        public void NotExistingTailedFiles()
        {
            var pulse = new Subject <Unit>();

            using (var files = new TestFileCollection())
            {
                for (int i = 0; i < 10; i++)
                {
                    files.Add(new TestFile());
                }
                files.Dispose();

                FileSearchResult fileSearchResult = null;
                var search = files.Select(t => t.Info.WatchFile(pulse))
                             .Merge()
                             .Search(str => str.Contains("9"));

                using (search.Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();
                    fileSearchResult.Should().BeNull();
                }
            }
        }