adamdebreceni commented on code in PR #1367: URL: https://github.com/apache/nifi-minifi-cpp/pull/1367#discussion_r940172633
########## extensions/http-curl/tests/AlertTests.cpp: ########## @@ -0,0 +1,148 @@ +/** + * + * 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 +#define CATCH_CONFIG_MAIN +#include "TestBase.h" +#include "Catch.h" +#include "ServerAwareHandler.h" +#include "CivetServer.h" +#include "TestServer.h" +#include "HTTPIntegrationBase.h" +#include "rapidjson/document.h" +#include "EmptyFlow.h" +#include "Utils.h" +#include "TestUtils.h" + +class AlertHandler : public ServerAwareHandler { + public: + explicit AlertHandler(std::string agent_id): agent_id_(std::move(agent_id)) {} + + bool handlePut(CivetServer* , struct mg_connection *conn) override { + auto msg = readPayload(conn); + rapidjson::Document doc; + rapidjson::ParseResult res = doc.Parse(msg.c_str()); + REQUIRE(static_cast<bool>(res)); + REQUIRE(doc.IsObject()); + REQUIRE(doc.HasMember("agentId")); + REQUIRE(doc["agentId"].IsString()); + REQUIRE(doc.HasMember("alerts")); + REQUIRE(doc["alerts"].IsArray()); + REQUIRE(doc["alerts"].Size() > 0); + std::string id(doc["agentId"].GetString(), doc["agentId"].GetStringLength()); + REQUIRE(id == agent_id_); + std::vector<std::string> batch; + for (size_t i = 0; i < doc["alerts"].Size(); ++i) { + REQUIRE(doc["alerts"][i].IsString()); + batch.emplace_back(doc["alerts"][i].GetString(), doc["alerts"][i].GetStringLength()); + } + alerts_.enqueue(std::move(batch)); + return true; + } + + std::string agent_id_; + utils::ConditionConcurrentQueue<std::vector<std::string>> alerts_; +}; + +class VerifyAlerts : public HTTPIntegrationBase { + public: + void testSetup() override {} + + void runAssertions() override { + verify_(); + } + + std::function<bool()> verify_; +}; + +TEST_CASE("Alert system forwards logs") { + auto clock = std::make_shared<utils::ManualClock>(); + utils::timeutils::setClock(clock); + + TempDirectory dir; + auto flow_file = std::filesystem::path(dir.getPath()) / "config.yml"; Review Comment: changed it -- 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