fgerlits commented on a change in pull request #1066:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1066#discussion_r630356615



##########
File path: extensions/pdh/tests/PerformanceDataMonitorTests.cpp
##########
@@ -0,0 +1,268 @@
+/**
+ *
+ * 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 <memory>
+#include <string>
+#include <vector>
+#include <set>
+#include <fstream>
+
+#include "TestBase.h"
+#include "processors/PutFile.h"
+#include "utils/file/FileUtils.h"
+#include "PerformanceDataMonitor.h"
+#include "rapidjson/filereadstream.h"
+
+using PutFile = org::apache::nifi::minifi::processors::PutFile;
+using PerformanceDataMonitor = 
org::apache::nifi::minifi::processors::PerformanceDataMonitor;
+using PerformanceDataCounter = 
org::apache::nifi::minifi::processors::PerformanceDataCounter;
+
+class PerformanceDataMonitorTester {
+ public:
+  PerformanceDataMonitorTester() {
+    LogTestController::getInstance().setTrace<TestPlan>();
+    dir_ = test_controller_.createTempDirectory("/tmp/gt.XXXXXX");

Review comment:
       This really shouldn't compile (I don't know why VS allows it), as the 
parameter is a non-const `char*`; the input string even gets modified.  Please 
use `minifi::utils::createTempDir(&test_controller_)` instead.

##########
File path: extensions/pdh/tests/PerformanceDataCounterTests.cpp
##########
@@ -0,0 +1,185 @@
+/**
+ *
+ * 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 "TestBase.h"
+#include "PDHCounters.h"
+#include "MemoryConsumptionCounter.h"
+
+using PDHCounter = org::apache::nifi::minifi::processors::PDHCounter;
+using PDHCounterArray = org::apache::nifi::minifi::processors::PDHCounterArray;
+using PDHCounterBase = org::apache::nifi::minifi::processors::PDHCounterBase;
+using MemoryConsumptionCounter = 
org::apache::nifi::minifi::processors::MemoryConsumptionCounter;
+
+
+TEST_CASE("PDHCounterNameTests", "[pdhcounternametests]") {
+  PDHCounterBase* test_counter = 
PDHCounterBase::createPDHCounter("\\System\\Threads");
+  REQUIRE(nullptr != dynamic_cast<PDHCounter*> (test_counter));
+  REQUIRE("\\System\\Threads" == test_counter->getName());
+  REQUIRE("System" == test_counter->getObjectName());
+  REQUIRE("Threads" == test_counter->getCounterName());
+}
+
+TEST_CASE("PDHCounterArrayNameTests", "[pdhcounterarraytests]") {
+  PDHCounterBase* test_counter_array = 
PDHCounterBase::createPDHCounter("\\LogicalDisk(*)\\% Free Space");
+  REQUIRE(nullptr != dynamic_cast<PDHCounterArray*> (test_counter_array));
+  REQUIRE("\\LogicalDisk(*)\\% Free Space" == test_counter_array->getName());
+  REQUIRE("LogicalDisk" == test_counter_array->getObjectName());
+  REQUIRE("% Free Space" == test_counter_array->getCounterName());
+}
+
+TEST_CASE("PDHCountersInvalidNameTests", "[pdhcountersinvalidnametests]") {
+  REQUIRE(nullptr == PDHCounterBase::createPDHCounter("Invalid Name"));
+  REQUIRE(nullptr == PDHCounterBase::createPDHCounter(""));
+  REQUIRE(nullptr == PDHCounterBase::createPDHCounter("Something\\Counter"));
+  REQUIRE(nullptr == 
PDHCounterBase::createPDHCounter("\\Too\\Many\\Separators"));
+  REQUIRE(nullptr == 
PDHCounterBase::createPDHCounter("Too\\Many\\Separators"));
+  REQUIRE(nullptr != PDHCounterBase::createPDHCounter("\\Valid\\Counter"));
+}
+
+class TestablePDHCounter : public PDHCounter {
+ public:
+  explicit TestablePDHCounter(const std::string& query_name, bool is_double = 
true) : PDHCounter(query_name, is_double) {
+  }
+};
+
+class TestablePDHCounterArray : public PDHCounterArray {
+ public:
+  explicit TestablePDHCounterArray(const std::string& query_name, bool 
is_double = true) : PDHCounterArray(query_name, is_double) {
+  }
+};
+
+TEST_CASE("PDHCountersAddingToQueryTests", "[pdhcountersaddingtoquerytests]") {
+  PDH_HQUERY pdh_query;
+  PdhOpenQuery(NULL, NULL, &pdh_query);
+  PDH_HQUERY unopened_pdh_query;
+
+  TestablePDHCounter valid_counter("\\System\\Threads");
+  REQUIRE(ERROR_SUCCESS == valid_counter.addToQuery(pdh_query));
+  REQUIRE_FALSE(ERROR_SUCCESS == valid_counter.addToQuery(unopened_pdh_query));
+
+  TestablePDHCounter counter_with_invalid_object_name("\\Invalid\\Threads");
+  REQUIRE(PDH_CSTATUS_NO_OBJECT == 
counter_with_invalid_object_name.addToQuery(pdh_query));
+
+  TestablePDHCounter counter_with_invalid_counter_name("\\System\\Invalid");
+  REQUIRE(PDH_CSTATUS_NO_COUNTER == 
counter_with_invalid_counter_name.addToQuery(pdh_query));
+
+  TestablePDHCounter unparsable_counter("asd");  // Unparsable names are also 
filtered when using PDHCounterBase::createPDHCounter
+  REQUIRE(PDH_CSTATUS_BAD_COUNTERNAME == 
unparsable_counter.addToQuery(pdh_query));
+
+  PdhCloseQuery(&pdh_query);

Review comment:
       not super-important, but these `PdhCloseQuery()` calls should be wrapped 
in a `gsl::finally` to make sure they get called if any of the assertions fail

##########
File path: extensions/pdh/tests/PerformanceDataMonitorTests.cpp
##########
@@ -0,0 +1,268 @@
+/**
+ *
+ * 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 <memory>
+#include <string>
+#include <vector>
+#include <set>
+#include <fstream>
+
+#include "TestBase.h"
+#include "processors/PutFile.h"
+#include "utils/file/FileUtils.h"
+#include "PerformanceDataMonitor.h"
+#include "rapidjson/filereadstream.h"
+
+using PutFile = org::apache::nifi::minifi::processors::PutFile;
+using PerformanceDataMonitor = 
org::apache::nifi::minifi::processors::PerformanceDataMonitor;
+using PerformanceDataCounter = 
org::apache::nifi::minifi::processors::PerformanceDataCounter;
+
+class PerformanceDataMonitorTester {
+ public:
+  PerformanceDataMonitorTester() {
+    LogTestController::getInstance().setTrace<TestPlan>();
+    dir_ = test_controller_.createTempDirectory("/tmp/gt.XXXXXX");
+    plan_ = test_controller_.createPlan();
+    performance_monitor_ = plan_->addProcessor("PerformanceDataMonitor", 
"pdhsys");
+    putfile_ = plan_->addProcessor("PutFile", "putfile", 
core::Relationship("success", "description"), true);
+    plan_->setProperty(putfile_, PutFile::Directory.getName(), dir_);
+  }
+
+  void runProcessors() {
+    plan_->runNextProcessor();      // PerformanceMonitor
+    std::this_thread::sleep_for(std::chrono::milliseconds(200));
+    plan_->runCurrentProcessor();   // PerformanceMonitor
+    plan_->runNextProcessor();      // PutFile
+    plan_->runCurrentProcessor();   // PutFile
+  }
+
+  void setPerformanceMonitorProperty(core::Property property, const 
std::string& value) {

Review comment:
       `property` could be `const&`, too




-- 
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


Reply via email to