Skip to content

Commit d12fc1b

Browse files
committed
Fix test on Windows
1 parent 9dd8d01 commit d12fc1b

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

PROCESSORS.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,16 +2212,16 @@ Put a document to Couchbase Server via Key/Value access.
22122212

22132213
In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.
22142214

2215-
| Name | Default Value | Allowable Values | Description |
2216-
|------------------------------------------|---------------|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2217-
| **Couchbase Cluster Controller Service** | | | A Couchbase Cluster Controller Service which manages connections to a Couchbase cluster. |
2218-
| **Bucket Name** | default | | The name of bucket to access.<br/>**Supports Expression Language: true** |
2219-
| Scope Name | | | Scope to use inside the bucket. If not specified, the _default scope is used.<br/>**Supports Expression Language: true** |
2220-
| Collection Name | | | Collection to use inside the bucket scope. If not specified, the _default collection is used.<br/>**Supports Expression Language: true** |
2221-
| **Document Type** | Json | Json<br/>Binary<br/>String | Content type to store data as. |
2222-
| Document Id | | | A static, fixed Couchbase document id, or an expression to construct the Couchbase document id. If not specified, the FlowFile UUID will be used.<br/>**Supports Expression Language: true** |
2223-
| **Persist To** | NONE | NONE<br/>ACTIVE<br/>ONE<br/>TWO<br/>THREE<br/>FOUR | Durability constraint about disk persistence. |
2224-
| **Replicate To** | NONE | NONE<br/>ONE<br/>TWO<br/>THREE | Durability constraint about replication. |
2215+
| Name | Default Value | Allowable Values | Description |
2216+
|------------------------------------------|---------------|----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2217+
| **Couchbase Cluster Controller Service** | | | A Couchbase Cluster Controller Service which manages connections to a Couchbase cluster. |
2218+
| **Bucket Name** | default | | The name of bucket to access.<br/>**Supports Expression Language: true** |
2219+
| Scope Name | | | Scope to use inside the bucket. If not specified, the _default scope is used.<br/>**Supports Expression Language: true** |
2220+
| Collection Name | | | Collection to use inside the bucket scope. If not specified, the _default collection is used.<br/>**Supports Expression Language: true** |
2221+
| **Document Type** | Json | Json<br/>Binary<br/>String | Content type to store data as. |
2222+
| Document Id | | | A static, fixed Couchbase document id, or an expression to construct the Couchbase document id. If not specified, either the FlowFile uuid attribute or if that's not found a generated uuid will be used.<br/>**Supports Expression Language: true** |
2223+
| **Persist To** | NONE | NONE<br/>ACTIVE<br/>ONE<br/>TWO<br/>THREE<br/>FOUR | Durability constraint about disk persistence. |
2224+
| **Replicate To** | NONE | NONE<br/>ONE<br/>TWO<br/>THREE | Durability constraint about replication. |
22252225

22262226
### Relationships
22272227

extensions/couchbase/processors/PutCouchbaseKey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void PutCouchbaseKey::onTrigger(core::ProcessContext& context, core::ProcessSess
5656

5757
std::string document_id;
5858
if (!context.getProperty(DocumentId, document_id, flow_file.get()) || document_id.empty()) {
59-
document_id = flow_file->getUUIDStr();
59+
document_id = flow_file->getAttribute(core::SpecialFlowAttribute::UUID).value_or(utils::IdGenerator::getIdGenerator()->generate().to_string());
6060
}
6161

6262
::couchbase::upsert_options options;

extensions/couchbase/processors/PutCouchbaseKey.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class PutCouchbaseKey final : public core::AbstractProcessor<PutCouchbaseKey> {
100100
.withAllowedValues(magic_enum::enum_names<CouchbaseValueType>())
101101
.build();
102102
EXTENSIONAPI static constexpr auto DocumentId = core::PropertyDefinitionBuilder<>::createProperty("Document Id")
103-
.withDescription("A static, fixed Couchbase document id, or an expression to construct the Couchbase document id. If not specified, the FlowFile UUID will be used.")
103+
.withDescription("A static, fixed Couchbase document id, or an expression to construct the Couchbase document id. "
104+
"If not specified, either the FlowFile uuid attribute or if that's not found a generated uuid will be used.")
104105
.supportsExpressionLanguage(true)
105106
.build();
106107
EXTENSIONAPI static constexpr auto PersistTo = core::PropertyDefinitionBuilder<6>::createProperty("Persist To")

extensions/couchbase/tests/PutCouchbaseKeyTests.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace org::apache::nifi::minifi::couchbase::test {
2727

2828
REGISTER_RESOURCE(MockCouchbaseClusterService, ControllerService);
2929

30+
const std::string TEST_UUID = "a53f0e78-b91a-4a82-939b-639174edb00b";
31+
3032
struct ExpectedCallOptions {
3133
std::string bucket_name;
3234
std::string scope_name;
@@ -40,6 +42,11 @@ struct ExpectedCallOptions {
4042
class PutCouchbaseKeyTestController : public TestController {
4143
public:
4244
PutCouchbaseKeyTestController() {
45+
LogTestController::getInstance().setDebug<TestPlan>();
46+
LogTestController::getInstance().setDebug<minifi::core::Processor>();
47+
LogTestController::getInstance().setTrace<minifi::core::ProcessSession>();
48+
LogTestController::getInstance().setDebug<controllers::CouchbaseClusterService>();
49+
LogTestController::getInstance().setDebug<processors::PutCouchbaseKey>();
4350
auto controller_service_node = controller_.plan->addController("MockCouchbaseClusterService", "MockCouchbaseClusterService");
4451
mock_couchbase_cluster_service_ = std::static_pointer_cast<MockCouchbaseClusterService>(controller_service_node->getControllerServiceImplementation());
4552
proc_->setProperty(processors::PutCouchbaseKey::CouchbaseClusterControllerService, "MockCouchbaseClusterService");
@@ -82,7 +89,7 @@ class PutCouchbaseKeyTestController : public TestController {
8289

8390
auto upsert_parameters = mock_couchbase_cluster_service_->getUpsertParameters();
8491
CHECK(upsert_parameters.document_type == expected_call_options.document_type);
85-
std::string expected_doc_id = expected_call_options.doc_id.empty() ? flow_file->getUUID().to_string() : expected_call_options.doc_id;
92+
auto expected_doc_id = expected_call_options.doc_id.empty() ? TEST_UUID : expected_call_options.doc_id;
8693
CHECK(upsert_parameters.document_id == expected_doc_id);
8794
CHECK(upsert_parameters.buffer == stringToByteVector(input));
8895

@@ -110,20 +117,20 @@ class PutCouchbaseKeyTestController : public TestController {
110117

111118
TEST_CASE_METHOD(PutCouchbaseKeyTestController, "Invalid Couchbase cluster controller service", "[putcouchbasekey]") {
112119
proc_->setProperty(processors::PutCouchbaseKey::CouchbaseClusterControllerService, "invalid");
113-
REQUIRE_THROWS_AS(controller_.trigger({minifi::test::InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}"}}), minifi::Exception);
120+
REQUIRE_THROWS_AS(controller_.trigger({minifi::test::InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}", {{"uuid", TEST_UUID}}}}), minifi::Exception);
114121
}
115122

116123
TEST_CASE_METHOD(PutCouchbaseKeyTestController, "Invalid bucket name", "[putcouchbasekey]") {
117124
proc_->setProperty(processors::PutCouchbaseKey::BucketName, "");
118-
auto results = controller_.trigger({minifi::test::InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}"}});
125+
auto results = controller_.trigger({minifi::test::InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}", {{"uuid", TEST_UUID}}}});
119126
REQUIRE(results[processors::PutCouchbaseKey::Failure].size() == 1);
120127
REQUIRE(LogTestController::getInstance().contains("Bucket '' is invalid or empty!", 1s));
121128
}
122129

123130
TEST_CASE_METHOD(PutCouchbaseKeyTestController, "Put succeeeds with default properties", "[putcouchbasekey]") {
124131
proc_->setProperty(processors::PutCouchbaseKey::BucketName, "mybucket");
125132
const std::string input = "{\"name\": \"John\"}\n{\"name\": \"Jill\"}";
126-
auto results = controller_.trigger({minifi::test::InputFlowFileData{input}});
133+
auto results = controller_.trigger({minifi::test::InputFlowFileData{input, {{"uuid", TEST_UUID}}}});
127134
verifyResults(results, processors::PutCouchbaseKey::Success, ExpectedCallOptions{"mybucket", "_default", "_default",
128135
::couchbase::persist_to::none, ::couchbase::replicate_to::none, CouchbaseValueType::Json, ""}, input);
129136
}
@@ -137,7 +144,7 @@ TEST_CASE_METHOD(PutCouchbaseKeyTestController, "Put succeeeds with optional pro
137144
proc_->setProperty(processors::PutCouchbaseKey::PersistTo, "ACTIVE");
138145
proc_->setProperty(processors::PutCouchbaseKey::ReplicateTo, "TWO");
139146
const std::string input = "{\"name\": \"John\"}\n{\"name\": \"Jill\"}";
140-
auto results = controller_.trigger({minifi::test::InputFlowFileData{input}});
147+
auto results = controller_.trigger({minifi::test::InputFlowFileData{input, {{"uuid", TEST_UUID}}}});
141148
verifyResults(results, processors::PutCouchbaseKey::Success, ExpectedCallOptions{"mybucket", "scope1", "collection1", ::couchbase::persist_to::active,
142149
::couchbase::replicate_to::two, CouchbaseValueType::Binary, "important_doc"}, input);
143150
}
@@ -146,7 +153,7 @@ TEST_CASE_METHOD(PutCouchbaseKeyTestController, "Put fails with default properti
146153
proc_->setProperty(processors::PutCouchbaseKey::BucketName, "mybucket");
147154
mock_couchbase_cluster_service_->setUpsertError(CouchbaseErrorType::FATAL);
148155
const std::string input = "{\"name\": \"John\"}\n{\"name\": \"Jill\"}";
149-
auto results = controller_.trigger({minifi::test::InputFlowFileData{input}});
156+
auto results = controller_.trigger({minifi::test::InputFlowFileData{input, {{"uuid", TEST_UUID}}}});
150157
verifyResults(results, processors::PutCouchbaseKey::Failure, ExpectedCallOptions{"mybucket", "_default", "_default", ::couchbase::persist_to::none, ::couchbase::replicate_to::none,
151158
CouchbaseValueType::Json, ""}, input);
152159
}
@@ -155,7 +162,7 @@ TEST_CASE_METHOD(PutCouchbaseKeyTestController, "FlowFile is transferred to retr
155162
proc_->setProperty(processors::PutCouchbaseKey::BucketName, "mybucket");
156163
mock_couchbase_cluster_service_->setUpsertError(CouchbaseErrorType::TEMPORARY);
157164
const std::string input = "{\"name\": \"John\"}\n{\"name\": \"Jill\"}";
158-
auto results = controller_.trigger({minifi::test::InputFlowFileData{input}});
165+
auto results = controller_.trigger({minifi::test::InputFlowFileData{input, {{"uuid", TEST_UUID}}}});
159166
verifyResults(results, processors::PutCouchbaseKey::Retry, ExpectedCallOptions{"mybucket", "_default", "_default", ::couchbase::persist_to::none, ::couchbase::replicate_to::none,
160167
CouchbaseValueType::Json, ""}, input);
161168
}

0 commit comments

Comments
 (0)