public void RunTasks_RunErrors() { var pc1 = new ProcessControl { Id = ProcessControlId.EnvironmentCheckSqlConfig, Frequency = 60, LastProcessExecDateTime = DateTime.UtcNow.AddYears(-1), LastExecSucceeded = true }; var processControls = new List <ProcessControl>() { pc1 }; _pcRepo.Setup(r => r.ReadAll()).Returns(processControls); _sqlRepo.Setup(r => r.ReadServerUtcTime()).Returns(DateTime.UtcNow); _sqlRepo.SetupGet(r => r.ProcessControlRepository).Returns(_pcRepo.Object); var taskE = new Mock <IProcessControlTask>(); taskE.Setup(t => t.Execute(It.IsAny <ProcessControl>())).Throws(new Exception("Error running task E")); taskE.SetupGet(t => t.ProcessControlID).Returns(ProcessControlId.EnvironmentCheckSqlConfig); var manager = new ProcessControlTaskManager(_sqlRepo.Object, _logger.Object); manager.Subscribe(taskE.Object); manager.Execute(); taskE.Verify(t => t.Execute(It.IsAny <ProcessControl>()), Times.Once); Assert.That(pc1.LastExecSucceeded, Is.False); Assert.That(pc1.LastErrorMessage, Is.Not.Empty); }
public void RunTasks_RunSkipped() { var pc3 = new ProcessControl { Id = ProcessControlId.ReadErrorLog, Frequency = 60, LastProcessExecDateTime = DateTime.UtcNow, }; var processControls = new List <ProcessControl>() { pc3 }; _pcRepo.Setup(r => r.ReadAll()).Returns(processControls); _sqlRepo.Setup(r => r.ReadServerUtcTime()).Returns(DateTime.UtcNow); _sqlRepo.SetupGet(r => r.ProcessControlRepository).Returns(_pcRepo.Object); var taskD = new Mock <IProcessControlTask>(); taskD.Setup(t => t.Execute(It.IsAny <ProcessControl>())); taskD.SetupGet(t => t.ProcessControlID).Returns(ProcessControlId.ReadErrorLog); //Act var manager = new ProcessControlTaskManager(_sqlRepo.Object, _logger.Object); manager.Subscribe(taskD.Object); manager.Execute(); //Assert taskD.Verify(t => t.Execute(It.IsAny <ProcessControl>()), Times.Never); }
public void RunTasks_RunMultiple() { var pc1 = new ProcessControl { Id = ProcessControlId.CollectWaitStatistics, Frequency = 60, LastProcessExecDateTime = DateTime.UtcNow.AddYears(-1), }; var pc2 = new ProcessControl { Id = ProcessControlId.CycleErrorLog, Frequency = 60, LastProcessExecDateTime = DateTime.UtcNow.AddYears(-1), }; var processControls = new List <ProcessControl>() { pc1, pc2 }; _pcRepo.Setup(r => r.ReadAll()).Returns(processControls); _sqlRepo.Setup(r => r.ReadServerUtcTime()).Returns(DateTime.UtcNow); var taskA = new Mock <IProcessControlTask>(); var taskB = new Mock <IProcessControlTask>(); taskA.Setup(t => t.Execute(It.IsAny <ProcessControl>())); taskB.Setup(t => t.Execute(It.IsAny <ProcessControl>())); taskA.SetupGet(t => t.ProcessControlID).Returns(ProcessControlId.CollectWaitStatistics); taskB.SetupGet(t => t.ProcessControlID).Returns(ProcessControlId.CycleErrorLog); _sqlRepo.SetupGet(r => r.ProcessControlRepository).Returns(_pcRepo.Object); //Act var manager = new ProcessControlTaskManager(_sqlRepo.Object, _logger.Object); manager.Subscribe(taskA.Object, taskB.Object); manager.Execute(); //Assert taskA.Verify(t => t.Execute(It.IsAny <ProcessControl>()), Times.Once); taskB.Verify(t => t.Execute(It.IsAny <ProcessControl>()), Times.Once); }
public void Execute() { this.logger.WithClassName().LogVerbose("RunAggregations Called"); try { // var wmiHelper = new WMIHelper(this.logger); var manager = new ProcessControlTaskManager(this.sqlRepo, this.logger); manager.Subscribe( new RunServerDataRefreshTask(this.logger, this.sqlRepo, this.AgentId), new ApplicationPerformanceTask(this.logger, this.sqlRepo, this.AgentId), new LoadApplicationSummaryTask(this.sqlRepo, this.AgentId), new LoadServerHealthSummaryTask(this.logger, this.sqlRepo, this.AgentId), new CollectWaitStatisticsTask(this.sqlRepo, this.AgentId), new FileLevelLatencyTask(this.logger, this.sqlRepo, this.AgentId), new ReadErrorLogTask(this.logger, this.sqlRepo, this.AgentId), new MonitorVirtualLogFilesTask(this.logger, this.sqlRepo, this.AgentId), new CycleErrorLogTask(this.logger, this.sqlRepo, this.AgentId), new EnvironmentCheckRelativityTask(this.logger, this.sqlRepo, this.AgentId), new EnvironmentCheckSqlConfigTask(this.logger, this.sqlRepo, this.AgentId), new EnvironmentCheckServerInfoTask(this.logger, this.sqlRepo, this.AgentId), new DataTableCleanupTask(this.sqlRepo, this.AgentId)); // Analytics checks temporarily disabled // new AnalyticsCheckProcessorCheck(wmiHelper, this.sqlRepo, dataContext, this.AgentId), // new AnalyticsCheckMemoryCheck(wmiHelper, workspaceRepository, this.logger, this.sqlRepo, dataContext, this.AgentId), manager.Execute(); this.logger.WithClassName().LogVerbose("RunAggregations Called - Success"); } catch (Exception ex) { var message = ex.GetExceptionDetails(); this.logger.WithClassName().LogError($"RunAggregations Called - Failure. Details: {message}"); } }