Exemplo n.º 1
0
        public void ProcessRequestsShouldProcessRequests()
        {
            var message = new Message();

            message.MessageType = MessageType.BeforeTestRunStart;
            message.Payload     = "settingsXml";

            this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(message).Returns(new Message()
            {
                MessageType = MessageType.AfterTestRunEnd, Payload = "false"
            });

            this.mockDataCollectionManager.Setup(x => x.SessionStarted()).Returns(true);

            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            requestHandler.ProcessRequests();

            mockDataCollectionTestCaseEventHandler.Verify(x => x.InitializeCommunication(), Times.Once);
            mockDataCollectionTestCaseEventHandler.Verify(x => x.WaitForRequestHandlerConnection(It.IsAny <int>()), Times.Once);
            mockDataCollectionTestCaseEventHandler.Verify(x => x.ProcessRequests(), Times.Once);

            mockDataCollectionManager.Verify(x => x.SessionStarted(), Times.Once);

            this.mockCommunicationManager.Verify(x => x.SendMessage(MessageType.BeforeTestRunStartResult, It.IsAny <BeforeTestRunStartResult>()), Times.Once);

            // Verify AfterTestRun events.
            mockDataCollectionManager.Verify(x => x.SessionEnded(It.IsAny <bool>()), Times.Once);
            this.mockCommunicationManager.Verify(x => x.SendMessage(MessageType.AfterTestRunEndResult, It.IsAny <Collection <AttachmentSet> >()), Times.Once);
        }
Exemplo n.º 2
0
 public void CreateInstanceShouldThrowExceptinIfInstanceMessageSinkIsNull()
 {
     Assert.ThrowsException <ArgumentNullException>(() =>
     {
         DataCollectionRequestHandler.Create(this.mockCommunicationManager.Object, null);
     });
 }
Exemplo n.º 3
0
 public DataCollectorMain() :
     this(
         new ProcessHelper(),
         new PlatformEnvironment(),
         DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink())
         )
 {
 }
Exemplo n.º 4
0
        public void WaitForRequestSenderConnectionShouldInvokeCommunicationManager()
        {
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            requestHandler.WaitForRequestSenderConnection(0);

            this.mockCommunicationManager.Verify(x => x.WaitForServerConnection(It.IsAny <int>()), Times.Once);
        }
Exemplo n.º 5
0
        public void InitializeCommunicationShouldInitializeCommunication()
        {
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            requestHandler.InitializeCommunication(123);

            this.mockCommunicationManager.Verify(x => x.SetupClientAsync(123), Times.Once);
        }
Exemplo n.º 6
0
        public void ProcessRequestsShouldThrowExceptionIfThrownByCommunicationManager()
        {
            this.mockCommunicationManager.Setup(x => x.ReceiveMessage()).Throws <Exception>();

            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            Assert.ThrowsException <Exception>(() => { requestHandler.ProcessRequests(); });
        }
Exemplo n.º 7
0
        public void DisposeShouldCloseCommunicationChannel()
        {
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            requestHandler.Dispose();

            this.mockCommunicationManager.Verify(x => x.StopClient(), Times.Once);
        }
Exemplo n.º 8
0
        public void SendDataCollectionMessageShouldSendMessageToCommunicationManager()
        {
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);
            var message        = new DataCollectionMessageEventArgs(TestMessageLevel.Error, "message");

            requestHandler.SendDataCollectionMessage(message);

            this.mockCommunicationManager.Verify(x => x.SendMessage(MessageType.DataCollectionMessage, message), Times.Once);
        }
Exemplo n.º 9
0
        public void WaitForRequestSenderConnectionShouldThrowExceptionIfThrownByCommunicationManager()
        {
            this.mockCommunicationManager.Setup(x => x.WaitForServerConnection(It.IsAny <int>())).Throws <Exception>();
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            Assert.ThrowsException <Exception>(() =>
            {
                requestHandler.WaitForRequestSenderConnection(0);
            });
        }
