mod_highVoltageBase.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #ifndef _MOD_HIGH_VOLTAGE_BASE_H__
  2. #define _MOD_HIGH_VOLTAGE_BASE_H__
  3. #include "stdafx.h"
  4. #include "SpBase.h"
  5. #include "SpTest.h"
  6. #include "SpUtility.hpp"
  7. /*one of test module: use to high voltage test*/
  8. namespace HighVoltage
  9. {
  10. #define eMsg_MessageBroadcase1 0
  11. #define eMsg_MessageBroadcase2 0
  12. #define eMsgSig_MessageBroadcase1 4367746706
  13. #define eMsgSig_MessageBroadcase2 4367746606
  14. struct MessageBroadcase1
  15. {
  16. CSimpleStringA context;
  17. void Serialize(SpBuffer& Buf)
  18. {
  19. auto& buf = Buf & context;
  20. }
  21. };
  22. struct MessageBroadcase2
  23. {
  24. CSimpleStringA context;
  25. void Serialize(SpBuffer& Buf)
  26. {
  27. auto& buf = Buf & context;
  28. }
  29. };
  30. }
  31. #include "HelloService_client_g.h"
  32. #include "SampleEntity_client_g.h"
  33. class SubSampleClient : public SampleEntity::SampleService_ClientBase
  34. {
  35. public:
  36. SubSampleClient(CEntityBase* pEntity) :SampleService_ClientBase(pEntity) {}
  37. void OnMessage(ErrorCodeEnum Error, SampleEntity::SampleService_SubscribeOverlap_Message_Info& Msg, CSmartPointer<IReleasable> pData)
  38. {
  39. LOG_FUNCTION();
  40. }
  41. };
  42. class CHighVoltageBase : public CEntityBase
  43. {
  44. public:
  45. CHighVoltageBase():m_stopFlag(false), m_maxTimes(-1) {}
  46. virtual ~CHighVoltageBase() {}
  47. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  48. {
  49. LOG_FUNCTION();
  50. pTransactionContext->SendAnswer(Error_Succeed);
  51. }
  52. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  53. {
  54. LOG_FUNCTION();
  55. pTransactionContext->SendAnswer(Error_Succeed);
  56. }
  57. virtual void OnStarted()
  58. {
  59. InitializeRandomSeed();
  60. TestCaseInvoke();
  61. }
  62. void OnExam(CSmartPointer<ITransactionContext> pTransactionContext)
  63. {
  64. pTransactionContext->SendAnswer(Error_Succeed);
  65. }
  66. virtual void TestCaseInvoke();
  67. void UpdateSysVal()
  68. {
  69. LOG_FUNCTION();
  70. UINT64 uTimes = 0;
  71. const char* lpcszSysValStr[] = {
  72. "fsfjlkmfdklfasjff;iewjfofdnfksdfdsnfdsklfjsdlffdf332231u09-9=-89=-90764sdffsfdsf3erwerwo",
  73. "wpkopmnoinvoivncoihsdjfo3h32898y12u3hujeop[pokl;k.ghsadhdjkw3oeqoiqjhiokqrjh3hoqh2j1k2jefjklajl"
  74. };
  75. do {
  76. Sleep(GetRandomDigit(5, 8) * 100);
  77. CSimpleStringA strValue;
  78. IFFAILBREAK(GetFunction()->GetSysVar("AlwaysUpdate", strValue));
  79. if (strValue.Compare(lpcszSysValStr[0]) == 0)
  80. strValue = lpcszSysValStr[1];
  81. else
  82. strValue = lpcszSysValStr[0];
  83. IFFAILBREAK(GetFunction()->SetSysVar("AlwaysUpdate", strValue, true));
  84. LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
  85. } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
  86. }
  87. void SendBroadCast()
  88. {
  89. LOG_FUNCTION();
  90. UINT64 uTimes = 0;
  91. do {
  92. Sleep(GetRandomDigit(1, 10) * 200);
  93. HighVoltage::MessageBroadcase1 broad1;
  94. broad1.context = "broad1::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
  95. IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase1), SP_MSG_SIG_OF(MessageBroadcase1), broad1));
  96. Sleep(GetRandomDigit(1, 5) * 100);
  97. HighVoltage::MessageBroadcase2 broad2;
  98. broad2.context = "broad2::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
  99. IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase2), SP_MSG_SIG_OF(MessageBroadcase2), broad2));
  100. LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
  101. } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
  102. }
  103. void CommunicateWithRemoteEntity()
  104. {
  105. LOG_FUNCTION();
  106. UINT64 uTimes = 0;
  107. do {
  108. SubSampleClient* sampleClient = new SubSampleClient(this);
  109. IFFAILBREAK(sampleClient->Connect());
  110. {
  111. SampleEntity::SampleService_OnewayFuncOverlap_Info info;
  112. info.req_context = "SampleService_OnewayFuncOverlap_Info::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
  113. IFFAILBREAK(sampleClient->OnewayFuncOverlap(info));
  114. }
  115. {
  116. SampleEntity::SampleService_OnewayFuncNormal_Info info;
  117. info.tstring = "SampleService_OnewayFuncNormal_Info::tstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
  118. info.twstring = L"SampleService_OnewayFuncNormal_Info::twstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
  119. IFFAILBREAK(sampleClient->OnewayFuncNormal(info));
  120. }
  121. Sleep(GetRandomDigit(3, 30) * 50);
  122. {
  123. SampleEntity::SampleService_TwoWayFuncNormal_Req Req;
  124. SampleEntity::SampleService_TwoWayFuncNormal_Ans Ans;
  125. Req.tbool = true;
  126. Req.tchar = 'I';
  127. Req.tint = 123;
  128. Req.tuint = 123;
  129. Req.tshort = 123;
  130. Req.tushort = 123;
  131. Req.tuchar = 'I';
  132. Req.tstring = "SampleService_TwoWayFuncNormal_Req::tstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
  133. Req.twstring = "SampleService_TwoWayFuncNormal_Req::twstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
  134. Req.tfloat = 123.456f;
  135. Req.tdouble = 123.456;
  136. Req.tblob.Clear();
  137. Req.tint64 = 123;
  138. Req.tuint64 = 123;
  139. IFFAILBREAK(sampleClient->TwoWayFuncNormal(Req, Ans, 10000));
  140. }
  141. Sleep(GetRandomDigit(5, 10) * 100);
  142. sampleClient->GetFunction()->CloseSession();
  143. LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
  144. } while (!m_stopFlag && (m_maxTimes == (UINT64)(-1) || uTimes < m_maxTimes));
  145. }
  146. void Stop()
  147. {
  148. m_stopFlag = true;
  149. }
  150. void SetMaxTimes(UINT64 times = -1)
  151. {
  152. m_maxTimes = times;
  153. }
  154. private:
  155. bool m_stopFlag;
  156. UINT64 m_maxTimes;
  157. };
  158. struct UpdateSysValTask : public ITaskSp
  159. {
  160. UpdateSysValTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
  161. CHighVoltageBase* m_pEntity;
  162. void Process()
  163. {
  164. m_pEntity->UpdateSysVal();
  165. }
  166. };
  167. struct SendBroadCastTask : public ITaskSp
  168. {
  169. SendBroadCastTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
  170. CHighVoltageBase* m_pEntity;
  171. void Process()
  172. {
  173. m_pEntity->SendBroadCast();
  174. }
  175. };
  176. struct CommunicateWithRemoteEntityTask : public ITaskSp
  177. {
  178. CommunicateWithRemoteEntityTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
  179. CHighVoltageBase* m_pEntity;
  180. void Process()
  181. {
  182. m_pEntity->CommunicateWithRemoteEntity();
  183. }
  184. };
  185. void CHighVoltageBase::TestCaseInvoke()
  186. {
  187. #if 0
  188. {
  189. char szProcessID[12];
  190. sprintf(szProcessID, "%u", GetCurrentProcessId());
  191. MessageBoxA(NULL, szProcessID, "", MB_OK);
  192. }
  193. #endif
  194. LOG_FUNCTION();
  195. //Stop();
  196. SetMaxTimes(10000);
  197. IFFAILBREAK(GetFunction()->PostThreadPoolTask(new UpdateSysValTask(this)));
  198. IFFAILBREAK(GetFunction()->PostThreadPoolTask(new SendBroadCastTask(this)));
  199. IFFAILBREAK(GetFunction()->PostThreadPoolTask(new CommunicateWithRemoteEntityTask(this)));
  200. #if 0
  201. {
  202. char szProcessID[12];
  203. sprintf(szProcessID, "%u", GetCurrentProcessId());
  204. MessageBoxA(NULL, szProcessID, "", MB_OK);
  205. THROW_FATAL("force quit");
  206. }
  207. #endif
  208. }
  209. #endif //_MOD_HIGH_VOLTAGE_BASE_H__