[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #920: MINIFICPP-1296 - All tests should use volatile state storage

2020-11-11 Thread GitBox


szaszm commented on a change in pull request #920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/920#discussion_r521406606



##
File path: 
libminifi/test/keyvalue-tests/UnorderedMapKeyValueStoreServiceTest.cpp
##
@@ -0,0 +1,173 @@
+/**
+ *
+ * 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.
+ */
+
+#define CATCH_CONFIG_RUNNER
+#include 
+#include "../TestBase.h"
+#include "core/controller/ControllerService.h"
+#include "core/ProcessGroup.h"
+#include "core/yaml/YamlConfiguration.h"
+
+#include "catch.hpp"
+
+namespace {
+  std::string config_yaml; // NOLINT
+
+  void configYamlHandler(Catch::ConfigData&, const std::string& path) {
+config_yaml = path;
+  }
+}
+
+int main(int argc, char* argv[]) {
+  Catch::Session session;
+
+  auto& cli = 
const_cast&>(session.cli());
+  cli["--config-yaml"]
+  .describe("path to the config.yaml containing the 
UnorderedMapKeyValueStoreServiceTest controller service configuration")
+  .bind(, "path");
+
+  int ret = session.applyCommandLine(argc, argv);
+  if (ret != 0) {
+return ret;
+  }
+
+  if (config_yaml.empty()) {
+std::cerr << "Missing --config-yaml . It must contain the path to 
the config.yaml containing the UnorderedMapKeyValueStoreServiceTest controller 
service configuration." << std::endl;
+return -1;
+  }
+
+  return session.run();
+}
+
+class UnorderedMapKeyValueStoreServiceTestFixture {

Review comment:
   Minor, optional:
   Since `UnorderedMapKeyValueStoreService` just became a 
`PersistableKeyValueStoreService`, I would add a test that you can actually 
treat it as persistable. A simple
   
   ```
   static_assert(std::is_convertible::value, "UnorderedMapKeyValueStoreService is 
a PersistableKeyValueStoreService");
   ```
   
   should do the trick. Or check that 
`unorderedMapKeyValueStoreService->persist()` is a valid boolean expression.

##
File path: libminifi/test/TestBase.h
##
@@ -282,18 +274,10 @@ class TestPlan {
 return prov_repo_;
   }
 
-  std::shared_ptr getContentRepo() {
-return content_repo_;
-  }
-
   std::shared_ptr getLogger() const {
 return logger_;
   }
 
-  std::string getStateDir() {
-return state_dir_;
-  }
-

Review comment:
   ```
   /home/szaszm/nifi-minifi-cpp-2/extensions/sftp/tests/ListSFTPTests.cpp: In 
member function ‘void 
ListSFTPTestsFixture::createPlan(org::apache::nifi::minifi::utils::Identifier*)’:
   
/home/szaszm/nifi-minifi-cpp-2/extensions/sftp/tests/ListSFTPTests.cpp:92:64: 
error: ‘using element_type = class TestPlan’ {aka ‘class TestPlan’} has no 
member named ‘getStateDir’
   92 | const std::string state_dir = plan == nullptr ? "" : 
plan->getStateDir();
   |^~~
   make[2]: *** 
[extensions/sftp/tests/CMakeFiles/ListSFTPTests.dir/build.make:82: 
extensions/sftp/tests/CMakeFiles/ListSFTPTests.dir/ListSFTPTests.cpp.o] Error 1
   make[1]: *** [CMakeFiles/Makefile2:8318: 
extensions/sftp/tests/CMakeFiles/ListSFTPTests.dir/all] Error 2
   make[1]: *** Waiting for unfinished jobs
   ```





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




[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #920: MINIFICPP-1296 - All tests should use volatile state storage

2020-10-12 Thread GitBox


szaszm commented on a change in pull request #920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/920#discussion_r503376897



##
File path: 
extensions/standard-processors/controllers/UnorderedMapKeyValueStoreService.h
##
@@ -29,19 +29,21 @@
 #include "core/logging/Logger.h"
 #include "core/logging/LoggerConfiguration.h"
 #include "core/Resource.h"
+#include "controllers/keyvalue/PersistableKeyValueStoreService.h"
 
 namespace org {
 namespace apache {
 namespace nifi {
 namespace minifi {
 namespace controllers {
 
-class UnorderedMapKeyValueStoreService : virtual public KeyValueStoreService {
+/// Key-value store serice purely in RAM without disk usage
+class UnorderedMapKeyValueStoreService : virtual public 
PersistableKeyValueStoreService {

Review comment:
   If it's RAM only, then why is it `PersistableKeyValueStoreService`?

##
File path: 
extensions/standard-processors/controllers/UnorderedMapPersistableKeyValueStoreService.h
##
@@ -59,20 +61,30 @@ class UnorderedMapPersistableKeyValueStoreService : public 
AbstractAutoPersistin
 
   bool update(const std::string& key, const std::function& update_func) override;
 
-  bool persist() override;
+  bool persist() override {
+persistNonVirtual();
+  }
 
  protected:
+  using AbstractAutoPersistingKeyValueStoreService::getImpl;
+  using AbstractAutoPersistingKeyValueStoreService::setImpl;
+  using AbstractAutoPersistingKeyValueStoreService::persistImpl;
+  using AbstractAutoPersistingKeyValueStoreService::removeImpl;
+
+
   static constexpr const char* FORMAT_VERSION_KEY = 
"__UnorderedMapPersistableKeyValueStoreService_FormatVersion";
   static constexpr int FORMAT_VERSION = 1;
 
   std::string file_;
 
   bool load();
 
-  std::string escape(const std::string& str);
   bool parseLine(const std::string& line, std::string& key, std::string& 
value);
 
  private:
+  void initializeNonVirtual();
+  bool persistNonVirtual();

Review comment:
   Why are these necessary? If subclasses need to call the base class 
implementation, they can always qualify the call with the base class name to 
avoid dynamic dispatching,





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