logging_test.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jlib.hpp"
  14. #include "jfile.hpp"
  15. #include "jprop.hpp"
  16. #include "loggingmanager.h"
  17. Owned<IPropertyTree> loggingInput;
  18. IPropertyTree* loggingConfig = NULL;
  19. IPropertyTree* testData = NULL;
  20. Owned<ILoggingManager> loggingManager;
  21. ILoggingManager* loadLogggingManager()
  22. {
  23. StringBuffer realName;
  24. realName.append(SharedObjectPrefix).append(LOGGINGMANAGERLIB).append(SharedObjectExtension);
  25. HINSTANCE loggingManagerLib = LoadSharedObject(realName.str(), true, false);
  26. if(loggingManagerLib == NULL)
  27. {
  28. printf("can't load library %s\n", realName.str());
  29. return NULL;
  30. }
  31. newLoggingManager_t_ xproc = NULL;
  32. xproc = (newLoggingManager_t_)GetSharedProcedure(loggingManagerLib, "newLoggingManager");
  33. if (!xproc)
  34. {
  35. printf("procedure newLogggingManager of %s can't be loaded\n", realName.str());
  36. return NULL;
  37. }
  38. return (ILoggingManager*) xproc();
  39. }
  40. ILoggingManager* init(const char* inputFileName)
  41. {
  42. if(!inputFileName || !*inputFileName)
  43. {
  44. printf("Input file not defined.\n");
  45. return NULL;
  46. }
  47. printf("Input file: %s\n", inputFileName);
  48. loggingInput.setown(createPTreeFromXMLFile(inputFileName, ipt_caseInsensitive));
  49. if (!loggingInput)
  50. {
  51. printf("can't read input file.\n");
  52. return NULL;
  53. }
  54. loggingConfig = loggingInput->queryPropTree("config/LoggingManager");
  55. testData = loggingInput->queryPropTree("test");
  56. if (!loggingConfig || !testData)
  57. {
  58. printf("can't read input file.\n");
  59. return NULL;
  60. }
  61. loggingManager.setown(loadLogggingManager());
  62. if (!loggingManager)
  63. {
  64. printf("No logging manager\n");
  65. return NULL;
  66. }
  67. loggingManager->init(loggingConfig, "test_service");
  68. return loggingManager;
  69. }
  70. void sendRequest()
  71. {
  72. if (!loggingManager)
  73. {
  74. printf("No logging manager.\n");
  75. return;
  76. }
  77. StringBuffer action, option, status;
  78. testData->getProp("action", action);
  79. testData->getProp("option", option);
  80. if (action.length() && strieq(action.str(), "getTransactionSeed"))
  81. {
  82. StringBuffer transactionSeed;
  83. loggingManager->getTransactionSeed(transactionSeed, status);
  84. if (transactionSeed.length())
  85. printf("Got transactionSeed: <%s>\n", transactionSeed.str());
  86. }
  87. else if (action.length() && strieq(action.str(), "UpdateLog"))
  88. {
  89. IPropertyTree* logContentTree = testData->queryPropTree("LogContent");
  90. if (!logContentTree)
  91. {
  92. printf("can't read log content.\n");
  93. return;
  94. }
  95. StringBuffer logContentXML;
  96. toXML(logContentTree, logContentXML);
  97. printf("log content: <%s>.\n", logContentXML.str());
  98. Owned<IEspContext> espContext = createEspContext();
  99. const char* userName = logContentTree->queryProp("ESPContext/UserName");
  100. const char* sourceIP = logContentTree->queryProp("ESPContext/SourceIP");
  101. short servPort = logContentTree->getPropInt("ESPContext/Port");
  102. espContext->setUserID(userName);
  103. espContext->setServAddress(sourceIP, servPort);
  104. const char* backEndResp = logContentTree->queryProp("BackEndResponse");
  105. IPropertyTree* userContextTree = logContentTree->queryPropTree("MyUserContext");
  106. IPropertyTree* userRequestTree = logContentTree->queryPropTree("MyUserRequest");
  107. IPropertyTree* userRespTree = logContentTree->queryPropTree("MyUserResponseEx");
  108. StringBuffer userContextXML, userRequestXML, userRespXML;
  109. toXML(userRespTree, userRespXML);
  110. toXML(userContextTree, userContextXML);
  111. toXML(userRequestTree, userRequestXML);
  112. printf("userContextXML: <%s>.\n", userContextXML.str());
  113. printf("userRequestXML: <%s>.\n", userRequestXML.str());
  114. printf("userRespXML: <%s>.\n", userRespXML.str());
  115. printf("backEndResp: <%s>.\n", backEndResp);
  116. //Sleep(5000); //Waiting for loggingManager to start
  117. loggingManager->updateLog(option.str(), *espContext, userContextTree, userRequestTree, backEndResp, userRespXML.str(), status);
  118. }
  119. else if (action.length() && strieq(action.str(), "UpdateLog1"))
  120. {
  121. IPropertyTree* logContentTree = testData->queryPropTree("LogContent");
  122. if (!logContentTree)
  123. {
  124. printf("can't read log content.\n");
  125. return;
  126. }
  127. StringBuffer logContentXML;
  128. toXML(logContentTree, logContentXML);
  129. printf("log content: <%s>.\n", logContentXML.str());
  130. //Sleep(5000); //Waiting for loggingManager to start
  131. loggingManager->updateLog(option.str(), logContentXML.str(), status);
  132. }
  133. else
  134. printf("Invalid action.\n");
  135. }
  136. void doWork(const char* inputFileName)
  137. {
  138. printf("Enter dowork()\n");
  139. init(inputFileName);
  140. sendRequest();
  141. printf("Waiting for log queue to be read.\n");
  142. Sleep(10000); //Waiting for loggingManager to process queue
  143. printf("Finish dowork()\n");
  144. }