nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject nifi-minifi-cpp git commit: MINIFI-256: Resolve Putfile name and ensure that call backs over 1k that rely on the return code to be zero when finished receive zero
Date Tue, 17 Oct 2017 15:30:39 GMT
Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 488677321 -> 49ed50945


MINIFI-256: Resolve Putfile name and ensure that call backs over 1k that rely on the return
code to be zero when finished receive zero


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/49ed5094
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/49ed5094
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/49ed5094

Branch: refs/heads/master
Commit: 49ed5094552fe98c289d15168587ff3e63042309
Parents: 4886773
Author: Marc Parisi <phrocker@apache.org>
Authored: Mon Oct 9 20:09:08 2017 -0400
Committer: Bin Qiu <bqiu@apache.org>
Committed: Tue Oct 17 08:29:53 2017 -0700

----------------------------------------------------------------------
 libminifi/src/io/FileStream.cpp         |  3 ++-
 libminifi/src/processors/PutFile.cpp    |  2 +-
 libminifi/test/unit/FileStreamTests.cpp | 37 +++++++++++++++++++++++++++-
 3 files changed, 39 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/49ed5094/libminifi/src/io/FileStream.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/io/FileStream.cpp b/libminifi/src/io/FileStream.cpp
index a3e7ee1..93d6411 100644
--- a/libminifi/src/io/FileStream.cpp
+++ b/libminifi/src/io/FileStream.cpp
@@ -135,13 +135,14 @@ int FileStream::readData(uint8_t *buf, int buflen) {
     file_stream_->read(reinterpret_cast<char*>(buf), buflen);
     if ((file_stream_->rdstate() & (file_stream_->eofbit | file_stream_->failbit))
!= 0) {
       file_stream_->clear();
+      size_t prev_offset = offset_;
       file_stream_->seekg(0, file_stream_->end);
       file_stream_->seekp(0, file_stream_->end);
       int len = file_stream_->tellg();
       offset_ = len;
       length_ = len;
       logger_->log_info("%s eof bit, ended at %d", path_, offset_);
-      return offset_;
+      return offset_-prev_offset;
     } else {
       offset_ += buflen;
       file_stream_->seekp(offset_);

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/49ed5094/libminifi/src/processors/PutFile.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/processors/PutFile.cpp b/libminifi/src/processors/PutFile.cpp
index 80aea6c..cf70690 100644
--- a/libminifi/src/processors/PutFile.cpp
+++ b/libminifi/src/processors/PutFile.cpp
@@ -46,7 +46,7 @@ namespace processors {
 
 std::shared_ptr<utils::IdGenerator> PutFile::id_generator_ = utils::IdGenerator::getIdGenerator();
 
-core::Property PutFile::Directory("Output Directory", "The output directory to which to put
files", ".");
+core::Property PutFile::Directory("Directory", "The output directory to which to put files",
".");
 core::Property PutFile::ConflictResolution("Conflict Resolution Strategy", "Indicates what
should happen when a file with the same name already exists in the output directory",
                                            CONFLICT_RESOLUTION_STRATEGY_FAIL);
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/49ed5094/libminifi/test/unit/FileStreamTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/unit/FileStreamTests.cpp b/libminifi/test/unit/FileStreamTests.cpp
index 5c86f19..92ff092 100644
--- a/libminifi/test/unit/FileStreamTests.cpp
+++ b/libminifi/test/unit/FileStreamTests.cpp
@@ -19,6 +19,7 @@
 #include "io/FileStream.h"
 #include <string>
 #include <vector>
+#include <iostream>
 #include <uuid/uuid.h>
 #include "../TestBase.h"
 
@@ -174,7 +175,6 @@ TEST_CASE("TestFileBadArgumentNoChange3", "[TestLoader]") {
   unlink(ss.str().c_str());
 }
 
-
 TEST_CASE("TestFileBeyondEnd3", "[TestLoader]") {
   TestController testController;
   char format[] = "/tmp/gt.XXXXXX";
@@ -208,3 +208,38 @@ TEST_CASE("TestFileBeyondEnd3", "[TestLoader]") {
 
   unlink(ss.str().c_str());
 }
+
+TEST_CASE("TestFileExceedSize", "[TestLoader]") {
+  TestController testController;
+  char format[] = "/tmp/gt.XXXXXX";
+  char *dir = testController.createTempDirectory(format);
+
+  std::fstream file;
+  std::stringstream ss;
+  ss << dir << "/" << "tstFile.ext";
+  std::string path = ss.str();
+  file.open(path, std::ios::out);
+  for (int i = 0; i < 10240; i++)
+    file << "tempFile";
+  file.close();
+
+  minifi::io::FileStream stream(path, 0, true);
+  std::vector<uint8_t> readBuffer;
+  REQUIRE(stream.readData(readBuffer, stream.getSize()) == stream.getSize());
+
+  uint8_t* data = readBuffer.data();
+
+  stream.seek(0);
+
+  std::vector<uint8_t> verifybuffer;
+
+  for (int i = 0; i < 10; i++)
+    REQUIRE(stream.readData(verifybuffer, 8192) == 8192);
+  REQUIRE(stream.readData(verifybuffer, 8192) == 0);
+  stream.seek(0);
+  for (int i = 0; i < 10; i++)
+    REQUIRE(stream.readData(verifybuffer, 8192) == 8192);
+  REQUIRE(stream.readData(verifybuffer, 8192) == 0);
+
+  unlink(ss.str().c_str());
+}


Mime
View raw message