Exemplo n.º 1
0
        public bool HandleMessage(MessageBase message)
        {
            bool          state         = false;
            RmtGenMessage rmtGenMessage = (RmtGenMessage)message;

            if (rmtGenMessage.Params["MsgType"].Equals("Success"))
            {
                state = true;
                TestGenEventInfo genEventInfo = new TestGenEventInfo(rmtGenMessage.Id, TestGenState.GenerationOver,
                                                                     rmtGenMessage.Time);
                _globalInfo.EventQueue.Enqueue(genEventInfo);
                _runtimeContainers[rmtGenMessage.Id].HostReady = true;
            }
            else if (rmtGenMessage.Params["MsgType"].Equals("Failed"))
            {
                state = false;
                TestGenEventInfo genEventInfo = new TestGenEventInfo(rmtGenMessage.Id, TestGenState.Error,
                                                                     rmtGenMessage.Time)
                {
                    ErrorInfo = rmtGenMessage.Params["FailedInfo"]
                };
                _globalInfo.EventQueue.Enqueue(genEventInfo);
                FreeHost(rmtGenMessage.Id);
            }
            // 如果所有的host都已经ready,则释放主线程等待生成结束的锁
            if (_runtimeContainers.Values.All(item => item.HostReady))
            {
                _blockHandle.Free(Constants.RmtGenState);
            }
            return(state);
        }
Exemplo n.º 2
0
 private ISessionGenerationInfo SetGenerationInfo(TestGenEventInfo eventInfo, GenerationStatus status)
 {
     _generationInfo.Status = status;
     foreach (int sequenceIndex in _generationInfo.SequenceStatus.Keys)
     {
         _generationInfo.SequenceStatus[sequenceIndex] = status;
     }
     return(_generationInfo);
 }
Exemplo n.º 3
0
        // 完成的功能:执行结束后构造TestInstanceData并持久化,转发测试消息和事件到下级
        #region 事件和消息处理

        private void TestGenEventProcess(EventInfoBase eventInfo)
        {
            TestGenEventInfo testGenEventInfo = (TestGenEventInfo)eventInfo;

            switch (testGenEventInfo.GenState)
            {
            case TestGenState.StartGeneration:
                if (RuntimeState.Idle == _globalInfo.StateMachine.State)
                {
                    _globalInfo.StateMachine.State = RuntimeState.TestGen;

                    _stateManageContext.TestInstance.StartGenTime = eventInfo.TimeStamp;
                    _stateManageContext.DatabaseProxy.WriteData(_stateManageContext.TestInstance);

                    _stateManageContext.EventDispatcher.RaiseEvent(Constants.TestGenerationStart, eventInfo.Session,
                                                                   _stateManageContext.TestGenerationInfo);
                }

                _sessionStateHandles[eventInfo.Session].TestGenEventProcess(testGenEventInfo);
                break;

            case TestGenState.GenerationOver:
                _sessionStateHandles[testGenEventInfo.Session].TestGenEventProcess(testGenEventInfo);

                if (_sessionStateHandles.Values.All(item => item.State == RuntimeState.StartIdle))
                {
                    _globalInfo.StateMachine.State = RuntimeState.StartIdle;

                    _stateManageContext.TestInstance.EndGenTime = testGenEventInfo.TimeStamp;
                    _stateManageContext.DatabaseProxy.UpdateData(_stateManageContext.TestInstance);

                    _stateManageContext.EventDispatcher.RaiseEvent(Constants.TestGenerationEnd, testGenEventInfo.Session,
                                                                   _stateManageContext.TestGenerationInfo);
                }
                break;

            case TestGenState.Error:
                _sessionStateHandles[eventInfo.Session].TestGenEventProcess(testGenEventInfo);

                _globalInfo.StateMachine.State = RuntimeState.Error;

                SetTestInstanceEndTime(testGenEventInfo.TimeStamp);
                _stateManageContext.DatabaseProxy.UpdateData(_stateManageContext.TestInstance);

                _stateManageContext.EventDispatcher.RaiseEvent(Constants.TestGenerationEnd, testGenEventInfo.Session,
                                                               _stateManageContext.TestGenerationInfo);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 4
0
        public void SendTestGenMessage(int session, string sequenceData)
        {
            // TODO 暂时不配置Host信息
            RunnerType runnerType = (session == Constants.TestProjectSessionId)
                ? RunnerType.TestProject
                : RunnerType.SequenceGroup;
            RmtGenMessage rmtGenMessage = new RmtGenMessage(MessageNames.DownRmtGenMsgName, session, runnerType,
                                                            sequenceData);

            rmtGenMessage.Params.Add("MsgType", "Generation");
            _globalInfo.MessageTransceiver.Send(rmtGenMessage);
            // 发送生成事件
            TestGenEventInfo testGenEventInfo = new TestGenEventInfo(rmtGenMessage, TestGenState.StartGeneration);

            _globalInfo.EventQueue.Enqueue(testGenEventInfo);
        }
Exemplo n.º 5
0
        // 事件处理和消息处理需要完成:Handle状态更新、外部事件触发、数据库写入三个功能
        // SeesionHandle主要实现会话级别的管理(SequenceGroup),例如TestGen、全局状态维护、会话时间统计、性能统计、全局结束和全局终止。
        // SequenceStateHandle实现序列级别的管理,例如当前栈维护、序列级别的时间统计、序列的时间维护。
        // 写入数据库的状态数据包含两部分,分别是以Sequence为单位和Session为单位执行统计
        // 该类的处理方法完成的工作有:
        // 更新SessionStateHandle的状态、生成PerformanceData并持久化、序列执行结束后生成SessionResultData并持久化、更新TestResult、整体执行结束后触发结束事件
        #region 消息处理和内部事件处理

        public void TestGenEventProcess(TestGenEventInfo eventInfo)
        {
            // TODO 暂时不更新所有Sequence的状态,按照SequenceGroup为单位进行报告
            ISessionGenerationInfo generationInfo;

            switch (eventInfo.GenState)
            {
            case TestGenState.StartGeneration:
                this.State        = RuntimeState.TestGen;
                this.StartGenTime = eventInfo.TimeStamp;
                RefreshTime(eventInfo);

                SetGenerationInfo(eventInfo, GenerationStatus.InProgress);
                break;

            case TestGenState.GenerationOver:
                this.State      = RuntimeState.StartIdle;
                this.EndGenTime = eventInfo.TimeStamp;
                RefreshTime(eventInfo);

                SetGenerationInfo(eventInfo, GenerationStatus.Success);
                break;

            case TestGenState.Error:
                // 更新Handle状态
                this.State = RuntimeState.Error;
                RefreshTime(eventInfo);

                // 停止所有Handle,写入错误数据
                foreach (SequenceStateHandle sequenceStateHandle in _sequenceHandles.Values)
                {
                    sequenceStateHandle.StopStateHandle(eventInfo.TimeStamp, State, eventInfo.ErrorInfo);
                }
                // 持久化会话失败信息
                UpdateSessionResultData(eventInfo.ErrorInfo);
                // 更新TestResults信息
                SetTestResultStatistics(null);
                // 触发生成失败的事件
                SetGenerationInfo(eventInfo, GenerationStatus.Failed);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }