lordgamez commented on a change in pull request #1064:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1064#discussion_r622308397
##########
File path: extensions/standard-processors/tests/unit/GetFileTests.cpp
##########
@@ -91,12 +113,30 @@ TEST_CASE("GetFile: MaxSize", "[getFileFifo]") { // NOLINT
#endif
}
-
-TEST_CASE("GetFile: Directory", "[getFileDir]") {
- TestController testController;
+TEST_CASE("GetFile onSchedule() throws if the required Directory property is
not set", "[GetFile]") {
+ TestController test_controller;
LogTestController::getInstance().setTrace<TestPlan>();
LogTestController::getInstance().setTrace<processors::GetFile>();
- auto plan = testController.createPlan();
+ auto plan = test_controller.createPlan();
auto get_file = plan->addProcessor("GetFile", "Get");
REQUIRE_THROWS_AS(plan->runNextProcessor(), minifi::Exception&);
}
+
+TEST_CASE("GetFile removes the source file if KeepSourceFile is false") {
+ GetFileTestController test_controller;
+ SECTION("KeepSourceFile is not set, so defaults to false") {}
+ SECTION("KeepSourceFile is set to false explicitly") {
test_controller.setProperty(processors::GetFile::KeepSourceFile, "false"); }
+
+ test_controller.runSession();
+
+
REQUIRE_FALSE(utils::file::FileUtils::exists(test_controller.input_file_name_));
+}
+
+TEST_CASE("GetFile keeps the source file if KeepSourceFile is true") {
+ GetFileTestController test_controller;
+ test_controller.setProperty(processors::GetFile::KeepSourceFile, "true");
+
+ test_controller.runSession();
+
+ REQUIRE(utils::file::FileUtils::exists(test_controller.input_file_name_));
+}
Review comment:
There are some uncovered properties in the test suite like Recurse,
*Age, BatchSize, FileFilter etc. We could add some tests for those, or as it is
not really part of this issue, have it in separate PR with a newly opened issue.
##########
File path: extensions/standard-processors/processors/GetFile.cpp
##########
@@ -159,47 +148,54 @@ void GetFile::onSchedule(core::ProcessContext *context,
core::ProcessSessionFact
}
void GetFile::onTrigger(core::ProcessContext* /*context*/,
core::ProcessSession *session) {
- // Perform directory list
-
metrics_->iterations_++;
- const bool isDirEmptyBeforePoll = isListingEmpty();
- logger_->log_debug("Is listing empty before polling directory %i",
isDirEmptyBeforePoll);
- if (isDirEmptyBeforePoll) {
+ const bool is_dir_empty_before_poll = isListingEmpty();
+ logger_->log_debug("Listing is %s before polling directory",
is_dir_empty_before_poll ? "empty" : "not empty");
+ if (is_dir_empty_before_poll) {
if (request_.pollInterval == 0 || (utils::timeutils::getTimeMillis() -
last_listing_time_) > request_.pollInterval) {
performListing(request_);
last_listing_time_.store(utils::timeutils::getTimeMillis());
}
}
- const bool isDirEmptyAfterPoll = isListingEmpty();
- logger_->log_debug("Is listing empty after polling directory %i",
isDirEmptyAfterPoll);
+ const bool is_dir_empty_after_poll = isListingEmpty();
+ logger_->log_debug("Listing is %s after polling directory",
is_dir_empty_after_poll ? "empty" : "not empty");
+ if (is_dir_empty_after_poll) {
+ yield();
+ return;
+ }
+
+ std::queue<std::string> list_of_file_names = pollListing(request_.batchSize);
+ while (!list_of_file_names.empty()) {
Review comment:
Minor: I may extract the core of the loop as a separate function to keep
onTrigger shorter and more clear.
##########
File path: libminifi/src/utils/FileReaderCallback.cpp
##########
@@ -0,0 +1,72 @@
+/**
+ *
+ * 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 "utils/FileReaderCallback.h"
+
+#include <cinttypes>
+
+#include "Exception.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace {
+
+constexpr std::size_t BUFFER_SIZE = 4096;
+
+} // namespace
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+FileReaderCallback::FileReaderCallback(const std::string& file_name)
+ : logger_(core::logging::LoggerFactory<FileReaderCallback>::getLogger()) {
+ logger_->log_debug("Opening %s", file_name);
+ input_stream_.open(file_name.c_str(), std::fstream::in |
std::fstream::binary);
+ if (!input_stream_.is_open() || !input_stream_.good()) {
Review comment:
Nit: Could the `input_stream_.good()` be enough in this condition? Or is
it possible that we get a good input stream, but the `is_open` returns false?
--
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]