Repository: nifi-minifi-cpp Updated Branches: refs/heads/master c9940e945 -> 1498ec87a
MINIFI-304: Update testing strategy MINIFI-306: Move Docs and Docker cmake code into a separate module. this will clean-up the end of the file. We will continue to do cleanup but this has a great impact to improve the readability of the root cmake MINIFI-305: Add header to iOS.cmake module This closes #96. Signed-off-by: Aldrin Piri <[email protected]> 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/1498ec87 Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/1498ec87 Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/1498ec87 Branch: refs/heads/master Commit: 1498ec87a67bc05632a3a99cf870828316fd6c01 Parents: c9940e9 Author: Marc Parisi <[email protected]> Authored: Mon May 8 19:13:00 2017 -0400 Committer: Aldrin Piri <[email protected]> Committed: Thu May 18 12:18:27 2017 -0400 ---------------------------------------------------------------------- CMakeLists.txt | 195 +--------- cmake/BuildDocs.cmake | 42 ++ cmake/BuildTests.cmake | 90 +++++ cmake/DockerConfig.cmake | 28 ++ cmake/iOS.cmake | 18 + libminifi/CMakeLists.txt | 2 +- libminifi/test/integration/ProcessorTests.cpp | 411 -------------------- libminifi/test/integration/SocketTests.cpp | 185 --------- libminifi/test/resource/TestHTTPGet.yml | 73 ++++ libminifi/test/resource/TestHTTPPost.yml | 87 +++++ libminifi/test/unit/CRCTests.cpp | 2 + libminifi/test/unit/ClassLoaderTests.cpp | 5 +- libminifi/test/unit/ControllerServiceTests.cpp | 1 + libminifi/test/unit/InvokeHTTPTests.cpp | 2 + libminifi/test/unit/LoggerTests.cpp | 2 +- libminifi/test/unit/ProcessorTests.cpp | 411 ++++++++++++++++++++ libminifi/test/unit/PropertyTests.cpp | 2 +- libminifi/test/unit/ProvenanceTests.cpp | 1 + libminifi/test/unit/RepoTests.cpp | 2 +- libminifi/test/unit/SerializationTests.cpp | 2 +- libminifi/test/unit/Site2SiteTests.cpp | 1 + libminifi/test/unit/SocketTests.cpp | 185 +++++++++ libminifi/test/unit/ThreadPoolTests.cpp | 1 + libminifi/test/unit/TimeUtilsTest.cpp | 21 - libminifi/test/unit/YamlCongifurationTests.cpp | 2 +- 25 files changed, 958 insertions(+), 813 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index e441c44..bf349a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ set(PROJECT_VERSION_MINOR 3) set(PROJECT_VERSION_PATCH 0) option(test "Build all tests." ON) + #### Establish Project Configuration #### # Enable usage of the VERSION specifier # https://cmake.org/cmake/help/v3.0/policy/CMP0048.html#policy:CMP0048 @@ -135,198 +136,16 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_FILE_NAME "${ASSEMBLY_BASE_NAME}") set(CPACK_BINARY_TGZ, "ON") - set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) set(CPACK_COMPONENTS_ALL bin) -include(CPack) - -enable_testing(test) - file(GLOB LIBMINIFI_TEST_SOURCES "libminifi/test/unit/*.cpp") - add_executable(unit_tests ${LIBMINIFI_TEST_SOURCES} ${SPD_SOURCES}) - target_include_directories(unit_tests PRIVATE BEFORE "thirdparty/catch") - target_include_directories(unit_tests PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(unit_tests PRIVATE BEFORE "thirdparty/jsoncpp/include") - target_include_directories(unit_tests PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(unit_tests PRIVATE BEFORE "include") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/core") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/core/controller") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/core/yaml") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/io") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(unit_tests PRIVATE BEFORE "libminifi/include/provenance") - target_link_libraries(unit_tests ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - if (CURL_FOUND) - target_include_directories(unit_tests PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) - target_link_libraries(unit_tests ${CURL_LIBRARIES}) - endif(CURL_FOUND) - add_test(NAME LibMinifiUnitTests COMMAND unit_tests) - - - file(GLOB LIBMINIFI_TEST_CS "libminifi/test/integration/ControllerServiceIntegrationTests.cpp") - add_executable(testControllerServices ${LIBMINIFI_TEST_CS} ${SPD_SOURCES}) - target_include_directories(testControllerServices PRIVATE BEFORE "thirdparty/catch") - target_include_directories(testControllerServices PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(testControllerServices PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(testControllerServices PRIVATE BEFORE "include") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/core") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/core/controller") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/io") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(testControllerServices PRIVATE BEFORE "libminifi/include/provenance") - target_link_libraries(testControllerServices ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - add_test(NAME TestControllerServices COMMAND testControllerServices "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestControllerServices.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") - - - file(GLOB LIBMINIFI_TEST_CS "libminifi/test/integration/HttpGetIntegrationTest.cpp") - add_executable(testHttpGet ${LIBMINIFI_TEST_CS} ${SPD_SOURCES}) - target_include_directories(testHttpGet PRIVATE BEFORE "thirdparty/catch") - target_include_directories(testHttpGet PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(testHttpGet PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(testHttpGet PRIVATE BEFORE "include") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/core") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/core/controller") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/io") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(testHttpGet PRIVATE BEFORE "libminifi/include/provenance") - target_link_libraries(testHttpGet ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - if (CURL_FOUND) - target_include_directories(testHttpGet PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) - target_link_libraries(testHttpGet ${CURL_LIBRARIES}) - endif(CURL_FOUND) - add_test(NAME testHttpGet COMMAND testHttpGet "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPGet.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") - add_test(NAME testHttpGetSecure COMMAND testHttpGet "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPGetSecure.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") - - file(GLOB LIBMINIFI_TEST_CS "libminifi/test/integration/HttpPostIntegrationTest.cpp") - add_executable(testHttpPost ${LIBMINIFI_TEST_CS} ${SPD_SOURCES}) - target_include_directories(testHttpPost PRIVATE BEFORE "thirdparty/catch") - target_include_directories(testHttpPost PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(testHttpPost PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(testHttpPost PRIVATE BEFORE "include") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/core") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/core/controller") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/io") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(testHttpPost PRIVATE BEFORE "libminifi/include/provenance") - target_link_libraries(testHttpPost ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - if (CURL_FOUND) - target_include_directories(testHttpPost PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) - target_link_libraries(testHttpPost ${CURL_LIBRARIES}) - endif(CURL_FOUND) - add_test(NAME testHttpPost COMMAND testHttpPost "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPPost.yml") - - - file(GLOB LIBMINIFI_TEST_EXECUTE_PROCESS "libminifi/test/integration/TestExecuteProcess.cpp") - add_executable(testExecuteProcess ${LIBMINIFI_TEST_EXECUTE_PROCESS} ${SPD_SOURCES}) - target_include_directories(testExecuteProcess PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(testExecuteProcess PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(testExecuteProcess PRIVATE BEFORE "include") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/core") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/core/controller") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/core/yaml") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/io") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(testExecuteProcess PRIVATE BEFORE "libminifi/include/provenance") - if (CURL_FOUND) - target_include_directories(testExecuteProcess PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) - target_link_libraries(testExecuteProcess ${CURL_LIBRARIES}) - endif(CURL_FOUND) - target_link_libraries(testExecuteProcess ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - add_test(NAME ExecuteProcess COMMAND testExecuteProcess) - - file(GLOB LIBMINIFI_TEST_SOCKETS "libminifi/test/integration/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 ${JSON_CPP_LIB}) - add_test(NAME TestSockets COMMAND testSockets) - - file(GLOB LIBMINIFI_TEST_PROCESSORS "libminifi/test/integration/ProcessorTests.cpp") - add_executable(testProcessors ${LIBMINIFI_TEST_PROCESSORS} ${SPD_SOURCES}) - target_include_directories(testProcessors PRIVATE BEFORE "thirdparty/catch") - target_include_directories(testProcessors PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") - target_include_directories(testProcessors PRIVATE BEFORE "thirdparty/jsoncpp/include") - target_include_directories(testProcessors PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) - target_include_directories(testProcessors PRIVATE BEFORE "include") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/core") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/core/repository") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/io") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/utils") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/processors") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/core/reporting") - target_include_directories(testProcessors PRIVATE BEFORE "libminifi/include/provenance") - if (CURL_FOUND) - target_include_directories(testProcessors PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) - target_link_libraries(testProcessors ${CURL_LIBRARIES}) - endif(CURL_FOUND) - target_link_libraries(testProcessors ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) - add_test(NAME TestProcessors COMMAND testProcessors) - - - -# Create a custom build target called "docker" that will invoke DockerBuild.sh and create the NiFi-MiNiFi-CPP Docker image -add_custom_target( - docker - COMMAND ${CMAKE_SOURCE_DIR}/docker/DockerBuild.sh 1000 1000 ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} minificppsource ${CMAKE_SOURCE_DIR} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docker/) - -# Create a custom build target that will run the linter. -add_custom_target( - linter - COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh ${CMAKE_SOURCE_DIR}/libminifi/include/ ${CMAKE_SOURCE_DIR}/libminifi/src/ ) +### include modules +include(CPack) -FIND_PACKAGE(Doxygen) - -if(DOXYGEN_FOUND) -if(EXISTS ${DOXYGEN_EXECUTABLE}) - -MESSAGE("Creating API Documentation ${DOXYGEN_EXECUTABLE}") -SET(DOXYGEN_INPUT "../docs/Doxyfile") -SET(DOXYGEN_OUTPUT "../docs") +include(BuildTests) + +include(BuildDocs) -ADD_CUSTOM_COMMAND( - OUTPUT ${DOXYGEN_OUTPUT} - COMMAND ${CMAKE_COMMAND} -E echo_append "Building LibMiNiFi API Documentation..." - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT} - COMMAND ${CMAKE_COMMAND} -E echo "Done." - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${DOXYGEN_INPUT} - ) +include(DockerConfig) -ADD_CUSTOM_TARGET(docs ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}) -else() -ADD_CUSTOM_TARGET(docs echo "Doxygen binary does not exist. Cannot create documentation... Please install Doxygen or verify correct installation.") -endif() -else() -ADD_CUSTOM_TARGET(docs echo "Doxygen does not exist. Please install it. Cannot create documentation...") -endif(DOXYGEN_FOUND) http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/cmake/BuildDocs.cmake ---------------------------------------------------------------------- diff --git a/cmake/BuildDocs.cmake b/cmake/BuildDocs.cmake new file mode 100644 index 0000000..bb75604 --- /dev/null +++ b/cmake/BuildDocs.cmake @@ -0,0 +1,42 @@ +# 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. + +FIND_PACKAGE(Doxygen) + +if(DOXYGEN_FOUND) +if(EXISTS ${DOXYGEN_EXECUTABLE}) + +MESSAGE("-- Creating API Documentation using ${DOXYGEN_EXECUTABLE}") +SET(DOXYGEN_INPUT "../docs/Doxyfile") +SET(DOXYGEN_OUTPUT "../docs") + +ADD_CUSTOM_COMMAND( + OUTPUT ${DOXYGEN_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E echo_append "Building LibMiNiFi API Documentation..." + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT} + COMMAND ${CMAKE_COMMAND} -E echo "Done." + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${DOXYGEN_INPUT} + ) + +ADD_CUSTOM_TARGET(docs ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}) +else() +ADD_CUSTOM_TARGET(docs echo "Doxygen binary does not exist. Cannot create documentation... Please install Doxygen or verify correct installation.") +endif() +else() +ADD_CUSTOM_TARGET(docs echo "Doxygen does not exist. Please install it. Cannot create documentation...") +endif(DOXYGEN_FOUND) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/cmake/BuildTests.cmake ---------------------------------------------------------------------- diff --git a/cmake/BuildTests.cmake b/cmake/BuildTests.cmake new file mode 100644 index 0000000..84cbf58 --- /dev/null +++ b/cmake/BuildTests.cmake @@ -0,0 +1,90 @@ +# 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. + + +### test functions +MACRO(GETSOURCEFILES result curdir) + FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) + SET(dirlist "") + FOREACH(child ${children}) + IF( "${curdir}/${child}" MATCHES .*\\.cpp) + + LIST(APPEND dirlist ${child}) + ENDIF() + ENDFOREACH() + SET(${result} ${dirlist}) +ENDMACRO() + +function(createTests testName) + message ("File name is ${testName}") + target_include_directories(${testName} PRIVATE BEFORE ${UUID_INCLUDE_DIRS}) + target_include_directories(${testName} PRIVATE BEFORE "thirdparty/catch") + target_include_directories(${testName} PRIVATE BEFORE "thirdparty/yaml-cpp-yaml-cpp-0.5.3/include") + target_include_directories(${testName} PRIVATE BEFORE "thirdparty/jsoncpp/include") + target_include_directories(${testName} PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS}) + target_include_directories(${testName} PRIVATE BEFORE "include") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/core") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/core/controller") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/core/repository") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/core/yaml") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/io") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/utils") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/processors") + target_include_directories(${testName} PRIVATE BEFORE "libminifi/include/provenance") + target_link_libraries(${testName} ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp ${JSON_CPP_LIB}) + if (CURL_FOUND) + target_include_directories(${testName} PRIVATE BEFORE ${CURL_INCLUDE_DIRS}) + target_link_libraries(${testName} ${CURL_LIBRARIES}) + endif(CURL_FOUND) +endfunction() + + +enable_testing(test) + +GETSOURCEFILES(UNIT_TESTS "${CMAKE_SOURCE_DIR}/libminifi/test/unit/") +GETSOURCEFILES(INTEGRATION_TESTS "${CMAKE_SOURCE_DIR}/libminifi/test/integration/") + +SET(UNIT_TEST_COUNT 0) +FOREACH(testfile ${UNIT_TESTS}) + get_filename_component(testfilename "${testfile}" NAME_WE) + add_executable("${testfilename}" "${CMAKE_SOURCE_DIR}/libminifi/test/unit/${testfile}" ${SPD_SOURCES}) + createTests("${testfilename}") + MATH(EXPR UNIT_TEST_COUNT "${UNIT_TEST_COUNT}+1") + add_test(NAME "${testfilename}" COMMAND "${testfilename}") +ENDFOREACH() +message("-- Finished building ${UNIT_TEST_COUNT} unit test file(s)...") + +SET(INT_TEST_COUNT 0) +FOREACH(testfile ${INTEGRATION_TESTS}) + get_filename_component(testfilename "${testfile}" NAME_WE) + add_executable("${testfilename}" "${CMAKE_SOURCE_DIR}/libminifi/test/integration/${testfile}" ${SPD_SOURCES}) + createTests("${testfilename}") + #message("Adding ${testfilename} from ${testfile}") + MATH(EXPR INT_TEST_COUNT "${INT_TEST_COUNT}+1") +ENDFOREACH() +message("-- Finished building ${INT_TEST_COUNT} integration test file(s)...") + +add_test(NAME ControllerServiceIntegrationTests COMMAND ControllerServiceIntegrationTests "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestControllerServices.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") + +add_test(NAME HttpGetIntegrationTest COMMAND HttpGetIntegrationTest "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPGet.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") + +add_test(NAME HttpGetIntegrationTestSecure COMMAND HttpGetIntegrationTest "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPGetSecure.yml" "${CMAKE_SOURCE_DIR}/libminifi/test/resources/") + +add_test(NAME HttpPostIntegrationTest COMMAND HttpPostIntegrationTest "${CMAKE_SOURCE_DIR}/libminifi/test/resources/TestHTTPPost.yml" ) + +add_test(NAME TestExecuteProcess COMMAND TestExecuteProcess ) http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/cmake/DockerConfig.cmake ---------------------------------------------------------------------- diff --git a/cmake/DockerConfig.cmake b/cmake/DockerConfig.cmake new file mode 100644 index 0000000..78a1140 --- /dev/null +++ b/cmake/DockerConfig.cmake @@ -0,0 +1,28 @@ +# 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. + +# Create a custom build target called "docker" that will invoke DockerBuild.sh and create the NiFi-MiNiFi-CPP Docker image +add_custom_target( + docker + COMMAND ${CMAKE_SOURCE_DIR}/docker/DockerBuild.sh 1000 1000 ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} minificppsource ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docker/) + +# Create a custom build target that will run the linter. +add_custom_target( + linter + COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh ${CMAKE_SOURCE_DIR}/libminifi/include/ ${CMAKE_SOURCE_DIR}/libminifi/src/ ) + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/cmake/iOS.cmake ---------------------------------------------------------------------- diff --git a/cmake/iOS.cmake b/cmake/iOS.cmake index 57b82f9..b390a97 100644 --- a/cmake/iOS.cmake +++ b/cmake/iOS.cmake @@ -1,3 +1,21 @@ +# 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. + + # This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake # files which are included with CMake 2.8.4 # It has been altered for iOS development http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/libminifi/CMakeLists.txt b/libminifi/CMakeLists.txt index 7e260d3..a0ec75f 100644 --- a/libminifi/CMakeLists.txt +++ b/libminifi/CMakeLists.txt @@ -71,7 +71,7 @@ add_library(spdlog STATIC ${SPD_SOURCES}) add_library(minifi STATIC ${SOURCES}) add_dependencies(minifi jsoncpp_project) -target_link_libraries(minifi ${JSONCPP_LIB}) +target_link_libraries(minifi ${UUID_LIBRARIES} ${JSONCPP_LIB}) find_package(ZLIB REQUIRED) include_directories(${ZLIB_INCLUDE_DIRS}) http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/integration/ProcessorTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/ProcessorTests.cpp b/libminifi/test/integration/ProcessorTests.cpp deleted file mode 100644 index 1c447a8..0000000 --- a/libminifi/test/integration/ProcessorTests.cpp +++ /dev/null @@ -1,411 +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. - */ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include <uuid/uuid.h> -#include <fstream> -#include "../unit/ProvenanceTestHelper.h" -#include "../TestBase.h" -#include "core/logging/LogAppenders.h" -#include "core/logging/BaseLogger.h" -#include "processors/ListenHTTP.h" -#include "processors/LogAttribute.h" -#include "processors/GetFile.h" -#include "core/Core.h" -#include "core/FlowFile.h" -#include "core/Processor.h" -#include "core/ProcessContext.h" -#include "core/ProcessSession.h" -#include "core/ProcessorNode.h" -#include "core/reporting/SiteToSiteProvenanceReportingTask.h" - - - -TEST_CASE("Test Creation of GetFile", "[getfileCreate]") { - std::shared_ptr<core::Processor> processor = std::make_shared< - org::apache::nifi::minifi::processors::GetFile>("processorname"); - REQUIRE(processor->getName() == "processorname"); -} - -TEST_CASE("Test Find file", "[getfileCreate2]") { - - TestController testController; - - testController.enableDebug(); - - std::shared_ptr<core::Processor> processor = std::make_shared< - org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); - - std::shared_ptr<core::Processor> processorReport = - std::make_shared< - org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask>(std::make_shared<org::apache::nifi::minifi::io::StreamFactory>(std::make_shared<org::apache::nifi::minifi::Configure>())); - - std::shared_ptr<core::Repository> test_repo = - std::make_shared<TestRepository>(); - - std::shared_ptr<TestRepository> repo = - std::static_pointer_cast<TestRepository>(test_repo); - - char format[] = "/tmp/gt.XXXXXX"; - char *dir = testController.createTempDirectory(format); - - uuid_t processoruuid; - REQUIRE(true == processor->getUUID(processoruuid)); - - std::shared_ptr<minifi::Connection> connection = std::make_shared< - minifi::Connection>(test_repo, "getfileCreate2Connection"); - connection->setRelationship(core::Relationship("success", "description")); - - // link the connections so that we can test results at the end for this - connection->setSource(processor); - connection->setDestination(processor); - - connection->setSourceUUID(processoruuid); - connection->setDestinationUUID(processoruuid); - - processor->addConnection(connection); - REQUIRE(dir != NULL); - - core::ProcessorNode node(processor); - std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = - nullptr; - core::ProcessContext context(node, controller_services_provider, test_repo); - core::ProcessSessionFactory factory(&context); - context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, - dir); - core::ProcessSession session(&context); - - processor->onSchedule(&context, &factory); - REQUIRE(processor->getName() == "getfileCreate2"); - - std::shared_ptr<core::FlowFile> record; - processor->setScheduledState(core::ScheduledState::RUNNING); - processor->onTrigger(&context, &session); - - provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); - std::set<provenance::ProvenanceEventRecord*> records = reporter->getEvents(); - record = session.get(); - REQUIRE(record == nullptr); - REQUIRE(records.size() == 0); - - std::fstream file; - std::stringstream ss; - ss << dir << "/" << "tstFile.ext"; - file.open(ss.str(), std::ios::out); - file << "tempFile"; - file.close(); - - processor->incrementActiveTasks(); - processor->setScheduledState(core::ScheduledState::RUNNING); - processor->onTrigger(&context, &session); - unlink(ss.str().c_str()); - reporter = session.getProvenanceReporter(); - - REQUIRE(processor->getName() == "getfileCreate2"); - - records = reporter->getEvents(); - - for (provenance::ProvenanceEventRecord *provEventRecord : records) { - REQUIRE(provEventRecord->getComponentType() == processor->getName()); - } - session.commit(); - std::shared_ptr<core::FlowFile> ffr = session.get(); - - ffr->getResourceClaim()->decreaseFlowFileRecordOwnedCount(); - REQUIRE(2 == repo->getRepoMap().size()); - - for (auto entry : repo->getRepoMap()) { - provenance::ProvenanceEventRecord newRecord; - newRecord.DeSerialize((uint8_t*) entry.second.data(), - entry.second.length()); - - bool found = false; - for (auto provRec : records) { - if (provRec->getEventId() == newRecord.getEventId()) { - REQUIRE(provRec->getEventId() == newRecord.getEventId()); - REQUIRE(provRec->getComponentId() == newRecord.getComponentId()); - REQUIRE(provRec->getComponentType() == newRecord.getComponentType()); - REQUIRE(provRec->getDetails() == newRecord.getDetails()); - REQUIRE(provRec->getEventDuration() == newRecord.getEventDuration()); - found = true; - break; - } - } - if (!found) - throw std::runtime_error("Did not find record"); - - } - - core::ProcessorNode nodeReport(processorReport); - core::ProcessContext contextReport(nodeReport,controller_services_provider, test_repo); - core::ProcessSessionFactory factoryReport(&contextReport); - core::ProcessSession sessionReport(&contextReport); - processorReport->onSchedule(&contextReport, &factoryReport); - std::shared_ptr< - org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask> taskReport = - std::static_pointer_cast< - org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask>( - processorReport); - taskReport->setBatchSize(1); - std::vector<std::shared_ptr<provenance::ProvenanceEventRecord>> recordsReport; - processorReport->incrementActiveTasks(); - processorReport->setScheduledState(core::ScheduledState::RUNNING); - std::string jsonStr; - repo->getProvenanceRecord(recordsReport, 1); - taskReport->getJsonReport(&contextReport, &sessionReport, recordsReport, - jsonStr); - REQUIRE(recordsReport.size() == 1); - REQUIRE( - taskReport->getName() - == std::string( - org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask::ReportTaskName)); - REQUIRE( - jsonStr.find("\"componentType\" : \"getfileCreate2\"") - != std::string::npos); -} - -TEST_CASE("Test GetFileLikeIt'sThreaded", "[getfileCreate3]") { - - TestController testController; - - testController.enableDebug(); - - std::shared_ptr<core::Processor> processor = std::make_shared< - org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); - - std::shared_ptr<core::Repository> test_repo = - std::make_shared<TestRepository>(); - - std::shared_ptr<TestRepository> repo = - std::static_pointer_cast<TestRepository>(test_repo); - - char format[] = "/tmp/gt.XXXXXX"; - char *dir = testController.createTempDirectory(format); - - uuid_t processoruuid; - REQUIRE(true == processor->getUUID(processoruuid)); - - std::shared_ptr<minifi::Connection> connection = std::make_shared< - minifi::Connection>(test_repo, "getfileCreate2Connection"); - connection->setRelationship(core::Relationship("success", "description")); - - // link the connections so that we can test results at the end for this - connection->setSource(processor); - connection->setDestination(processor); - - connection->setSourceUUID(processoruuid); - connection->setDestinationUUID(processoruuid); - - processor->addConnection(connection); - REQUIRE(dir != NULL); - - core::ProcessorNode node(processor); - std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = - nullptr; - core::ProcessContext context(node, controller_services_provider, test_repo); - core::ProcessSessionFactory factory(&context); - context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, - dir); - // replicate 10 threads - processor->setScheduledState(core::ScheduledState::RUNNING); - processor->onSchedule(&context, &factory); - - int prev = 0; - for (int i = 0; i < 10; i++) { - - core::ProcessSession session(&context); - REQUIRE(processor->getName() == "getfileCreate2"); - - std::shared_ptr<core::FlowFile> record; - - processor->onTrigger(&context, &session); - - provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); - std::set<provenance::ProvenanceEventRecord*> records = - reporter->getEvents(); - record = session.get(); - REQUIRE(record == nullptr); - REQUIRE(records.size() == 0); - - std::fstream file; - std::stringstream ss; - ss << dir << "/" << "tstFile.ext"; - file.open(ss.str(), std::ios::out); - file << "tempFile"; - file.close(); - - processor->incrementActiveTasks(); - processor->setScheduledState(core::ScheduledState::RUNNING); - processor->onTrigger(&context, &session); - unlink(ss.str().c_str()); - reporter = session.getProvenanceReporter(); - - REQUIRE(processor->getName() == "getfileCreate2"); - - records = reporter->getEvents(); - - for (provenance::ProvenanceEventRecord *provEventRecord : records) { - REQUIRE(provEventRecord->getComponentType() == processor->getName()); - } - session.commit(); - std::shared_ptr<core::FlowFile> ffr = session.get(); - - REQUIRE((repo->getRepoMap().size() % 2) == 0); - REQUIRE(repo->getRepoMap().size() == (prev + 2)); - prev += 2; - - } - -} - -TEST_CASE("LogAttributeTest", "[getfileCreate3]") { - std::ostringstream oss; - std::unique_ptr<logging::BaseLogger> outputLogger = std::unique_ptr< - logging::BaseLogger>( - new org::apache::nifi::minifi::core::logging::OutputStreamAppender(oss, - 0)); - std::shared_ptr<logging::Logger> logger = logging::Logger::getLogger(); - logger->updateLogger(std::move(outputLogger)); - - TestController testController; - - testController.enableDebug(); - - std::shared_ptr<core::Repository> repo = std::make_shared<TestRepository>(); - - std::shared_ptr<core::Processor> processor = std::make_shared< - org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); - - std::shared_ptr<core::Processor> logAttribute = std::make_shared< - org::apache::nifi::minifi::processors::LogAttribute>("logattribute"); - - char format[] = "/tmp/gt.XXXXXX"; - char *dir = testController.createTempDirectory(format); - - uuid_t processoruuid; - REQUIRE(true == processor->getUUID(processoruuid)); - - uuid_t logattribute_uuid; - REQUIRE(true == logAttribute->getUUID(logattribute_uuid)); - - std::shared_ptr<minifi::Connection> connection = std::make_shared< - minifi::Connection>(repo, "getfileCreate2Connection"); - connection->setRelationship(core::Relationship("success", "description")); - - std::shared_ptr<minifi::Connection> connection2 = std::make_shared< - minifi::Connection>(repo, "logattribute"); - connection2->setRelationship(core::Relationship("success", "description")); - - // link the connections so that we can test results at the end for this - connection->setSource(processor); - - // link the connections so that we can test results at the end for this - connection->setDestination(logAttribute); - - connection2->setSource(logAttribute); - - connection2->setSourceUUID(logattribute_uuid); - connection->setSourceUUID(processoruuid); - connection->setDestinationUUID(logattribute_uuid); - - processor->addConnection(connection); - logAttribute->addConnection(connection); - logAttribute->addConnection(connection2); - REQUIRE(dir != NULL); - - core::ProcessorNode node(processor); - core::ProcessorNode node2(logAttribute); - std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = - nullptr; - core::ProcessContext context(node, controller_services_provider, repo); - core::ProcessContext context2(node2, controller_services_provider, repo); - context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, - dir); - core::ProcessSession session(&context); - core::ProcessSession session2(&context2); - - REQUIRE(processor->getName() == "getfileCreate2"); - - std::shared_ptr<core::FlowFile> record; - processor->setScheduledState(core::ScheduledState::RUNNING); - - core::ProcessSessionFactory factory(&context); - processor->onSchedule(&context, &factory); - processor->onTrigger(&context, &session); - - logAttribute->incrementActiveTasks(); - logAttribute->setScheduledState(core::ScheduledState::RUNNING); - core::ProcessSessionFactory factory2(&context2); - logAttribute->onSchedule(&context2, &factory2); - logAttribute->onTrigger(&context2, &session2); - - provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); - std::set<provenance::ProvenanceEventRecord*> records = reporter->getEvents(); - record = session.get(); - REQUIRE(record == nullptr); - REQUIRE(records.size() == 0); - - std::fstream file; - std::stringstream ss; - ss << dir << "/" << "tstFile.ext"; - file.open(ss.str(), std::ios::out); - file << "tempFile"; - file.close(); - - processor->incrementActiveTasks(); - processor->setScheduledState(core::ScheduledState::RUNNING); - processor->onTrigger(&context, &session); - unlink(ss.str().c_str()); - reporter = session.getProvenanceReporter(); - - records = reporter->getEvents(); - session.commit(); - oss.str(""); - oss.clear(); - - logAttribute->incrementActiveTasks(); - logAttribute->setScheduledState(core::ScheduledState::RUNNING); - logAttribute->onTrigger(&context2, &session2); - - //session2.commit(); - records = reporter->getEvents(); - - std::string log_attribute_output = oss.str(); - REQUIRE( - log_attribute_output.find("key:absolute.path value:" + ss.str()) - != std::string::npos); - REQUIRE(log_attribute_output.find("Size:8 Offset:0") != std::string::npos); - REQUIRE( - log_attribute_output.find("key:path value:" + std::string(dir)) - != std::string::npos); - - outputLogger = std::unique_ptr<logging::BaseLogger>( - new org::apache::nifi::minifi::core::logging::NullAppender()); - logger->updateLogger(std::move(outputLogger)); - -} - -int fileSize(const char *add) { - std::ifstream mySource; - mySource.open(add, std::ios_base::binary); - mySource.seekg(0, std::ios_base::end); - int size = mySource.tellg(); - mySource.close(); - return size; -} - http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/integration/SocketTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/SocketTests.cpp b/libminifi/test/integration/SocketTests.cpp deleted file mode 100644 index 157e685..0000000 --- a/libminifi/test/integration/SocketTests.cpp +++ /dev/null @@ -1,185 +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. - */ - -#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(std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()), "localhost", 8183); - REQUIRE(-1 == socket.initialize()); - REQUIRE("localhost" == socket.getHostname()); - socket.closeStream(); - -} - -TEST_CASE("TestSocketWriteTest1", "[TestSocket2]") { - - Socket socket(std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()), "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'); - - std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); - - Socket server(socket_context, "localhost", 9183, 1); - - REQUIRE(-1 != server.initialize()); - - Socket client(socket_context, "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'); - - std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); - - Socket server(socket_context, "localhost", 9183, 1); - - REQUIRE(-1 != server.initialize()); - - Socket client(socket_context, "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'); - - std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); - - Socket server(socket_context, "localhost", 9183, 1); - - REQUIRE(-1 != server.initialize()); - - Socket client(socket_context, "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'); - - std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); - - Socket server(socket_context, "localhost", 9183, 1); - - REQUIRE(-1 != server.initialize()); - - Socket client(socket_context, "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/1498ec87/libminifi/test/resource/TestHTTPGet.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resource/TestHTTPGet.yml b/libminifi/test/resource/TestHTTPGet.yml new file mode 100644 index 0000000..0783b8e --- /dev/null +++ b/libminifi/test/resource/TestHTTPGet.yml @@ -0,0 +1,73 @@ +# +# 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. +# +Flow Controller: + name: MiNiFi Flow + id: 2438e3c8-015a-1000-79ca-83af40ec1990 +Processors: + - name: invoke + id: 2438e3c8-015a-1000-79ca-83af40ec1991 + class: org.apache.nifi.processors.standard.InvokeHTTP + max concurrent tasks: 1 + scheduling strategy: TIMER_DRIVEN + scheduling period: 1 sec + penalization period: 30 sec + yield period: 1 sec + run duration nanos: 0 + auto-terminated relationships list: + Properties: + HTTP Method: GET + Remote URL: https://curl.haxx.se/libcurl/c/httpput.html + - name: OhJeez + id: 2438e3c8-015a-1000-79ca-83af40ec1992 + class: org.apache.nifi.processors.standard.LogAttribute + max concurrent tasks: 1 + scheduling strategy: TIMER_DRIVEN + scheduling period: 1 sec + penalization period: 30 sec + yield period: 1 sec + run duration nanos: 0 + auto-terminated relationships list: response + Properties: + Log Level: info + Log Payload: true + +Connections: + - name: TransferFilesToRPG + id: 2438e3c8-015a-1000-79ca-83af40ec1997 + source name: invoke + source id: 2438e3c8-015a-1000-79ca-83af40ec1991 + source relationship name: success + destination name: OhJeez + destination id: 2438e3c8-015a-1000-79ca-83af40ec1992 + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec + - name: TransferFilesToRPG2 + id: 2438e3c8-015a-1000-79ca-83af40ec1917 + source name: OhJeez + source id: 2438e3c8-015a-1000-79ca-83af40ec1992 + destination name: OhJeez + destination id: 2438e3c8-015a-1000-79ca-83af40ec1992 + source relationship name: success + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec + +Remote Processing Groups: + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/resource/TestHTTPPost.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resource/TestHTTPPost.yml b/libminifi/test/resource/TestHTTPPost.yml new file mode 100644 index 0000000..837194d --- /dev/null +++ b/libminifi/test/resource/TestHTTPPost.yml @@ -0,0 +1,87 @@ +# +# 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. +# +Flow Controller: + name: MiNiFi Flow + id: 2438e3c8-015a-1000-79ca-83af40ec1990 +Processors: + - name: invoke + id: 2438e3c8-015a-1000-79ca-83af40ec1991 + class: org.apache.nifi.processors.standard.GetFile + max concurrent tasks: 1 + scheduling strategy: TIMER_DRIVEN + scheduling period: 1 sec + penalization period: 30 sec + yield period: 1 sec + run duration nanos: 0 + auto-terminated relationships list: + Properties: + Input Directory: /tmp/aljr39 + Keep Source File: false + + - name: OhJeez + id: 2438e3c8-015a-1000-79ca-83af40ec1992 + class: org.apache.nifi.processors.standard.InvokeHTTP + max concurrent tasks: 1 + scheduling strategy: TIMER_DRIVEN + scheduling period: 1 sec + penalization period: 30 sec + yield period: 1 sec + run duration nanos: 0 + auto-terminated relationships list: response + Properties: + HTTP Method: POST + Remote URL: http://requestb.in/u8ax9uu8 + + - name: Loggit + id: 2438e3c8-015a-1000-79ca-83af40ec1993 + class: org.apache.nifi.processors.standard.LogAttribute + max concurrent tasks: 1 + scheduling strategy: TIMER_DRIVEN + scheduling period: 1 sec + penalization period: 30 sec + yield period: 1 sec + run duration nanos: 0 + auto-terminated relationships list: response + Properties: + LogLevel: info + +Connections: + - name: TransferFilesToRPG + id: 2438e3c8-015a-1000-79ca-83af40ec1997 + source name: invoke + source id: 2438e3c8-015a-1000-79ca-83af40ec1991 + source relationship name: success + destination name: OhJeez + destination id: 2438e3c8-015a-1000-79ca-83af40ec1992 + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec + - name: TransferFilesToRPG2 + id: 2438e3c8-015a-1000-79ca-83af40ec1917 + source name: OhJeez + source id: 2438e3c8-015a-1000-79ca-83af40ec1992 + destination name: OhJeez + destination id: 2438e3c8-015a-1000-79ca-83af40ec1993 + source relationship name: success + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec + +Remote Processing Groups: + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/CRCTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/CRCTests.cpp b/libminifi/test/unit/CRCTests.cpp index 54f27bc..74279f4 100644 --- a/libminifi/test/unit/CRCTests.cpp +++ b/libminifi/test/unit/CRCTests.cpp @@ -16,6 +16,8 @@ * limitations under the License. */ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file + #include <string> #include <vector> #include "io/CRCStream.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/ClassLoaderTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ClassLoaderTests.cpp b/libminifi/test/unit/ClassLoaderTests.cpp index f5cb6e9..d2d2664 100644 --- a/libminifi/test/unit/ClassLoaderTests.cpp +++ b/libminifi/test/unit/ClassLoaderTests.cpp @@ -15,8 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "../../include/core/ClassLoader.h" +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include <uuid/uuid.h> +#include "core/ClassLoader.h" #include "../TestBase.h" #include "io/ClientSocket.h" #include "core/Processor.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/ControllerServiceTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ControllerServiceTests.cpp b/libminifi/test/unit/ControllerServiceTests.cpp index e8fb4ce..d657d87 100644 --- a/libminifi/test/unit/ControllerServiceTests.cpp +++ b/libminifi/test/unit/ControllerServiceTests.cpp @@ -15,6 +15,7 @@ * 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 <uuid/uuid.h> #include <fstream> #include "FlowController.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/InvokeHTTPTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/InvokeHTTPTests.cpp b/libminifi/test/unit/InvokeHTTPTests.cpp index 0200710..f5df8d8 100644 --- a/libminifi/test/unit/InvokeHTTPTests.cpp +++ b/libminifi/test/unit/InvokeHTTPTests.cpp @@ -15,6 +15,8 @@ * 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 <uuid/uuid.h> #include <fstream> #include "FlowController.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/LoggerTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/LoggerTests.cpp b/libminifi/test/unit/LoggerTests.cpp index 48942f0..b083671 100644 --- a/libminifi/test/unit/LoggerTests.cpp +++ b/libminifi/test/unit/LoggerTests.cpp @@ -15,7 +15,7 @@ * 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 <memory> #include <ctime> #include "../TestBase.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/ProcessorTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ProcessorTests.cpp b/libminifi/test/unit/ProcessorTests.cpp new file mode 100644 index 0000000..1c447a8 --- /dev/null +++ b/libminifi/test/unit/ProcessorTests.cpp @@ -0,0 +1,411 @@ + +/** + * + * 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 <uuid/uuid.h> +#include <fstream> +#include "../unit/ProvenanceTestHelper.h" +#include "../TestBase.h" +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include "processors/ListenHTTP.h" +#include "processors/LogAttribute.h" +#include "processors/GetFile.h" +#include "core/Core.h" +#include "core/FlowFile.h" +#include "core/Processor.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "core/ProcessorNode.h" +#include "core/reporting/SiteToSiteProvenanceReportingTask.h" + + + +TEST_CASE("Test Creation of GetFile", "[getfileCreate]") { + std::shared_ptr<core::Processor> processor = std::make_shared< + org::apache::nifi::minifi::processors::GetFile>("processorname"); + REQUIRE(processor->getName() == "processorname"); +} + +TEST_CASE("Test Find file", "[getfileCreate2]") { + + TestController testController; + + testController.enableDebug(); + + std::shared_ptr<core::Processor> processor = std::make_shared< + org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); + + std::shared_ptr<core::Processor> processorReport = + std::make_shared< + org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask>(std::make_shared<org::apache::nifi::minifi::io::StreamFactory>(std::make_shared<org::apache::nifi::minifi::Configure>())); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + + char format[] = "/tmp/gt.XXXXXX"; + char *dir = testController.createTempDirectory(format); + + uuid_t processoruuid; + REQUIRE(true == processor->getUUID(processoruuid)); + + std::shared_ptr<minifi::Connection> connection = std::make_shared< + minifi::Connection>(test_repo, "getfileCreate2Connection"); + connection->setRelationship(core::Relationship("success", "description")); + + // link the connections so that we can test results at the end for this + connection->setSource(processor); + connection->setDestination(processor); + + connection->setSourceUUID(processoruuid); + connection->setDestinationUUID(processoruuid); + + processor->addConnection(connection); + REQUIRE(dir != NULL); + + core::ProcessorNode node(processor); + std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = + nullptr; + core::ProcessContext context(node, controller_services_provider, test_repo); + core::ProcessSessionFactory factory(&context); + context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, + dir); + core::ProcessSession session(&context); + + processor->onSchedule(&context, &factory); + REQUIRE(processor->getName() == "getfileCreate2"); + + std::shared_ptr<core::FlowFile> record; + processor->setScheduledState(core::ScheduledState::RUNNING); + processor->onTrigger(&context, &session); + + provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); + std::set<provenance::ProvenanceEventRecord*> records = reporter->getEvents(); + record = session.get(); + REQUIRE(record == nullptr); + REQUIRE(records.size() == 0); + + std::fstream file; + std::stringstream ss; + ss << dir << "/" << "tstFile.ext"; + file.open(ss.str(), std::ios::out); + file << "tempFile"; + file.close(); + + processor->incrementActiveTasks(); + processor->setScheduledState(core::ScheduledState::RUNNING); + processor->onTrigger(&context, &session); + unlink(ss.str().c_str()); + reporter = session.getProvenanceReporter(); + + REQUIRE(processor->getName() == "getfileCreate2"); + + records = reporter->getEvents(); + + for (provenance::ProvenanceEventRecord *provEventRecord : records) { + REQUIRE(provEventRecord->getComponentType() == processor->getName()); + } + session.commit(); + std::shared_ptr<core::FlowFile> ffr = session.get(); + + ffr->getResourceClaim()->decreaseFlowFileRecordOwnedCount(); + REQUIRE(2 == repo->getRepoMap().size()); + + for (auto entry : repo->getRepoMap()) { + provenance::ProvenanceEventRecord newRecord; + newRecord.DeSerialize((uint8_t*) entry.second.data(), + entry.second.length()); + + bool found = false; + for (auto provRec : records) { + if (provRec->getEventId() == newRecord.getEventId()) { + REQUIRE(provRec->getEventId() == newRecord.getEventId()); + REQUIRE(provRec->getComponentId() == newRecord.getComponentId()); + REQUIRE(provRec->getComponentType() == newRecord.getComponentType()); + REQUIRE(provRec->getDetails() == newRecord.getDetails()); + REQUIRE(provRec->getEventDuration() == newRecord.getEventDuration()); + found = true; + break; + } + } + if (!found) + throw std::runtime_error("Did not find record"); + + } + + core::ProcessorNode nodeReport(processorReport); + core::ProcessContext contextReport(nodeReport,controller_services_provider, test_repo); + core::ProcessSessionFactory factoryReport(&contextReport); + core::ProcessSession sessionReport(&contextReport); + processorReport->onSchedule(&contextReport, &factoryReport); + std::shared_ptr< + org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask> taskReport = + std::static_pointer_cast< + org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask>( + processorReport); + taskReport->setBatchSize(1); + std::vector<std::shared_ptr<provenance::ProvenanceEventRecord>> recordsReport; + processorReport->incrementActiveTasks(); + processorReport->setScheduledState(core::ScheduledState::RUNNING); + std::string jsonStr; + repo->getProvenanceRecord(recordsReport, 1); + taskReport->getJsonReport(&contextReport, &sessionReport, recordsReport, + jsonStr); + REQUIRE(recordsReport.size() == 1); + REQUIRE( + taskReport->getName() + == std::string( + org::apache::nifi::minifi::core::reporting::SiteToSiteProvenanceReportingTask::ReportTaskName)); + REQUIRE( + jsonStr.find("\"componentType\" : \"getfileCreate2\"") + != std::string::npos); +} + +TEST_CASE("Test GetFileLikeIt'sThreaded", "[getfileCreate3]") { + + TestController testController; + + testController.enableDebug(); + + std::shared_ptr<core::Processor> processor = std::make_shared< + org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + + char format[] = "/tmp/gt.XXXXXX"; + char *dir = testController.createTempDirectory(format); + + uuid_t processoruuid; + REQUIRE(true == processor->getUUID(processoruuid)); + + std::shared_ptr<minifi::Connection> connection = std::make_shared< + minifi::Connection>(test_repo, "getfileCreate2Connection"); + connection->setRelationship(core::Relationship("success", "description")); + + // link the connections so that we can test results at the end for this + connection->setSource(processor); + connection->setDestination(processor); + + connection->setSourceUUID(processoruuid); + connection->setDestinationUUID(processoruuid); + + processor->addConnection(connection); + REQUIRE(dir != NULL); + + core::ProcessorNode node(processor); + std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = + nullptr; + core::ProcessContext context(node, controller_services_provider, test_repo); + core::ProcessSessionFactory factory(&context); + context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, + dir); + // replicate 10 threads + processor->setScheduledState(core::ScheduledState::RUNNING); + processor->onSchedule(&context, &factory); + + int prev = 0; + for (int i = 0; i < 10; i++) { + + core::ProcessSession session(&context); + REQUIRE(processor->getName() == "getfileCreate2"); + + std::shared_ptr<core::FlowFile> record; + + processor->onTrigger(&context, &session); + + provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); + std::set<provenance::ProvenanceEventRecord*> records = + reporter->getEvents(); + record = session.get(); + REQUIRE(record == nullptr); + REQUIRE(records.size() == 0); + + std::fstream file; + std::stringstream ss; + ss << dir << "/" << "tstFile.ext"; + file.open(ss.str(), std::ios::out); + file << "tempFile"; + file.close(); + + processor->incrementActiveTasks(); + processor->setScheduledState(core::ScheduledState::RUNNING); + processor->onTrigger(&context, &session); + unlink(ss.str().c_str()); + reporter = session.getProvenanceReporter(); + + REQUIRE(processor->getName() == "getfileCreate2"); + + records = reporter->getEvents(); + + for (provenance::ProvenanceEventRecord *provEventRecord : records) { + REQUIRE(provEventRecord->getComponentType() == processor->getName()); + } + session.commit(); + std::shared_ptr<core::FlowFile> ffr = session.get(); + + REQUIRE((repo->getRepoMap().size() % 2) == 0); + REQUIRE(repo->getRepoMap().size() == (prev + 2)); + prev += 2; + + } + +} + +TEST_CASE("LogAttributeTest", "[getfileCreate3]") { + std::ostringstream oss; + std::unique_ptr<logging::BaseLogger> outputLogger = std::unique_ptr< + logging::BaseLogger>( + new org::apache::nifi::minifi::core::logging::OutputStreamAppender(oss, + 0)); + std::shared_ptr<logging::Logger> logger = logging::Logger::getLogger(); + logger->updateLogger(std::move(outputLogger)); + + TestController testController; + + testController.enableDebug(); + + std::shared_ptr<core::Repository> repo = std::make_shared<TestRepository>(); + + std::shared_ptr<core::Processor> processor = std::make_shared< + org::apache::nifi::minifi::processors::GetFile>("getfileCreate2"); + + std::shared_ptr<core::Processor> logAttribute = std::make_shared< + org::apache::nifi::minifi::processors::LogAttribute>("logattribute"); + + char format[] = "/tmp/gt.XXXXXX"; + char *dir = testController.createTempDirectory(format); + + uuid_t processoruuid; + REQUIRE(true == processor->getUUID(processoruuid)); + + uuid_t logattribute_uuid; + REQUIRE(true == logAttribute->getUUID(logattribute_uuid)); + + std::shared_ptr<minifi::Connection> connection = std::make_shared< + minifi::Connection>(repo, "getfileCreate2Connection"); + connection->setRelationship(core::Relationship("success", "description")); + + std::shared_ptr<minifi::Connection> connection2 = std::make_shared< + minifi::Connection>(repo, "logattribute"); + connection2->setRelationship(core::Relationship("success", "description")); + + // link the connections so that we can test results at the end for this + connection->setSource(processor); + + // link the connections so that we can test results at the end for this + connection->setDestination(logAttribute); + + connection2->setSource(logAttribute); + + connection2->setSourceUUID(logattribute_uuid); + connection->setSourceUUID(processoruuid); + connection->setDestinationUUID(logattribute_uuid); + + processor->addConnection(connection); + logAttribute->addConnection(connection); + logAttribute->addConnection(connection2); + REQUIRE(dir != NULL); + + core::ProcessorNode node(processor); + core::ProcessorNode node2(logAttribute); + std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = + nullptr; + core::ProcessContext context(node, controller_services_provider, repo); + core::ProcessContext context2(node2, controller_services_provider, repo); + context.setProperty(org::apache::nifi::minifi::processors::GetFile::Directory, + dir); + core::ProcessSession session(&context); + core::ProcessSession session2(&context2); + + REQUIRE(processor->getName() == "getfileCreate2"); + + std::shared_ptr<core::FlowFile> record; + processor->setScheduledState(core::ScheduledState::RUNNING); + + core::ProcessSessionFactory factory(&context); + processor->onSchedule(&context, &factory); + processor->onTrigger(&context, &session); + + logAttribute->incrementActiveTasks(); + logAttribute->setScheduledState(core::ScheduledState::RUNNING); + core::ProcessSessionFactory factory2(&context2); + logAttribute->onSchedule(&context2, &factory2); + logAttribute->onTrigger(&context2, &session2); + + provenance::ProvenanceReporter *reporter = session.getProvenanceReporter(); + std::set<provenance::ProvenanceEventRecord*> records = reporter->getEvents(); + record = session.get(); + REQUIRE(record == nullptr); + REQUIRE(records.size() == 0); + + std::fstream file; + std::stringstream ss; + ss << dir << "/" << "tstFile.ext"; + file.open(ss.str(), std::ios::out); + file << "tempFile"; + file.close(); + + processor->incrementActiveTasks(); + processor->setScheduledState(core::ScheduledState::RUNNING); + processor->onTrigger(&context, &session); + unlink(ss.str().c_str()); + reporter = session.getProvenanceReporter(); + + records = reporter->getEvents(); + session.commit(); + oss.str(""); + oss.clear(); + + logAttribute->incrementActiveTasks(); + logAttribute->setScheduledState(core::ScheduledState::RUNNING); + logAttribute->onTrigger(&context2, &session2); + + //session2.commit(); + records = reporter->getEvents(); + + std::string log_attribute_output = oss.str(); + REQUIRE( + log_attribute_output.find("key:absolute.path value:" + ss.str()) + != std::string::npos); + REQUIRE(log_attribute_output.find("Size:8 Offset:0") != std::string::npos); + REQUIRE( + log_attribute_output.find("key:path value:" + std::string(dir)) + != std::string::npos); + + outputLogger = std::unique_ptr<logging::BaseLogger>( + new org::apache::nifi::minifi::core::logging::NullAppender()); + logger->updateLogger(std::move(outputLogger)); + +} + +int fileSize(const char *add) { + std::ifstream mySource; + mySource.open(add, std::ios_base::binary); + mySource.seekg(0, std::ios_base::end); + int size = mySource.tellg(); + mySource.close(); + return size; +} + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/PropertyTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/PropertyTests.cpp b/libminifi/test/unit/PropertyTests.cpp index dee809f..cd686a1 100644 --- a/libminifi/test/unit/PropertyTests.cpp +++ b/libminifi/test/unit/PropertyTests.cpp @@ -15,7 +15,7 @@ * 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 "../../include/core/Property.h" #include "utils/StringUtils.h" #include "../TestBase.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/ProvenanceTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ProvenanceTests.cpp b/libminifi/test/unit/ProvenanceTests.cpp index 6a134ed..947932e 100644 --- a/libminifi/test/unit/ProvenanceTests.cpp +++ b/libminifi/test/unit/ProvenanceTests.cpp @@ -16,6 +16,7 @@ * 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 "../unit/ProvenanceTestHelper.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/RepoTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/RepoTests.cpp b/libminifi/test/unit/RepoTests.cpp index c8deb89..83ea49d 100644 --- a/libminifi/test/unit/RepoTests.cpp +++ b/libminifi/test/unit/RepoTests.cpp @@ -15,7 +15,7 @@ * 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 "../unit/ProvenanceTestHelper.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/SerializationTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/SerializationTests.cpp b/libminifi/test/unit/SerializationTests.cpp index 039ed57..d9cea0f 100644 --- a/libminifi/test/unit/SerializationTests.cpp +++ b/libminifi/test/unit/SerializationTests.cpp @@ -15,7 +15,7 @@ * 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 "io/BaseStream.h" #include "Site2SitePeer.h" #include "Site2SiteClientProtocol.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/Site2SiteTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/Site2SiteTests.cpp b/libminifi/test/unit/Site2SiteTests.cpp index 5af86d5..43afa0e 100644 --- a/libminifi/test/unit/Site2SiteTests.cpp +++ b/libminifi/test/unit/Site2SiteTests.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include "io/BaseStream.h" #include "Site2SitePeer.h" #include "Site2SiteClientProtocol.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/SocketTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/SocketTests.cpp b/libminifi/test/unit/SocketTests.cpp new file mode 100644 index 0000000..157e685 --- /dev/null +++ b/libminifi/test/unit/SocketTests.cpp @@ -0,0 +1,185 @@ +/** + * + * 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(std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()), "localhost", 8183); + REQUIRE(-1 == socket.initialize()); + REQUIRE("localhost" == socket.getHostname()); + socket.closeStream(); + +} + +TEST_CASE("TestSocketWriteTest1", "[TestSocket2]") { + + Socket socket(std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()), "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'); + + std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); + + Socket server(socket_context, "localhost", 9183, 1); + + REQUIRE(-1 != server.initialize()); + + Socket client(socket_context, "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'); + + std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); + + Socket server(socket_context, "localhost", 9183, 1); + + REQUIRE(-1 != server.initialize()); + + Socket client(socket_context, "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'); + + std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); + + Socket server(socket_context, "localhost", 9183, 1); + + REQUIRE(-1 != server.initialize()); + + Socket client(socket_context, "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'); + + std::shared_ptr<SocketContext> socket_context = std::make_shared<SocketContext>(std::make_shared<minifi::Configure>()); + + Socket server(socket_context, "localhost", 9183, 1); + + REQUIRE(-1 != server.initialize()); + + Socket client(socket_context, "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/1498ec87/libminifi/test/unit/ThreadPoolTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ThreadPoolTests.cpp b/libminifi/test/unit/ThreadPoolTests.cpp index 5c85e19..cd34293 100644 --- a/libminifi/test/unit/ThreadPoolTests.cpp +++ b/libminifi/test/unit/ThreadPoolTests.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include <future> #include "../TestBase.h" #include "utils/ThreadPool.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/TimeUtilsTest.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/TimeUtilsTest.cpp b/libminifi/test/unit/TimeUtilsTest.cpp deleted file mode 100644 index 9470338..0000000 --- a/libminifi/test/unit/TimeUtilsTest.cpp +++ /dev/null @@ -1,21 +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. - */ - - - - http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1498ec87/libminifi/test/unit/YamlCongifurationTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/YamlCongifurationTests.cpp b/libminifi/test/unit/YamlCongifurationTests.cpp index 0c229d0..f598f38 100644 --- a/libminifi/test/unit/YamlCongifurationTests.cpp +++ b/libminifi/test/unit/YamlCongifurationTests.cpp @@ -15,7 +15,7 @@ * 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 <memory> #include <string> #include <core/RepositoryFactory.h>
