public async Task WhenSendingTracesThenTracesAreSaved() { // Create the log tracer, trace a bit, and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { Assert.AreEqual("mylog", tracer.SessionId, "Mismatch on the tracer's session ID"); tracer.TraceVerbose("0"); tracer.TraceInformation("1"); tracer.TraceWarning("2"); tracer.TraceError("3"); } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(3, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(1, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(4, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(4, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); AssertTraceLine(log, 0, TraceLevel.Verbose, "0"); AssertTraceLine(log, 1, TraceLevel.Info, "1"); AssertTraceLine(log, 2, TraceLevel.Warning, "2"); AssertTraceLine(log, 3, TraceLevel.Error, "3"); // Now reopen the tracer and validate again pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(3, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(1, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(4, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(4, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); AssertTraceLine(log, 0, TraceLevel.Verbose, "0"); AssertTraceLine(log, 1, TraceLevel.Info, "1"); AssertTraceLine(log, 2, TraceLevel.Warning, "2"); AssertTraceLine(log, 3, TraceLevel.Error, "3"); }
public async Task WhenGettingLogFromEmptyArchiveThenLogIsCreatedOnce() { // Create the log tracer and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); IPageableLog log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); // Create the log tracer again, and validate that nothing has happened pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); }
public async Task WhenGettingTwoLogsFromEmptyArchiveThenLogsAreCreated() { // Create the first log tracer and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); IPageableLog log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); // Create the second log tracer and validate pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog2", TestPageSize); AssertEmptyLogTracer(log, "mylog2"); AssertArchiveFile(expectedNumberOfEntries: 2); AssertEmptyArchiveLogEntry("mylog"); AssertEmptyArchiveLogEntry("mylog2"); }
public async Task WhenUpdatingPageSizeThenPagesAreHandledCorrectly() { // Create the log tracer, trace a lot, validate, update page size, trace and validate more var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = 0; i < TestPageSize * 10; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(9, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(90, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(99, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } log.CurrentPageIndex = 3; log.PageSize = 7; Assert.AreEqual(4, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(28, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(34, log.CurrentPageEnd, "Mismatch on the log's current page end"); for (int i = 0; i < 7; i++) { AssertTraceLine(log, i, TraceLevel.Info, $"{(4 * 7) + i}"); } }
public async Task WhenSendingManyTracesThenPagesAreHandledCorrectly() { // Create the log tracer, trace a lot, and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = 0; i < TestPageSize * 10; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(9, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(90, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(99, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); log.CurrentPageIndex = 4; for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } // Now reopen the tracer, validate, trace some more and validate again pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(9, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = TestPageSize * 10; i < TestPageSize * 11; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(10, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(100, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(109, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(11, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 11, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 11; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } }