adamdebreceni commented on a change in pull request #822:
URL: https://github.com/apache/nifi-minifi-cpp/pull/822#discussion_r450884735



##########
File path: libminifi/test/flow-tests/FlowBuilder.h
##########
@@ -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.
+ */
+#ifndef NIFI_MINIFI_CPP_FLOWCREATOR_H
+#define NIFI_MINIFI_CPP_FLOWCREATOR_H
+
+#include <unordered_map>
+#include <string>
+#include <random>
+#include <YamlConfiguration.h>
+#include "core/Processor.h"
+#include "TestBase.h"
+
+struct Flow{
+  Flow(std::shared_ptr<minifi::FlowController>&& controller, 
std::shared_ptr<core::ProcessGroup>&& root)
+  : controller_(std::move(controller)), root_(std::move(root)) {
+    controller_->load(root_);
+    controller_->start();
+  }
+  ~Flow() {
+    controller_->stop(true);
+    controller_->unload();
+  }
+  std::shared_ptr<minifi::FlowController> controller_;
+  std::shared_ptr<core::ProcessGroup> root_;
+};
+
+Flow createFlow(const std::string& yamlPath) {
+  std::shared_ptr<minifi::Configure> configuration = 
std::make_shared<minifi::Configure>();
+  std::shared_ptr<core::Repository> prov_repo = 
std::make_shared<core::repository::VolatileContentRepository>();
+  std::shared_ptr<core::Repository> ff_repo = 
std::make_shared<core::repository::VolatileContentRepository>();
+  std::shared_ptr<core::ContentRepository> content_repo = 
std::make_shared<core::repository::VolatileContentRepository>();
+
+  configuration->set(minifi::Configure::nifi_flow_configuration_file, 
yamlPath);
+
+  std::shared_ptr<minifi::io::StreamFactory> stream_factory = 
minifi::io::StreamFactory::getInstance(configuration);
+  content_repo->initialize(configuration);
+
+  std::unique_ptr<core::FlowConfiguration> flow = 
utils::make_unique<core::YamlConfiguration>(prov_repo, ff_repo, content_repo, 
stream_factory, configuration, yamlPath);
+  std::shared_ptr<core::ProcessGroup> root = flow->getRoot();
+
+  std::shared_ptr<minifi::FlowController> controller = 
std::make_shared<minifi::FlowController>(
+      prov_repo, ff_repo, configuration,
+      std::move(flow),
+      content_repo, DEFAULT_ROOT_GROUP_NAME, true);
+
+  return Flow{std::move(controller), std::move(root)};
+}
+
+double calculateCongestion(const std::shared_ptr<minifi::Connection>& conn) {

Review comment:
       removed

##########
File path: libminifi/test/flow-tests/CustomProcessors.h
##########
@@ -0,0 +1,106 @@
+/**
+ *
+ * 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.
+ */
+
+#ifndef NIFI_MINIFI_CPP_CUSTOMPROCESSORS_H
+#define NIFI_MINIFI_CPP_CUSTOMPROCESSORS_H
+
+#include <unordered_map>
+#include <string>
+#include <random>
+#include <YamlConfiguration.h>
+#include "core/Processor.h"
+#include "TestBase.h"
+#include "../../extensions/standard-processors/processors/GenerateFlowFile.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace processors {
+
+static core::Relationship Apple{"apple", ""};
+static core::Relationship Banana{"banana", ""};
+// The probability that this processor routes to Apple
+static core::Property AppleProbability = 
core::PropertyBuilder::createProperty("AppleProbability")->withDefaultValue<int>(100)->build();
+// The probability that this processor routes to Banana
+static core::Property BananaProbability = 
core::PropertyBuilder::createProperty("BananaProbability")->withDefaultValue<int>(0)->build();
+
+class ProcessorWithStatistics {
+ public:
+  std::atomic<int> trigger_count{0};
+};
+
+class TestProcessor : public core::Processor, public ProcessorWithStatistics {
+ public:
+  TestProcessor(std::string name, utils::Identifier &uuid) : Processor(name, 
uuid) {}
+  TestProcessor(std::string name) : Processor(name) {}
+  void initialize() override {
+    setSupportedProperties({AppleProbability, BananaProbability});
+    setSupportedRelationships({Apple, Banana});
+  }
+  void onTrigger(const std::shared_ptr<core::ProcessContext> &context, const 
std::shared_ptr<core::ProcessSession> &session) override {
+    ++trigger_count;
+    auto flowFile = session->get();
+    if (!flowFile) return;
+    std::random_device rd{};
+    std::uniform_int_distribution<int> dis(0, 100);
+    int rand = dis(rd);
+    if (rand <= apple_probability_) {
+      session->transfer(flowFile, Apple);
+      return;
+    }
+    rand -= apple_probability_;
+    if (rand <= banana_probability_) {
+      session->transfer(flowFile, Banana);
+      return;
+    }
+    throw std::runtime_error("Couldn't route file");
+  }
+  void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const 
std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override {
+    int apple;
+    assert(context->getProperty(AppleProbability.getName(), apple));
+    int banana;
+    assert(context->getProperty(BananaProbability.getName(), banana));

Review comment:
       done




----------------------------------------------------------------
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:
[email protected]


Reply via email to