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); }
public void CreateInstanceShouldThrowExceptinIfInstanceMessageSinkIsNull() { Assert.ThrowsException <ArgumentNullException>(() => { DataCollectionRequestHandler.Create(this.mockCommunicationManager.Object, null); }); }
public DataCollectorMain() : this( new ProcessHelper(), new PlatformEnvironment(), DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink()) ) { }
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); }
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); }
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(); }); }
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); }
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); }
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); }); }
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); }); }
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); }); }
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); }
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(); } }
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(); } }
public void CreateInstanceShouldCreateInstance() { var result = DataCollectionRequestHandler.Create(this.mockCommunicationManager.Object, this.mockMessageSink.Object); Assert.AreEqual(result, DataCollectionRequestHandler.Instance); }