From 5701198ebf447a14874677c2be1899abd5d363ec Mon Sep 17 00:00:00 2001 From: Arpad Boda Date: Tue, 30 Oct 2018 14:48:04 +0100 Subject: [PATCH] MINIFICPP-640 - C API: how to support dynamic properties? --- libminifi/src/capi/api.cpp | 3 ++- libminifi/test/capi/CAPITests.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libminifi/src/capi/api.cpp b/libminifi/src/capi/api.cpp index 58328ef195..e135fe1670 100644 --- a/libminifi/src/capi/api.cpp +++ b/libminifi/src/capi/api.cpp @@ -412,7 +412,8 @@ int set_failure_strategy(flow *flow, FailureStrategy strategy) { int set_property(processor *proc, const char *name, const char *value) { if (name != nullptr && value != nullptr && proc != nullptr) { core::Processor *p = static_cast(proc->processor_ptr); - return p->setProperty(name, value) ? 0 : -2; + bool success = p->setProperty(name, value) || (p->supportsDynamicProperties() && p->setDynamicProperty(name, value)); + return success ? 0 : -2; } return -1; } diff --git a/libminifi/test/capi/CAPITests.cpp b/libminifi/test/capi/CAPITests.cpp index 368c9a142b..b7bf784f62 100644 --- a/libminifi/test/capi/CAPITests.cpp +++ b/libminifi/test/capi/CAPITests.cpp @@ -165,10 +165,10 @@ TEST_CASE("Test manipulation of attributes", "[testAttributes]") { processor *extract_test = add_processor_with_linkage(test_flow, "ExtractText"); REQUIRE(extract_test != nullptr); REQUIRE(set_property(extract_test, "Attribute", "TestAttr") == 0); - /*processor *update_attribute = add_processor_with_linkage(test_flow, "UpdateAttribute"); - REQUIRE(update_attribute != nullptr); + processor *update_attr = add_processor_with_linkage(test_flow, "UpdateAttribute"); + REQUIRE(update_attr != nullptr); - REQUIRE(set_property(update_attribute, "TestAttribute", "TestValue") == 0);*/ + REQUIRE(set_property(update_attr, "UpdatedAttribute", "UpdatedValue") == 0); flow_file_record *record = get_next_flow_file(instance, test_flow); @@ -203,12 +203,17 @@ TEST_CASE("Test manipulation of attributes", "[testAttributes]") { REQUIRE(get_all_attributes(record, &attr_set) == attr_set.size); bool test_attr_found = false; + bool updated_attr_found = false; for (int i = 0; i < attr_set.size; ++i) { if (strcmp(attr_set.attributes[i].key, test_attr.key) == 0) { test_attr_found = true; REQUIRE(std::string(static_cast(attr_set.attributes[i].value), attr_set.attributes[i].value_size) == new_testattr_value); + } else if (strcmp(attr_set.attributes[i].key, "UpdatedAttribute") == 0) { + updated_attr_found = true; + REQUIRE(std::string(static_cast(attr_set.attributes[i].value), attr_set.attributes[i].value_size) == "UpdatedValue"); } } + REQUIRE(updated_attr_found == true); REQUIRE(test_attr_found == true); free_flowfile(record);