hunyadi-dev commented on a change in pull request #940: URL: https://github.com/apache/nifi-minifi-cpp/pull/940#discussion_r534973423
########## File path: libminifi/test/TestBase.cpp ########## @@ -247,45 +221,65 @@ void TestPlan::reset(bool reschedule) { } } -bool TestPlan::runNextProcessor(std::function<void(const std::shared_ptr<core::ProcessContext>, const std::shared_ptr<core::ProcessSession>)> verify) { - if (!finalized) { - finalize(); +std::vector<std::shared_ptr<core::Processor>>::iterator TestPlan::getProcessorItByUuid(const std::string& uuid) { + const auto processor_node_matches_processor = [&uuid] (const std::shared_ptr<core::Processor>& processor) { + return processor->getUUIDStr() == uuid; + }; + auto processor_found_at = std::find_if(processor_queue_.begin(), processor_queue_.end(), processor_node_matches_processor); + if (processor_found_at == processor_queue_.end()) { + throw std::runtime_error("Processor not found in test plan."); } - logger_->log_info("Running next processor %d, processor_queue_.size %d, processor_contexts_.size %d", location, processor_queue_.size(), processor_contexts_.size()); - std::lock_guard<std::recursive_mutex> guard(mutex); - location++; - std::shared_ptr<core::Processor> processor = processor_queue_.at(location); - std::shared_ptr<core::ProcessContext> context = processor_contexts_.at(location); - std::shared_ptr<core::ProcessSessionFactory> factory = std::make_shared<core::ProcessSessionFactory>(context); - factories_.push_back(factory); + return processor_found_at; +} + +std::shared_ptr<core::ProcessContext> TestPlan::getProcessContextForProcessor(const std::shared_ptr<core::Processor>& processor) { + const auto contextMatchesProcessor = [&processor] (const std::shared_ptr<core::ProcessContext>& context) { + return context->getProcessorNode()->getUUIDStr() == processor->getUUIDStr(); + }; + const auto context_found_at = std::find_if(processor_contexts_.begin(), processor_contexts_.end(), contextMatchesProcessor); + if (context_found_at == processor_contexts_.end()) { + throw std::runtime_error("Context not found in test plan."); + } + return *context_found_at; +} + +void TestPlan::schedule_processors() { + for(std::size_t target_location = 0; target_location < processor_queue_.size(); ++target_location) { + std::shared_ptr<core::Processor> processor = processor_queue_.at(target_location); + std::shared_ptr<core::ProcessContext> context = processor_contexts_.at(target_location); + schedule_processor(processor, context); + } +} + +void TestPlan::schedule_processor(const std::shared_ptr<core::Processor>& processor) { + schedule_processor(processor, getProcessContextForProcessor(processor)); +} + +void TestPlan::schedule_processor(const std::shared_ptr<core::Processor>& processor, const std::shared_ptr<core::ProcessContext>& context) { Review comment: Will change this to camelCase. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org