コード例 #1
0
        public static void Setup()
        {
            ObjectFactory.Configure(
                config =>
                {
                    /* common */
                    config.For<IEncodingProvider>().Use<DefaultEncodingProvider>();
                    config.For<IMemoryUnitConverter>().Use<MemoryUnitConverter>();
                    config.For<ITimeProvider>().Use<UTCTimeProvider>();

                    /* collector */
                    config.For<ISystemInformationProvider>().Use<SystemInformationProvider>();
                    config.For<IUrlComponentExtractor>().Use<UrlComponentExtractor>();
                    config.For<IMachineNameProvider>().Use<EnvironmentMachineNameProvider>();

                    /* system performance */
                    config.For<ILogicalDiscInstanceNameProvider>().Use<LogicalDiscInstanceNameProvider>();
                    config.For<ISystemPerformanceDataProvider>().Use<SystemPerformanceDataProvider>();
                    config.For<IProcessorStatusProvider>().Use<ProcessorStatusProvider>();
                    config.For<ISystemStorageStatusProvider>().Use<SystemStorageStatusProvider>();
                    config.For<ISystemMemoryStatusProvider>().Use<SystemMemoryStatusProvider>();

                    /* http status code */
                    config.For<IHttpStatusCodeFetcher>().Use<HttpStatusCodeFetcher>();
                    config.For<IHttpStatusCodeCheckResultProvider>().Use<HttpStatusCodeCheckResultProvider>();

                    /* coordination */
                    config.For<IAgentCoordinationServiceFactory>().Use<AgentCoordinationServiceFactory>();

                    /* queuing */
                    var workQueue = new SystemInformationMessageQueue();
                    var errorQueue = new SystemInformationMessageQueue();
                    var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);
                    config.For<IMessageQueueProvider<SystemInformation>>().Singleton().Use(() => messageQueueProvider);

                    config.For<IMessageQueuePersistence<SystemInformation>>().Use<JSONSystemInformationMessageQueuePersistence>();
                    config.For<IJSONMessageQueuePersistenceConfigurationProvider>().Use<AppConfigJSONMessageQueuePersistenceConfigurationProvider>();

                    config.For<IMessageQueueFeederFactory>().Use<SystemInformationMessageQueueFeederFactory>();
                    config.For<IMessageQueueWorkerFactory>().Use<SystemInformationMessageQueueWorkerFactory>();

                    /* sender configuration */
                    config.For<IAgentControlDefinitionAccessor>().Use<AgentControlDefinitionAccessor>();
                    config.For<IAgentControlDefinitionProvider>().Use<AgentControlDefinitionProvider>();
                    config.For<IAgentControlDefinitionServiceUrlProvider>().Use<AppConfigAgentControlDefinitionServiceUrlProvider>();
                    config.For<IRESTBasedSystemInformationSenderConfigurationProvider>().Use<RESTBasedSystemInformationSenderConfigurationProvider>();

                    /* sender */
                    config.For<IRESTClientFactory>().Use<RESTClientFactory>();
                    config.For<IRESTRequestFactory>().Use<JSONRequestFactory>();
                    config.For<ISystemInformationSender>().Use<RESTBasedSystemInformationSender>();

                    config.For<ISystemInformationDispatchingService>().Use<SystemInformationDispatchingService>();
                });
        }
