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



##########
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:
       changed it in 
[7422bb3](https://github.com/martinzink/nifi-minifi-cpp/commit/7422bb3217a1770e3a7f272436f25be5ca417377)

##########
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:
       changed it in 
[7422bb3](https://github.com/martinzink/nifi-minifi-cpp/commit/7422bb3217a1770e3a7f272436f25be5ca417377)

##########
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:
       good idea thanks, changed it in 
[7422bb3](https://github.com/martinzink/nifi-minifi-cpp/commit/7422bb3217a1770e3a7f272436f25be5ca417377)

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

Review comment:
       good idea thanks, changed it in 
[d5959c3](https://github.com/martinzink/nifi-minifi-cpp/commit/d5959c3b1b5d0f377e7b7f2c13cc22a484b2e4a6)

##########
File path: extensions/pdh/PDHCounters.h
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include <TCHAR.h>
+#include <pdh.h>
+#include <pdhmsg.h>
+#include <string>
+
+#include "PerformanceDataCounter.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace processors {
+
+class PDHCounterBase : public PerformanceDataCounter {
+ public:
+  virtual ~PDHCounterBase() {}
+  static PDHCounterBase* createPDHCounter(const std::string& query_name, bool 
is_double = true);
+
+  const std::string& getName() const;
+  virtual std::string getObjectName() const;
+  virtual std::string getCounterName() const;
+  virtual PDH_STATUS addToQuery(PDH_HQUERY& pdh_query) = 0;
+  virtual PDH_STATUS collectData() = 0;
+ protected:
+  PDHCounterBase(const std::string& query_name, bool is_double) : 
PerformanceDataCounter(),
+    is_double_format_(is_double), pdh_english_counter_name_(query_name) {
+  }
+  DWORD getDWFormat() const;
+  const bool is_double_format_;
+  std::string pdh_english_counter_name_;
+};
+
+class PDHCounter : public PDHCounterBase {
+ public:
+  void addToJson(rapidjson::Value& body, rapidjson::Document::AllocatorType& 
alloc) const override;
+
+  PDH_STATUS addToQuery(PDH_HQUERY& pdh_query) override;
+  PDH_STATUS collectData() override;
+
+ protected:
+  friend PDHCounterBase* PDHCounterBase::createPDHCounter(const std::string& 
query_name, bool is_double);
+  explicit PDHCounter(const std::string& query_name, bool is_double) : 
PDHCounterBase(query_name, is_double),
+    counter_(), current_value_() {
+  }
+  rapidjson::Value getValue() const;
+
+  PDH_HCOUNTER counter_;
+  PDH_FMT_COUNTERVALUE current_value_;
+};
+
+class PDHCounterArray : public PDHCounterBase {
+ public:
+  virtual ~PDHCounterArray() { clearCurrentData(); }
+  void addToJson(rapidjson::Value& body, rapidjson::Document::AllocatorType& 
alloc) const override;
+
+  std::string getObjectName() const override;
+  PDH_STATUS addToQuery(PDH_HQUERY& pdh_query) override;
+  PDH_STATUS collectData() override;
+
+ protected:
+  friend PDHCounterBase* PDHCounterBase::createPDHCounter(const std::string& 
query_name, bool is_double);
+  explicit PDHCounterArray(std::string query_name, bool is_double) : 
PDHCounterBase(query_name, is_double),

Review comment:
       The by-value was on accident (changed it to by const ref in 
[d5959c3](https://github.com/martinzink/nifi-minifi-cpp/commit/d5959c3b1b5d0f377e7b7f2c13cc22a484b2e4a6)




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