This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch bugfix/zmq_wrong_sender_connections in repository https://gitbox.apache.org/repos/asf/celix.git
commit 7f0c46b363c925b40f0ec05a75fc9dc71365276a Author: Pepijn Noltes <[email protected]> AuthorDate: Mon Jun 29 16:52:56 2020 +0200 Updates the scope handling of pubsub to a more flexible setup. Now a scope of NULL is handled to same as an scope of "default" for key and matching. --- .../pubsub/pubsub_spi/gtest/src/PubSubEndpointUtilsTestSuite.cc | 8 +++++++- bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c | 3 ++- bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bundles/pubsub/pubsub_spi/gtest/src/PubSubEndpointUtilsTestSuite.cc b/bundles/pubsub/pubsub_spi/gtest/src/PubSubEndpointUtilsTestSuite.cc index eecdc74..46ff62c 100644 --- a/bundles/pubsub/pubsub_spi/gtest/src/PubSubEndpointUtilsTestSuite.cc +++ b/bundles/pubsub/pubsub_spi/gtest/src/PubSubEndpointUtilsTestSuite.cc @@ -32,7 +32,7 @@ TEST_F(PubSubEndpointUtilsTestSuite, pubsubEndpoint_matchWithTopicAndScope) { EXPECT_TRUE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", nullptr)); EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topicaa", nullptr)); - EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "default")); + EXPECT_TRUE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "default")); //Note "default" is the same as NULL scope EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "scope")); celix_properties_set(endpoint, PUBSUB_ENDPOINT_TOPIC_SCOPE, "scope"); @@ -42,5 +42,11 @@ TEST_F(PubSubEndpointUtilsTestSuite, pubsubEndpoint_matchWithTopicAndScope) { EXPECT_TRUE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "scope")); EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "scopeaa")); + celix_properties_set(endpoint, PUBSUB_ENDPOINT_TOPIC_SCOPE, "default"); + EXPECT_TRUE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", nullptr)); //Note NULL is the same as "default" scope + EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topicaa", nullptr)); + EXPECT_TRUE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "default")); + EXPECT_FALSE(pubsubEndpoint_matchWithTopicAndScope(endpoint, "topic", "scope")); + celix_properties_destroy(endpoint); } diff --git a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c index 2aa052d..7ef620d 100644 --- a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c +++ b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c @@ -204,7 +204,8 @@ char* pubsubEndpoint_createScopeTopicKey(const char* scope, const char* topic) { if (scope != NULL) { asprintf(&result, "%s:%s", scope, topic); } else { - asprintf(&result, "scopeless %s", topic); + //NOTE scope == NULL, equal to scope="default" + asprintf(&result, "%s:%s", PUBSUB_DEFAULT_ENDPOINT_SCOPE, topic); } return result; } diff --git a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c index cc18beb..fc442ef 100644 --- a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c +++ b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c @@ -325,8 +325,12 @@ bool pubsubEndpoint_match( } bool pubsubEndpoint_matchWithTopicAndScope(const celix_properties_t* endpoint, const char *topic, const char *scope) { - const char *endpointScope = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TOPIC_SCOPE, NULL); + const char *endpointScope = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TOPIC_SCOPE, PUBSUB_DEFAULT_ENDPOINT_SCOPE); const char *endpointTopic = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TOPIC_NAME, NULL); + if (scope == NULL) { + scope = PUBSUB_DEFAULT_ENDPOINT_SCOPE; + } + if (celix_utils_stringEquals(topic, endpointTopic) && celix_utils_stringEquals(scope, endpointScope)) { return true; }
