Ejemplo n.º 1
0
 public async void RunAsync(IPerformanceCounterGroup[] counterGroups)
 {
     foreach (var counterGroup in counterGroups)
     {
         var engine = new CollectorEngine(counterGroup, _sendBusiness, _tagLoader);
         await engine.StartAsync();
         engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
     }
 }
Ejemplo n.º 2
0
        public async void Should_send_data_to_database_when_started()
        {
            //Arrange
            var databaseName = "AA";
            var performanceCounterGroupMock = new Mock<IPerformanceCounterGroup>(MockBehavior.Strict);
            performanceCounterGroupMock.SetupGet(x => x.SecondsInterval).Returns(1);
            performanceCounterGroupMock.SetupGet(x => x.Name).Returns("A");
            performanceCounterGroupMock.SetupGet(x => x.PerformanceCounterInfos).Returns(new List<IPerformanceCounterInfo> { new PerformanceCounterInfo(string.Empty, new PerformanceCounter("Processor", "% Processor Time", "_Total")) });
            var sendBusinessMock = new Mock<ISendBusiness>(MockBehavior.Strict);
            var tagLaoderMock = new Mock<ITagLoader>(MockBehavior.Strict);
            var collectorEngine = new CollectorEngine(performanceCounterGroupMock.Object, sendBusinessMock.Object, tagLaoderMock.Object);

            //Act
            await collectorEngine.StartAsync();

            //Assert
            sendBusinessMock.Verify(x => x.Enqueue(It.IsAny<Point[]>()), Times.Once);
        }
Ejemplo n.º 3
0
        public async void Should_not_send_data_to_database_when_no_SecondsInterval()
        {
            //Arrange
            var databaseName = "AA";
            var performanceCounterGroupMock = new Mock<IPerformanceCounterGroup>(MockBehavior.Strict);
            performanceCounterGroupMock.SetupGet(x => x.SecondsInterval).Returns(0);
            performanceCounterGroupMock.SetupGet(x => x.Name).Returns("A");
            performanceCounterGroupMock.SetupGet(x => x.PerformanceCounterInfos).Returns(new List<IPerformanceCounterInfo> { });
            var sendBusinessMock = new Mock<ISendBusiness>(MockBehavior.Strict);
            var tagLaoderMock = new Mock<ITagLoader>(MockBehavior.Strict);
            var collectorEngine = new CollectorEngine(performanceCounterGroupMock.Object, sendBusinessMock.Object, tagLaoderMock.Object);

            //Act
            await collectorEngine.StartAsync();

            //Assert
            sendBusinessMock.Verify(x => x.Enqueue(It.IsAny<Point[]>()), Times.Never);
        }
        public void Should_not_send_data_to_database_if_there_are_no_counters()
        {
            //Arrange
            string databaseName = "AA";
            var performanceCounterGroupMock = new Mock<IPerformanceCounterGroup>(MockBehavior.Strict);
            performanceCounterGroupMock.SetupGet(x => x.SecondsInterval).Returns(1);
            performanceCounterGroupMock.SetupGet(x => x.Name).Returns("A");
            performanceCounterGroupMock.SetupGet(x => x.PerformanceCounterInfos).Returns(new List<IPerformanceCounterInfo> { });
            performanceCounterGroupMock.SetupGet(x => x.Tags).Returns(new ITag[] { });
            var sendBusinessMock = new Mock<ISendBusiness>(MockBehavior.Strict);
            sendBusinessMock.Setup(x => x.Enqueue(It.IsAny<Point[]>()));
            var tagLaoderMock = new Mock<ITagLoader>(MockBehavior.Strict);
            tagLaoderMock.Setup(x => x.GetGlobalTags()).Returns(new[] { Mock.Of<ITag>(x => x.Name == "B") });
            var collectorEngine = new CollectorEngine(performanceCounterGroupMock.Object, sendBusinessMock.Object, tagLaoderMock.Object);

            //Act
            var response = collectorEngine.CollectRegisterCounterValuesAsync().Result;

            //Assert
            tagLaoderMock.Verify(x => x.GetGlobalTags(), Times.Once);
            sendBusinessMock.Verify(x => x.Enqueue(It.IsAny<Point[]>()), Times.Once);
            Assert.That(response, Is.EqualTo(0));
        }
Ejemplo n.º 5
0
 public async Task<int> CollectAssync(IPerformanceCounterGroup counterGroup)
 {
     var engine = new CollectorEngine(counterGroup, _sendBusiness, _tagLoader);
     engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
     return await engine.CollectRegisterCounterValuesAsync();
 }