You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2017/04/29 16:46:00 UTC

nifi-minifi-cpp git commit: MINIFI-282: Move Socket tests and remove includes

Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master ab3cf9770 -> 678c602c8


MINIFI-282: Move Socket tests and remove includes

This closes #86.

Signed-off-by: Aldrin Piri <al...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/678c602c
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/678c602c
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/678c602c

Branch: refs/heads/master
Commit: 678c602c81d60285aee91a842f14cefa6606205c
Parents: ab3cf97
Author: Marc <ma...@gmail.com>
Authored: Fri Apr 28 17:56:38 2017 -0400
Committer: Aldrin Piri <al...@apache.org>
Committed: Sat Apr 29 12:45:15 2017 -0400

----------------------------------------------------------------------
 CMakeLists.txt                          |  20 +++
 libminifi/src/io/ClientSocket.cpp       |   3 -
 libminifi/src/processors/InvokeHTTP.cpp |   3 -
 libminifi/test/SocketTests.cpp          | 177 +++++++++++++++++++++++++++
 libminifi/test/unit/SocketTests.cpp     | 175 --------------------------
 5 files changed, 197 insertions(+), 181 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/678c602c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42c86d7..835c63c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -206,6 +206,26 @@ enable_testing(test)
     endif(CURL_FOUND)
     target_link_libraries(testExecuteProcess ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp jsoncpp_lib_static)
     add_test(NAME ExecuteProcess COMMAND testExecuteProcess)
