adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1565319124


##########
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##########
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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.
+ */
+
+#undef NDEBUG
+#include <vector>
+#include <string>
+#include <fstream>
+#include <iterator>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+
+class FileProvider : public ServerAwareHandler {
+ public:
+  explicit FileProvider(std::string file_content): 
file_content_(std::move(file_content)) {}
+
+  bool handleGet(CivetServer* /*server*/, struct mg_connection* conn) override 
{
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
+              file_content_.length());
+    mg_printf(conn, "%s", file_content_.c_str());
+    return true;
+  }
+
+ private:
+  std::string file_content_;
+};
+
+class C2HeartbeatHandler : public HeartbeatHandler {
+ public:
+  using HeartbeatHandler::HeartbeatHandler;
+  using AssetDescription = 
org::apache::nifi::minifi::utils::file::AssetDescription;
+
+  void handleHeartbeat(const rapidjson::Document& root, struct mg_connection* 
conn) override {
+    std::string hb_str;
+    {
+      rapidjson::StringBuffer buffer;
+      rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+      root.Accept(writer);
+
+      hb_str = std::string{buffer.GetString(), buffer.GetSize()};
+    }
+    auto& asset_info_node = root["assetInfo"];
+    auto& asset_hash_node = asset_info_node["hash"];
+    std::string asset_hash{asset_hash_node.GetString(), 
asset_hash_node.GetStringLength()};
+
+    std::vector<C2Operation> operations;
+    {
+      std::lock_guard guard(asset_mtx_);
+      agent_asset_hash_ = asset_hash;
+      if (asset_hash != assetHash()) {
+        std::unordered_map<std::string, std::string> args;
+        for (auto& asset : expected_assets_) {
+          args[asset.id + ".path"] = asset.path;
+          args[asset.id + ".url"] = asset.url;
+        }
+        operations.push_back(C2Operation{
+          .operation = "sync",
+          .operand = "asset",
+          .operation_id = std::to_string(next_op_id_++),
+          .args = std::move(args)
+        });
+      }
+    }
+    sendHeartbeatResponse(operations, conn);
+  }
+
+  void addAsset(std::string id, std::string path, std::string url) {
+    std::lock_guard guard(asset_mtx_);
+    expected_assets_.insert(AssetDescription{
+      .id = id,
+      .path = path,
+      .url = url
+    });
+  }
+
+  void removeAsset(std::string id) {
+    std::lock_guard guard{asset_mtx_};
+    expected_assets_.erase(AssetDescription{.id = id, .path = {}, .url = {}});
+  }
+
+  std::optional<std::string> getAgentAssetHash() const {
+    std::lock_guard lock(asset_mtx_);
+    return agent_asset_hash_;
+  }
+
+  std::string assetHash() const {

Review Comment:
   done



##########
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##########


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.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to