szaszm commented on code in PR #1640:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1640#discussion_r1334400062
##########
libminifi/test/unit/FileSystemRepositoryTests.cpp:
##########
@@ -177,4 +177,46 @@ TEST_CASE("FileSystemRepository removes non-existing
resource file from purge li
REQUIRE(content_repo->getPurgeList().empty());
}
+TEST_CASE("Append Claim") {
+ TestController testController;
+ auto dir = testController.createTempDirectory();
+ auto content_repo = std::make_shared<TestFileSystemRepository>();
+
+ auto configuration =
std::make_shared<org::apache::nifi::minifi::Configure>();
+
configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default,
dir.string());
+ REQUIRE(content_repo->initialize(configuration));
+
+
+ const std::string content = "well hello there";
+
+ auto claim = std::make_shared<minifi::ResourceClaim>(content_repo);
+ content_repo->write(*claim)->write(as_bytes(std::span(content)));
+
+ // requesting append before content end fails
+ CHECK(content_repo->append(*claim, 0) == nullptr);
+ auto lock = content_repo->append(*claim, content.length());
+ // trying to append to the end succeeds
+ CHECK(lock != nullptr);
+ // simultaneously trying to append to the same claim fails
+ CHECK(content_repo->append(*claim, content.length()) == nullptr);
Review Comment:
Wouldn't it be better if instead of failing, we copied the contents to a new
entry, and then appended the new content there? It doesn't necessarily have to
be done in the content repo, the session would be fine, too.
##########
libminifi/include/core/ContentRepository.h:
##########
@@ -62,15 +73,24 @@ class ContentRepository : public core::CoreComponent,
public StreamManager<minif
return getName();
}
+ std::unique_ptr<StreamAppendLock> append(const ResourceClaim& claim, size_t
offset) override;
Review Comment:
Shouldn't this return a `ContentStreamAppendLock`?
##########
libminifi/include/core/StreamAppendLock.h:
##########
@@ -0,0 +1,27 @@
+/**
+ * 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.
+ */
+#pragma once
+
+
+namespace org::apache::nifi::minifi::core {
+
+class StreamAppendLock {
Review Comment:
Since its derived class `ContentStreamAppendLock` arrives in the file of the
associated `ContentRepository`, wouldn't this also be better next to
`StreamManager`?
##########
libminifi/src/io/FileStream.cpp:
##########
@@ -74,6 +74,7 @@ FileStream::FileStream(std::filesystem::path path, uint32_t
offset, bool write_e
} else {
file_stream_->open(path_, std::fstream::in | std::fstream::binary);
}
+ length_ = 0;
Review Comment:
Why not initialize this on the initializer list?
##########
libminifi/include/core/ContentSession.h:
##########
@@ -39,6 +52,12 @@ class ContentSession {
virtual void rollback() = 0;
virtual ~ContentSession() = default;
+
+ protected:
+ virtual std::shared_ptr<io::BaseStream> append(const
std::shared_ptr<ResourceClaim>& resource_id) = 0;
+
+ std::map<std::shared_ptr<ResourceClaim>, ExtensionData> extensions_;
Review Comment:
What is an extension, and why is it needed now?
--
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]