public void Test_LogEventAsynchronously() { Trace.WriteLine(Configuration.GetGenericHeader()); Guid testId = Guid.NewGuid(); ILogController logController = LogControllerFactory.CreateLogController(); int?initialRowCount = -1 , rowCount = -1; LogManager.GetEventPage(1, 0, out initialRowCount); for (int i = 0; i < logController.AsynchronousBatchSize; i++) { testId = Guid.NewGuid(); LogManager.GetEventPage(1, 0, out rowCount); // the events must no be logged yet... Assert.AreEqual(initialRowCount, rowCount); AsynchronousLogManager.LogEvent(ApplicationLocation.Application, EventType.Verbose, GetTestMessage(testId)); } // since the for-loop reached the batch size limit, the last LogEvent call must have saved the events at the db LogManager.GetEventPage(1, 0, out rowCount); Assert.Greater(rowCount, initialRowCount); Trace.WriteLine(Configuration.GetGenericFooter()); }
public void Test_LogEventSpeedTest() { Trace.WriteLine(Configuration.GetGenericHeader()); Guid testId = Guid.NewGuid(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < _TotalLogInsertsForSpeedTests; i++) { LogManager.LogEvent(ApplicationLocation.Application, EventType.Verbose, GetTestMessage(testId)); } stopwatch.Stop(); decimal avg = (decimal)stopwatch.ElapsedMilliseconds / (decimal)_TotalLogInsertsForSpeedTests; Trace.WriteLine("Elapsed Milliseconds: " + stopwatch.ElapsedMilliseconds.ToString() + " for " + _TotalLogInsertsForSpeedTests.ToString() + " inserts"); Trace.WriteLine("Average Log insert time: " + avg.ToString() + " ms."); Assert.IsTrue(avg < (decimal)_ExpectedLogInsertTimeInMilliseconds, string.Format("Average Event Log insert time ({0}) exceeds the expected time ({1}).", TimeSpan.FromMilliseconds((double)avg).ToString(), _ExpectedLogInsertTime.ToString())); stopwatch.Reset(); stopwatch.Start(); for (int i = 0; i < _TotalLogInsertsForSpeedTests; i++) { AsynchronousLogManager.LogEvent(ApplicationLocation.Application, EventType.Verbose, GetTestMessage(testId)); } AsynchronousLogManager.SafeAllPendingEvents(); stopwatch.Stop(); avg = (decimal)stopwatch.ElapsedMilliseconds / (decimal)_TotalLogInsertsForSpeedTests; Trace.WriteLine("Elapsed Milliseconds: " + stopwatch.ElapsedMilliseconds.ToString() + " for " + _TotalLogInsertsForSpeedTests.ToString() + " inserts"); Trace.WriteLine("Average Log insert time: " + avg.ToString() + " ms."); Assert.IsTrue(avg < (decimal)_ExpectedLogInsertTimeInMilliseconds, string.Format("Average Event Log insert time ({0}) exceeds the expected time ({1}).", TimeSpan.FromMilliseconds((double)avg).ToString(), _ExpectedLogInsertTime.ToString())); Trace.WriteLine(Configuration.GetGenericFooter()); }