コード例 #2
0
        public static void Setup()
        {
            ObjectFactory.Configure(
                config =>
            {
                /* common */
                config.For <IEncodingProvider>().Use <DefaultEncodingProvider>();
                config.For <IMemoryUnitConverter>().Use <MemoryUnitConverter>();
                config.For <ITimeProvider>().Use <UTCTimeProvider>();

                /* collector */
                config.For <ISystemInformationProvider>().Use <SystemInformationProvider>();
                config.For <IUrlComponentExtractor>().Use <UrlComponentExtractor>();
                config.For <IMachineNameProvider>().Use <EnvironmentMachineNameProvider>();

                /* system performance */
                config.For <ILogicalDiscInstanceNameProvider>().Use <LogicalDiscInstanceNameProvider>();
                config.For <ISystemPerformanceDataProvider>().Use <SystemPerformanceDataProvider>();
                config.For <IProcessorStatusProvider>().Use <ProcessorStatusProvider>();
                config.For <ISystemStorageStatusProvider>().Use <SystemStorageStatusProvider>();
                config.For <ISystemMemoryStatusProvider>().Use <SystemMemoryStatusProvider>();

                /* http status code */
                config.For <IHttpStatusCodeFetcher>().Use <HttpStatusCodeFetcher>();
                config.For <IHttpStatusCodeCheckResultProvider>().Use <HttpStatusCodeCheckResultProvider>();

                /* coordination */
                config.For <IAgentCoordinationServiceFactory>().Use <AgentCoordinationServiceFactory>();

                /* queuing */
                var workQueue            = new SystemInformationMessageQueue();
                var errorQueue           = new SystemInformationMessageQueue();
                var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);
                config.For <IMessageQueueProvider <SystemInformation> >().Singleton().Use(() => messageQueueProvider);

                config.For <IMessageQueuePersistence <SystemInformation> >().Use <JSONSystemInformationMessageQueuePersistence>();
                config.For <IJSONMessageQueuePersistenceConfigurationProvider>().Use <AppConfigJSONMessageQueuePersistenceConfigurationProvider>();

                config.For <IMessageQueueFeederFactory>().Use <SystemInformationMessageQueueFeederFactory>();
                config.For <IMessageQueueWorkerFactory>().Use <SystemInformationMessageQueueWorkerFactory>();

                /* sender configuration */
                config.For <IAgentControlDefinitionAccessor>().Use <AgentControlDefinitionAccessor>();
                config.For <IAgentControlDefinitionProvider>().Use <AgentControlDefinitionProvider>();
                config.For <IAgentControlDefinitionServiceUrlProvider>().Use <AppConfigAgentControlDefinitionServiceUrlProvider>();
                config.For <IRESTBasedSystemInformationSenderConfigurationProvider>().Use <RESTBasedSystemInformationSenderConfigurationProvider>();

                /* sender */
                config.For <IRESTClientFactory>().Use <RESTClientFactory>();
                config.For <IRESTRequestFactory>().Use <JSONRequestFactory>();
                config.For <ISystemInformationSender>().Use <RESTBasedSystemInformationSender>();

                config.For <ISystemInformationDispatchingService>().Use <SystemInformationDispatchingService>();
            });
        }
        public void Constructor_AllParamatersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();
            var errorQueue = new Mock<IMessageQueue<SystemInformation>>();

            // Act
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue.Object, errorQueue.Object);

            // Assert
            Assert.IsNotNull(messageQueueProvider);
        }
コード例 #4
0
        public void Constructor_AllParamatersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var workQueue  = new Mock <IMessageQueue <SystemInformation> >();
            var errorQueue = new Mock <IMessageQueue <SystemInformation> >();

            // Act
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue.Object, errorQueue.Object);

            // Assert
            Assert.IsNotNull(messageQueueProvider);
        }
        public void ErrorQueueProperty_ReturnsTheSameObjectThatHasBeenPassedToTheConstructor()
        {
            // Arrange
            var workQueue = new Mock<IMessageQueue<SystemInformation>>().Object;
            var errorQueue = new Mock<IMessageQueue<SystemInformation>>().Object;
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            // Act
            var result = messageQueueProvider.ErrorQueue;

            // Assert
            Assert.AreSame(errorQueue, result);
        }
        public void ErrorQueueProperty_IsNotNull()
        {
            // Arrange
            var workQueue = new Mock<IMessageQueue<SystemInformation>>().Object;
            var errorQueue = new Mock<IMessageQueue<SystemInformation>>().Object;
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            // Act
            var result = messageQueueProvider.ErrorQueue;

            // Assert
            Assert.IsNotNull(result);
        }
