コード例 #1
0
        public void CpuSampleEvents(string payload, bool expectEvent, int expectedCpuUtil, int?expectedTotalUtil)
        {
            var processingNotificationsCollector = new ProcessingNotificationsCollector(10);

            using (var eventProcessor = new ResourceManagerEventsProcessor(_testWriterFactory, processingNotificationsCollector))
            {
                eventProcessor.ProcessEvent(_testBaseEvent, payload, _testLogLine, TestProcessName);
            }

            var cpuSampleWriter = _testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <ResourceManagerCpuSample>("ResourceManagerCpuSamples", 5);

            cpuSampleWriter.ReceivedObjects.Count.Should().Be(expectEvent ? 1 : 0);
            processingNotificationsCollector.TotalErrorsReported.Should().Be(expectEvent ? 0 : 1);
            if (expectEvent)
            {
                var expectedRecord = new
                {
                    FileName   = TestLogFileInfo.FileName,
                    FilePath   = TestLogFileInfo.FilePath,
                    LineNumber = _testLogLine.LineNumber,
                    Timestamp  = _testBaseEvent.Timestamp,
                    Worker     = TestLogFileInfo.Worker,

                    ProcessId    = _testBaseEvent.ProcessId,
                    ProcessIndex = (int?)null,
                    ProcessName  = TestProcessName,

                    ProcessCpuUtil = expectedCpuUtil,
                    TotalCpuUtil   = expectedTotalUtil,
                };
                cpuSampleWriter.ReceivedObjects[0].Should().BeEquivalentTo(expectedRecord);
            }
        }
コード例 #2
0
        public void BackgrounderPluginTest()
        {
            var testWriterFactory = new TestWriterFactory();

            using (var plugin = new BackgrounderPlugin())
            {
                plugin.Configure(testWriterFactory, null, null, new NullLoggerFactory());

                foreach (var testCase in _testCases)
                {
                    var logLine = testCase.GetLogLine();
                    plugin.ProcessLogLine(logLine, testCase.LogType);
                }

                plugin.CompleteProcessing();
            }

            var expectedOutput = _testCases
                                 .Where(@case => @case.ExpectedOutput != null)
                                 .Select(@case => @case.ExpectedOutput)
                                 .ToList();
            var jobWriter = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <BackgrounderJob>("BackgrounderJobs", 4);

            jobWriter.ReceivedObjects.Should().BeEquivalentTo(expectedOutput);
        }
コード例 #3
0
        public void ErrorEvent()
        {
            _persister.AddErrorEvent(_errorEvent);
            _persister.Dispose();
            var writer = _writerFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <BackgrounderJobError>("BackgrounderJobErrors", 4);

            writer.ReceivedObjects.Count.Should().Be(1);
            writer.ReceivedObjects[0].Should().BeEquivalentTo(_errorEvent);
        }
コード例 #4
0
        public void SpecialCase_CompletelyIncompatibleJsonInArtData()
        {
            var testWriterFactory = new TestWriterFactory();

            using (var plugin = new ArtPlugin())
            {
                plugin.Configure(testWriterFactory, null, null, new NullLoggerFactory());

                var incorrectJsonInArtPayload = new LogLine(new ReadLogLineResult(123, new NativeJsonLogsBaseEvent {
                    EventType = "msg", ArtData = JToken.FromObject(new { SomeOtherKey = "test" })
                }), TestLogFileInfo);
                plugin.ProcessLogLine(incorrectJsonInArtPayload, LogType.VizqlserverCpp);
            }

            var testWriter = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <FlattenedArtEvent>("Art", 2);

            testWriter.ReceivedObjects.Count.Should().Be(1);
            testWriter.ReceivedObjects.First().Should().NotBeNull(); // All props are null, but object still exists
        }
