123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #ifndef _MOD_HIGH_VOLTAGE_BASE_H__
- #define _MOD_HIGH_VOLTAGE_BASE_H__
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpTest.h"
- #include "SpUtility.hpp"
- /*one of test module: use to high voltage test*/
- namespace HighVoltage
- {
- #define eMsg_MessageBroadcase1 0
- #define eMsg_MessageBroadcase2 0
- #define eMsgSig_MessageBroadcase1 4367746706
- #define eMsgSig_MessageBroadcase2 4367746606
- struct MessageBroadcase1
- {
- CSimpleStringA context;
- void Serialize(SpBuffer& Buf)
- {
- auto& buf = Buf & context;
- }
- };
- struct MessageBroadcase2
- {
- CSimpleStringA context;
- void Serialize(SpBuffer& Buf)
- {
- auto& buf = Buf & context;
- }
- };
- }
- #include "HelloService_client_g.h"
- #include "SampleEntity_client_g.h"
- class SubSampleClient : public SampleEntity::SampleService_ClientBase
- {
- public:
- SubSampleClient(CEntityBase* pEntity) :SampleService_ClientBase(pEntity) {}
- void OnMessage(ErrorCodeEnum Error, SampleEntity::SampleService_SubscribeOverlap_Message_Info& Msg, CSmartPointer<IReleasable> pData)
- {
- LOG_FUNCTION();
- }
- };
- class CHighVoltageBase : public CEntityBase
- {
- public:
- CHighVoltageBase():m_stopFlag(false), m_maxTimes(-1) {}
- virtual ~CHighVoltageBase() {}
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnStarted()
- {
- InitializeRandomSeed();
- TestCaseInvoke();
- }
- void OnExam(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
-
- }
- virtual void TestCaseInvoke();
- void UpdateSysVal()
- {
- LOG_FUNCTION();
- UINT64 uTimes = 0;
- const char* lpcszSysValStr[] = {
- "fsfjlkmfdklfasjff;iewjfofdnfksdfdsnfdsklfjsdlffdf332231u09-9=-89=-90764sdffsfdsf3erwerwo",
- "wpkopmnoinvoivncoihsdjfo3h32898y12u3hujeop[pokl;k.ghsadhdjkw3oeqoiqjhiokqrjh3hoqh2j1k2jefjklajl"
- };
- do {
- Sleep(GetRandomDigit(5, 8) * 100);
- CSimpleStringA strValue;
- IFFAILBREAK(GetFunction()->GetSysVar("AlwaysUpdate", strValue));
- if (strValue.Compare(lpcszSysValStr[0]) == 0)
- strValue = lpcszSysValStr[1];
- else
- strValue = lpcszSysValStr[0];
- IFFAILBREAK(GetFunction()->SetSysVar("AlwaysUpdate", strValue, true));
- LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
- } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
- }
- void SendBroadCast()
- {
- LOG_FUNCTION();
- UINT64 uTimes = 0;
- do {
- Sleep(GetRandomDigit(1, 10) * 200);
- HighVoltage::MessageBroadcase1 broad1;
- broad1.context = "broad1::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
- IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase1), SP_MSG_SIG_OF(MessageBroadcase1), broad1));
- Sleep(GetRandomDigit(1, 5) * 100);
- HighVoltage::MessageBroadcase2 broad2;
- broad2.context = "broad2::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
- IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase2), SP_MSG_SIG_OF(MessageBroadcase2), broad2));
- LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
- } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
- }
- void CommunicateWithRemoteEntity()
- {
- LOG_FUNCTION();
- UINT64 uTimes = 0;
- do {
- SubSampleClient* sampleClient = new SubSampleClient(this);
- IFFAILBREAK(sampleClient->Connect());
- {
- SampleEntity::SampleService_OnewayFuncOverlap_Info info;
- info.req_context = "SampleService_OnewayFuncOverlap_Info::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
- IFFAILBREAK(sampleClient->OnewayFuncOverlap(info));
- }
- {
- SampleEntity::SampleService_OnewayFuncNormal_Info info;
- info.tstring = "SampleService_OnewayFuncNormal_Info::tstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
- info.twstring = L"SampleService_OnewayFuncNormal_Info::twstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
- IFFAILBREAK(sampleClient->OnewayFuncNormal(info));
- }
- Sleep(GetRandomDigit(3, 30) * 50);
- {
- SampleEntity::SampleService_TwoWayFuncNormal_Req Req;
- SampleEntity::SampleService_TwoWayFuncNormal_Ans Ans;
- Req.tbool = true;
- Req.tchar = 'I';
- Req.tint = 123;
- Req.tuint = 123;
- Req.tshort = 123;
- Req.tushort = 123;
- Req.tuchar = 'I';
- Req.tstring = "SampleService_TwoWayFuncNormal_Req::tstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
- Req.twstring = "SampleService_TwoWayFuncNormal_Req::twstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
- Req.tfloat = 123.456f;
- Req.tdouble = 123.456;
- Req.tblob.Clear();
- Req.tint64 = 123;
- Req.tuint64 = 123;
- IFFAILBREAK(sampleClient->TwoWayFuncNormal(Req, Ans, 10000));
- }
- Sleep(GetRandomDigit(5, 10) * 100);
-
- sampleClient->GetFunction()->CloseSession();
- LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
- } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
- }
- void Stop()
- {
- m_stopFlag = true;
- }
- void SetMaxTimes(UINT64 times = -1)
- {
- m_maxTimes = times;
- }
- private:
- bool m_stopFlag;
- UINT64 m_maxTimes;
- };
- struct UpdateSysValTask : public ITaskSp
- {
- UpdateSysValTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
- CHighVoltageBase* m_pEntity;
- void Process()
- {
- m_pEntity->UpdateSysVal();
- }
- };
- struct SendBroadCastTask : public ITaskSp
- {
- SendBroadCastTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
- CHighVoltageBase* m_pEntity;
- void Process()
- {
- m_pEntity->SendBroadCast();
- }
- };
- struct CommunicateWithRemoteEntityTask : public ITaskSp
- {
- CommunicateWithRemoteEntityTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
- CHighVoltageBase* m_pEntity;
- void Process()
- {
- m_pEntity->CommunicateWithRemoteEntity();
- }
- };
- void CHighVoltageBase::TestCaseInvoke()
- {
- #if 0
- {
- char szProcessID[12];
- sprintf(szProcessID, "%u", GetCurrentProcessId());
- MessageBoxA(NULL, szProcessID, "", MB_OK);
- }
- #endif
- LOG_FUNCTION();
- //Stop();
- SetMaxTimes(10000);
- IFFAILBREAK(GetFunction()->PostThreadPoolTask(new UpdateSysValTask(this)));
- IFFAILBREAK(GetFunction()->PostThreadPoolTask(new SendBroadCastTask(this)));
- IFFAILBREAK(GetFunction()->PostThreadPoolTask(new CommunicateWithRemoteEntityTask(this)));
- #if 0
- {
- char szProcessID[12];
- sprintf(szProcessID, "%u", GetCurrentProcessId());
- MessageBoxA(NULL, szProcessID, "", MB_OK);
- THROW_FATAL("force quit");
- }
- #endif
- }
- #endif //_MOD_HIGH_VOLTAGE_BASE_H__
|