+    
+    file(GLOB LIBMINIFI_TEST_SOCKETS "libminifi/test/SocketTests.cpp")
+    add_executable(testSockets ${LIBMINIFI_TEST_SOCKETS} ${SPD_SOURCES})
+    target_include_directories(testSockets PRIVATE BEFORE "thirdparty/catch")
+    target_include_directories(testSockets PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include")
+    target_include_directories(testSockets PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS})
+    target_include_directories(testSockets PRIVATE BEFORE "include")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/core")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/core/repository")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/io")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/utils")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/processors")
+    target_include_directories(testSockets PRIVATE BEFORE "libminifi/include/provenance")
+    if (CURL_FOUND)
+        target_include_directories(testSockets PRIVATE BEFORE ${CURL_INCLUDE_DIRS})
+    	target_link_libraries(testSockets ${CURL_LIBRARIES})
+    endif(CURL_FOUND)
+    target_link_libraries(testSockets ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp jsoncpp_lib_static)
+    add_test(NAME TestSockets COMMAND testSockets)
 
 # Create a custom build target called "docker" that will invoke DockerBuild.sh and create the NiFi-MiNiFi-CPP Docker image
 add_custom_target(

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/678c602c/libminifi/src/io/ClientSocket.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/io/ClientSocket.cpp b/libminifi/src/io/ClientSocket.cpp
index e62d4f1..98e0205 100644
--- a/libminifi/src/io/ClientSocket.cpp
+++ b/libminifi/src/io/ClientSocket.cpp
@@ -120,8 +120,6 @@ int8_t Socket::createConnection(const addrinfo *p, in_addr_t &addr) {
       if (connect(socket_file_descriptor_, p->ai_addr, p->ai_addrlen) == -1) {
         close(socket_file_descriptor_);
         socket_file_descriptor_ = -1;
-        logger_->log_warn("Could not connect to socket, error:%s",
-                          strerror(errno));
         return -1;
       }
     }
@@ -130,7 +128,6 @@ int8_t Socket::createConnection(const addrinfo *p, in_addr_t &addr) {
   // listen
   if (listeners_ > 0) {
     if (listen(socket_file_descriptor_, listeners_) == -1) {
-      logger_->log_warn("attempted connection, saw %s", strerror(errno));
       return -1;
     }
   }

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/678c602c/libminifi/src/processors/InvokeHTTP.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/processors/InvokeHTTP.cpp b/libminifi/src/processors/InvokeHTTP.cpp
index 5a76751..61398b8 100644
--- a/libminifi/src/processors/InvokeHTTP.cpp
+++ b/libminifi/src/processors/InvokeHTTP.cpp
@@ -17,11 +17,8 @@
  */
 
 #include "processors/InvokeHTTP.h"
-
 #include <curl/curlbuild.h>
 #include <curl/easy.h>
-#include <sys/_types/_size_t.h>
-#include <sys/_types/_uuid_t.h>
 #include <uuid/uuid.h>
 #include <memory>
 #include <algorithm>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/678c602c/libminifi/test/SocketTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/SocketTests.cpp b/libminifi/test/SocketTests.cpp
new file mode 100644
index 0000000..263a8f3
--- /dev/null
+++ b/libminifi/test/SocketTests.cpp
@@ -0,0 +1,177 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
+
+#include "TestBase.h"
+#include "io/ClientSocket.h"
+
+using namespace org::apache::nifi::minifi::io;
+TEST_CASE("TestSocket", "[TestSocket1]") {
+
+  Socket socket("localhost", 8183);
+  REQUIRE(-1 == socket.initialize());
+  REQUIRE("localhost" == socket.getHostname());
+  socket.closeStream();
+
+}
+
+TEST_CASE("TestSocketWriteTest1", "[TestSocket2]") {
+
+  Socket socket("localhost", 8183);
+  REQUIRE(-1 == socket.initialize());
+
+  socket.writeData(0, 0);
+
+  std::vector<uint8_t> buffer;
+  buffer.push_back('a');
+
+  REQUIRE(-1 == socket.writeData(buffer, 1));
+
+  socket.closeStream();
+
+}
+
+TEST_CASE("TestSocketWriteTest2", "[TestSocket3]") {
+
+  std::vector<uint8_t> buffer;
+  buffer.push_back('a');
+
+  Socket server("localhost", 9183, 1);
+
+  REQUIRE(-1 != server.initialize());
+
+  Socket client("localhost", 9183);
+
+  REQUIRE(-1 != client.initialize());
+
+  REQUIRE(1 == client.writeData(buffer, 1));
+
+  std::vector<uint8_t> readBuffer;
+  readBuffer.resize(1);
+
+  REQUIRE(1 == server.readData(readBuffer, 1));
+
+  REQUIRE(readBuffer == buffer);
+
+  server.closeStream();
+
+  client.closeStream();
+
+}
+
+TEST_CASE("TestGetHostName", "[TestSocket4]") {
+
+  REQUIRE(Socket::getMyHostName().length() > 0);
+
+}
+
+TEST_CASE("TestWriteEndian64", "[TestSocket4]") {
+
+  std::vector<uint8_t> buffer;
+  buffer.push_back('a');
+
+  Socket server("localhost", 9183, 1);
+
+  REQUIRE(-1 != server.initialize());
+
+  Socket client("localhost", 9183);
+
+  REQUIRE(-1 != client.initialize());
+
+  uint64_t negative_one = -1;
+  REQUIRE(8 == client.write(negative_one));
+
+  uint64_t negative_two = 0;
+  REQUIRE(8 == server.read(negative_two));
+
+  REQUIRE(negative_two == negative_one);
+
+  server.closeStream();
+
+  client.closeStream();
+
+}
+
+TEST_CASE("TestWriteEndian32", "[TestSocket5]") {
+
+  std::vector<uint8_t> buffer;
+  buffer.push_back('a');
+
+  Socket server("localhost", 9183, 1);
+
+  REQUIRE(-1 != server.initialize());
+
+  Socket client("localhost", 9183);
+
+  REQUIRE(-1 != client.initialize());
+
+  {
+    uint32_t negative_one = -1;
+    REQUIRE(4 == client.write(negative_one));
+
+    uint32_t negative_two = 0;
+    REQUIRE(4 == server.read(negative_two));
+
+    REQUIRE(negative_two == negative_one);
+  }
+
+  {
+    uint16_t negative_one = -1;
+    REQUIRE(2 == client.write(negative_one));
+
+    uint16_t negative_two = 0;
+    REQUIRE(2 == server.read(negative_two));
+
+    REQUIRE(negative_two == negative_one);
+  }
+  server.closeStream();
+
+  client.closeStream();
+
+}
+
+TEST_CASE("TestSocketWriteTestAfterClose", "[TestSocket6]") {
+
+  std::vector<uint8_t> buffer;
+  buffer.push_back('a');
+
+  Socket server("localhost", 9183, 1);
+
+  REQUIRE(-1 != server.initialize());
+
+  Socket client("localhost", 9183);
+
+  REQUIRE(-1 != client.initialize());
+
+  REQUIRE(1 == client.writeData(buffer, 1));
+
+  std::vector<uint8_t> readBuffer;
+  readBuffer.resize(1);
+
+  REQUIRE(1 == server.readData(readBuffer, 1));
+
+  REQUIRE(readBuffer == buffer);
+
+  client.closeStream();
+
+  REQUIRE(-1 == client.writeData(buffer, 1));
+
+  server.closeStream();
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/678c602c/libminifi/test/unit/SocketTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/unit/SocketTests.cpp b/libminifi/test/unit/SocketTests.cpp
deleted file mode 100644
index e735f15..0000000
--- a/libminifi/test/unit/SocketTests.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "../TestBase.h"
-#include "io/ClientSocket.h"
-
-using namespace org::apache::nifi::minifi::io;
-TEST_CASE("TestSocket", "[TestSocket1]") {
-
-  Socket socket("localhost", 8183);
-  REQUIRE(-1 == socket.initialize());
-  REQUIRE("localhost" == socket.getHostname());
-  socket.closeStream();
-
-}
-
-TEST_CASE("TestSocketWriteTest1", "[TestSocket2]") {
-
-  Socket socket("localhost", 8183);
-  REQUIRE(-1 == socket.initialize());
-
-  socket.writeData(0, 0);
-
-  std::vector<uint8_t> buffer;
-  buffer.push_back('a');
-
-  REQUIRE(-1 == socket.writeData(buffer, 1));
-
-  socket.closeStream();
-
-}
-
-TEST_CASE("TestSocketWriteTest2", "[TestSocket3]") {
-
-  std::vector<uint8_t> buffer;
-  buffer.push_back('a');
-
-  Socket server("localhost", 9183, 1);
-
-  REQUIRE(-1 != server.initialize());
-
-  Socket client("localhost", 9183);
-
-  REQUIRE(-1 != client.initialize());
-
-  REQUIRE(1 == client.writeData(buffer, 1));
-
-  std::vector<uint8_t> readBuffer;
-  readBuffer.resize(1);
-
-  REQUIRE(1 == server.readData(readBuffer, 1));
-
-  REQUIRE(readBuffer == buffer);
-
-  server.closeStream();
-
-  client.closeStream();
-
-}
-
-TEST_CASE("TestGetHostName", "[TestSocket4]") {
-
-  REQUIRE(Socket::getMyHostName().length() > 0);
-
-}
-
-TEST_CASE("TestWriteEndian64", "[TestSocket4]") {
-
-  std::vector<uint8_t> buffer;
-  buffer.push_back('a');
-
-  Socket server("localhost", 9183, 1);
-
-  REQUIRE(-1 != server.initialize());
-
-  Socket client("localhost", 9183);
-
-  REQUIRE(-1 != client.initialize());
-
-  uint64_t negative_one = -1;
-  REQUIRE(8 == client.write(negative_one));
-
-  uint64_t negative_two = 0;
-  REQUIRE(8 == server.read(negative_two));
-
-  REQUIRE(negative_two == negative_one);
-
-  server.closeStream();
-
-  client.closeStream();
-
-}
-
-TEST_CASE("TestWriteEndian32", "[TestSocket5]") {
-
-  std::vector<uint8_t> buffer;
-  buffer.push_back('a');
-
-  Socket server("localhost", 9183, 1);
-
-  REQUIRE(-1 != server.initialize());
-
-  Socket client("localhost", 9183);
-
-  REQUIRE(-1 != client.initialize());
-
-  {
-    uint32_t negative_one = -1;
-    REQUIRE(4 == client.write(negative_one));
-
-    uint32_t negative_two = 0;
-    REQUIRE(4 == server.read(negative_two));
-
-    REQUIRE(negative_two == negative_one);
-  }
-
-  {
-    uint16_t negative_one = -1;
-    REQUIRE(2 == client.write(negative_one));
-
-    uint16_t negative_two = 0;
-    REQUIRE(2 == server.read(negative_two));
-
-    REQUIRE(negative_two == negative_one);
-  }
-  server.closeStream();
-
-  client.closeStream();
-
-}
-
-TEST_CASE("TestSocketWriteTestAfterClose", "[TestSocket6]") {
-
-  std::vector<uint8_t> buffer;
-  buffer.push_back('a');
-
-  Socket server("localhost", 9183, 1);
-
-  REQUIRE(-1 != server.initialize());
-
-  Socket client("localhost", 9183);
-
-  REQUIRE(-1 != client.initialize());
-
-  REQUIRE(1 == client.writeData(buffer, 1));
-
-  std::vector<uint8_t> readBuffer;
-  readBuffer.resize(1);
-
-  REQUIRE(1 == server.readData(readBuffer, 1));
-
-  REQUIRE(readBuffer == buffer);
-
-  client.closeStream();
-
-  REQUIRE(-1 == client.writeData(buffer, 1));
-
-  server.closeStream();
-
-}