diff --git a/CHANGELOG.md b/CHANGELOG.md index dbff114530..7babb9508d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Introduce `cxx::FunctionalInterface` to enrich nullable classes with `and_then`, `or_else`, `value_or`, `expect` [\#996](https://github.com/eclipse-iceoryx/iceoryx/issues/996) - Add C++17 `std::perms` as `cxx::perms` to `iceoryx_hoofs/cxx/filesystem.hpp`. [#1059](https://github.com/eclipse-iceoryx/iceoryx/issues/1059) - Support FreeBSD as a representative for the UNIX platforms [#1054](https://github.com/eclipse-iceoryx/iceoryx/issues/1054) +- Add event parameter to `findService` method [#415](https://github.com/eclipse-iceoryx/iceoryx/issues/415) **Bugfixes:** @@ -240,17 +241,21 @@ capro::ServiceDescription::deserialize(serialisedObj) }); ``` -The service-related methods have been moved from `PoshRuntime` to `ServiceDiscovery`. Additionally, the -`offerService` and `stopOfferService` methods have been removed: +The service-related methods have been moved from `PoshRuntime` to `ServiceDiscovery`. The `offerService` +and `stopOfferService` methods have been removed and `findService` has now an additional event paramter: ```cpp // before +#include "iceoryx_posh/runtime/posh_runtime.hpp" + poshRuntime.offerService(myServiceDescription); poshRuntime.stopOfferService(myServiceDescription); poshRuntime.findService({"ServiceA", iox::capro::AnyInstanceString}); // after -serviceDiscovery.findService("ServiceA", Wildcard); +#include "iceoryx_posh/runtime/service_discovery.hpp" + +serviceDiscovery.findService("ServiceA", Wildcard, Wildcard); ``` The `iox::cxx::expected` has dropped the requirement for `INVALID_STATE`. With this, the diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp index edca02488a..f6d358b99b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp @@ -97,7 +97,8 @@ class PortManager const std::atomic* serviceRegistryChangeCounter() noexcept; runtime::IpcMessage findService(const cxx::optional& service, - const cxx::optional& instance) noexcept; + const cxx::optional& instance, + const cxx::optional& event) noexcept; protected: void makeAllPublisherPortsToStopOffer() noexcept; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/process_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/process_manager.hpp index 9c4501abc1..922709eae2 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/process_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/process_manager.hpp @@ -109,7 +109,8 @@ class ProcessManager : public ProcessManagerInterface void findServiceForProcess(const RuntimeName_t& name, const cxx::optional& service, - const cxx::optional& instance) noexcept; + const cxx::optional& instance, + const cxx::optional& event) noexcept; void addInterfaceForProcess(const RuntimeName_t& name, capro::Interfaces interface, const NodeName_t& node) noexcept; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp index 5c455b33a5..f0183e031b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp @@ -61,9 +61,11 @@ class ServiceRegistry /// @param[in] searchResult, reference to the vector which will be filled with the results /// @param[in] service, string or wildcard (= iox::cxx::nullopt) to search for /// @param[in] instance, string or wildcard (= iox::cxx::nullopt) to search for + /// @param[in] event, string or wildcard (= iox::cxx::nullopt) to search for void find(ServiceDescriptionVector_t& searchResult, const cxx::optional& service, - const cxx::optional& instance) const noexcept; + const cxx::optional& instance, + const cxx::optional& event) const noexcept; /// @brief Returns all service descriptions as copy /// @return ServiceDescriptionVector_t, copy of complete service registry @@ -73,6 +75,7 @@ class ServiceRegistry /// @todo #859 replace std::multimap with prefix tree ::std::multimap m_serviceMap; ::std::multimap m_instanceMap; + ::std::multimap m_eventMap; ServiceDescriptionVector_t m_serviceDescriptionVector; }; } // namespace roudi diff --git a/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp b/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp index 605d485fe3..d381703d6a 100644 --- a/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp +++ b/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp @@ -37,12 +37,14 @@ class ServiceDiscovery /// @brief find all services that match the provided service description /// @param[in] service service string to search for, a nullopt corresponds to a wildcard /// @param[in] instance instance string to search for, a nullopt corresponds to a wildcard + /// @param[in] event event string to search for, a nullopt corresponds to a wildcard /// @return cxx::expected /// ServiceContainer: on success, container that is filled with all matching instances /// FindServiceError: if any, encountered during the operation cxx::expected findService(const cxx::optional& service, - const cxx::optional& instance) noexcept; + const cxx::optional& instance, + const cxx::optional& event) noexcept; /// @brief requests the serviceRegistryChangeCounter from the shared memory /// @return pointer to the serviceRegistryChangeCounter diff --git a/iceoryx_posh/source/roudi/port_manager.cpp b/iceoryx_posh/source/roudi/port_manager.cpp index 01ff3931d0..77946d8abc 100644 --- a/iceoryx_posh/source/roudi/port_manager.cpp +++ b/iceoryx_posh/source/roudi/port_manager.cpp @@ -559,12 +559,13 @@ void PortManager::destroySubscriberPort(SubscriberPortType::MemberType_t* const } runtime::IpcMessage PortManager::findService(const cxx::optional& service, - const cxx::optional& instance) noexcept + const cxx::optional& instance, + const cxx::optional& event) noexcept { runtime::IpcMessage response; ServiceRegistry::ServiceDescriptionVector_t searchResult; - m_serviceRegistry.find(searchResult, service, instance); + m_serviceRegistry.find(searchResult, service, instance, event); for (auto& service : searchResult) { diff --git a/iceoryx_posh/source/roudi/process_manager.cpp b/iceoryx_posh/source/roudi/process_manager.cpp index 444731dbe2..8055804954 100644 --- a/iceoryx_posh/source/roudi/process_manager.cpp +++ b/iceoryx_posh/source/roudi/process_manager.cpp @@ -347,12 +347,13 @@ void ProcessManager::updateLivelinessOfProcess(const RuntimeName_t& name) noexce void ProcessManager::findServiceForProcess(const RuntimeName_t& name, const cxx::optional& service, - const cxx::optional& instance) noexcept + const cxx::optional& instance, + const cxx::optional& event) noexcept { searchForProcessAndThen( name, [&](Process& process) { - process.sendViaIpcChannel({m_portManager.findService(service, instance)}); + process.sendViaIpcChannel({m_portManager.findService(service, instance, event)}); LogDebug() << "Sent all found services to application " << name; }, [&]() { LogWarn() << "Unknown process " << name << " requested to find services."; }); diff --git a/iceoryx_posh/source/roudi/roudi.cpp b/iceoryx_posh/source/roudi/roudi.cpp index 2ca7ec93f9..6d700c3ae8 100644 --- a/iceoryx_posh/source/roudi/roudi.cpp +++ b/iceoryx_posh/source/roudi/roudi.cpp @@ -346,7 +346,7 @@ void RouDi::processMessage(const runtime::IpcMessage& message, } case runtime::IpcMessageType::FIND_SERVICE: { - if (message.getNumberOfElements() != 6) + if (message.getNumberOfElements() != 8) { LogError() << "Wrong number of parameters for \"IpcMessageType::FIND_SERVICE\" from \"" << runtimeName << "\"received!"; @@ -355,8 +355,10 @@ void RouDi::processMessage(const runtime::IpcMessage& message, { cxx::optional service; cxx::optional instance; + cxx::optional event; bool isServiceWildcard = false; bool isInstanceWildcard = false; + bool isEventWildcard = false; cxx::convert::fromString(message.getElementAtIndex(2).c_str(), isServiceWildcard); if (!isServiceWildcard) { @@ -367,8 +369,13 @@ void RouDi::processMessage(const runtime::IpcMessage& message, { instance.emplace(cxx::TruncateToCapacity, message.getElementAtIndex(5)); } + cxx::convert::fromString(message.getElementAtIndex(6).c_str(), isEventWildcard); + if (!isEventWildcard) + { + event.emplace(cxx::TruncateToCapacity, message.getElementAtIndex(7)); + } - m_prcMgr->findServiceForProcess(runtimeName, service, instance); + m_prcMgr->findServiceForProcess(runtimeName, service, instance, event); } break; } diff --git a/iceoryx_posh/source/roudi/service_registry.cpp b/iceoryx_posh/source/roudi/service_registry.cpp index bfa8cdddb4..61d81d20ab 100644 --- a/iceoryx_posh/source/roudi/service_registry.cpp +++ b/iceoryx_posh/source/roudi/service_registry.cpp @@ -45,6 +45,7 @@ cxx::expected ServiceRegistry::add(const capro::ServiceD auto serviceIndex = m_serviceDescriptionVector.size() - 1; m_serviceMap.insert({serviceDescription.getServiceIDString(), serviceIndex}); m_instanceMap.insert({serviceDescription.getInstanceIDString(), serviceIndex}); + m_eventMap.insert({serviceDescription.getEventIDString(), serviceIndex}); return cxx::success<>(); } @@ -96,19 +97,21 @@ void ServiceRegistry::remove(const capro::ServiceDescription& serviceDescription { removeIndexFromMap(m_serviceMap, index); removeIndexFromMap(m_instanceMap, index); + removeIndexFromMap(m_eventMap, index); } } void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, const cxx::optional& service, - const cxx::optional& instance) const noexcept + const cxx::optional& instance, + const cxx::optional& event) const noexcept { - cxx::vector intersection; - + ServiceDescriptionVector_t serviceInstanceResult; // Find (K1, K2) // O(log n + log n + max(#PossibleServices + #possiblesInstances) + #intersection) if (instance && service) { + cxx::vector intersection; cxx::vector possibleServices; cxx::vector possibleInstances; @@ -132,7 +135,7 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, for (auto& value : intersection) { - searchResult.push_back(m_serviceDescriptionVector[value]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[value]); } } // Find (*, K2) @@ -142,7 +145,7 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, auto range = m_instanceMap.equal_range(instance.value()); for (auto entry = range.first; entry != range.second; ++entry) { - searchResult.push_back(m_serviceDescriptionVector[entry->second]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[entry->second]); } } // Find (K1, *) @@ -152,14 +155,29 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, auto range = m_serviceMap.equal_range(service.value()); for (auto entry = range.first; entry != range.second; ++entry) { - searchResult.push_back(m_serviceDescriptionVector[entry->second]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[entry->second]); } } else { // Find (*, *) // O(n) - searchResult = m_serviceDescriptionVector; + serviceInstanceResult = m_serviceDescriptionVector; + } + + if (event) + { + for (auto iterator = serviceInstanceResult.begin(); iterator != serviceInstanceResult.end(); iterator++) + { + if (iterator->serviceDescription.getEventIDString() == event.value()) + { + searchResult.push_back(*iterator); + } + } + } + else + { + searchResult = serviceInstanceResult; } } diff --git a/iceoryx_posh/source/runtime/service_discovery.cpp b/iceoryx_posh/source/runtime/service_discovery.cpp index 69f23dda60..b7ce481542 100644 --- a/iceoryx_posh/source/runtime/service_discovery.cpp +++ b/iceoryx_posh/source/runtime/service_discovery.cpp @@ -23,13 +23,16 @@ namespace runtime { cxx::expected ServiceDiscovery::findService(const cxx::optional& service, - const cxx::optional& instance) noexcept + const cxx::optional& instance, + const cxx::optional& event) noexcept { /// @todo #415 remove the string mapping, once the find call is done via shared memory capro::IdString_t serviceString; capro::IdString_t instanceString; + capro::IdString_t eventString; bool isServiceWildcard = !service; bool isInstanceWildcard = !instance; + bool isEventWildcard = !event; if (!isServiceWildcard) { @@ -39,11 +42,16 @@ ServiceDiscovery::findService(const cxx::optional& service, { instanceString = instance.value(); } + if (!isEventWildcard) + { + eventString = event.value(); + } IpcMessage sendBuffer; sendBuffer << IpcMessageTypeToString(IpcMessageType::FIND_SERVICE) << PoshRuntime::getInstance().getInstanceName() << cxx::convert::toString(isServiceWildcard) << serviceString - << cxx::convert::toString(isInstanceWildcard) << instanceString; + << cxx::convert::toString(isInstanceWildcard) << instanceString + << cxx::convert::toString(isEventWildcard) << eventString; IpcMessage requestResponse; diff --git a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp index eda0e4125d..7ca1f62081 100644 --- a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp +++ b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp @@ -61,7 +61,7 @@ TIMING_TEST_F(ServiceDiscovery_test, GetServiceRegistryChangeCounterOfferStopOff TEST_F(ServiceDiscovery_test, FindServiceWithWildcardsReturnsOnlyIntrospectionServices) { ::testing::Test::RecordProperty("TEST_ID", "d944f32c-edef-44f5-a6eb-c19ee73c98eb"); - auto serviceContainer = sut.findService(iox::capro::Wildcard, iox::capro::Wildcard); + auto serviceContainer = sut.findService(iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); ASSERT_FALSE(serviceContainer.has_error()); auto searchResult = serviceContainer.value(); @@ -78,8 +78,9 @@ TEST_F(ServiceDiscovery_test, FindServiceReturnsOfferedService) const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event"); iox::popo::UntypedPublisher publisher(SERVICE_DESCRIPTION); - auto serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); @@ -92,24 +93,27 @@ TEST_F(ServiceDiscovery_test, ReofferedServiceWithValidServiceDescriptionCanBeFo const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event"); iox::popo::UntypedPublisher publisher(SERVICE_DESCRIPTION); - auto serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION)); publisher.stopOffer(); this->InterOpWait(); - serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_TRUE(serviceContainer.value().empty()); publisher.offer(); this->InterOpWait(); - serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION)); @@ -123,8 +127,9 @@ TEST_F(ServiceDiscovery_test, OfferExsistingServiceMultipleTimesIsRedundant) publisher.offer(); this->InterOpWait(); - auto serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); @@ -137,20 +142,22 @@ TEST_F(ServiceDiscovery_test, FindSameServiceMultipleTimesReturnsSingleInstance) const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event"); iox::popo::UntypedPublisher publisher(SERVICE_DESCRIPTION); - auto serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION)); - serviceContainer = - sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), SERVICE_DESCRIPTION.getInstanceIDString()); + serviceContainer = sut.findService(SERVICE_DESCRIPTION.getServiceIDString(), + SERVICE_DESCRIPTION.getInstanceIDString(), + SERVICE_DESCRIPTION.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION)); } -TEST_F(ServiceDiscovery_test, OfferDifferentServicesWithSameInstance) +TEST_F(ServiceDiscovery_test, OfferDifferentServicesWithSameInstanceAndEvent) { ::testing::Test::RecordProperty("TEST_ID", "25bf794d-450e-47ce-a920-ab2ea479af39"); @@ -163,23 +170,23 @@ TEST_F(ServiceDiscovery_test, OfferDifferentServicesWithSameInstance) const iox::capro::ServiceDescription SERVICE_DESCRIPTION3("service3", INSTANCE, EVENT); iox::popo::UntypedPublisher publisher_sd3(SERVICE_DESCRIPTION3); - auto serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), INSTANCE); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION1)); - serviceContainer = sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), INSTANCE); + serviceContainer = sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION2)); - serviceContainer = sut.findService(SERVICE_DESCRIPTION3.getServiceIDString(), INSTANCE); + serviceContainer = sut.findService(SERVICE_DESCRIPTION3.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3)); } -TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnServiceWhenServiceAndIdStringDoNotMatch) +TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnServiceWhenStringsDoNotMatch) { ::testing::Test::RecordProperty("TEST_ID", "1984e907-e990-48b2-8cbd-eab3f67cd162"); const iox::capro::ServiceDescription SERVICE_DESCRIPTION1("service1", "instance1", "event1"); @@ -187,25 +194,26 @@ TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnServiceWhenServiceAndIdStr const iox::capro::ServiceDescription SERVICE_DESCRIPTION2("service2", "instance2", "event2"); iox::popo::UntypedPublisher publisher_sd2(SERVICE_DESCRIPTION2); - auto serviceContainer = - sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), SERVICE_DESCRIPTION1.getInstanceIDString()); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), + SERVICE_DESCRIPTION1.getInstanceIDString(), + SERVICE_DESCRIPTION2.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); - ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION1)); + ASSERT_THAT(serviceContainer.value().size(), Eq(0U)); - serviceContainer = - sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), SERVICE_DESCRIPTION1.getInstanceIDString()); + serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), + SERVICE_DESCRIPTION2.getInstanceIDString(), + SERVICE_DESCRIPTION1.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); - serviceContainer = - sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), SERVICE_DESCRIPTION2.getInstanceIDString()); + serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), + SERVICE_DESCRIPTION2.getInstanceIDString(), + SERVICE_DESCRIPTION2.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); - ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION2)); + EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); } -TEST_F(ServiceDiscovery_test, FindServiceWithInstanceWildcardReturnsAllMatchingServices) +TEST_F(ServiceDiscovery_test, FindServiceWithInstanceAndEventWildcardReturnsAllMatchingServices) { ::testing::Test::RecordProperty("TEST_ID", "6e0b1a12-6995-45f4-8fd8-59acbca9bfa8"); @@ -222,28 +230,79 @@ TEST_F(ServiceDiscovery_test, FindServiceWithInstanceWildcardReturnsAllMatchingS serviceContainerExp.push_back(SERVICE_DESCRIPTION2); serviceContainerExp.push_back(SERVICE_DESCRIPTION3); - auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard); + auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard, iox::capro::Wildcard); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(3U)); EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); } -TEST_F(ServiceDiscovery_test, FindServiceWithServiceWildcardReturnsAllServices) +TEST_F(ServiceDiscovery_test, FindServiceWithServiceWildcardReturnsCorrectServices) { ::testing::Test::RecordProperty("TEST_ID", "f4731a52-39d8-4d49-b247-008a2e9181f9"); const IdString_t INSTANCE = "instance"; - const iox::capro::ServiceDescription SERVICE_DESCRIPTION1("service1", INSTANCE, "event1"); + const IdString_t EVENT = "event"; + const iox::capro::ServiceDescription SERVICE_DESCRIPTION1("service1", INSTANCE, EVENT); + iox::popo::UntypedPublisher publisher_sd1(SERVICE_DESCRIPTION1); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION2("service2", "another_instance", EVENT); + iox::popo::UntypedPublisher publisher_sd2(SERVICE_DESCRIPTION2); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION3("service3", INSTANCE, EVENT); + iox::popo::UntypedPublisher publisher_sd3(SERVICE_DESCRIPTION3); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION4("service4", INSTANCE, "another_event"); + iox::popo::UntypedPublisher publisher_sd4(SERVICE_DESCRIPTION4); + + ServiceContainer serviceContainerExp; + serviceContainerExp.push_back(SERVICE_DESCRIPTION1); + serviceContainerExp.push_back(SERVICE_DESCRIPTION3); + + auto serviceContainer = sut.findService(iox::capro::Wildcard, INSTANCE, EVENT); + ASSERT_FALSE(serviceContainer.has_error()); + ASSERT_THAT(serviceContainer.value().size(), Eq(2U)); + EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); +} + +TEST_F(ServiceDiscovery_test, FindServiceWithEventWildcardReturnsCorrectServices) +{ + ::testing::Test::RecordProperty("TEST_ID", "e78b35f4-b3c3-4c39-b10a-67712c72e28a"); + const IdString_t SERVICE = "service"; + const IdString_t INSTANCE = "instance"; + const iox::capro::ServiceDescription SERVICE_DESCRIPTION1(SERVICE, INSTANCE, "event1"); iox::popo::UntypedPublisher publisher_sd1(SERVICE_DESCRIPTION1); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION2("service2", "another_instance", "event2"); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION2("another_service", INSTANCE, "event2"); iox::popo::UntypedPublisher publisher_sd2(SERVICE_DESCRIPTION2); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION3("service3", INSTANCE, "event3"); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION3(SERVICE, INSTANCE, "event3"); iox::popo::UntypedPublisher publisher_sd3(SERVICE_DESCRIPTION3); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION4(SERVICE, "another_instance", "event4"); + iox::popo::UntypedPublisher publisher_sd4(SERVICE_DESCRIPTION4); ServiceContainer serviceContainerExp; serviceContainerExp.push_back(SERVICE_DESCRIPTION1); serviceContainerExp.push_back(SERVICE_DESCRIPTION3); - auto serviceContainer = sut.findService(iox::capro::Wildcard, INSTANCE); + auto serviceContainer = sut.findService(SERVICE, INSTANCE, iox::capro::Wildcard); + ASSERT_FALSE(serviceContainer.has_error()); + ASSERT_THAT(serviceContainer.value().size(), Eq(2U)); + EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); +} + +TEST_F(ServiceDiscovery_test, FindServiceWithInstanceWildcardReturnsCorrectServices) +{ + ::testing::Test::RecordProperty("TEST_ID", "2ec4b422-3ded-4af3-9e72-3b870c55031c"); + const IdString_t SERVICE = "service"; + const IdString_t EVENT = "event"; + const iox::capro::ServiceDescription SERVICE_DESCRIPTION1(SERVICE, "instance1", EVENT); + iox::popo::UntypedPublisher publisher_sd1(SERVICE_DESCRIPTION1); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION2("another_service", "instance2", EVENT); + iox::popo::UntypedPublisher publisher_sd2(SERVICE_DESCRIPTION2); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION3(SERVICE, "instance3", EVENT); + iox::popo::UntypedPublisher publisher_sd3(SERVICE_DESCRIPTION3); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION4(SERVICE, "instance4", "another_event"); + iox::popo::UntypedPublisher publisher_sd4(SERVICE_DESCRIPTION4); + + ServiceContainer serviceContainerExp; + serviceContainerExp.push_back(SERVICE_DESCRIPTION1); + serviceContainerExp.push_back(SERVICE_DESCRIPTION3); + + auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard, EVENT); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(2U)); EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); @@ -261,17 +320,20 @@ TEST_F(ServiceDiscovery_test, OfferSingleServiceMultiInstance) const iox::capro::ServiceDescription SERVICE_DESCRIPTION3(SERVICE, "instance3", "event3"); iox::popo::UntypedPublisher publisher_sd3(SERVICE_DESCRIPTION3); - auto serviceContainer = sut.findService(SERVICE, SERVICE_DESCRIPTION1.getInstanceIDString()); + auto serviceContainer = + sut.findService(SERVICE, SERVICE_DESCRIPTION1.getInstanceIDString(), SERVICE_DESCRIPTION1.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION1)); - serviceContainer = sut.findService(SERVICE, SERVICE_DESCRIPTION2.getInstanceIDString()); + serviceContainer = + sut.findService(SERVICE, SERVICE_DESCRIPTION2.getInstanceIDString(), SERVICE_DESCRIPTION2.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION2)); - serviceContainer = sut.findService(SERVICE, SERVICE_DESCRIPTION3.getInstanceIDString()); + serviceContainer = + sut.findService(SERVICE, SERVICE_DESCRIPTION3.getInstanceIDString(), SERVICE_DESCRIPTION3.getEventIDString()); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3)); @@ -282,57 +344,48 @@ TEST_F(ServiceDiscovery_test, FindServiceReturnsCorrectServiceInstanceCombinatio ::testing::Test::RecordProperty("TEST_ID", "360839a7-9309-4e7e-8e89-892097a87f7a"); const IdString_t SERVICE1 = "service1"; - const IdString_t SERVICE2 = "service2"; const IdString_t INSTANCE1 = "instance1"; const IdString_t INSTANCE2 = "instance2"; - const IdString_t INSTANCE3 = "instance3"; const IdString_t EVENT1 = "event1"; const IdString_t EVENT2 = "event2"; const IdString_t EVENT3 = "event3"; - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_1(SERVICE1, INSTANCE1, EVENT1); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_2(SERVICE1, INSTANCE2, EVENT2); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_3(SERVICE1, INSTANCE3, EVENT3); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_2_1(SERVICE2, INSTANCE1, EVENT1); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_2_2(SERVICE2, INSTANCE2, EVENT2); - const iox::capro::ServiceDescription SERVICE_DESCRIPTION_2_3(SERVICE2, INSTANCE3, EVENT3); - - iox::popo::UntypedPublisher publisher_sd_1_1(SERVICE_DESCRIPTION_1_1); - iox::popo::UntypedPublisher publisher_sd_1_2(SERVICE_DESCRIPTION_1_2); - iox::popo::UntypedPublisher publisher_sd_1_3(SERVICE_DESCRIPTION_1_3); - iox::popo::UntypedPublisher publisher_sd_2_1(SERVICE_DESCRIPTION_2_1); - iox::popo::UntypedPublisher publisher_sd_2_2(SERVICE_DESCRIPTION_2_2); - iox::popo::UntypedPublisher publisher_sd_2_3(SERVICE_DESCRIPTION_2_3); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_1_1(SERVICE1, INSTANCE1, EVENT1); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_1_2(SERVICE1, INSTANCE1, EVENT2); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_2_1(SERVICE1, INSTANCE2, EVENT1); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_2_2(SERVICE1, INSTANCE2, EVENT2); + const iox::capro::ServiceDescription SERVICE_DESCRIPTION_1_2_3(SERVICE1, INSTANCE2, EVENT3); - auto serviceContainer = sut.findService(SERVICE1, INSTANCE1); - ASSERT_FALSE(serviceContainer.has_error()); - ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_1)); + iox::popo::UntypedPublisher publisher_sd_1_1_1(SERVICE_DESCRIPTION_1_1_1); + iox::popo::UntypedPublisher publisher_sd_1_1_2(SERVICE_DESCRIPTION_1_1_2); + iox::popo::UntypedPublisher publisher_sd_1_2_1(SERVICE_DESCRIPTION_1_2_1); + iox::popo::UntypedPublisher publisher_sd_1_2_2(SERVICE_DESCRIPTION_1_2_2); + iox::popo::UntypedPublisher publisher_sd_1_2_3(SERVICE_DESCRIPTION_1_2_3); - serviceContainer = sut.findService(SERVICE1, INSTANCE2); + auto serviceContainer = sut.findService(SERVICE1, INSTANCE1, EVENT1); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_2)); + EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_1_1)); - serviceContainer = sut.findService(SERVICE1, INSTANCE3); + serviceContainer = sut.findService(SERVICE1, INSTANCE1, EVENT2); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_3)); + EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_1_2)); - serviceContainer = sut.findService(SERVICE2, INSTANCE1); + serviceContainer = sut.findService(SERVICE1, INSTANCE2, EVENT1); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_2_1)); + EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_2_1)); - serviceContainer = sut.findService(SERVICE2, INSTANCE2); + serviceContainer = sut.findService(SERVICE1, INSTANCE2, EVENT2); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_2_2)); + EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_2_2)); - serviceContainer = sut.findService(SERVICE2, INSTANCE3); + serviceContainer = sut.findService(SERVICE1, INSTANCE2, EVENT3); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); - EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_2_3)); + EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION_1_2_3)); } TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnNotOfferedServices) @@ -352,16 +405,16 @@ TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnNotOfferedServices) publisher_sd3.stopOffer(); this->InterOpWait(); - auto serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), INSTANCE); + auto serviceContainer = sut.findService(SERVICE_DESCRIPTION1.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); - serviceContainer = sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), INSTANCE); + serviceContainer = sut.findService(SERVICE_DESCRIPTION2.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); ASSERT_THAT(serviceContainer.value().size(), Eq(1U)); EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION2)); - serviceContainer = sut.findService(SERVICE_DESCRIPTION3.getServiceIDString(), INSTANCE); + serviceContainer = sut.findService(SERVICE_DESCRIPTION3.getServiceIDString(), INSTANCE, EVENT); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); } @@ -372,15 +425,31 @@ TEST_F(ServiceDiscovery_test, NonExistingServicesAreNotFound) const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event"); iox::popo::UntypedPublisher publisher_sd(SERVICE_DESCRIPTION); - auto serviceContainer = sut.findService(IdString_t("service"), IdString_t("schlomo")); + auto serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("schlomo"), IdString_t("hypnotoad")); + ASSERT_FALSE(serviceContainer.has_error()); + EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); + + serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("schlomo"), IdString_t("event")); + ASSERT_FALSE(serviceContainer.has_error()); + EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); + + serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("instance"), IdString_t("hypnotoad")); + ASSERT_FALSE(serviceContainer.has_error()); + EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); + + serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("instance"), IdString_t("event")); + ASSERT_FALSE(serviceContainer.has_error()); + EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); + + serviceContainer = sut.findService(IdString_t("service"), IdString_t("schlomo"), IdString_t("hypnotoad")); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); - serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("instance")); + serviceContainer = sut.findService(IdString_t("service"), IdString_t("schlomo"), IdString_t("hypnotoad")); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); - serviceContainer = sut.findService(IdString_t("ignatz"), IdString_t("schlomo")); + serviceContainer = sut.findService(IdString_t("service"), IdString_t("instance"), IdString_t("hypnotoad")); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); } @@ -402,7 +471,7 @@ TEST_F(ServiceDiscovery_test, FindServiceReturnsMaxServices) serviceContainerExp.push_back(SERVICE_DESCRIPTION); } - auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard); + auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard, iox::capro::Wildcard); ASSERT_FALSE(serviceContainer.has_error()); EXPECT_THAT(serviceContainer.value().size(), Eq(iox::MAX_NUMBER_OF_SERVICES)); @@ -423,7 +492,7 @@ TEST_F(ServiceDiscovery_test, FindServiceReturnsContainerOverflowErrorWhenMoreTh publishers.emplace_back(SERVICE_DESCRIPTION); } - auto serviceContainer = sut.findService(IdString_t("s"), iox::capro::Wildcard); + auto serviceContainer = sut.findService(SERVICE, iox::capro::Wildcard, iox::capro::Wildcard); ASSERT_THAT(serviceContainer.has_error(), Eq(true)); } diff --git a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp index 3743c2f24c..857f11f9aa 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2021 by Apex.AI. All rights reserved. +// Copyright (c) 2021 - 2022 by Apex.AI. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ class ServiceRegistry_test : public Test TEST_F(ServiceRegistry_test, AddNoServiceDescriptionsAndWildcardSearchReturnsNothing) { ::testing::Test::RecordProperty("TEST_ID", "3a050209-01d8-4d0e-9e70-c0662b9dbe76"); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); EXPECT_THAT(searchResults.size(), Eq(0)); } @@ -105,9 +105,9 @@ TEST_F(ServiceRegistry_test, AddServiceDescriptionsWhichWasAlreadyAddedAndReturn auto result2 = sut.add(ServiceDescription("Li", "La", "Launebaer")); ASSERT_FALSE(result2.has_error()); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Li", "La", "Launebaer"))); EXPECT_THAT(searchResults[0].referenceCounter, Eq(2)); } @@ -123,9 +123,9 @@ TEST_F(ServiceRegistry_test, AddServiceDescriptionsTwiceAndRemoveOnceAndReturnsO sut.remove(ServiceDescription("Li", "La", "Launebaerli")); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Li", "La", "Launebaerli"))); EXPECT_THAT(searchResults[0].referenceCounter, Eq(1)); } @@ -156,9 +156,9 @@ TEST_F(ServiceRegistry_test, SingleEmptyServiceDescriptionsCanBeFoundWithWildcar { ::testing::Test::RecordProperty("TEST_ID", "be3e4b13-d930-47b2-aeaa-95c65f06deed"); ASSERT_FALSE(sut.add(ServiceDescription()).has_error()); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription())); } @@ -166,9 +166,9 @@ TEST_F(ServiceRegistry_test, SingleEmptyServiceDescriptionsCanBeFoundWithEmptySt { ::testing::Test::RecordProperty("TEST_ID", "1af0137f-6bf5-422e-a6ec-513f7d3f6191"); ASSERT_FALSE(sut.add(ServiceDescription()).has_error()); - sut.find(searchResults, iox::capro::IdString_t(""), iox::capro::IdString_t("")); + sut.find(searchResults, iox::capro::IdString_t(""), iox::capro::IdString_t(""), iox::capro::IdString_t("")); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription())); } @@ -177,32 +177,56 @@ TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithWildcardSearc ::testing::Test::RecordProperty("TEST_ID", "a12c9d39-6379-4296-8987-df56a87169f7"); auto result = sut.add(ServiceDescription("Foo", "Bar", "Baz")); ASSERT_FALSE(result.has_error()); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Foo", "Bar", "Baz"))); } +TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithEventName) +{ + ::testing::Test::RecordProperty("TEST_ID", "6df8fd7d-e4d1-4c51-8ad7-2fbe82e4ed09"); + iox::capro::ServiceDescription service("a", "b", "c"); + ASSERT_FALSE(sut.add(service).has_error()); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::IdString_t("c")); + + ASSERT_THAT(searchResults.size(), Eq(1)); + EXPECT_THAT(searchResults[0].serviceDescription, Eq(service)); +} + +TEST_F(ServiceRegistry_test, ServiceDescriptionNotFoundWhenEventDoesNotMatch) +{ + ::testing::Test::RecordProperty("TEST_ID", "ba7785d1-08ec-4f7c-b341-dff033dae2c7"); + iox::capro::ServiceDescription service("Besser", "Wisser", "Girl"); + ASSERT_FALSE(sut.add(service).has_error()); + sut.find(searchResults, + iox::capro::IdString_t("Besser"), + iox::capro::IdString_t("Wisser"), + iox::capro::IdString_t("Boy")); + + EXPECT_THAT(searchResults.size(), Eq(0)); +} + TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithInstanceName) { ::testing::Test::RecordProperty("TEST_ID", "1dfaa836-f1da-466f-a794-a7ac1b599ce3"); auto result = sut.add(ServiceDescription("Baz", "Bar", "Foo")); ASSERT_FALSE(result.has_error()); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::IdString_t("Bar")); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::IdString_t("Bar"), iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Baz", "Bar", "Foo"))); } TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithServiceName) { ::testing::Test::RecordProperty("TEST_ID", "0890013c-e14b-4ae2-89cb-757624c12b4e"); - iox::capro::ServiceDescription service1("a", "b", "c"); - ASSERT_FALSE(sut.add(service1).has_error()); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard); + iox::capro::ServiceDescription service("a", "b", "c"); + ASSERT_FALSE(sut.add(service).has_error()); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); - EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1)); + ASSERT_THAT(searchResults.size(), Eq(1)); + EXPECT_THAT(searchResults[0].serviceDescription, Eq(service)); } TEST_F(ServiceRegistry_test, EmptyAndNotEmptyServiceDescriptionsCanAllBeFoundWithWildcardSearch) @@ -213,9 +237,9 @@ TEST_F(ServiceRegistry_test, EmptyAndNotEmptyServiceDescriptionsCanAllBeFoundWit ASSERT_FALSE(sut.add(service1).has_error()); ASSERT_FALSE(sut.add(service2).has_error()); - sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard); + sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(2)); + ASSERT_THAT(searchResults.size(), Eq(2)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1)); EXPECT_THAT(searchResults[1].serviceDescription, Eq(service2)); } @@ -230,9 +254,9 @@ TEST_F(ServiceRegistry_test, MultipleServiceDescriptionWithSameServiceNameCanAll ASSERT_FALSE(sut.add(service1).has_error()); ASSERT_FALSE(sut.add(service2).has_error()); ASSERT_FALSE(sut.add(service3).has_error()); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(3)); + ASSERT_THAT(searchResults.size(), Eq(3)); bool hasFoundB = false; bool hasFoundC = false; @@ -259,14 +283,14 @@ TEST_F(ServiceRegistry_test, MultipleServiceDescriptionWithDifferentServiceNameC ASSERT_FALSE(sut.add(service1).has_error()); ASSERT_FALSE(sut.add(service2).has_error()); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1)); searchResults.clear(); - sut.find(searchResults, iox::capro::IdString_t("c"), iox::capro::Wildcard); - EXPECT_THAT(searchResults.size(), Eq(1)); + sut.find(searchResults, iox::capro::IdString_t("c"), iox::capro::Wildcard, iox::capro::Wildcard); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(service2)); } @@ -280,9 +304,9 @@ TEST_F(ServiceRegistry_test, MultipleServiceDescriptionWithSameServiceNameFindsS ASSERT_FALSE(sut.add(service1).has_error()); ASSERT_FALSE(sut.add(service2).has_error()); ASSERT_FALSE(sut.add(service3).has_error()); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("c")); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("c"), iox::capro::IdString_t("c")); - EXPECT_THAT(searchResults.size(), Eq(1)); + ASSERT_THAT(searchResults.size(), Eq(1)); EXPECT_THAT(searchResults[0].serviceDescription, Eq(service2)); } @@ -304,7 +328,7 @@ TEST_F(ServiceRegistry_test, MultipleServiceDescriptionAddedInNonLinearOrderFind sut.remove(service5); sut.remove(service1); EXPECT_THAT(sut.getServices().size(), Eq(3)); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); EXPECT_THAT(searchResults.size(), Eq(0)); } @@ -319,7 +343,7 @@ TEST_F(ServiceRegistry_test, FindSpecificNonExistingServiceDescriptionFails) ASSERT_FALSE(sut.add(service1).has_error()); ASSERT_FALSE(sut.add(service2).has_error()); ASSERT_FALSE(sut.add(service3).has_error()); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("g")); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("g"), iox::capro::IdString_t("f")); EXPECT_THAT(searchResults.size(), Eq(0)); } @@ -338,7 +362,7 @@ TEST_F(ServiceRegistry_test, AddingMultipleServiceDescriptionWithSameServicesAnd sut.remove(service2); EXPECT_THAT(sut.getServices().size(), Eq(2)); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("c")); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::IdString_t("c"), iox::capro::IdString_t("c")); EXPECT_THAT(searchResults.size(), Eq(0)); } @@ -356,7 +380,7 @@ TEST_F(ServiceRegistry_test, ServiceNotFoundAfterAddingAndRemovingToServiceRegis sut.remove(service2); EXPECT_THAT(sut.getServices().size(), Eq(2)); - sut.find(searchResults, iox::capro::IdString_t("b"), iox::capro::IdString_t("c")); + sut.find(searchResults, iox::capro::IdString_t("b"), iox::capro::IdString_t("c"), iox::capro::IdString_t("c")); EXPECT_THAT(searchResults.size(), Eq(0)); } @@ -375,7 +399,7 @@ TEST_F(ServiceRegistry_test, AddingMultipleServiceDescriptionAndRemovingAllDoesN sut.remove(service2); sut.remove(service3); - sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard); + sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); EXPECT_THAT(searchResults.size(), Eq(0)); }