예제 #1
0
파일: ThreadAgent.cs 프로젝트: cjus/mcww
 public ThreadAgent(ThreadAgentInfo threadInfo)
 {
     this.threadInfo = threadInfo;
 }
예제 #2
0
파일: Tester.cs 프로젝트: cjus/mcww
        public void ExecuteSingleTest(string testName)
        {
            currentTestName = testName;
            TreeNode node = testTree.GetSelectedNodesParent();
            int threadCount = 0;
            int threadIterations = 0;
            int threadDelay = 0;
            int threadDelayRange1 = -1;
            int threadDelayRange2 = -1;
            int threadTimeout = 0;
            string messageType = "";
            string messageCommand = "";
            string messageHeaders = "";
            string messageAddr = "";
            string messagePort = "";
            string messageContentType = "";
            byte[]messagePayload = null;

            string taskName = node.Text;

            TreeNode nodeThreads = node.Nodes[0];
            TreeNode nodeMessage = node.Nodes[1];

            int nodeCount = node.Nodes.Count;
            for (int i=0; i< nodeCount; i++)
            {
                if (node.Nodes[i].Text == "Threads")
                {
                    foreach (TreeNode threadChildNode in node.Nodes[i].Nodes)
                    {
                        if (threadChildNode.Text.IndexOf("Count:") != -1)
                            threadCount = Convert.ToInt32(threadChildNode.Tag.ToString());
                        else if (threadChildNode.Text.IndexOf("Iterations:") != -1)
                            threadIterations = Convert.ToInt32(threadChildNode.Tag.ToString());
                        else if (threadChildNode.Text.IndexOf("Delay:") != -1)
                        {
                            Regex expr = new Regex(@"-");
                            string []array = expr.Split(threadChildNode.Tag.ToString());
                            if (array.Length == 2)
                            {
                                threadDelay = -1;
                                threadDelayRange1 = Convert.ToInt32(array[0].ToString().Trim());
                                threadDelayRange2 = Convert.ToInt32(array[1].ToString().Trim());
                            }
                            else
                            {
                                threadDelay = Convert.ToInt32(threadChildNode.Tag.ToString().Trim());
                                threadDelayRange1 = -1;
                                threadDelayRange2 = -1;
                            }
                        }
                        else if (threadChildNode.Text.IndexOf("Timeout:") != -1)
                            threadTimeout = Convert.ToInt32(threadChildNode.Tag.ToString());
                    }
                }
                else if (node.Nodes[i].Text == "Message")
                {
                    foreach (TreeNode messageChildNode in node.Nodes[i].Nodes)
                    {
                        if (messageChildNode.Text.IndexOf("Command:") != -1)
                            messageCommand = messageChildNode.Tag.ToString();
                        else if (messageChildNode.Text.IndexOf("Headers:") != -1)
                            messageHeaders = messageChildNode.Tag.ToString();
                        else if (messageChildNode.Text.IndexOf("Address:") != -1)
                            messageAddr = messageChildNode.Tag.ToString();
                        else if (messageChildNode.Text.IndexOf("Port:") != -1)
                            messagePort = messageChildNode.Tag.ToString();
                        else if (messageChildNode.Text.IndexOf("Type:") != -1)
                            messageType = messageChildNode.Tag.ToString();
                        else if (messageChildNode.Text.IndexOf("Payload:") != -1)
                        {
                            TestTreeNodeTag tag = messageChildNode.Tag as TestTreeNodeTag;
                            if (tag != null)
                            {
                                Payload payload = tag.userData as Payload;
                                if (payload != null)
                                {
                                    messageContentType = payload.MIMEType;
                                    messagePayload = payload.buffer;
                                }
                            }
                        }
                    }
                }
            }

            if (messageType.IndexOf("TCP/HTTP") != -1)
            {
                Url url = new Url(messageCommand);
                if (url.Protocol.Length != 0)
                {
                    try
                    {
                        IPHostEntry hostInfo = Dns.Resolve(url.Host);
                        IPAddress[] address = hostInfo.AddressList;
                        messageAddr = address[0].ToString();
                        messagePort = (url.Port == 0) ? "80" : url.Port.ToString();
                        //messageCommand = url.Protocol + "://" + url.Host + "/" + url.Path;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(null, ex.Message, "MCWhirlWind",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }

            // remove all items
            foreach (ListViewItem item in listView.Items)
                item.Remove();

            testDataList.Clear();
            threads = new ArrayList();
            Random rand = new Random();
            for (int i=0; i<threadCount; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Text = i.ToString();		// 0 #
                item.SubItems.Add(taskName);	// 1 TaskName
                item.SubItems.Add("0");			// 2 %Complete
                item.SubItems.Add("0");			// 3 MinRes
                item.SubItems.Add("0");			// 4 MaxRes
                item.SubItems.Add("0");			// 5 AvgRes
                item.SubItems.Add("0");			// 6 Pass
                item.SubItems.Add("0");			// 7 Fail
                item.SubItems.Add("Pending..."); // 8 Status Message

                listView.Items.Add(item);

                ThreadAgentInfo threadInfo = new ThreadAgentInfo();
                item.Tag = threadInfo;

                threadInfo.threadCount = threadCount;
                threadInfo.threadIterations = threadIterations;
                if (threadDelay == -1)
                    threadInfo.threadDelay = rand.Next(threadDelayRange1, threadDelayRange2);
                else
                    threadInfo.threadDelay = threadDelay;
                threadInfo.threadTimeout = threadTimeout;
                threadInfo.messageType = messageType;
                threadInfo.messageCommand = messageCommand;
                threadInfo.messageHeaders = messageHeaders;
                threadInfo.messageAddr = messageAddr;
                threadInfo.messagePort = messagePort;
                threadInfo.messageContentType = messageContentType;
                threadInfo.messagePayload = messagePayload;
                threadInfo.item = item;
                threadInfo.tester = this;
                threadInfo.testData = new TestDataElement();
                threadInfo.testData.taskName = node.Text;

                testDataList.Add(threadInfo.testData);
                threadInfo.msgLog = new ThreadAgentMsgLog();
                threadInfo.msgLog.goodSendHeaders = "";
                threadInfo.msgLog.goodRecvHeaders = "";
                threadInfo.msgLog.badRecvHeaders = "";
                ThreadAgent threadAgent = new ThreadAgent(threadInfo);
                Thread t = new Thread(new ThreadStart(threadAgent.Run));
                threads.Add(t);
                t.Start();
            }

            Thread.Sleep(0);

            totalTasks = threadCount;
            completeTasks = 0;
        }