コード例 #7
0
        public void ErrorQueueProperty_IsNotNull()
        {
            // Arrange
            var workQueue            = new Mock <IMessageQueue <SystemInformation> >().Object;
            var errorQueue           = new Mock <IMessageQueue <SystemInformation> >().Object;
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            // Act
            var result = messageQueueProvider.ErrorQueue;

            // Assert
            Assert.IsNotNull(result);
        }
コード例 #8
0
        public void WorkQueueProperty_ReturnsTheSameObjectThatHasBeenPassedToTheConstructor()
        {
            // Arrange
            var workQueue            = new Mock <IMessageQueue <SystemInformation> >().Object;
            var errorQueue           = new Mock <IMessageQueue <SystemInformation> >().Object;
            var messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            // Act
            var result = messageQueueProvider.WorkQueue;

            // Assert
            Assert.AreSame(workQueue, result);
        }
        public void RunFor10Seconds_SendFailsForAllItems_DispatcherStopsOnlyIfTheQueueIsEmptyAndAllRetryAttempsHaveFailed()
        {
            // Arrange
            int runtimeInMilliseconds = 10 * 1000;
            int itemsReturnedFromSystemInformationProvider = 0;
            int attemptsToSend = 0;

            // prepare system information provider
            var provider = new Mock <ISystemInformationProvider>();

            provider.Setup(p => p.GetSystemInfo()).Returns(() =>
            {
                itemsReturnedFromSystemInformationProvider++;
                return(new SystemInformation {
                    MachineName = Environment.MachineName, Timestamp = DateTime.UtcNow
                });
            });

            // prepare sender
            var sender = new Mock <ISystemInformationSender>();

            sender.Setup(s => s.Send(It.IsAny <SystemInformation>())).Callback(() => { attemptsToSend++; }).Throws(new SendSystemInformationFailedException("Send failed.", null));

            IMessageQueue <SystemInformation>         workQueue            = new SystemInformationMessageQueue();
            IMessageQueue <SystemInformation>         errorQueue           = new SystemInformationMessageQueue();
            IMessageQueueProvider <SystemInformation> messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            IMessageQueueFeeder messageQueueFeeder = new SystemInformationMessageQueueFeeder(provider.Object, workQueue);
            IMessageQueueWorker messageQueueWorker = new SystemInformationMessageQueueWorker(sender.Object, workQueue, errorQueue);

            var agentCoordinationService        = new Mock <IAgentCoordinationService>();
            var agentCoordinationServiceFactory = new Mock <IAgentCoordinationServiceFactory>();

            agentCoordinationServiceFactory.Setup(f => f.GetAgentCoordinationService(It.IsAny <Action>(), It.IsAny <Action>())).Returns(
                agentCoordinationService.Object);

            var messageQueueFeederFactory = new Mock <IMessageQueueFeederFactory>();

            messageQueueFeederFactory.Setup(f => f.GetMessageQueueFeeder()).Returns(messageQueueFeeder);

            var messageQueueWorkerFactory = new Mock <IMessageQueueWorkerFactory>();

            messageQueueWorkerFactory.Setup(f => f.GetMessageQueueWorker()).Returns(messageQueueWorker);

            IMessageQueuePersistence <SystemInformation> messageQueuePersistence =
                new JSONSystemInformationMessageQueuePersistence(this.jsonMessageQueuePersistenceConfigurationProvider, this.encodingProvider);

            var systemInformationDispatchingService = new SystemInformationDispatchingService(
                agentCoordinationServiceFactory.Object,
                messageQueueFeederFactory.Object,
                messageQueueWorkerFactory.Object,
                messageQueueProvider,
                messageQueuePersistence);

            // Act
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var dispatcher = new Task(systemInformationDispatchingService.Start);

            dispatcher.Start();

            Thread.Sleep(runtimeInMilliseconds);
            systemInformationDispatchingService.Stop();

            Task.WaitAll(new[] { dispatcher });

            stopwatch.Stop();

            // Assert
            int queueSize = workQueue.GetSize();

            Console.WriteLine(
                "After a runtime of {0} milliseconds the dispatcher has been stopped with {1} items in queue. It took {2} milliseconds until the queue worker stopped sending out all queue items (Attempts To Send: {3}).",
                runtimeInMilliseconds,
                itemsReturnedFromSystemInformationProvider,
                stopwatch.ElapsedMilliseconds,
                attemptsToSend);

            Assert.AreEqual(0, queueSize);
        }
        public void RunFor10Seconds_SendFailsForAllItems_DispatcherStopsOnlyIfTheQueueIsEmptyAndAllRetryAttempsHaveFailed()
        {
            // Arrange
            int runtimeInMilliseconds = 10 * 1000;
            int itemsReturnedFromSystemInformationProvider = 0;
            int attemptsToSend = 0;

            // prepare system information provider
            var provider = new Mock<ISystemInformationProvider>();
            provider.Setup(p => p.GetSystemInfo()).Returns(() =>
                {
                    itemsReturnedFromSystemInformationProvider++;
                    return new SystemInformation { MachineName = Environment.MachineName, Timestamp = DateTime.UtcNow };
                });

            // prepare sender
            var sender = new Mock<ISystemInformationSender>();
            sender.Setup(s => s.Send(It.IsAny<SystemInformation>())).Callback(() => { attemptsToSend++; }).Throws(new SendSystemInformationFailedException("Send failed.", null));

            IMessageQueue<SystemInformation> workQueue = new SystemInformationMessageQueue();
            IMessageQueue<SystemInformation> errorQueue = new SystemInformationMessageQueue();
            IMessageQueueProvider<SystemInformation> messageQueueProvider = new SystemInformationMessageQueueProvider(workQueue, errorQueue);

            IMessageQueueFeeder messageQueueFeeder = new SystemInformationMessageQueueFeeder(provider.Object, workQueue);
            IMessageQueueWorker messageQueueWorker = new SystemInformationMessageQueueWorker(sender.Object, workQueue, errorQueue);

            var agentCoordinationService = new Mock<IAgentCoordinationService>();
            var agentCoordinationServiceFactory = new Mock<IAgentCoordinationServiceFactory>();
            agentCoordinationServiceFactory.Setup(f => f.GetAgentCoordinationService(It.IsAny<Action>(), It.IsAny<Action>())).Returns(
                agentCoordinationService.Object);

            var messageQueueFeederFactory = new Mock<IMessageQueueFeederFactory>();
            messageQueueFeederFactory.Setup(f => f.GetMessageQueueFeeder()).Returns(messageQueueFeeder);

            var messageQueueWorkerFactory = new Mock<IMessageQueueWorkerFactory>();
            messageQueueWorkerFactory.Setup(f => f.GetMessageQueueWorker()).Returns(messageQueueWorker);

            IMessageQueuePersistence<SystemInformation> messageQueuePersistence =
                new JSONSystemInformationMessageQueuePersistence(this.jsonMessageQueuePersistenceConfigurationProvider, this.encodingProvider);

            var systemInformationDispatchingService = new SystemInformationDispatchingService(
                agentCoordinationServiceFactory.Object,
                messageQueueFeederFactory.Object,
                messageQueueWorkerFactory.Object,
                messageQueueProvider,
                messageQueuePersistence);

            // Act
            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var dispatcher = new Task(systemInformationDispatchingService.Start);
            dispatcher.Start();

            Thread.Sleep(runtimeInMilliseconds);
            systemInformationDispatchingService.Stop();

            Task.WaitAll(new[] { dispatcher });

            stopwatch.Stop();

            // Assert
            int queueSize = workQueue.GetSize();
            Console.WriteLine(
                "After a runtime of {0} milliseconds the dispatcher has been stopped with {1} items in queue. It took {2} milliseconds until the queue worker stopped sending out all queue items (Attempts To Send: {3}).",
                runtimeInMilliseconds,
                itemsReturnedFromSystemInformationProvider,
                stopwatch.ElapsedMilliseconds,
                attemptsToSend);

            Assert.AreEqual(0, queueSize);
        }