예제 #1
0
        /// <summary>
        /// 启动压力测试
        /// </summary>
        public void DoStart()
        {
            StartEnable = false;
            LogHelper.Logger.Info("开始启动");
            ExcelHelper excel = new ExcelHelper(@"defaultvalue.xlsx");

            defaultTable = excel.ExcelToDataTable("Sheet1", true);
            IsWork       = false;
            ReplyRateInfos.Clear();
            caseList.Clear();
            IsWork = true;
            foreach (var item in CaseGroups)
            {
                if (item.Check == 1)
                {
                    Task task = Task.Factory.StartNew(() =>
                    {
                        Work(item);
                    });
                }
            }
        }
예제 #2
0
 private void GetAndOpenCase()
 {
     try
     {
         if (_LoadCase != null)
         {
             System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
             ofd.Filter           = "(*.xml)|*.xml";
             ofd.InitialDirectory = Environment.CurrentDirectory;
             ofd.Multiselect      = false;
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 caseFilePath = ofd.FileName;
                 ReplyRateInfos.Clear();
             }
         }
         DoCaseLoad();
     }
     catch (Exception error)
     {
         this.Dispatcher.Invoke(() => { MessageBox.Show($"{error.Message} \r\n {error.StackTrace}"); });
     }
 }
예제 #3
0
        /// <summary>
        /// 死循环处理队列里的应答包
        /// </summary>
        private void DealRespPackage()
        {
            Task.Run(
                () =>
            {
                while (true)
                {
                    RespDataPackageModel RDP = new RespDataPackageModel();
                    if (RespDataPackageModel.DataQueue.TryDequeue(out RDP))
                    {
                        Task.Run(
                            () =>
                        {
                            int hSend = RDP.hSend;
                            LDFastMessageAdapter lpFastMsg = RDP.lpFastMsg;

                            DateTime timeStamp = DateTime.Now;
                            ReqDTO req         = null;
                            lock (ReqLock)
                            {
                                req = ReqAllList.FirstOrDefault(o => o.SendID == hSend);
                                ReqAllList.Remove(req);
                            }
                            if (req != null && lpFastMsg != null)
                            {
                                Interlocked.Increment(ref req.CaseData.RecCount);        //递增应答数量
                                if (req.CaseData.SendCount - req.CaseData.RecCount <= req.CaseData.DownStage)
                                {
                                    req.CaseData.ResetEvent.Set();
                                }
                                //功能号
                                string strFunCode = lpFastMsg.GetString(LDSdkTag.LDTAG_FUNCID);
                                /***********************************郑建翔新加部分,用于计算应答频率***************************************/
                                lock (lockFlag)
                                {
                                    //如果集合中不存这个功能号则添加
                                    if (ReplyRateInfos.Count(i => i.functionId == strFunCode) == 0)
                                    {
                                        DateTime startTime = DateTime.Now;
                                        this.Dispatcher.Invoke(() => ReplyRateInfos.Add(new ReplyRateModel(strFunCode, startTime)));
                                        /*****************************接收到每个功能号的第一条应答时,保存应答信息**************************/
                                        //文件保存路径
                                        string savePath = Environment.CurrentDirectory + @"\ScriptOutPut.txt";
                                        LogAnswerPackageInfo.OutPutResult(lpFastMsg, savePath);
                                    }
                                    else
                                    {
                                        //如果集合中已经存在这个功能号,开始更新并计算数据
                                        ReplyRateModel replyInfo = ReplyRateInfos.FirstOrDefault(i => i.functionId == strFunCode);
                                        replyInfo.timeStamp      = timeStamp;
                                        replyInfo.replyCount++;
                                    }
                                }
                                /*******************************************修改结束*********************************************************/


                                int iErrorNo = lpFastMsg.GetInt32(LDSdkTag.LDTAG_ERRORNO);
                                // LogHelper.Logger.Info("系统错误号:" + iErrorNo);
                                if (iErrorNo != 0)
                                {
                                    //如果是中间件返回的错误
                                    // Interlocked.Increment(ref req.CaseData.RecFailCount);//递增应答失败数量
                                }
                                else
                                {
                                    string strErrorCode = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_CODE_STR);
                                    //LogHelper.Logger.Info("业务错误号:" + strErrorCode);
                                    Interlocked.Increment(ref req.CaseData.RecOkCount);        //递增应答成功数量
                                    if (!"0".Equals(strErrorCode))
                                    {
                                        Interlocked.Increment(ref req.CaseData.RecFailCount);        //递增应答失败数量

                                        string strErrorInfo   = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_INFO_STR);
                                        string strErrorPrompt = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_PROMPT_STR);
                                        string logInfo        = string.Format("功能号[{0}],errorCode[{1}],errorinfo[{2}],errorprompt[{3}]", strFunCode, strErrorCode, strErrorInfo, strErrorPrompt);
                                        LogHelper.Logger.Error(logInfo);
                                    }
                                    //else
                                    //{
                                    //    Interlocked.Increment(ref req.CaseData.RecOkCount);//递增应答成功数量
                                    //}
                                }
                            }
                            if (lpFastMsg != null)
                            {
                                lpFastMsg.FreeMsg();
                            }
                        }
                            );
                    }
                    //else
                    //{
                    //    pauseFlag.WaitOne(10);
                    //}
                }
            }
                );
        }