public void CollectionLimitsSizeOfTheFirstFile()
        {
            var encoding = Encoding.UTF8;

            File.WriteAllText(immutableFilePath_, ImmutableContent, encoding);
            File.WriteAllText(mutableFilePath_, MutableContentPart1, encoding);

            var immutableSize = GetSize(immutableFilePath_);
            var mutableSize   = GetSize(mutableFilePath_);

            var initialFiles = new[]
            {
                mutableFilePath_,
                immutableFilePath_
            };
            var initialCollection         = new LogFilesCollection(initialFiles, encoding, String.Empty);
            var initialCollectionSnapshot = initialCollection.GetSnapshot();

            File.AppendAllText(mutableFilePath_, MutableContentPart2);
            File.WriteAllText(newFilePath_, ImmutableContent);

            var files = new[]
            {
                newFilePath_,
                mutableFilePath_,
                immutableFilePath_
            };
            var subject = new LogFilesCollection(files, encoding, initialCollectionSnapshot);

            using (var enumerator = subject.GetEnumerator())
            {
                var actualMovedToMutableFile = enumerator.MoveNext();
                Assert.That(actualMovedToMutableFile, Is.True);

                var actualMutableFile = enumerator.Current;
                Assert.That(actualMutableFile.FileName, Is.EqualTo(mutableFilePath_));
                Assert.That(actualMutableFile.Size, Is.EqualTo(mutableSize));

                var actualMovedToImmutableFile = enumerator.MoveNext();
                Assert.That(actualMovedToImmutableFile, Is.True);

                var actualImutableFile = enumerator.Current;
                Assert.That(actualImutableFile.FileName, Is.EqualTo(immutableFilePath_));
                var events = actualImutableFile.GetEvents();
                Assert.That(actualImutableFile.Size, Is.EqualTo(immutableSize));

                var actualMovedPastFiles = enumerator.MoveNext();
                Assert.That(actualMovedPastFiles, Is.False);
            }
        }
示例#2
0
        public EventsCollection GetEvents(ILogQuery query)
        {
            Debug.Assert(query != null, "LogSource.GetEvents: query is null.");

            var files    = GetFiles(true);
            var encoding = config_.Encoding;

            var logFiles = new LogFilesCollection(files, encoding, query.Snapshot);
            var size     = logFiles.GetSnapshot();

            var accumulator = new LogAccumulator(statsCache_, query);
            var hintMaker   = new CacheHintMaker(statsCache_, query, accumulator);
            var events      = logFiles
                              .Aggregate(hintMaker, (a, f) => a.Consume(f))
                              .Events
                              .ToList();

            events.Reverse();

            return(new EventsCollection(events, Name, size));
        }