public void TestRemoveAt() { var entries = new LogBufferList(Core.Columns.DeltaTime); entries.Add(TimeSpan.FromSeconds(5)); entries.Add(TimeSpan.FromSeconds(6)); entries.Add(TimeSpan.FromSeconds(7)); entries.Count.Should().Be(3); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(5)); entries[1].DeltaTime.Should().Be(TimeSpan.FromSeconds(6)); entries[2].DeltaTime.Should().Be(TimeSpan.FromSeconds(7)); entries.RemoveAt(2); entries.Count.Should().Be(2); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(5)); entries[1].DeltaTime.Should().Be(TimeSpan.FromSeconds(6)); entries.RemoveAt(0); entries.Count.Should().Be(1); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(6)); entries.RemoveAt(0); entries.Count.Should().Be(0); }
public void TestRemoveRangeInvalidIndex2([Values(3, 42)] int invalidIndex) { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add("foo"); entries.Add("bar"); entries.Count.Should().Be(2); new Action(() => entries.RemoveRange(invalidIndex, 1)).Should().Throw <ArgumentException>(); entries.Count.Should().Be(2); entries[0].RawContent.Should().Be("foo"); entries[1].RawContent.Should().Be("bar"); }
public void TestResizeRemoveRows() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Hello," } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "World!" } })); entries.Resize(1); entries.Count.Should().Be(1, "because we just removed a cell"); entries[0].RawContent.Should().Be("Hello,", "Because the content of the first cell should been left untouched"); }
public void TestRemoveRange() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add("foo"); entries.Add("clondyke"); entries.Add("bar"); entries.Count.Should().Be(3); entries.RemoveRange(1, 1); entries.Count.Should().Be(2); entries[0].RawContent.Should().Be("foo", "because the first message shouldn't have been modified"); entries[1].RawContent.Should().Be("bar", "because the second cell should have been removed, the third cell should have moved down"); }
public void TestResizeInvalidCount() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Hello," } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "World!" } })); new Action(() => entries.Resize(-1)).Should().Throw <ArgumentOutOfRangeException>(); entries.Count.Should().Be(2, "because the list shouldn't have been modified"); entries[0].RawContent.Should().Be("Hello,", "Because the content of the first cell should been left untouched"); entries[1].RawContent.Should().Be("World!", "Because the content of the second cell should been left untouched"); }
public void TestRequestFullyCached_Contiguous_ReadFromMultiplePages() { var buffer = new PagedLogBuffer(1024, 10, Core.Columns.RawContent); var data = new LogBufferList(Core.Columns.Index, Core.Columns.RawContent); for (int i = 0; i < 5 * 1024; ++i) { data.Add(new LogEntry { Index = i, RawContent = i.ToString() }); } buffer.ResizeTo(data.Count); buffer.TryAdd(new LogSourceSection(0, data.Count), data, 0); var destination = new LogBufferArray(2048, Core.Columns.Index, Core.Columns.RawContent); var readOffset = 1024; buffer.TryGetEntries(new LogSourceSection(readOffset, destination.Count), destination, 0).Should().BeTrue("because all requested data is part of the cache"); for (int i = 0; i < destination.Count; ++i) { var logEntry = destination[i]; logEntry.Index.Should().Be(readOffset + i); logEntry.RawContent.Should().Be((readOffset + i).ToString()); } }
public void TestAddRange() { var entries = new LogBufferList(Core.Columns.RawContent); var other = new LogBufferList(Core.Columns.RawContent); other.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "rob" } })); other.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "ert" } })); entries.AddRange(other); entries.Count.Should().Be(2, "because we've added all two entries from the other list"); entries[0].RawContent.Should().Be("rob"); entries[1].RawContent.Should().Be("ert"); }
public void TestClearMany() { var entries = new LogBufferList(Core.Columns.LineNumber); entries.Add(42); entries.Add(9001); entries.Count.Should().Be(2); entries.Clear(); entries.Count.Should().Be(0); entries.AddEmpty(); entries.AddEmpty(); entries.Count.Should().Be(2); entries[0].LineNumber.Should().Be(0); entries[1].LineNumber.Should().Be(0); }
public void TestClearOneEntry() { var entries = new LogBufferList(); entries.Add(); entries.Count.Should().Be(1); entries.Clear(); entries.Count.Should().Be(0); }
public void TestAddOneEntry() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Count.Should().Be(0); entries.Add(ReadOnlyLogEntry.Create(new[] { Core.Columns.RawContent }, new[] { "Foobar" })); entries.Count.Should().Be(1); entries[0].RawContent.Should().Be("Foobar"); }
public void TestInsertEmpty2() { var entries = new LogBufferList(Core.Columns.DeltaTime); entries.Add(TimeSpan.FromSeconds(10)); entries.Count.Should().Be(1); entries.InsertEmpty(1); entries.Count.Should().Be(2); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(10)); entries[1].DeltaTime.Should().BeNull(); }
public void TestInsertEmpty1() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add("Foo"); entries.Count.Should().Be(1); entries.InsertEmpty(1); entries.Count.Should().Be(2); entries[0].RawContent.Should().Be("Foo"); entries[1].RawContent.Should().BeNull(); }
public void TestAddEmpty_InvalidCount() { var entries = new LogBufferList(Core.Columns.RawContent, Core.Columns.LogLevel); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "I" }, { Core.Columns.LogLevel, LevelFlags.Debug } })); new Action(() => entries.AddEmpty(-1)).Should().Throw <ArgumentOutOfRangeException>(); entries.Count.Should().Be(1); entries[0].RawContent.Should().Be("I"); entries[0].LogLevel.Should().Be(LevelFlags.Debug); }
public void TestResizeAddRows() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Hello!" } })); entries.Resize(3); entries.Count.Should().Be(3); entries[0].RawContent.Should().Be("Hello!", "because the content of the first cell should have been left untouched"); entries[1].RawContent.Should().BeNull("because an default value should have been placed in the newly added cell"); entries[2].RawContent.Should().BeNull("because an default value should have been placed in the newly added cell"); }
public void TestCopyFromArray_NoSuchColumn() { var entries = new LogBufferList(Core.Columns.LogLevel); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.LogLevel, LevelFlags.Info } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.LogLevel, LevelFlags.Trace } })); var buffer = new string[] { "Foo", "Bar" }; new Action(() => entries.CopyFrom(Core.Columns.RawContent, 0, buffer, 0, buffer.Length)) .Should().Throw <NoSuchColumnException>(); entries[0].LogLevel.Should().Be(LevelFlags.Info, "because the first entry's level should have been overwritten"); entries[1].LogLevel.Should().Be(LevelFlags.Trace, "because the second entry's level should have been overwritten"); }
public void TestCopyFromArray_PartiallyOutOfBounds2() { var entries = new LogBufferList(Core.Columns.LogLevel); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.LogLevel, LevelFlags.Info } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.LogLevel, LevelFlags.Trace } })); var buffer = new LevelFlags[] { LevelFlags.All, LevelFlags.Debug }; new Action(() => entries.CopyFrom(Core.Columns.LogLevel, -1, buffer, 0, buffer.Length)) .Should().Throw <ArgumentOutOfRangeException>(); entries[0].LogLevel.Should().Be(LevelFlags.Info, "because the first entry's level should have been overwritten"); entries[1].LogLevel.Should().Be(LevelFlags.Trace, "because the second entry's level should have been overwritten"); }
public void TestCopyFrom_Buffer([Values(0, 1, 2)] int offset) { var count = 3; var surplus = 5; var originalBuffer = new int[offset + count + surplus]; var buffer = new int[offset + count + surplus]; for (int i = 0; i < offset + count + surplus; ++i) { originalBuffer[i] = buffer[i] = i + 1; } var view = new SingleColumnLogBufferView <int>(Core.Columns.LineNumber, buffer, offset, count); var source = new LogBufferList(Core.Columns.OriginalLineNumber, Core.Columns.LineNumber); source.Add(new LogEntry { OriginalLineNumber = 10, LineNumber = 42 }); source.Add(new LogEntry { OriginalLineNumber = 12, LineNumber = 9001 }); view.CopyFrom(Core.Columns.LineNumber, 1, source, new[] { 1, 0 }); for (int i = 0; i < offset; ++i) { buffer[i].Should().Be(originalBuffer[i]); } buffer[offset + 0].Should().Be(originalBuffer[offset + 0], "because we wanted to copy the data at index 1 of the view and thus the data at index 0 should be left unharmed"); buffer[offset + 1].Should().Be(source[1].LineNumber, "because we wanted to reverse the order in which the data was copied from the source"); buffer[offset + 2].Should().Be(source[0].LineNumber, "because we wanted to reverse the order in which the data was copied from the source"); for (int i = offset + count; i < offset + count + surplus; ++i) { buffer[i].Should().Be(originalBuffer[i]); } }
public void TestFillDefault_SingleColumn() { var entries = new LogBufferList(Core.Columns.RawContent, Core.Columns.LogLevel); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "I" }, { Core.Columns.LogLevel, LevelFlags.Debug } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "want" }, { Core.Columns.LogLevel, LevelFlags.Info } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "a" }, { Core.Columns.LogLevel, LevelFlags.Warning } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Clondyke" }, { Core.Columns.LogLevel, LevelFlags.Error } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Bar" }, { Core.Columns.LogLevel, LevelFlags.Fatal } })); entries.FillDefault(Core.Columns.RawContent, 1, 3); entries.Count.Should().Be(5, "because the count shouldn't have been modified"); entries[0].RawContent.Should().Be("I", "because the first entry's raw content should NOT have been overwritten"); entries[0].LogLevel.Should().Be(LevelFlags.Debug, "because the first entry's raw content should NOT have been overwritten"); entries[1].RawContent.Should().Be(null, "because the second entry's raw content should have been overwritten"); entries[1].LogLevel.Should().Be(LevelFlags.Info, "because the second entry's raw content should NOT have been overwritten"); entries[2].RawContent.Should().Be(null, "because the third entry's raw content should have been overwritten"); entries[2].LogLevel.Should().Be(LevelFlags.Warning, "because the third entry's log level should NOT have been overwritten"); entries[3].RawContent.Should().Be(null, "because the fourth entry's raw content should have been overwritten"); entries[3].LogLevel.Should().Be(LevelFlags.Error, "because the fourth entry's log level should NOT have been overwritten"); entries[4].RawContent.Should().Be("Bar", "because the fifth entry's raw content should NOT have been overwritten"); entries[4].LogLevel.Should().Be(LevelFlags.Fatal, "because the fifth entry's log level should NOT have been overwritten"); }
protected override ILogBuffer Create(IEnumerable <IReadOnlyLogEntry> entries) { if (entries.Any()) { var list = new LogBufferList(entries.First().Columns); foreach (var entry in entries) { list.Add(entry); } return(list); } return(new LogBufferList(new IColumnDescriptor[0])); }
public void TestAddPartialEntry() { var entries = new LogBufferList(Core.Columns.RawContent, Core.Columns.Timestamp); var logEntry = new LogEntry { RawContent = "Foobar" }; entries.Add(logEntry); logEntry = new LogEntry { Timestamp = new DateTime(2017, 12, 19, 16, 08, 0) }; entries.Add(logEntry); entries[0].RawContent.Should().Be("Foobar"); entries[0].Timestamp.Should().BeNull(); entries[1].RawContent.Should().BeNull(); entries[1].Timestamp.Should().Be(new DateTime(2017, 12, 19, 16, 08, 0)); }
public void TestRemoveAtInvalidIndex([Values(-1, 1, 2)] int invalidIndex) { var entries = new LogBufferList(Core.Columns.DeltaTime, Core.Columns.RawContent); entries.Add(TimeSpan.FromSeconds(44), "stuff"); entries.Count.Should().Be(1); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(44)); entries[0].RawContent.Should().Be("stuff"); new Action(() => entries.RemoveAt(invalidIndex)).Should().Throw <ArgumentOutOfRangeException>(); entries.Count.Should().Be(1); entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(44)); entries[0].RawContent.Should().Be("stuff"); }
public void TestAddRange_SingleColumn_NoSuchColumn() { var entries = new LogBufferList(Core.Columns.RawContent, Core.Columns.Index); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "I" }, { Core.Columns.Index, (LogLineIndex)42 } })); new Action(() => entries.AddRange(Core.Columns.Message, new[] { "A", "Speed" }, 2)).Should() .Throw <NoSuchColumnException>(); entries.Count.Should().Be(1); entries[0].RawContent.Should().Be("I"); entries[0].Index.Should().Be(42); }
public void TestCopyFromLogFile_Non_Contiguous() { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "I" } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "want" } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "a" } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Clondyke" } })); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Bar" } })); var logFile = new InMemoryLogSource(); logFile.AddEntry("What", LevelFlags.Debug); logFile.AddEntry("are", LevelFlags.Debug); logFile.AddEntry("you", LevelFlags.Debug); logFile.AddEntry("doing", LevelFlags.Debug); logFile.AddEntry("Turn?", LevelFlags.Info); entries.CopyFrom(Core.Columns.RawContent, 3, logFile, new[] { new LogLineIndex(2), new LogLineIndex(4) }); entries.Count.Should().Be(5, "because the count shouldn't have been modified"); entries[0].RawContent.Should().Be("I", "because the first entry's raw content should not have been overwritten"); entries[1].RawContent.Should().Be("want", "because the second entry's raw content should not have been overwritten"); entries[2].RawContent.Should().Be("a", "because the third entry's raw content should not have been overwritten"); entries[3].RawContent.Should().Be("you", "because the fourth entry's raw content should have been overwritten"); entries[4].RawContent.Should().Be("Turn?", "because the fifth entry's raw content should have been overwritten"); }
public void TestReadOnlyEnumerable() { var inner = new LogBufferList(Core.Columns.Minimum); inner.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "Hello!" }, { Core.Columns.Timestamp, new DateTime(2021, 02, 11, 18, 49, 32) } })); var view = new LogBufferView(inner, Core.Columns.RawContent); var logEntries = view.ToList <IReadOnlyLogEntry>(); logEntries.Should().HaveCount(1); var logEntryView = logEntries[0]; logEntryView.Columns.Should().Equal(new object[] { Core.Columns.RawContent }); logEntryView.RawContent.Should().Be("Hello!"); }
public void TestAddManyEntries() { const int count = 101; var entries = new LogBufferList(Core.Columns.Index, Core.Columns.RawContent); for (int i = 0; i < count; ++i) { entries.Add(new LogLineIndex(i), i.ToString()); entries.Count.Should().Be(i + 1); } for (int i = 0; i < count; ++i) { entries[i].Index.Should().Be(i); entries[i].RawContent.Should().Be(i.ToString()); } }
public void TestEnumerateItems([Range(1, 10)] int count) { var entries = new LogBufferList(Core.Columns.LineNumber); for (int i = 0; i < count; ++i) { entries.Add(42 + i); } int n = 0; foreach (var logEntry in entries) { logEntry.LineNumber.Should().Be(42 + n); ++n; } }
public void TestAddRange_SingleColumn() { var entries = new LogBufferList(Core.Columns.RawContent, Core.Columns.Index); entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Core.Columns.RawContent, "I" }, { Core.Columns.Index, (LogLineIndex)42 } })); entries.AddRange(Core.Columns.RawContent, new [] { "A", "Speed" }, 2); entries.Count.Should().Be(3); entries[0].RawContent.Should().Be("I"); entries[1].RawContent.Should().Be("A"); entries[2].RawContent.Should().Be("Speed"); entries[0].Index.Should().Be(42); entries[1].Index.Should().Be(LogLineIndex.Invalid); entries[2].Index.Should().Be(LogLineIndex.Invalid); }
private void Add(ILogSource logSource, LogSourceSection section) { // !!!We deliberately retrieve this section OUTSIDE of our own lock!!! logSource.GetEntries(section, _array); // Calculating the max width of a line takes time and is therefore done outside // the lock! var indices = new List <ILogEntry>(section.Count); for (var i = 0; i < section.Count; ++i) { var logEntry = _array[i]; indices.Add(CreateIndex(logEntry)); } lock (_syncRoot) { if (!ReferenceEquals(logSource, _source)) { // We've retrieved data from a different log file than we wanted to... Log.WarnFormat("Ignoring add '{0}': It's probably from a previous log file", section); } else { foreach (var index in indices) { if (_indices.Count > 0) { var last = _indices[_indices.Count - 1]; var maxWidth = last.GetValue(PresentationStartingLineNumber) + last.GetValue(PresentationLineCount); index.SetValue(PresentationStartingLineNumber, maxWidth); } _indices.Add(index); _maxWidth = Math.Max(_maxWidth, index.GetValue(RawContentMaxPresentationWidth)); _lineCount += index.GetValue(PresentationLineCount); } } } }
public void TestRemoveRangePartiallyInvalidRange([Values(0, 1, 2)] int index) { var entries = new LogBufferList(Core.Columns.RawContent); entries.Add("f"); entries.Add("o"); entries.Add("o"); entries.Add("b"); entries.Add("a"); entries.Add("r"); entries.Count.Should().Be(6); new Action(() => entries.RemoveRange(index, 7)).Should().Throw <ArgumentException>(); entries.Count.Should().Be(6); entries[0].RawContent.Should().Be("f"); entries[1].RawContent.Should().Be("o"); entries[2].RawContent.Should().Be("o"); entries[3].RawContent.Should().Be("b"); entries[4].RawContent.Should().Be("a"); entries[5].RawContent.Should().Be("r"); }
public void TestGetPartiallyAdornedProperties() { var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero); _sourceEntries.Add(new LogEntry { Index = 0, Timestamp = new DateTime(2021, 02, 20, 18, 31, 45) }); _listeners.OnRead(_sourceEntries.Count); _sourceProperties.SetValue(TextProperties.Encoding, Encoding.UTF32); _scheduler.RunOnce(); var buffer = new PropertiesBufferList(); adorner.GetAllProperties(buffer); buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 31, 45)); buffer.GetValue(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 18, 31, 45)); buffer.GetValue(TextProperties.Encoding).Should().Be(Encoding.UTF32, "because those properties which are not adorned should have been retrieved from the source"); }