This is an automated email from the ASF dual-hosted git repository.

aboda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new 0795a17  MINIFICPP-962 - C2 tests should use random port
0795a17 is described below

commit 0795a17f2134f2cbad80936d1ac89268fd2ef234
Author: Arpad Boda <[email protected]>
AuthorDate: Wed Jul 10 17:46:31 2019 +0200

    MINIFICPP-962 - C2 tests should use random port
    
    Signed-off-by: Arpad Boda <[email protected]>
    
    Approved by bakaid and phrocker on GH
    
    This closes #609
---
 extensions/http-curl/tests/C2FailedUpdateTest.cpp       | 13 +++++++++----
 extensions/http-curl/tests/C2JstackTest.cpp             |  9 +++++++--
 extensions/http-curl/tests/C2UpdateAgentTest.cpp        | 12 +++++++++---
 extensions/http-curl/tests/C2UpdateTest.cpp             | 11 ++++++++---
 extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp |  8 +++++---
 extensions/http-curl/tests/HTTPIntegrationBase.h        | 16 ++++++++++++++++
 6 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/extensions/http-curl/tests/C2FailedUpdateTest.cpp 
b/extensions/http-curl/tests/C2FailedUpdateTest.cpp
index ec98cf7..d70f337 100644
--- a/extensions/http-curl/tests/C2FailedUpdateTest.cpp
+++ b/extensions/http-curl/tests/C2FailedUpdateTest.cpp
@@ -126,13 +126,16 @@ int main(int argc, char **argv) {
   LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
   LogTestController::getInstance().setDebug<minifi::c2::C2Agent>();
 
-  const char *options[] = { "document_root", ".", "listening_ports", "7071", 0 
};
+  const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
   std::vector<std::string> cpp_options;
   for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
     cpp_options.push_back(options[i]);
   }
 
   CivetServer server(cpp_options);
+
+  std::string port_str = std::to_string(server.getListeningPorts()[0]);
+
   ConfigHandler h_ex;
   server.addHandler("/update", h_ex);
   std::string key_dir, test_file_location;