Exemplo n.º 10
0
        public void InitializeCommunicationShouldThrowExceptionIfThrownByCommunicationManager()
        {
            this.mockCommunicationManager.Setup(x => x.SetupClientAsync(It.IsAny <int>())).Throws <Exception>();
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);

            Assert.ThrowsException <Exception>(() =>
            {
                requestHandler.InitializeCommunication(123);
            });
        }
Exemplo n.º 11
0
        public void SendDataCollectionMessageShouldThrowExceptionIfThrownByCommunicationManager()
        {
            this.mockCommunicationManager.Setup(x => x.SendMessage(MessageType.DataCollectionMessage, It.IsAny <DataCollectionMessageEventArgs>())).Throws <Exception>();
            var requestHandler = new DataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object);
            var message        = new DataCollectionMessageEventArgs(TestMessageLevel.Error, "message");

            Assert.ThrowsException <Exception>(() =>
            {
                requestHandler.SendDataCollectionMessage(message);
            });
        }
Exemplo n.º 12
0
        private static void Run(string[] args)
        {
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args);

            // Setup logging if enabled
            string logFile;

            if (argsDictionary.TryGetValue(LogFileArgument, out logFile))
            {
                EqtTrace.InitializeVerboseTrace(logFile);
            }

            // Attach to exit of parent process
            var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument);

            EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId);

            var processHelper = new ProcessHelper();

            processHelper.SetExitCallback(
                parentProcessId,
                (obj) =>
            {
                EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId);
                Environment.Exit(1);
            });

            // Get server port and initialize communication.
            string portValue;
            int    port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0;

            if (port <= 0)
            {
                throw new ArgumentException("Incorrect/No Port number");
            }

            var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink());

            requestHandler.InitializeCommunication(port);

            // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized
            if (!string.IsNullOrEmpty(EqtTrace.LogFile))
            {
                requestHandler.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile)));
            }

            // Start processing async in a different task
            EqtTrace.Info("DataCollector: Start Request Processing.");
            var processingTask = StartProcessingAsync(requestHandler);

            // Wait for processing to complete.
            Task.WaitAny(processingTask);
        }
Exemplo n.º 13
0
        private static void Run()
        {
            var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink());

            requestHandler.InitializeCommunication(port);

            // Wait for the connection to the sender and start processing requests from sender
            if (requestHandler.WaitForRequestSenderConnection(ClientListenTimeOut))
            {
                requestHandler.ProcessRequests();
            }
            else
            {
                EqtTrace.Info("DataCollector: RequestHandler timed out while connecting to the Sender.");
                requestHandler.Close();
                throw new TimeoutException();
            }
        }
Exemplo n.º 14
0
        private static void Run(string[] args)
        {
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args);
            var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink());

            // Setup logging if enabled
            string logFile;

            if (argsDictionary.TryGetValue(LogFileArgument, out logFile))
            {
                EqtTrace.InitializeVerboseTrace(logFile);
            }

            // Get server port and initialize communication.
            string portValue;
            int    port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0;

            if (port <= 0)
            {
                throw new ArgumentException("Incorrect/No Port number");
            }

            requestHandler.InitializeCommunication(port);

            // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized
            if (!string.IsNullOrEmpty(EqtTrace.LogFile))
            {
                requestHandler.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile)));
            }

            // Wait for the connection to the sender and start processing requests from sender
            if (requestHandler.WaitForRequestSenderConnection(ClientListenTimeOut))
            {
                requestHandler.ProcessRequests();
            }
            else
            {
                EqtTrace.Info("DataCollector: RequestHandler timed out while connecting to the Sender.");
                requestHandler.Close();
                throw new TimeoutException();
            }
        }
Exemplo n.º 15
0
        public void CreateInstanceShouldCreateInstance()
        {
            var result = DataCollectionRequestHandler.Create(this.mockCommunicationManager.Object, this.mockMessageSink.Object);

            Assert.AreEqual(result, DataCollectionRequestHandler.Instance);
        }