/// <summary> /// Starts the interop test client running. This causes it to start listening for incoming test invites. /// </summary> private void Start() { log.Info("private void Start(): called"); // Use a class path scanner to find all the interop test case implementations. ArrayList testCaseClasses = new ArrayList(); // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true); // Hard code the test classes till the classpath scanner is fixed. testCaseClasses.Add(typeof(TestCase1DummyRun)); testCaseClasses.Add(typeof(TestCase2BasicP2P)); testCaseClasses.Add(typeof(TestCase3BasicPubSub)); testCaseClasses.Add(typeof(TestCase4P2PMessageSize)); testCaseClasses.Add(typeof(TestCase5PubSubMessageSize)); // Create all the test case implementations and index them by the test names. foreach (Type testClass in testCaseClasses) { InteropClientTestCase testCase = (InteropClientTestCase)Activator.CreateInstance(testClass); testCases.Add(testCase.GetName(), testCase); log.Info("Found test case: " + testClass); } // Open a connection to communicate with the coordinator on. log.Info("brokerUrl = " + brokerUrl); IConnection connection = CreateConnection(brokerUrl, virtualHost); channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); // Set this up to listen for control messages. string responseQueueName = channel.GenerateUniqueName(); channel.DeclareQueue(responseQueueName, false, true, true); channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control." + clientName); channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control"); IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) .Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); // Create a publisher to send replies with. publisherBuilder = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.DIRECT); // Start listening for incoming control messages. connection.Start(); Console.WriteLine("Test client " + clientName + " ready to receive test control messages..."); }
/// <summary> /// Handles all incoming control messages. /// </summary> /// /// <param name="message"> The incoming message. </param> public void OnMessage(IMessage message) { log.Info("public void OnMessage(IMessage message = " + message + "): called"); try { string controlType = message.Headers.GetString("CONTROL_TYPE"); string testName = message.Headers.GetString("TEST_NAME"); // Check if the message is a test invite. if ("INVITE" == controlType) { string testCaseName = message.Headers.GetString("TEST_NAME"); // Flag used to indicate that an enlist should be sent. Only enlist to compulsory invites or invites // for which test cases exist. bool enlist = false; if (testCaseName != null) { log.Info("Got an invite to test: " + testCaseName); // Check if the requested test case is available. InteropClientTestCase testCase = (InteropClientTestCase)testCases[testCaseName]; if (testCase != null) { // Make the requested test case the current test case. currentTestCase = testCase; enlist = true; } } else { log.Info("Got a compulsory invite."); enlist = true; } log.Info("enlist = " + enlist); if (enlist) { // Reply with the client name in an Enlist message. IMessage enlistMessage = channel.CreateMessage(); enlistMessage.Headers.SetString("CONTROL_TYPE", "ENLIST"); enlistMessage.Headers.SetString("CLIENT_NAME", clientName); enlistMessage.Headers.SetString("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName); enlistMessage.CorrelationId = message.CorrelationId; Send(enlistMessage, message.ReplyToRoutingKey); } } else if ("ASSIGN_ROLE" == controlType) { // Assign the role to the current test case. string roleName = message.Headers.GetString("ROLE"); log.Info("Got a role assignment to role: " + roleName); Roles role; if (roleName == "SENDER") { role = Roles.SENDER; } else { role = Roles.RECEIVER; } currentTestCase.AssignRole(role, message); // Reply by accepting the role in an Accept Role message. IMessage acceptRoleMessage = channel.CreateMessage(); acceptRoleMessage.Headers.SetString("CONTROL_TYPE", "ACCEPT_ROLE"); acceptRoleMessage.CorrelationId = message.CorrelationId; Send(acceptRoleMessage, message.ReplyToRoutingKey); } else if ("START" == controlType || "STATUS_REQUEST" == controlType) { if ("START" == controlType) { log.Info("Got a start notification."); // Start the current test case. currentTestCase.Start(); } else { log.Info("Got a status request."); } // Generate the report from the test case and reply with it as a Report message. IMessage reportMessage = currentTestCase.GetReport(channel); reportMessage.Headers.SetString("CONTROL_TYPE", "REPORT"); reportMessage.CorrelationId = message.CorrelationId; Send(reportMessage, message.ReplyToRoutingKey); } else if ("TERMINATE" == controlType) { Console.WriteLine("Received termination instruction from coordinator."); // Is a cleaner shutdown needed? System.Environment.Exit(1); } else { // Log a warning about this but otherwise ignore it. log.Warn("Got an unknown control message, controlType = " + controlType + ", message = " + message); } } catch (QpidException e) { // Log a warning about this, but otherwise ignore it. log.Warn("A QpidException occurred whilst handling a message."); log.Info("Got QpidException whilst handling message: " + message, e); } }
/// <summary> /// Handles all incoming control messages. /// </summary> /// /// <param name="message"> The incoming message. </param> public void OnMessage(IMessage message) { log.Info("public void OnMessage(IMessage message = " + message + "): called"); try { string controlType = message.Headers.GetString("CONTROL_TYPE"); string testName = message.Headers.GetString("TEST_NAME"); // Check if the message is a test invite. if ("INVITE" == controlType) { string testCaseName = message.Headers.GetString("TEST_NAME"); // Flag used to indicate that an enlist should be sent. Only enlist to compulsory invites or invites // for which test cases exist. bool enlist = false; if (testCaseName != null) { log.Info("Got an invite to test: " + testCaseName); // Check if the requested test case is available. InteropClientTestCase testCase = (InteropClientTestCase)testCases[testCaseName]; if (testCase != null) { // Make the requested test case the current test case. currentTestCase = testCase; enlist = true; } } else { log.Info("Got a compulsory invite."); enlist = true; } log.Info("enlist = " + enlist); if (enlist) { // Reply with the client name in an Enlist message. IMessage enlistMessage = channel.CreateMessage(); enlistMessage.Headers.SetString("CONTROL_TYPE", "ENLIST"); enlistMessage.Headers.SetString("CLIENT_NAME", clientName); enlistMessage.Headers.SetString("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName); enlistMessage.CorrelationId = message.CorrelationId; Send(enlistMessage, message.ReplyToRoutingKey); } } else if ("ASSIGN_ROLE" == controlType) { // Assign the role to the current test case. string roleName = message.Headers.GetString("ROLE"); log.Info("Got a role assignment to role: " + roleName); Roles role; if (roleName == "SENDER") { role = Roles.SENDER; } else { role = Roles.RECEIVER; } currentTestCase.AssignRole(role, message); // Reply by accepting the role in an Accept Role message. IMessage acceptRoleMessage = channel.CreateMessage(); acceptRoleMessage.Headers.SetString("CONTROL_TYPE", "ACCEPT_ROLE"); acceptRoleMessage.CorrelationId = message.CorrelationId; Send(acceptRoleMessage, message.ReplyToRoutingKey); } else if ("START" == controlType || "STATUS_REQUEST" == controlType) { if ("START" == controlType) { log.Info("Got a start notification."); // Start the current test case. currentTestCase.Start(); } else { log.Info("Got a status request."); } // Generate the report from the test case and reply with it as a Report message. IMessage reportMessage = currentTestCase.GetReport(channel); reportMessage.Headers.SetString("CONTROL_TYPE", "REPORT"); reportMessage.CorrelationId = message.CorrelationId; Send(reportMessage, message.ReplyToRoutingKey); } else if ("TERMINATE" == controlType) { Console.WriteLine("Received termination instruction from coordinator."); // Is a cleaner shutdown needed? System.Environment.Exit(1); } else { // Log a warning about this but otherwise ignore it. log.Warn("Got an unknown control message, controlType = " + controlType + ", message = " + message); } } catch (QpidException e) { // Log a warning about this, but otherwise ignore it. log.Warn("A QpidException occurred whilst handling a message."); log.Info("Got QpidException whilst handling message: " + message, e); } }