ConfigMgrHPCCTests.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 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. /*
  14. * Config Manager 2.0 Unit tests to validate specific HPCC features
  15. *
  16. */
  17. #ifdef _USE_CPPUNIT
  18. #include <cppunit/TestFixture.h>
  19. #include "unittests.hpp"
  20. // Config2 manager includes
  21. #include "jexcept.hpp"
  22. #include "mod_template_support/TemplateException.hpp"
  23. #include "mod_template_support/TemplateExecutionException.hpp"
  24. #include "EnvironmentMgr.hpp"
  25. #include "build-config.h"
  26. #include <string>
  27. #include <iterator>
  28. #include <algorithm>
  29. #include <vector>
  30. class ConfigMgrHPCCTests : public CppUnit::TestFixture
  31. {
  32. public:
  33. CPPUNIT_TEST_SUITE(ConfigMgrHPCCTests);
  34. CPPUNIT_TEST(duplicatePortSameService);
  35. CPPUNIT_TEST(portConflictSameHWInstance);
  36. CPPUNIT_TEST(portConflictAccrossProcesses);
  37. CPPUNIT_TEST_SUITE_END();
  38. protected:
  39. bool loadEnvironment(const std::string &envFile)
  40. {
  41. bool rc;
  42. if (m_pEnvMgr == nullptr)
  43. {
  44. m_pEnvMgr = getEnvironmentMgrInstance(EnvironmentType::XML);
  45. std::map<std::string, std::string> cfgParms;
  46. rc = m_pEnvMgr->loadSchema(CFG2_CONFIG_DIR, CFG2_MASTER_CONFIG_FILE, cfgParms);
  47. CPPUNIT_ASSERT_MESSAGE("Unable to load configuration schema, error = " + m_pEnvMgr->getLastSchemaMessage(), rc);
  48. }
  49. //
  50. // discard the current envionment and load the new one
  51. m_pEnvMgr->discardEnvironment();
  52. rc = m_pEnvMgr->loadEnvironment(envFile);
  53. CPPUNIT_ASSERT_MESSAGE("Unable to load environment file, error = " + m_pEnvMgr->getLastEnvironmentMessage(), rc);
  54. return rc;
  55. }
  56. void duplicatePortSameService()
  57. {
  58. printf("\nTesting binding two ESP Services of the same type on the same port as invalid...");
  59. if (loadEnvironment(m_xmlEnvDir + "hpcc_port_conflict_test1.xml"))
  60. {
  61. Status status;
  62. m_pEnvMgr->validate(status, false);
  63. auto msgs = status.getMessages(statusMsg::error, false, "", "port");
  64. CPPUNIT_ASSERT_MESSAGE("Port conflict was NOT detected", !msgs.empty());
  65. }
  66. printf("Test Complete.\n");
  67. printf("\n\nTesting binding two ESP Services of the same type on different ports as valid...");
  68. if (loadEnvironment(m_xmlEnvDir + "hpcc_port_conflict_test2.xml"))
  69. {
  70. Status status;
  71. m_pEnvMgr->validate(status, false);
  72. auto msgs = status.getMessages(statusMsg::error, false, "", "port");
  73. CPPUNIT_ASSERT_MESSAGE("Port conflict was detected when there are none", msgs.empty());
  74. }
  75. printf("Test Complete.\n");
  76. }
  77. void portConflictSameHWInstance()
  78. {
  79. printf("\nTesting two ESP processes with a port collision on an instance...");
  80. if (loadEnvironment(m_xmlEnvDir + "hpcc_port_conflict_test3.xml"))
  81. {
  82. Status status;
  83. m_pEnvMgr->validate(status, false);
  84. auto msgs = status.getMessages(statusMsg::error, false, "", "");
  85. CPPUNIT_ASSERT_MESSAGE("Port conflict was NOT detected", !msgs.empty());
  86. }
  87. printf("Test Complete.\n");
  88. }
  89. void portConflictAccrossProcesses()
  90. {
  91. printf("\nTesting two processes with a port collision on an instance...");
  92. if (loadEnvironment(m_xmlEnvDir + "hpcc_port_conflict_test4.xml"))
  93. {
  94. Status status;
  95. m_pEnvMgr->validate(status, false);
  96. auto msgs = status.getMessages(statusMsg::error, false, "", "");
  97. CPPUNIT_ASSERT_MESSAGE("Port conflict was NOT detected", !msgs.empty());
  98. }
  99. printf("Test Complete.\n");
  100. }
  101. private:
  102. EnvironmentMgr *m_pEnvMgr = nullptr;
  103. std::string m_templateDir = INSTALL_DIR PATHSEPSTR "testing/configmgr/templates/";
  104. std::string CFG2_MASTER_CONFIG_FILE = "environment.xsd";
  105. std::string CFG2_CONFIG_DIR = COMPONENTFILES_DIR PATHSEPSTR "configschema" PATHSEPSTR "xsd" PATHSEPSTR;
  106. std::string CFG2_SOURCE_DIR = CONFIG_SOURCE_DIR;
  107. std::string m_xmlEnvDir = INSTALL_DIR PATHSEPSTR "testing/configmgr/schema/environments/";
  108. };
  109. CPPUNIT_TEST_SUITE_REGISTRATION( ConfigMgrHPCCTests );
  110. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ConfigMgrHPCCTests, "ConfigMgrHPCCTests" );
  111. #endif