fgerlits commented on code in PR #2297: URL: https://github.com/apache/nifi-minifi-cpp/pull/2297#discussion_r4526338151
########## libminifi/test/flow-tests/MetricsDuringReloadTests.cpp: ########## @@ -0,0 +1,190 @@ +/** + * 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 <array> +#include <atomic> +#include <chrono> +#include <memory> +#include <ranges> +#include <string> +#include <string_view> +#include <thread> +#include <unordered_set> +#include <vector> + +#include "c2/C2MetricsPublisher.h" +#include "c2/C2Utils.h" +#include "core/state/MetricsPublisherStore.h" +#include "properties/Configuration.h" +#include "CustomProcessors.h" +#include "unit/Catch.h" +#include "unit/TestControllerWithFlow.h" + +namespace { + +constexpr std::string_view SinkProcessorName = "Sink Processor"; + +std::string createFlow(const std::string& generator_processor_name) { + return R"( +Flow Controller: + name: MiNiFi Flow +Processors: +- name: )" + generator_processor_name + R"( + id: 2438e3c8-015a-1000-79ca-83af40ec1991 + class: org.apache.nifi.processors.standard.TestFlowFileGenerator + scheduling strategy: TIMER_DRIVEN + scheduling period: 10 ms + auto-terminated relationships list: + Properties: + Batch Size: 1 +- name: )" + std::string{SinkProcessorName} + R"( + id: 2438e3c8-015a-1000-79ca-83af40ec1992 + class: org.apache.nifi.processors.standard.TestProcessor + scheduling strategy: TIMER_DRIVEN + scheduling period: 10 ms + auto-terminated relationships list: + - apple + - banana +Connections: +- name: GeneratorToSink + id: 2438e3c8-015a-1000-79ca-83af40ec1997 + source name: )" + generator_processor_name + R"( + source id: 2438e3c8-015a-1000-79ca-83af40ec1991 + source relationship name: success + destination name: )" + std::string{SinkProcessorName} + R"( + destination id: 2438e3c8-015a-1000-79ca-83af40ec1992 + max work queue size: 0 + max work queue data size: 1 MB + flowfile expiration: 60 sec +Remote Processing Groups: [] +Controller Services: [] +)"; +} + +constexpr std::string_view UnparseableFlow = "this is not a valid flow configuration"; + +constexpr std::array DescribedClasses = {"FlowInformation", "QueueMetrics", "processorMetrics/.*"}; + +std::unique_ptr<TestControllerWithFlow> createTestController(const std::string& flow) { + auto test_controller = std::make_unique<TestControllerWithFlow>(flow.c_str(), /* setup_flow = */ false); + test_controller->configuration_->set(minifi::Configuration::nifi_c2_root_classes, + "DeviceInfoNode,AgentInformation,FlowInformation,QueueMetrics"); + test_controller->setupFlow(); + return test_controller; +} + +std::unordered_set<std::string> processorNames(const std::vector<minifi::state::ComponentState>& components) { + REQUIRE_FALSE(components.empty()); + CHECK(components.back().name == "FlowController"); + return components | std::views::take(components.size() - 1) + | std::views::transform([](const auto& component) { return component.name; }) + | std::ranges::to<std::unordered_set>(); Review Comment: it does compile, and C++23 is required -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