@@ -151,6 +154,8 @@ int main(int argc, char **argv) {
 
   std::ifstream myfile(test_file_location.c_str());
 
+  std::string c2_rest_url = "http://localhost:"; + port_str + "/update";
+
   if (myfile.is_open()) {
     std::stringstream buffer;
     buffer << myfile.rdbuf();
@@ -159,7 +164,7 @@ int main(int argc, char **argv) {
     std::string response = "{\"operation\" : 
\"heartbeat\",\"requested_operations\": [  {"
         "\"operation\" : \"update\", "
         "\"operationid\" : \"8675309\", "
-        "\"name\": \"configuration\", \"content\": { \"location\": 
\"http://localhost:7071/update\"}}]}";;
+        "\"name\": \"configuration\", \"content\": { \"location\": \"" + 
c2_rest_url + "\"}}]}";
     responses.push_back(response);
   }
 
@@ -168,8 +173,8 @@ int main(int argc, char **argv) {
   configuration->set("nifi.c2.agent.protocol.class", "RESTSender");
   configuration->set("nifi.c2.enable", "true");
   configuration->set("nifi.c2.agent.class", "test");
-  configuration->set("nifi.c2.rest.url", "http://localhost:7071/update";);
-  configuration->set("nifi.c2.rest.url.ack", "http://localhost:7071/update";);
+  configuration->set("nifi.c2.rest.url", c2_rest_url);
+  configuration->set("nifi.c2.rest.url.ack", c2_rest_url);
   configuration->set("nifi.c2.agent.heartbeat.period", "1000");
   mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
 
diff --git a/extensions/http-curl/tests/C2JstackTest.cpp 
b/extensions/http-curl/tests/C2JstackTest.cpp
index 4141312..5e0538c 100644
--- a/extensions/http-curl/tests/C2JstackTest.cpp
+++ b/extensions/http-curl/tests/C2JstackTest.cpp
@@ -101,13 +101,16 @@ int main(int argc, char **argv) {
   LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
   LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
 
-  const char *options[] = { "document_root", ".", "listening_ports", "8727", 0 
};
+  const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
   std::vector<std::string> cpp_options;
   for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
     cpp_options.push_back(options[i]);
   }
 
   CivetServer server(cpp_options);
+
+  std::string port_str = std::to_string(server.getListeningPorts()[0]);
+
   ConfigHandler h_ex;
   server.addHandler("/update", h_ex);
   std::string key_dir, test_file_location;
@@ -119,7 +122,9 @@ int main(int argc, char **argv) {
 
   std::shared_ptr<minifi::Configure> configuration = 
std::make_shared<minifi::Configure>();
 
-  configuration->set("c2.rest.url", "http://localhost:8727/update";);
+  std::string c2_rest_url = "http://localhost:"; + port_str + "/update";
+
+  configuration->set("c2.rest.url", c2_rest_url);
   configuration->set("c2.agent.heartbeat.period", "1000");
   mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
 
diff --git a/extensions/http-curl/tests/C2UpdateAgentTest.cpp 
b/extensions/http-curl/tests/C2UpdateAgentTest.cpp
index 85d0d0e..2137c41 100644
--- a/extensions/http-curl/tests/C2UpdateAgentTest.cpp
+++ b/extensions/http-curl/tests/C2UpdateAgentTest.cpp
@@ -102,13 +102,16 @@ int main(int argc, char **argv) {
   LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
   LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
 
-  const char *options[] = { "document_root", ".", "listening_ports", "7072", 0 
};
+  const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
   std::vector<std::string> cpp_options;
   for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
     cpp_options.push_back(options[i]);
   }
 
   CivetServer server(cpp_options);
+
+  std::string port_str = std::to_string(server.getListeningPorts()[0]);
+
   ConfigHandler h_ex;
   server.addHandler("/update", h_ex);
   std::string key_dir, test_file_location;
@@ -126,6 +129,9 @@ int main(int argc, char **argv) {
 
   std::ifstream myfile(test_file_location.c_str());
 
+  std::string c2_rest_url = "http://localhost:"; + port_str + "/update";
+
+
   if (myfile.is_open()) {
     std::stringstream buffer;
     buffer << myfile.rdbuf();
@@ -134,7 +140,7 @@ int main(int argc, char **argv) {
     std::string response = "{\"operation\" : 
\"heartbeat\",\"requested_operations\": [  {"
         "\"operation\" : \"update\", "
         "\"operationid\" : \"8675309\", "
-        "\"name\": \"agent\", \"content\": { \"location\": 
\"http://localhost:7072/update\"}}]}";;
+        "\"name\": \"agent\", \"content\": { \"location\": \"" + c2_rest_url 
+"\"}}]}";
     responses.push_back(response);
   }
 
@@ -144,7 +150,7 @@ int main(int argc, char **argv) {
   configuration->set("nifi.c2.enable", "true");
   configuration->set("nifi.c2.agent.class", "test");
   configuration->set("nifi.c2.agent.update.allow","true");
-  configuration->set("nifi.c2.rest.url", "http://localhost:7072/update";);
+  configuration->set("nifi.c2.rest.url", c2_rest_url);
   configuration->set("nifi.c2.agent.heartbeat.period", "1000");
   mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
 
diff --git a/extensions/http-curl/tests/C2UpdateTest.cpp 
b/extensions/http-curl/tests/C2UpdateTest.cpp
index 64002c6..cb3a4c3 100644
--- a/extensions/http-curl/tests/C2UpdateTest.cpp
+++ b/extensions/http-curl/tests/C2UpdateTest.cpp
@@ -102,13 +102,16 @@ int main(int argc, char **argv) {
   LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
   LogTestController::getInstance().setDebug<minifi::c2::C2Agent>();
 
-  const char *options[] = { "document_root", ".", "listening_ports", "7070", 0 
};
+  const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
   std::vector<std::string> cpp_options;
   for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
     cpp_options.push_back(options[i]);
   }
 
   CivetServer server(cpp_options);
+
+  std::string port_str = std::to_string(server.getListeningPorts()[0]);
+
   ConfigHandler h_ex;
   server.addHandler("/update", h_ex);
   std::string key_dir, test_file_location;
@@ -126,6 +129,8 @@ int main(int argc, char **argv) {
 
   std::ifstream myfile(test_file_location.c_str());
 
+  std::string c2_rest_url = "http://localhost:"; + port_str + "/update";
+
   if (myfile.is_open()) {
     std::stringstream buffer;
     buffer << myfile.rdbuf();
@@ -134,7 +139,7 @@ int main(int argc, char **argv) {
     std::string response = "{\"operation\" : 
\"heartbeat\",\"requested_operations\": [  {"
         "\"operation\" : \"update\", "
         "\"operationid\" : \"8675309\", "
-        "\"name\": \"configuration\", \"content\": { \"location\": 
\"http://localhost:7070/update\"}}]}";;
+        "\"name\": \"configuration\", \"content\": { \"location\": \"" + 
c2_rest_url + "\"}}]}";
     responses.push_back(response);
   }
 
@@ -143,7 +148,7 @@ int main(int argc, char **argv) {
   configuration->set("nifi.c2.agent.protocol.class", "RESTSender");
   configuration->set("nifi.c2.enable", "true");
   configuration->set("nifi.c2.agent.class", "test");
-  configuration->set("nifi.c2.rest.url", "http://localhost:7070/update";);
+  configuration->set("nifi.c2.rest.url", c2_rest_url);
   configuration->set("nifi.c2.agent.heartbeat.period", "1000");
   mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
 
diff --git a/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp 
b/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
index e849b26..4c526b4 100644
--- a/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
+++ b/extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
@@ -162,12 +162,14 @@ class VerifyC2Heartbeat : public CoapIntegrationBase {
     std::string url = "";
     inv->getProperty(minifi::processors::InvokeHTTP::URL.getName(), url);
 
+    std::string c2_url = std::string("http") + (isSecure ? "s" : "") + 
"://localhost:" + getWebPort() + "/api/heartbeat" ;
+
     configuration->set("nifi.c2.agent.protocol.class", "RESTSender");
     configuration->set("nifi.c2.enable", "true");
     configuration->set("nifi.c2.agent.class", "test");
-    configuration->set("nifi.c2.rest.url", 
"http://localhost:8888/api/heartbeat";);
+    configuration->set("nifi.c2.rest.url", c2_url);
     configuration->set("nifi.c2.agent.heartbeat.period", "1000");
-    configuration->set("nifi.c2.rest.url.ack", 
"http://localhost:8888/api/heartbeat";);
+    configuration->set("nifi.c2.rest.url.ack", c2_url);
     configuration->set("nifi.c2.root.classes", 
"DeviceInfoNode,AgentInformation,FlowInformation");
   }
 
@@ -180,7 +182,7 @@ class VerifyC2Heartbeat : public CoapIntegrationBase {
 
 int main(int argc, char **argv) {
   std::string key_dir, test_file_location, url;
-  url = "http://localhost:8888/api/heartbeat";;
+  url = "http://localhost:0/api/heartbeat";;
   if (argc > 1) {
     test_file_location = argv[1];
     key_dir = argv[2];
diff --git a/extensions/http-curl/tests/HTTPIntegrationBase.h 
b/extensions/http-curl/tests/HTTPIntegrationBase.h
index 85cae26..01f1712 100644
--- a/extensions/http-curl/tests/HTTPIntegrationBase.h
+++ b/extensions/http-curl/tests/HTTPIntegrationBase.h
@@ -47,6 +47,14 @@ class CoapIntegrationBase : public IntegrationBase {
     stop_webserver(server);
   }
 
+  std::string getWebPort() {
+    std::string ret_val = port;
+    if(ret_val.back() == 's') {
+      ret_val = ret_val.substr(0, ret_val.size()-1);
+    }
+    return ret_val;
+  }
+
  protected:
   CivetServer *server;
 };
@@ -76,6 +84,14 @@ void CoapIntegrationBase::setUrl(std::string url, 
CivetHandler *handler) {
       server = start_webserver(port, path, handler);
     }
   }
+  if(port == "0" || port == "0s") {
+    bool secure = (port == "0s");
+    port = std::to_string(server->getListeningPorts()[0]);
+    if(secure) {
+      port += "s";
+    }
+  }
+
 }
 
 #endif /* LIBMINIFI_TEST_INTEGRATION_HTTPINTEGRATIONBASE_H_ */

Reply via email to