adamdebreceni commented on code in PR #1435:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1435#discussion_r1012704207


##########
libminifi/test/unit/ProcessSessionTests.cpp:
##########
@@ -138,3 +144,44 @@ TEST_CASE("ProcessSession::read can read zero length 
flowfiles without crash", "
   
ContentRepositoryDependentTests::testReadFromZeroLengthFlowFile(std::make_shared<core::repository::VolatileContentRepository>());
   
ContentRepositoryDependentTests::testReadFromZeroLengthFlowFile(std::make_shared<core::repository::FileSystemRepository>());
 }
+
+struct VolatileFlowFileRepositoryTestAccessor {
+  METHOD_ACCESSOR(flush);
+};
+
+class TestVolatileFlowFileRepository : public 
core::repository::VolatileFlowFileRepository {
+ public:
+  explicit TestVolatileFlowFileRepository(const std::string& name) : 
core::SerializableComponent(name) {}
+
+  bool MultiPut(const std::vector<std::pair<std::string, 
std::unique_ptr<minifi::io::BufferStream>>>& data) override {
+    auto flush_on_exit = gsl::finally([&] 
{VolatileFlowFileRepositoryTestAccessor::call_flush(*this);});
+    return VolatileFlowFileRepository::MultiPut(data);
+  }
+};
+
+TEST_CASE("ProcessSession::commit avoids dangling ResourceClaims when using 
VolatileFlowFileRepository", "[incrementbefore]") {
+  auto configuration = std::make_shared<minifi::Configure>();
+  
configuration->set(minifi::Configure::nifi_volatile_repository_options_flowfile_max_count,
 "2");
+  auto ff_repo = std::make_shared<TestVolatileFlowFileRepository>("flowfile");
+  Fixture fixture({
+    .configuration = std::move(configuration),
+    .flow_file_repo = ff_repo
+  });
+  auto& session = fixture.processSession();
+
+  const auto flow_file_1 = session.create();
+  const auto flow_file_2 = session.create();
+  const auto flow_file_3 = session.create();
+  session.transfer(flow_file_1, Success);
+  session.transfer(flow_file_2, Success);
+  session.transfer(flow_file_3, Success);
+  session.commit();
+
+  REQUIRE(flow_file_1->getResourceClaim()->getFlowFileRecordOwnedCount() == 1);
+  REQUIRE(flow_file_2->getResourceClaim()->getFlowFileRecordOwnedCount() == 2);
+  REQUIRE(flow_file_3->getResourceClaim()->getFlowFileRecordOwnedCount() == 2);

Review Comment:
   added comment, the shared_ptr on the stack is the other owner



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to