http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/TestExecuteProcess.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/TestExecuteProcess.cpp b/libminifi/test/TestExecuteProcess.cpp deleted file mode 100644 index 31509d7..0000000 --- a/libminifi/test/TestExecuteProcess.cpp +++ /dev/null @@ -1,131 +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 <uuid/uuid.h> -#include <fstream> -#include "FlowController.h" -#include "unit/ProvenanceTestHelper.h" -#include "core/logging/LogAppenders.h" -#include "core/logging/BaseLogger.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" - -int main(int argc, char **argv) -{ - - 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)); - - - outputLogger = std::unique_ptr<logging::BaseLogger>( - new org::apache::nifi::minifi::core::logging::NullAppender()); - logger->updateLogger(std::move(outputLogger)); - - std::shared_ptr<core::Processor> processor = std::make_shared< - org::apache::nifi::minifi::processors::ExecuteProcess>("executeProcess"); - processor->setMaxConcurrentTasks(1); - - std::shared_ptr<core::Repository> test_repo = - std::make_shared<TestRepository>(); - - std::shared_ptr<TestRepository> repo = - std::static_pointer_cast<TestRepository>(test_repo); - std::shared_ptr<minifi::FlowController> controller = std::make_shared< - TestFlowController>(test_repo, test_repo); - - uuid_t processoruuid; - assert(true == processor->getUUID(processoruuid)); - - std::shared_ptr<minifi::Connection> connection = std::make_shared< - minifi::Connection>(test_repo, "executeProcessConnection"); - 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); - assert(processor->getName() == "executeProcess"); - - std::shared_ptr<core::FlowFile> record; - processor->setScheduledState(core::ScheduledState::RUNNING); - - processor->initialize(); - - std::atomic<bool> is_ready(false); - - std::vector<std::thread> processor_workers; - - core::ProcessorNode node2(processor); - std::shared_ptr<core::ProcessContext> contextset = std::make_shared< - core::ProcessContext>(node2, test_repo); - core::ProcessSessionFactory factory(contextset.get()); - processor->onSchedule(contextset.get(), &factory); - - for (int i = 0; i < 1; i++) { - // - processor_workers.push_back( - std::thread( - [processor,test_repo,&is_ready]() - { - core::ProcessorNode node(processor); - std::shared_ptr<core::ProcessContext> context = std::make_shared<core::ProcessContext>(node, test_repo); - context->setProperty(org::apache::nifi::minifi::processors::ExecuteProcess::Command,"sleep 0.5"); - //context->setProperty(org::apache::nifi::minifi::processors::ExecuteProcess::CommandArguments," 1 >>" + ss.str()); - std::shared_ptr<core::ProcessSession> session = std::make_shared<core::ProcessSession>(context.get()); - while(!is_ready.load(std::memory_order_relaxed)) { - - } - - processor->onTrigger(context.get(), session.get()); - - })); - } - - is_ready.store(true, std::memory_order_relaxed); - //is_ready.store(true); - - std::for_each(processor_workers.begin(), processor_workers.end(), - [](std::thread &t) - { - t.join(); - }); - - outputLogger = std::unique_ptr<logging::BaseLogger>( - new org::apache::nifi::minifi::core::logging::NullAppender()); - logger->updateLogger(std::move(outputLogger)); - - - std::shared_ptr<org::apache::nifi::minifi::processors::ExecuteProcess> execp = - std::static_pointer_cast< - org::apache::nifi::minifi::processors::ExecuteProcess>(processor); - -}
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/integration/ControllerServiceIntegrationTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/ControllerServiceIntegrationTests.cpp b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp new file mode 100644 index 0000000..00add78 --- /dev/null +++ b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp @@ -0,0 +1,186 @@ +/** + * + * 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 <cassert> +#include <chrono> +#include <fstream> +#include <memory> +#include <string> +#include <thread> +#include <type_traits> +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include <vector> + +#include "../include/core/controller/ControllerServiceMap.h" +#include "../include/core/controller/StandardControllerServiceNode.h" +#include "../include/core/controller/StandardControllerServiceProvider.h" +#include "controllers/SSLContextService.h" +#include "../include/core/Core.h" +#include "../include/core/logging/Logger.h" +#include "../include/core/ProcessGroup.h" +#include "../include/core/Resource.h" +#include "../include/core/yaml/YamlConfiguration.h" +#include "../include/FlowController.h" +#include "../include/properties/Configure.h" +#include "../unit/MockClasses.h" +#include "../unit/ProvenanceTestHelper.h" + +REGISTER_RESOURCE(MockControllerService); +REGISTER_RESOURCE(MockProcessor); +std::string test_file_location; +std::string key_dir; + +std::shared_ptr<core::controller::StandardControllerServiceNode> newCsNode( + std::shared_ptr<core::controller::ControllerServiceProvider> provider, + const std::string id) { + std::shared_ptr<core::controller::ControllerService> service = + std::make_shared<MockControllerService>(); + std::shared_ptr<core::controller::StandardControllerServiceNode> testNode = + std::make_shared<core::controller::StandardControllerServiceNode>( + service, provider, id, std::make_shared<minifi::Configure>()); + + return testNode; +} + +void waitToVerifyProcessor() { + std::this_thread::sleep_for(std::chrono::seconds(2)); +} + +int main(int argc, char **argv) { + + if (argc > 2) { + test_file_location = argv[1]; + key_dir = argv[1]; + } + + logging::Logger::getLogger()->setLogLevel("trace"); + + std::shared_ptr<minifi::Configure> configuration = std::make_shared< + minifi::Configure>(); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + std::shared_ptr<core::Repository> test_flow_repo = std::make_shared< + TestFlowRepository>(); + + configuration->set(minifi::Configure::nifi_flow_configuration_file, + test_file_location); + /* + * nifi.security.client.certificate=/Users/mparisi/Downloads/nifi-toolkit-1.1.1/bin/cn.crt.pem + nifi.security.client.private.key=/Users/mparisi/Downloads/nifi-toolkit-1.1.1/bin/cn.ckey.pem + nifi.security.client.pass.phrase=/Users/mparisi/Downloads/nifi-toolkit-1.1.1/bin/cn.pass + nifi.security.client.ca.certificate=/Users/mparisi/Downloads/nifi-toolkit-1.1.1/bin/nifi-cert.pem + */ + std::string client_cert = "cn.crt.pem"; + std::string priv_key_file = "cn.ckey.pem"; + std::string passphrase = "cn.pass"; + std::string ca_cert = "nifi-cert.pem"; + configuration->set(minifi::Configure::nifi_security_client_certificate, + test_file_location); + configuration->set(minifi::Configure::nifi_security_client_private_key, + priv_key_file); + configuration->set(minifi::Configure::nifi_security_client_pass_phrase, + passphrase); + configuration->set(minifi::Configure::nifi_default_directory, key_dir); + + std::shared_ptr<minifi::io::StreamFactory> stream_factory = std::make_shared< + minifi::io::StreamFactory>(configuration); + + std::unique_ptr<core::FlowConfiguration> yaml_ptr = std::unique_ptr< + core::YamlConfiguration>( + new core::YamlConfiguration(test_repo, test_repo, stream_factory, + configuration, test_file_location)); + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + + std::shared_ptr<minifi::FlowController> controller = std::make_shared< + minifi::FlowController>(test_repo, test_flow_repo, configuration, + std::move(yaml_ptr), + DEFAULT_ROOT_GROUP_NAME, + true); + + disabled = false; + std::shared_ptr<core::controller::ControllerServiceMap> map = + std::make_shared<core::controller::ControllerServiceMap>(); + + core::YamlConfiguration yaml_config(test_repo, test_repo, stream_factory, + configuration, test_file_location); + + std::unique_ptr<core::ProcessGroup> ptr = yaml_config.getRoot( + test_file_location); + std::shared_ptr<core::ProcessGroup> pg = std::shared_ptr<core::ProcessGroup>( + ptr.get()); + ptr.release(); + + std::shared_ptr<core::controller::StandardControllerServiceProvider> provider = + std::make_shared<core::controller::StandardControllerServiceProvider>( + map, pg, std::make_shared<minifi::Configure>()); + std::shared_ptr<core::controller::ControllerServiceNode> mockNode = pg + ->findControllerService("MockItLikeIts1995"); + assert(mockNode != nullptr); + mockNode->enable(); + std::vector<std::shared_ptr<core::controller::ControllerServiceNode> > linkedNodes = + mockNode->getLinkedControllerServices(); + assert(linkedNodes.size() == 1); + + std::shared_ptr<core::controller::ControllerServiceNode> notexistNode = pg + ->findControllerService("MockItLikeItsWrong"); + assert(notexistNode == nullptr); + logging::Logger::getLogger()->log_info( + "STARTING FLOW CONTROLLER INTEGRATION TEST"); + controller->load(); + controller->start(); + waitToVerifyProcessor(); + std::shared_ptr<core::controller::ControllerServiceNode> ssl_client_cont = + controller->getControllerServiceNode("SSLClientServiceTest"); + ssl_client_cont->enable(); + assert(ssl_client_cont != nullptr); + assert(ssl_client_cont->getControllerServiceImplementation() != nullptr); + std::shared_ptr<minifi::controllers::SSLContextService> ssl_client = + std::static_pointer_cast<minifi::controllers::SSLContextService>( + ssl_client_cont->getControllerServiceImplementation()); + + assert(ssl_client->getCACertificate().length() > 0); + + // now let's disable one of the controller services. + std::shared_ptr<core::controller::ControllerServiceNode> cs_id = controller + ->getControllerServiceNode("ID"); + assert(cs_id != nullptr); + controller->disableControllerService(cs_id); + disabled = true; + waitToVerifyProcessor(); + controller->enableControllerService(cs_id); + disabled = false; + waitToVerifyProcessor(); + std::shared_ptr<core::controller::ControllerServiceNode> mock_cont = + controller->getControllerServiceNode("MockItLikeIts1995"); + assert(cs_id->enabled()); + + controller->disableReferencingServices(mock_cont); + disabled = true; + waitToVerifyProcessor(); + assert(cs_id->enabled() == false); + controller->enableReferencingServices(mock_cont); + disabled = false; + waitToVerifyProcessor(); + assert(cs_id->enabled() == true); + + controller->waitUnload(60000); + return 0; +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/integration/HttpGetIntegrationTest.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/HttpGetIntegrationTest.cpp b/libminifi/test/integration/HttpGetIntegrationTest.cpp new file mode 100644 index 0000000..aa24dfe --- /dev/null +++ b/libminifi/test/integration/HttpGetIntegrationTest.cpp @@ -0,0 +1,128 @@ +/** + * + * 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 <cassert> +#include <chrono> +#include <fstream> +#include <memory> +#include <string> +#include <thread> +#include <type_traits> +#include <vector> +#include <sys/stat.h> + +#include "utils/StringUtils.h" +#include "core/Core.h" +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include "core/logging/Logger.h" +#include "core/ProcessGroup.h" +#include "core/yaml/YamlConfiguration.h" +#include "FlowController.h" +#include "properties/Configure.h" +#include "../unit/ProvenanceTestHelper.h" +#include "io/StreamFactory.h" + + +void waitToVerifyProcessor() { + std::this_thread::sleep_for(std::chrono::seconds(10)); +} + +int main(int argc, char **argv) { + + std::string key_dir,test_file_location; + if (argc > 1) { + test_file_location = argv[1]; + key_dir = argv[2]; + } + std::shared_ptr<minifi::Configure> configuration = std::make_shared< + minifi::Configure>(); + configuration->set(minifi::Configure::nifi_default_directory, key_dir); + mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + 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)); + logger->setLogLevel("trace"); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + std::shared_ptr<core::Repository> test_flow_repo = std::make_shared< + TestFlowRepository>(); + + configuration->set(minifi::Configure::nifi_flow_configuration_file, + test_file_location); + + std::shared_ptr<minifi::io::StreamFactory> stream_factory = std::make_shared< + minifi::io::StreamFactory>(configuration); + std::unique_ptr<core::FlowConfiguration> yaml_ptr = std::unique_ptr< + core::YamlConfiguration>( + new core::YamlConfiguration(test_repo, test_repo, stream_factory, + configuration, test_file_location)); + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + + std::shared_ptr<minifi::FlowController> controller = std::make_shared< + minifi::FlowController>(test_repo, test_flow_repo, configuration, + std::move(yaml_ptr), + DEFAULT_ROOT_GROUP_NAME, + true); + + core::YamlConfiguration yaml_config(test_repo, test_repo, stream_factory,configuration, + test_file_location); + + std::unique_ptr<core::ProcessGroup> ptr = yaml_config.getRoot( + test_file_location); + std::shared_ptr<core::ProcessGroup> pg = std::shared_ptr<core::ProcessGroup>( + ptr.get()); + ptr.release(); + + controller->load(); + controller->start(); + waitToVerifyProcessor(); + + controller->waitUnload(60000); + std::string logs = oss.str(); + std::cout << logs << std::endl; + assert(logs.find("key:filename value:") != std::string::npos); + assert( + logs.find( + "key:invokehttp.request.url value:https://curl.haxx.se/libcurl/c/httpput.html") + != std::string::npos); + assert(logs.find("Size:8970 Offset:0") != std::string::npos); + assert( + logs.find("key:invokehttp.status.code value:200") != std::string::npos); + std::string stringtofind = "Resource Claim created ./content_repository/"; + + size_t loc = logs.find(stringtofind); + while (loc > 0) { + std::string id = logs.substr(loc + stringtofind.size(), 36); + + loc = logs.find(stringtofind, loc + 1); + std::string path = "content_repository/" + id; + unlink(path.c_str()); + + if (loc == std::string::npos) + break; + } + rmdir("./content_repository"); + return 0; +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/integration/HttpPostIntegrationTest.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/HttpPostIntegrationTest.cpp b/libminifi/test/integration/HttpPostIntegrationTest.cpp new file mode 100644 index 0000000..45abd34 --- /dev/null +++ b/libminifi/test/integration/HttpPostIntegrationTest.cpp @@ -0,0 +1,126 @@ +/** + * + * 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 <cassert> +#include <chrono> +#include <fstream> +#include <memory> +#include <string> +#include <thread> +#include <type_traits> +#include <vector> +#include <sys/stat.h> + +#include "utils/StringUtils.h" +#include "core/Core.h" +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include "core/logging/Logger.h" +#include "core/ProcessGroup.h" +#include "core/yaml/YamlConfiguration.h" +#include "FlowController.h" +#include "properties/Configure.h" +#include "../unit/ProvenanceTestHelper.h" +#include "io/StreamFactory.h" +#include "properties/Configure.h" + +std::string test_file_location; + +void waitToVerifyProcessor() { + std::this_thread::sleep_for(std::chrono::seconds(2)); +} + +int main(int argc, char **argv) { + + if (argc > 1) { + test_file_location = argv[1]; + } + mkdir("/tmp/aljr39/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + std::ofstream myfile; + myfile.open("/tmp/aljr39/example.txt"); + myfile << "Hello world" << std::endl; + myfile.close(); + mkdir("content_repository", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + 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)); + logger->setLogLevel("debug"); + + std::shared_ptr<minifi::Configure> configuration = std::make_shared< + minifi::Configure>(); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + std::shared_ptr<core::Repository> test_flow_repo = std::make_shared< + TestFlowRepository>(); + + configuration->set(minifi::Configure::nifi_flow_configuration_file, + test_file_location); + std::shared_ptr<minifi::io::StreamFactory> stream_factory = std::make_shared< + minifi::io::StreamFactory>(configuration); + + std::unique_ptr<core::FlowConfiguration> yaml_ptr = std::unique_ptr< + core::YamlConfiguration>( + new core::YamlConfiguration(test_repo, test_repo, stream_factory, + configuration, test_file_location)); + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + + std::shared_ptr<minifi::FlowController> controller = std::make_shared< + minifi::FlowController>(test_repo, test_flow_repo, configuration, + std::move(yaml_ptr), + DEFAULT_ROOT_GROUP_NAME, + true); + + core::YamlConfiguration yaml_config(test_repo, test_repo, stream_factory, + configuration, test_file_location); + + std::unique_ptr<core::ProcessGroup> ptr = yaml_config.getRoot( + test_file_location); + std::shared_ptr<core::ProcessGroup> pg = std::shared_ptr<core::ProcessGroup>( + ptr.get()); + ptr.release(); + + controller->load(); + controller->start(); + waitToVerifyProcessor(); + + controller->waitUnload(60000); + std::string logs = oss.str(); + assert(logs.find("curl performed") != std::string::npos); + assert(logs.find("Import offset 0 length 12") != std::string::npos); + + std::string stringtofind = "Resource Claim created ./content_repository/"; + + size_t loc = logs.find(stringtofind); + while (loc > 0 && loc != std::string::npos) { + std::string id = logs.substr(loc + stringtofind.size(), 36); + loc = logs.find(stringtofind, loc + 1); + std::string path = "content_repository/" + id; + unlink(path.c_str()); + if (loc == std::string::npos) + break; + } + + rmdir("./content_repository"); + return 0; +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/integration/ProcessorTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/ProcessorTests.cpp b/libminifi/test/integration/ProcessorTests.cpp new file mode 100644 index 0000000..1c447a8 --- /dev/null +++ b/libminifi/test/integration/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/c9940e94/libminifi/test/integration/SocketTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/SocketTests.cpp b/libminifi/test/integration/SocketTests.cpp new file mode 100644 index 0000000..157e685 --- /dev/null +++ b/libminifi/test/integration/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/c9940e94/libminifi/test/integration/TestExecuteProcess.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/integration/TestExecuteProcess.cpp b/libminifi/test/integration/TestExecuteProcess.cpp new file mode 100644 index 0000000..a7c6da6 --- /dev/null +++ b/libminifi/test/integration/TestExecuteProcess.cpp @@ -0,0 +1,137 @@ +/** + * + * 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 <uuid/uuid.h> +#include <fstream> + +#include "../unit/ProvenanceTestHelper.h" +#include "FlowController.h" +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include "processors/GetFile.h" +#include "core/Core.h" +#include "core/FlowFile.h" +#include "core/Processor.h" +#include "core/controller/ControllerServiceNode.h" +#include "core/controller/ControllerServiceProvider.h" +#include "processors/ExecuteProcess.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "core/ProcessorNode.h" + +int main(int argc, char **argv) +{ + + 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)); + + + outputLogger = std::unique_ptr<logging::BaseLogger>( + new org::apache::nifi::minifi::core::logging::NullAppender()); + logger->updateLogger(std::move(outputLogger)); + + std::shared_ptr<core::Processor> processor = std::make_shared< + org::apache::nifi::minifi::processors::ExecuteProcess>("executeProcess"); + processor->setMaxConcurrentTasks(1); + + std::shared_ptr<core::Repository> test_repo = + std::make_shared<TestRepository>(); + + std::shared_ptr<TestRepository> repo = + std::static_pointer_cast<TestRepository>(test_repo); + std::shared_ptr<minifi::FlowController> controller = std::make_shared< + TestFlowController>(test_repo, test_repo); + + uuid_t processoruuid; + assert(true == processor->getUUID(processoruuid)); + + std::shared_ptr<minifi::Connection> connection = std::make_shared< + minifi::Connection>(test_repo, "executeProcessConnection"); + 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); + assert(processor->getName() == "executeProcess"); + + std::shared_ptr<core::FlowFile> record; + processor->setScheduledState(core::ScheduledState::RUNNING); + + processor->initialize(); + + std::atomic<bool> is_ready(false); + + std::vector<std::thread> processor_workers; + + core::ProcessorNode node2(processor); + std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = nullptr; + std::shared_ptr<core::ProcessContext> contextset = std::make_shared< + core::ProcessContext>(node2,controller_services_provider, test_repo); + core::ProcessSessionFactory factory(contextset.get()); + processor->onSchedule(contextset.get(), &factory); + + for (int i = 0; i < 1; i++) { + // + processor_workers.push_back( + std::thread( + [processor,test_repo,&is_ready]() + { + core::ProcessorNode node(processor); + std::shared_ptr<core::controller::ControllerServiceProvider> controller_services_provider = nullptr; + std::shared_ptr<core::ProcessContext> context = std::make_shared<core::ProcessContext>(node,controller_services_provider, test_repo); + context->setProperty(org::apache::nifi::minifi::processors::ExecuteProcess::Command,"sleep 0.5"); + //context->setProperty(org::apache::nifi::minifi::processors::ExecuteProcess::CommandArguments," 1 >>" + ss.str()); + std::shared_ptr<core::ProcessSession> session = std::make_shared<core::ProcessSession>(context.get()); + while(!is_ready.load(std::memory_order_relaxed)) { + + } + + processor->onTrigger(context.get(), session.get()); + + })); + } + + is_ready.store(true, std::memory_order_relaxed); + //is_ready.store(true); + + std::for_each(processor_workers.begin(), processor_workers.end(), + [](std::thread &t) + { + t.join(); + }); + + outputLogger = std::unique_ptr<logging::BaseLogger>( + new org::apache::nifi::minifi::core::logging::NullAppender()); + logger->updateLogger(std::move(outputLogger)); + + + std::shared_ptr<org::apache::nifi::minifi::processors::ExecuteProcess> execp = + std::static_pointer_cast< + org::apache::nifi::minifi::processors::ExecuteProcess>(processor); + +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/TestControllerServices.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/TestControllerServices.yml b/libminifi/test/resources/TestControllerServices.yml new file mode 100644 index 0000000..3923c87 --- /dev/null +++ b/libminifi/test/resources/TestControllerServices.yml @@ -0,0 +1,62 @@ +Flow Controller: + name: MiNiFi Flow + id: 2438e3c8-015a-1000-79ca-83af40ec1990 + +Processors: + - name: MockProcessorIto + id: 1438e3c8-015a-1000-79ca-83af40ec1991 + class: org.apache.nifi.processors.standard.MockProcessor + 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: + linkedService: MockItLikeIts1995 + +Connections: + - name: TransferFilesToRPG + id: 1438e3c8-015a-1000-79ca-83af40ec1997 + source name: MockProcessorIto + source id: 1438e3c8-015a-1000-79ca-83af40ec1991 + source relationship name: success + destination name: MockProcessorIto + destination id: 1438e3c8-015a-1000-79ca-83af40ec1991 + destination relationship name: success + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec + +Controller Services: + - name: MockItLikeIts1995 + id: 2438e3c8-015a-1000-79ca-83af40ec1991 + class: MockControllerService + Properties: + Linked Services: + - value: ID + - name: SSLClientServiceTest + id: 2438e3c8-015a-1000-79ca-83af40ec1994 + class: SSLContextService + Properties: + Client Certificate: + - value: cn.crt.pem + Private Key: + - value: cn.ckey.pem + Passphrase: + - value: cn.pass + CA Certificate: + - value: nifi-cert.pem + - name: ID + id: 2438e3c8-015a-1000-79ca-83af40ec1992 + class: MockControllerService + Properties: + Linked Services: + - name: MockItLikeItsWrong + id: 2438e3c8-015a-1000-79ca-83af40ec1993 + class: MockControllerSer + Properties: + Linked Services: + - value: ID + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/TestHTTPGet.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/TestHTTPGet.yml b/libminifi/test/resources/TestHTTPGet.yml new file mode 100644 index 0000000..0783b8e --- /dev/null +++ b/libminifi/test/resources/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/c9940e94/libminifi/test/resources/TestHTTPGetSecure.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/TestHTTPGetSecure.yml b/libminifi/test/resources/TestHTTPGetSecure.yml new file mode 100644 index 0000000..2bb4f23 --- /dev/null +++ b/libminifi/test/resources/TestHTTPGetSecure.yml @@ -0,0 +1,88 @@ +# +# 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: + SSL Context Service: SSLContextService + 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 + +Controller Services: + - name: SSLContextService + id: 2438e3c8-015a-1000-79ca-83af40ec1994 + class: SSLContextService + Properties: + Client Certificate: + - value: cn.crt.pem + Private Key: + - value: cn.ckey.pem + Passphrase: + - value: cn.pass + CA Certificate: + - value: nifi-cert.pem + +Remote Processing Groups: + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/TestHTTPPost.yml ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/TestHTTPPost.yml b/libminifi/test/resources/TestHTTPPost.yml new file mode 100644 index 0000000..837194d --- /dev/null +++ b/libminifi/test/resources/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/c9940e94/libminifi/test/resources/cn.ckey.pem ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/cn.ckey.pem b/libminifi/test/resources/cn.ckey.pem new file mode 100644 index 0000000..23017fa --- /dev/null +++ b/libminifi/test/resources/cn.ckey.pem @@ -0,0 +1,31 @@ +Bag Attributes + friendlyName: nifi-key + localKeyID: 73 E6 90 32 31 08 F5 87 C2 CE 8D 17 10 32 05 F2 95 6A 9E 9C +Key Attributes: <No Attributes> +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAn9zCw5/EDWKe/jZWIou8aohC0wDhe8azYAORb45kEEqB2Q1p +JJDHIIoNgDukXhrcPWFz2FxdZ56so7kkrjkN507t11dJn+wuFwfVot0us35NvOcl +t3rHNy38nid4gV4+F01mXksrNWCnvTNSmp4XIWlRHxFkiZyKVTRxyo5U3fr2zmtm +80LtopoBEf5Lr29WYZrjgA+A8iDMKvVlgmpriau44Vie9L3DIot4eAO7eN3o5UG+ +oYE7RQ6BdXSo9+D/tbma0rZvS9WHw3Qin7gDygaGKbwWEFuwhSYO+lcsywsB5hT3 +uxGTRnskafE29/vvzmsygMlNoRXk5NaRlnf/NQIDAQABAoIBAD0Z6tNMiGm5TR3K +9OclU7HAPRJbHtPpYXwMQRVLblGPuMuWRZ61O3bjbT+bDDrvt0g6rEWBIC5PxpqZ +VDzHD9peH6gT888NPZyN4Qjr00LFvr659n+HjQc5K3njijqgI8lSSxM1VeGD/Pji +2erBDAQ4NcpTIoM6cuEYN3n9JtDk1B/nJ4vWD+1Ak/sS91hmaIy/1hOUofgaqp4W +8+pnur/lEn4d9yCfEbDOfkfep49si8kDw8SdBH6uFpr1s71E2q9PfGv5WN4LGxc+ +fX3zHHnxFRB9XRivo42bIxCRyf/U/GNeD0ldlXzmfUkVKw/V1CLioRKP+KaJ7aT6 +FYZE1GECgYEA6Wk4t7kkNGszWiFJpGlUmB50CmmH0zdb+qeiBhxuAAgcPveglXJX +qNAJOxDY29nSQqhtuRe/vhQEk88axNVfTIHBFF+29P8ODQPkQsOn5pyCeii+MTmJ +R1Kq8/5F08CPCJ2n/Rfd1xYKsiB6QJDeRCxbUHuqlOwwkuASNnHVPI0CgYEAr1Vd +SXToxlNOesCuvfK+IV+7qanAag49MSoHKYuzii4YhaS/9yC8HGNUNU4ZOr3gyOCo +rlPGsJx+7HGAIylg7M+w0xrAOlwcBIfD6DHSoFSCbpxKQGOdav5PpKvKmXDbnCeq +hvlJRSRepC9raZePRqHMeO+y0SCMCW/3kCvBZ0kCgYBPVEXEm5YkgrLHVTz0NiBc +Oy1xRIC3Vr9aJ5M3xH3WYOtIs1zOrjgA1gPtIUKzJgsCQMBaAipW7fLIUcFlWKe1 +FvyKciV6ix05azMvRdRQ2qy13BcYH9f6d6xGlQsidvWmFf88U9o/+evUspkaTKJe +RT0b04wcZVH0+Vb3TiUNGQKBgQCBmpxGfEDEuTe9zUhd6F1a1iUmGPC+dKAPA34f +28BvV/uQbmPoDS5/3XyVmpFTtp++XTLTCeJJEqVPqeaKF0AqTKvsoE2P1h5vytup +e4qyMUXo9WZ9iiUGvc2pb8NnAOGU4E1RUFw029mJi/PeLcYe8+LtUmHf7CsXnshk +rbNc4QKBgFAIoRZonaHDU4AYXx/6Xem2EneJ3tXyxMZ8WEjNQKaWmA5rkGbbSijk +0EaJ3bMexlyp1qgv86f4LrfLbZLdqTDSzhqlTV0x0b6D7MRBLuzcQUqsKmDmxkxq +CkJUqnNhVWM0SMG8cy9K1WMBecdot8I2OH8L00uwKkkM4pQ1En+o +-----END RSA PRIVATE KEY----- http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/cn.crt.pem ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/cn.crt.pem b/libminifi/test/resources/cn.crt.pem new file mode 100644 index 0000000..3a786db --- /dev/null +++ b/libminifi/test/resources/cn.crt.pem @@ -0,0 +1,25 @@ +Bag Attributes + friendlyName: nifi-key + localKeyID: 73 E6 90 32 31 08 F5 87 C2 CE 8D 17 10 32 05 F2 95 6A 9E 9C +subject=/OU=NIFI/CN=test +issuer=/OU=NIFI/CN=localhost +-----BEGIN CERTIFICATE----- +MIIDQTCCAimgAwIBAgIKAVpnU2lhAAAAADANBgkqhkiG9w0BAQsFADAjMQ0wCwYD +VQQLDAROSUZJMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTcwMjIyMTkzNjQ0WhcN +MjAwMjIyMTkzNjQ0WjAeMQ0wCwYDVQQLDAROSUZJMQ0wCwYDVQQDDAR0ZXN0MIIB +IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn9zCw5/EDWKe/jZWIou8aohC +0wDhe8azYAORb45kEEqB2Q1pJJDHIIoNgDukXhrcPWFz2FxdZ56so7kkrjkN507t +11dJn+wuFwfVot0us35NvOclt3rHNy38nid4gV4+F01mXksrNWCnvTNSmp4XIWlR +HxFkiZyKVTRxyo5U3fr2zmtm80LtopoBEf5Lr29WYZrjgA+A8iDMKvVlgmpriau4 +4Vie9L3DIot4eAO7eN3o5UG+oYE7RQ6BdXSo9+D/tbma0rZvS9WHw3Qin7gDygaG +KbwWEFuwhSYO+lcsywsB5hT3uxGTRnskafE29/vvzmsygMlNoRXk5NaRlnf/NQID +AQABo3wwejAdBgNVHQ4EFgQUc+aQMjEI9YfCzo0XEDIF8pVqnpwwHwYDVR0jBBgw +FoAUtz2ps5YYKDRnj1ixtUA8NOjmo2IwDgYDVR0PAQH/BAQDAgP4MAkGA1UdEwQC +MAAwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMA0GCSqGSIb3DQEBCwUA +A4IBAQBbpGba97qG7eXIQm3hiMKsuGpMNoybKxUlazOEeqG5QemMxSDOy2TDMBgM +2oQU3RImrNMLbfWCxnQ1biWclis9exR5IkUintb8hEE8Vbq/nTLCi7IvpEg+2oDc +kvSs8UTrI17EQAzh/vc9ljbgtvJD0L8khO8oPPSEpweD+vk/ZragQJOzeA7ohYMM +kJDJ/a9HNNe6nPx+NOCWQH2hJS8Ok2z57hBgy1oym/xJoT9z3vfjQcHtNK4qLNlx +P+o2mWNC2ZYNe84ghUfMD+btlnA3MrPEEOJHXOoE9UgaeNZXjwuF6N1qI2RCWSVW +IU4uwXjW1icAEYZbCK9f2l5cK+Vu +-----END CERTIFICATE----- http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/cn.pass ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/cn.pass b/libminifi/test/resources/cn.pass new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/resources/nifi-cert.pem ---------------------------------------------------------------------- diff --git a/libminifi/test/resources/nifi-cert.pem b/libminifi/test/resources/nifi-cert.pem new file mode 100644 index 0000000..4e404cd --- /dev/null +++ b/libminifi/test/resources/nifi-cert.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDSTCCAjGgAwIBAgIKAVpnU2gBAAAAADANBgkqhkiG9w0BAQsFADAjMQ0wCwYD +VQQLDAROSUZJMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTcwMjIyMTkzNjQzWhcN +MjAwMjIyMTkzNjQzWjAjMQ0wCwYDVQQLDAROSUZJMRIwEAYDVQQDDAlsb2NhbGhv +c3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDAIXpNyG57u1HroE+D +zzpY5g0+BLA1qrUolBK4ZwQcrbCUAS5h+JjP0tuMUtlEtFjYIX2YgZvrzdvKue84 +xyrpr5h1cNo4dmeQoFKwj/FPNJxdO/cQpK55nSwy4PsvTL/YKzaV/yF4FQRSqY17 +Xkn3K8RDUaknSPuIIKd4piON7MVaCVFK//2y6+pULEjGviP2Bc4ODJTfB3AjGRBQ +EleTga0OnTdHFzHoKHRUHCNwaRgeFywYdHODp1yvv3m0t85A0D9WWN7T5G0f8pT9 +ZeDOX2cq3EPtdTBnKGgSXM1x6E3RaYoOACYBKdy/Lv5hjMpTr0fXhD7af9ql2irH ++RNBAgMBAAGjfzB9MA4GA1UdDwEB/wQEAwIB/jAMBgNVHRMEBTADAQH/MB0GA1Ud +DgQWBBS3PamzlhgoNGePWLG1QDw06OajYjAfBgNVHSMEGDAWgBS3PamzlhgoNGeP +WLG1QDw06OajYjAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDQYJKoZI +hvcNAQELBQADggEBAKcXKG4rPnEuYS/AJfHs5RlGsg2h/VnbCT50A4OsUNcv5KSe +WFeP2ctp793MsIsUKA3FgGi+23aaUTtlAclQQs/xlBiDq6XmkED/DjLVzt5dTHrl +gS6aFtDHffMn5tLaUKOkNETOG/Fnc+XPAENB8GyqBd2Q/1L0SWSHXSTecX+aA9P6 +lvrRtWOqyGHiRoaRE5+VUjyO+0ToEgj9E+3rV8JL66BT7SWQusLGqbX1OoANCMTj +BRYeqB0g0PrXU+6chh6StpNSnYzkQdoxLUIDYYZx2XGsbkjDh/k6ni6bgJEKEOCu +T3Z2tyvGpc+PjLRXW/WyXCpg/xfr3+GSVKI6ark= +-----END CERTIFICATE----- http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/unit/ClassLoaderTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ClassLoaderTests.cpp b/libminifi/test/unit/ClassLoaderTests.cpp new file mode 100644 index 0000000..f5cb6e9 --- /dev/null +++ b/libminifi/test/unit/ClassLoaderTests.cpp @@ -0,0 +1,35 @@ +/** + * + * 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 "../../include/core/ClassLoader.h" +#include "../TestBase.h" +#include "io/ClientSocket.h" +#include "core/Processor.h" +#include "core/ClassLoader.h" +#include "processors/AppendHostInfo.h" +#include "core/logging/LogAppenders.h" + +using namespace org::apache::nifi::minifi::io; +TEST_CASE("TestLoader", "[TestLoader]") { + +REQUIRE ( nullptr != core::ClassLoader::getDefaultClassLoader().instantiate("AppendHostInfo","hosty")); +REQUIRE ( nullptr != core::ClassLoader::getDefaultClassLoader().instantiate("ListenHTTP","hosty2")); +REQUIRE ( nullptr == core::ClassLoader::getDefaultClassLoader().instantiate("Don'tExist","hosty3")); +REQUIRE ( nullptr == core::ClassLoader::getDefaultClassLoader().instantiate("","EmptyEmpty")); + +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/c9940e94/libminifi/test/unit/ControllerServiceTests.cpp ---------------------------------------------------------------------- diff --git a/libminifi/test/unit/ControllerServiceTests.cpp b/libminifi/test/unit/ControllerServiceTests.cpp new file mode 100644 index 0000000..e8fb4ce --- /dev/null +++ b/libminifi/test/unit/ControllerServiceTests.cpp @@ -0,0 +1,89 @@ +/** + * + * 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 <uuid/uuid.h> +#include <fstream> +#include "FlowController.h" +#include "../TestBase.h" +#include "properties/Configure.h" +#include "core/logging/LogAppenders.h" +#include "core/logging/BaseLogger.h" +#include "processors/GetFile.h" +#include "core/Core.h" +#include "Exception.h" +#include "../../include/core/FlowFile.h" +#include "../unit/MockClasses.h" +#include "../unit/ProvenanceTestHelper.h" +#include "core/yaml/YamlConfiguration.h" +#include "core/Processor.h" +#include "core/controller/ControllerServiceMap.h" +#include "core/controller/StandardControllerServiceNode.h" +namespace ControllerServiceTests { + +TEST_CASE("Test ControllerServicesMap", "[cs1]") { + core::controller::ControllerServiceMap map; + REQUIRE(0 == map.getAllControllerServices().size()); + + std::shared_ptr<core::controller::ControllerService> service = + std::make_shared<MockControllerService>(); + std::shared_ptr<core::controller::StandardControllerServiceNode> testNode = + std::make_shared<core::controller::StandardControllerServiceNode>( + service, "ID", std::make_shared<minifi::Configure>()); + + map.put("ID", testNode); + REQUIRE(1 == map.getAllControllerServices().size()); + + REQUIRE(nullptr != map.getControllerServiceNode("ID")); + + REQUIRE(false== map.put("",testNode)); + REQUIRE(false== map.put("",nullptr)); + + // ensure the pointer is the same + + REQUIRE( + service.get() + == map.getControllerServiceNode("ID") + ->getControllerServiceImplementation().get()); +} + +TEST_CASE("Test StandardControllerServiceNode nullPtr", "[cs1]") { + core::controller::ControllerServiceMap map; + + try { + std::shared_ptr<core::controller::StandardControllerServiceNode> testNode = + std::make_shared<core::controller::StandardControllerServiceNode>( + nullptr, "ID", std::make_shared<minifi::Configure>()); + } catch (minifi::Exception &ex) { + return; + } + + FAIL("Should have encountered exception"); +} + +std::shared_ptr<core::controller::StandardControllerServiceNode> newCsNode( + const std::string id) { + std::shared_ptr<core::controller::ControllerService> service = + std::make_shared<MockControllerService>(); + std::shared_ptr<core::controller::StandardControllerServiceNode> testNode = + std::make_shared<core::controller::StandardControllerServiceNode>( + service, id, std::make_shared<minifi::Configure>()); + + return testNode; +} + + +}
