This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/additional_pstm_test in repository https://gitbox.apache.org/repos/asf/celix.git
commit 1a24f81c003f8679fe0de55a71771fa54efb70a9 Author: Pepijn Noltes <[email protected]> AuthorDate: Fri May 7 16:28:09 2021 +0200 Adds tests for publisher with same topic, but different scopes --- bundles/pubsub/test/CMakeLists.txt | 28 +++++++++ .../PubSubTopicAndScopeIntegrationTestSuite.cc | 69 ++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/bundles/pubsub/test/CMakeLists.txt b/bundles/pubsub/test/CMakeLists.txt index a803025..260c7e7 100644 --- a/bundles/pubsub/test/CMakeLists.txt +++ b/bundles/pubsub/test/CMakeLists.txt @@ -753,3 +753,31 @@ if (BUILD_PUBSUB_PSA_ZMQ) add_test(NAME pstm_deadlock_zmq_v2_test COMMAND pstm_deadlock_zmq_v2_test WORKING_DIRECTORY $<TARGET_PROPERTY:pstm_deadlock_zmq_v2_test,CONTAINER_LOC>) setup_target_for_coverage(pstm_deadlock_zmq_v2_test SCAN_DIR ..) endif () + + +if (BUILD_PUBSUB_PSA_ZMQ) + #Test suite to test if component with same topic and different scope combinations work + add_executable(test_pubsub_topic_and_scope_integration + topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc + ) + target_link_libraries(test_pubsub_topic_and_scope_integration PRIVATE Celix::framework Celix::pubsub_api GTest::gtest GTest::gtest_main) + setup_target_for_coverage(test_pubsub_topic_and_scope_integration SCAN_DIR ..) + + #configure topology manager and pubsub zmq, json serializer and wire protocol v2 bundles + celix_get_bundle_file(Celix::pubsub_serializer_json PUBSUB_JSON_BUNDLE_FILE) + celix_get_bundle_file(Celix::pubsub_topology_manager PUBSUB_TOPMAN_BUNDLE_FILE) + celix_get_bundle_file(Celix::pubsub_admin_zmq_v2 PUBSUB_ZMQ_BUNDLE_FILE) + celix_get_bundle_file(Celix::pubsub_protocol_wire_v2 PUBSUB_WIRE_BUNDLE_FILE) + add_dependencies(test_pubsub_topic_and_scope_integration + celix_pubsub_serializer_json_bundle + celix_pubsub_topology_manager_bundle + celix_pubsub_admin_zmq_v2_bundle + celix_pubsub_protocol_wire_v2_bundle + ) + target_compile_definitions(test_pubsub_topic_and_scope_integration PRIVATE + PUBSUB_JSON_BUNDLE_FILE="${PUBSUB_JSON_BUNDLE_FILE}" + PUBSUB_TOPMAN_BUNDLE_FILE="${PUBSUB_TOPMAN_BUNDLE_FILE}" + PUBSUB_ZMQ_BUNDLE_FILE="${PUBSUB_ZMQ_BUNDLE_FILE}" + PUBSUB_WIRE_BUNDLE_FILE="${PUBSUB_WIRE_BUNDLE_FILE}" + ) +endif () \ No newline at end of file diff --git a/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc b/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc new file mode 100644 index 0000000..f900b4a --- /dev/null +++ b/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc @@ -0,0 +1,69 @@ +/* + * 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. + */ + +#include <gtest/gtest.h> +#include <thread> + +#include "celix/FrameworkFactory.h" +#include "pubsub/publisher.h" + +class PubSubTopicAndScopeIntegrationTestSuite : public ::testing::Test { +public: + + PubSubTopicAndScopeIntegrationTestSuite() { + celix::Properties config {{"CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "trace"}}; + fw = celix::createFramework(config); + ctx = fw->getFrameworkBundleContext(); + + EXPECT_GE(ctx->installBundle(PUBSUB_JSON_BUNDLE_FILE), 0); + EXPECT_GE(ctx->installBundle(PUBSUB_TOPMAN_BUNDLE_FILE), 0); + EXPECT_GE(ctx->installBundle(PUBSUB_ZMQ_BUNDLE_FILE), 0); + EXPECT_GE(ctx->installBundle(PUBSUB_WIRE_BUNDLE_FILE), 0); + } + + + std::shared_ptr<celix::Framework> fw{}; + std::shared_ptr<celix::BundleContext> ctx{}; +}; + +class TestComponent{}; + +TEST_F(PubSubTopicAndScopeIntegrationTestSuite, ComponentsWithSameTopicAndDifferentScope) { + //When I create publisher with the same topic, but different scope + //I expect the pubsub topology manager and a PSA can handle this and the + //publisher components will become active. + + auto& cmp1 = ctx->getDependencyManager()->createComponent<TestComponent>(); + cmp1.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME) + .setFilter("(topic=foo)"); + cmp1.build(); + EXPECT_EQ(cmp1.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL); + + auto& cmp2 = ctx->getDependencyManager()->createComponent<TestComponent>(); + cmp2.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME) + .setFilter("(&(topic=foo)(scope=bar))"); + cmp2.build(); + EXPECT_EQ(cmp2.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL); + + auto& cmp3 = ctx->getDependencyManager()->createComponent<TestComponent>(); + cmp3.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME) + .setFilter("(&(topic=foo)(scope=default))"); + cmp3.build(); + EXPECT_EQ(cmp3.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL); +} \ No newline at end of file
