bakaid commented on a change in pull request #605:
URL: https://github.com/apache/nifi-minifi-cpp/pull/605#discussion_r413766649



##########
File path: extensions/standard-processors/tests/unit/TailFileTests.cpp
##########
@@ -501,7 +481,7 @@ TEST_CASE("TailFileWithDelimiterMultipleDelimiters", 
"[tailfiletest2]") {
   std::string line1(4097, '\n');
   std::mt19937 gen(std::random_device { }());
   std::generate_n(line1.begin(), 4095, [&]() -> char {
-    return 32 + gen() % (127 - 32);
+  return 32 + gen() % (127 - 32);

Review comment:
       I am not really.

##########
File path: 
extensions/standard-processors/controllers/UnorderedMapKeyValueStoreService.cpp
##########
@@ -0,0 +1,107 @@
+/**
+ * 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 "UnorderedMapKeyValueStoreService.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace controllers {
+
+UnorderedMapKeyValueStoreService::UnorderedMapKeyValueStoreService(const 
std::string& name, const std::string& id)
+    : KeyValueStoreService(name, id)
+    , 
logger_(logging::LoggerFactory<UnorderedMapKeyValueStoreService>::getLogger()) {
+}
+
+UnorderedMapKeyValueStoreService::UnorderedMapKeyValueStoreService(const 
std::string& name, utils::Identifier uuid /*= utils::Identifier()*/)
+    : KeyValueStoreService(name, uuid)
+    , 
logger_(logging::LoggerFactory<UnorderedMapKeyValueStoreService>::getLogger()) {
+}
+
+UnorderedMapKeyValueStoreService::UnorderedMapKeyValueStoreService(const 
std::string& name, const std::shared_ptr<Configure> &configuration)
+    : KeyValueStoreService(name)
+    , 
logger_(logging::LoggerFactory<UnorderedMapKeyValueStoreService>::getLogger())  
{
+  setConfiguration(configuration);
+  initialize();
+}
+
+UnorderedMapKeyValueStoreService::~UnorderedMapKeyValueStoreService() {
+}
+
+bool UnorderedMapKeyValueStoreService::set(const std::string& key, const 
std::string& value) {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  map_[key] = value;
+  return true;
+}
+
+bool UnorderedMapKeyValueStoreService::get(const std::string& key, 
std::string& value) {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  auto it = map_.find(key);
+  if (it == map_.end()) {
+    return false;
+  } else {
+    value = it->second;
+    return true;
+  }
+}
+
+bool UnorderedMapKeyValueStoreService::get(std::unordered_map<std::string, 
std::string>& kvs) {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  kvs = map_;
+  return true;
+}
+
+bool UnorderedMapKeyValueStoreService::remove(const std::string& key) {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  return map_.erase(key) == 1U;
+}
+
+bool UnorderedMapKeyValueStoreService::clear() {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  map_.clear();
+  return true;
+}
+
+bool UnorderedMapKeyValueStoreService::update(const std::string& key, const 
std::function<bool(bool /*exists*/, std::string& /*value*/)>& update_func) {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  bool exists = false;
+  std::string value;
+  auto it = map_.find(key);
+  if (it != map_.end()) {
+    exists = true;
+    value = it->second;
+  }
+  try {
+    if (!update_func(exists, value)) {
+      return false;
+    }
+  } catch (...) {
+    return false;
+  }

Review comment:
       We are not silently swallowing it, we are making the operation fail, but 
added logging to the exception path.




----------------------------------------------------------------
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:
[email protected]


Reply via email to