MINIFICPP-2798 Mock library for C extensions#2170
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a C++ mock library intended to support testing/verification of C extensions, and refactors the C++ extension wrapper layer to rely on abstract ProcessContext / ProcessSession interfaces with concrete CFFI-backed implementations.
Changes:
- Refactor extension wrapper APIs (
ProcessContext,ProcessSession,Logger) to use abstract base classes and CFFI-backed concrete implementations (Cffi*). - Add a new
mocklib(mock process context/session/logger + stubbed C API symbols) for extension testing without a full agent runtime. - Extend/adjust C API utility helpers (
minifiStringView, conversions) and add new small common utilities (regex wrapper + attribute error category).
Reviewed changes
Copilot reviewed 24 out of 28 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| libminifi/test/integration/extension-verification-test/CApiExtension.cpp | Updates extension metadata string-view helper usage. |
| extensions/llamacpp/processors/RunLlamaCppInference.cpp | Adjusts property access to updated ProcessContext API. |
| extensions/llamacpp/processors/ExtensionInitializer.cpp | Updates extension metadata string-view helper usage. |
| extension-framework/cpp-extension-lib/src/core/ProcessSession.cpp | Implements CFFI-backed ProcessSession operations + new session APIs. |
| extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp | Implements CFFI-backed ProcessContext operations + dynamic props/SSL data. |
| extension-framework/cpp-extension-lib/src/core/logging/Logger.cpp | Renames/implements CFFI-backed logger wrapper. |
| extension-framework/cpp-extension-lib/src/core/ControllerServiceContext.cpp | Updates controller service property lookup string-view helper usage. |
| extension-framework/cpp-extension-lib/mocklib/src/MockProcessSession.cpp | Adds mock session implementation for tests (flow file lifecycle, content, attributes). |
| extension-framework/cpp-extension-lib/mocklib/src/MockProcessContext.cpp | Adds mock context implementation for tests (properties, defaults). |
| extension-framework/cpp-extension-lib/mocklib/src/mock-minifi-c.cpp | Adds stubbed C API symbol definitions for mock/test linkage. |
| extension-framework/cpp-extension-lib/mocklib/include/MockUtils.h | Adds small helpers for building mock processor metadata/logger. |
| extension-framework/cpp-extension-lib/mocklib/include/MockStreams.h | Adds in-memory mock InputStream/OutputStream implementations. |
| extension-framework/cpp-extension-lib/mocklib/include/MockProcessSession.h | Declares mock session class and mock flow file data model. |
| extension-framework/cpp-extension-lib/mocklib/include/MockProcessContext.h | Declares mock process context class. |
| extension-framework/cpp-extension-lib/mocklib/include/MockLogger.h | Adds a test logger capturing log strings by level. |
| extension-framework/cpp-extension-lib/mocklib/CMakeLists.txt | Adds build target for the new mock library. |
| extension-framework/cpp-extension-lib/include/api/utils/Ssl.h | Introduces SSL data structs for the extension API surface. |
| extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h | Updates property parsing helpers to use the new getProperty(PropertyReference, FlowFile*) API. |
| extension-framework/cpp-extension-lib/include/api/utils/minifi-c-utils.h | Introduces minifiStringView + adds conversions from MinifiStringView. |
| extension-framework/cpp-extension-lib/include/api/core/Resource.h | Updates registration helpers to use CFFI wrappers + adds variadic registration helpers. |
| extension-framework/cpp-extension-lib/include/api/core/ProcessSession.h | Refactors ProcessSession into abstract interface + adds CffiProcessSession. |
| extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h | Refactors ProcessContext into abstract interface + adds CffiProcessContext and new APIs. |
| extension-framework/cpp-extension-lib/include/api/core/logging/Logger.h | Renames wrapper to CffiLogger. |
| extension-framework/cpp-extension-lib/CMakeLists.txt | Adds mocklib subdirectory to build. |
| core-framework/common/src/utils/RegexUtils.cpp | Adds regex implementation backing new RegexUtils header. |
| core-framework/common/src/utils/AttributeErrors.cpp | Adds attribute error category implementation. |
| core-framework/common/include/utils/RegexUtils.h | Adds regex wrapper interface and libstdc++ workaround. |
| core-framework/common/include/utils/AttributeErrors.h | Adds attribute error code/category declarations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b89c26e to
a801889
Compare
a801889 to
6177d0c
Compare
50a15ed to
97edf58
Compare
97edf58 to
e4f700e
Compare
c9060a8 to
4d18c0d
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
4d18c0d to
0a3ae8b
Compare
lordgamez
left a comment
There was a problem hiding this comment.
Great stuff 👍 LGTM just some minor nitpicks.
There was a problem hiding this comment.
This looks like a copy of extension-framework/include/utils/net/Ssl.h. Can we remove the old file, or do we need both?
|
|
||
| SslServerOptions(SslData cert_data, ClientAuthOption client_auth_option) | ||
| : cert_data(cert_data), | ||
| client_auth_option(client_auth_option) {} |
There was a problem hiding this comment.
we could remove this constructor and leave the struct to be an aggregate
| SslServerOptions(SslData cert_data, ClientAuthOption client_auth_option) | |
| : cert_data(cert_data), | |
| client_auth_option(client_auth_option) {} |
|
|
||
| private: | ||
| std::vector<std::unique_ptr<MinifiFlowFile>> input_flow_files_; | ||
| std::map<std::string, std::vector<std::unique_ptr<MinifiFlowFile>>> transferred_flow_files_; |
There was a problem hiding this comment.
I'm guessing relationships are the key, I would add an inline comment to indicate that. Optionally you could also replace it with a Relationship object, the same one as session transfer takes
| std::map<std::string, std::vector<std::unique_ptr<MinifiFlowFile>>> transferred_flow_files_; | |
| std::map<std::string /* relationship name */, std::vector<std::unique_ptr<MinifiFlowFile>>> transferred_flow_files_; |
Separates the CPP wrapper into a abstract interface and the Cffi layer (that commincates via the stable API), and also introduces a Mock alternative implementation, with its easier to create new unit tests that only test the processors controllers services business logic without the need to depend on the libminifi library.
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically main)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.