phrocker commented on a change in pull request #531: MINIFICPP-797 - Maximum
File Count property of PutFile processor is not workin…
URL: https://github.com/apache/nifi-minifi-cpp/pull/531#discussion_r277813115
##########
File path: libminifi/test/unit/PutFileTests.cpp
##########
@@ -317,3 +317,67 @@ TEST_CASE("Test generation of temporary write path",
"[putfileTmpWritePath]") {
REQUIRE(processor->tmpWritePath("a/b/c", "").substr(1, strlen("a/b/.c")) ==
"a/b/.c");
}
+TEST_CASE("PutFileMaxFileCountTest", "[getfileputpfilemaxcount]") {
+ TestController testController;
+
+ LogTestController::getInstance().setDebug<minifi::processors::GetFile>();
+ LogTestController::getInstance().setDebug<TestPlan>();
+ LogTestController::getInstance().setDebug<minifi::processors::PutFile>();
+
LogTestController::getInstance().setDebug<minifi::processors::LogAttribute>();
+
+ std::shared_ptr<TestPlan> plan = testController.createPlan();
+
+ std::shared_ptr<core::Processor> getfile = plan->addProcessor("GetFile",
"getfileCreate");
+
+ std::shared_ptr<core::Processor> putfile = plan->addProcessor("PutFile",
"putfile", core::Relationship("success", "description"), true);
+
+ plan->addProcessor("LogAttribute", "logattribute", {
core::Relationship("success", "d"), core::Relationship("failure", "d") }, true);
+
+ char format[] = "/tmp/gt.XXXXXX";
+ const char *dir = testController.createTempDirectory(format);
+ char format2[] = "/tmp/ft.XXXXXX";
+ const char *putfiledir = testController.createTempDirectory(format2);
+ plan->setProperty(getfile,
org::apache::nifi::minifi::processors::GetFile::Directory.getName(), dir);
+ plan->setProperty(getfile,
org::apache::nifi::minifi::processors::GetFile::BatchSize.getName(), "1");
+ plan->setProperty(putfile,
org::apache::nifi::minifi::processors::PutFile::Directory.getName(),
putfiledir);
+ plan->setProperty(putfile,
org::apache::nifi::minifi::processors::PutFile::MaxDestFiles.getName(), "1");
+
+
+
+ for (int i = 0; i < 2; ++i) {
+ std::stringstream ss;
+ ss << dir << "/" << "tstFile" << i << ".ext";
+ std::fstream file;
+ file.open(ss.str(), std::ios::out);
+ file << "tempFile";
+ file.close();
+ }
+
+ plan->reset();
+
+ testController.runSession(plan);
+
+ plan->reset();
+
+ testController.runSession(plan);
+
+
+ REQUIRE(LogTestController::getInstance().contains("key:absolute.path value:"
+ std::string(dir) + "/tstFile0.ext"));
+ REQUIRE(LogTestController::getInstance().contains("Size:8 Offset:0"));
+ REQUIRE(LogTestController::getInstance().contains("key:path value:" +
std::string(dir)));
+
+ // Only 1 of the 2 files should make it to the target dir
+ // Non-determistic, so let's just count them
+ int files_in_dir = 0;
+ auto lambda = [&files_in_dir](const std::string&, const std::string&) ->
bool {
+ return ++files_in_dir < 2;
+ };
+
+ utils::file::FileUtils::list_dir(putfiledir, lambda,
testController.getLogger(), false);
Review comment:
I don't believe that introduced tests, did it? A quick grep did not show
anything testing list_dir itself, as a result the only two functions that use
this sort of dog food their own tests...but I'm not going to hold this PR up. I
think a follow on is sufficient. We'll need to add that later ( just like I'm
adding docker integration targets for JNI ). I'll merge once appveyor is green.
Thanks!
----------------------------------------------------------------
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]
With regards,
Apache Git Services