コード例 #5
0
        public void RunTestCases()
        {
            var testWriterFactory = new TestWriterFactory();

            using (var plugin = new VizportalPlugin())
            {
                plugin.Configure(testWriterFactory, null, null, new NullLoggerFactory());

                foreach (var testCase in _testCases)
                {
                    var logLine = testCase.GetLogLine();
                    plugin.ProcessLogLine(logLine, LogType.VizportalJava);
                }

                plugin.CompleteProcessing();
            }

            var expectedOutput = _testCases.Select(testCase => testCase.ExpectedOutput).ToList();
            var testWriter     = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <VizportalEvent>("VizportalEvents", 1);

            testWriter.ReceivedObjects.Should().BeEquivalentTo(expectedOutput);
        }
コード例 #6
0
        public void BasicTests()
        {
            var testWriterFactory = new TestWriterFactory();

            using (var plugin = new LogShark.Plugins.ResourceManager.ResourceManagerPlugin())
            {
                plugin.Configure(testWriterFactory, null, null, new NullLoggerFactory());

                foreach (var testCase in _testCases)
                {
                    var logLine = testCase.GetLogLine();
                    plugin.ProcessLogLine(logLine, testCase.LogType);
                }
            }

            var expectedOutput = _testCases.Select(testCase => testCase.ExpectedOutput).ToList();

            testWriterFactory.Writers.Count.Should().Be(5);
            var writerWithOutput = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <ResourceManagerThreshold>("ResourceManagerThresholds", 5);

            ((List <object>)writerWithOutput.ReceivedObjects).Should().BeEquivalentTo(expectedOutput);
        }
コード例 #7
0
        public void RunTestCases(LogType logTypeToUse, string expectedNonEmptyWriterName)
        {
            var testWriterFactory = new TestWriterFactory();

            using (var plugin = new ArtPlugin())
            {
                plugin.Configure(testWriterFactory, null, null, new NullLoggerFactory());

                foreach (var testCase in _testCases)
                {
                    var logLine = testCase.GetLogLine();
                    plugin.ProcessLogLine(logLine, logTypeToUse);
                }
            }

            var expectedOutput = _testCases.Select(testCase => testCase.ExpectedOutput).ToList();

            testWriterFactory.Writers.Count.Should().Be(2);

            var testWriter = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <FlattenedArtEvent>(expectedNonEmptyWriterName, 2);

            testWriter.WasDisposed.Should().Be(true);
            testWriter.ReceivedObjects.Should().BeEquivalentTo(expectedOutput);
        }
コード例 #8
0
        public void RunTestCases(string testName, string logLineText, DateTime timestamp, LogType logType, IDictionary <string, object> nonNullProps)
        {
            var testWriterFactory = new TestWriterFactory();
            var logLine           = new LogLine(new ReadLogLineResult(123, logLineText), TestLogFileInfo);
            SinglePluginExecutionResults processingResults;

            using (var plugin = new LogShark.Plugins.TabadminController.TabadminControllerPlugin())
            {
                plugin.Configure(testWriterFactory, null, _processingNotificationsCollectorMock.Object, new NullLoggerFactory());
                plugin.ProcessLogLine(logLine, logType);
                processingResults = plugin.CompleteProcessing();
            }

            _processingNotificationsCollectorMock.VerifyNoOtherCalls();

            processingResults.AdditionalTags.Should().BeEmpty();
            processingResults.HasAdditionalTags.Should().BeFalse();
            processingResults.WritersStatistics.Count.Should().Be(1);

            if (nonNullProps == null)
            {
                testWriterFactory.AssertAllWritersAreDisposedAndEmpty(1);
                processingResults.WritersStatistics[0].LinesPersisted.Should().Be(0);
                return;
            }

            processingResults.WritersStatistics[0].LinesPersisted.Should().Be(1);
            var testWriter = testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed <TabadminControllerEvent>("TabadminControllerEvents", 1);

            testWriter.ReceivedObjects.Count.Should().Be(1);
            var result = testWriter.ReceivedObjects.FirstOrDefault() as TabadminControllerEvent;

            result.Should().NotBeNull();
            AssertMethods.AssertThatAllClassOwnPropsAreAtDefaultExpectFor(result, nonNullProps, testName);
            result.VerifyBaseEventProperties(timestamp, logLine);
        }