Skip to content

Commit

Permalink
iox-#415 Add logic for event search
Browse files Browse the repository at this point in the history
Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
  • Loading branch information
FerdinandSpitzschnueffler committed Feb 3, 2022
1 parent 2c50495 commit ad69dcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ServiceRegistry
/// @todo #859 replace std::multimap with prefix tree
::std::multimap<capro::IdString_t, uint64_t> m_serviceMap;
::std::multimap<capro::IdString_t, uint64_t> m_instanceMap;
::std::multimap<capro::IdString_t, uint64_t> m_eventMap;
ServiceDescriptionVector_t m_serviceDescriptionVector;
};
} // namespace roudi
Expand Down
32 changes: 24 additions & 8 deletions iceoryx_posh/source/roudi/service_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cxx::expected<ServiceRegistry::Error> 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<>();
}

Expand Down Expand Up @@ -96,21 +97,21 @@ void ServiceRegistry::remove(const capro::ServiceDescription& serviceDescription
{
removeIndexFromMap(m_serviceMap, index);
removeIndexFromMap(m_instanceMap, index);
removeIndexFromMap(m_eventMap, index);
}
}

/// @todo #415 add logic for event search once the prefix tree is integrated into the service registry
void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult,
const cxx::optional<capro::IdString_t>& service,
const cxx::optional<capro::IdString_t>& instance,
const cxx::optional<capro::IdString_t>& /*event*/) const noexcept
const cxx::optional<capro::IdString_t>& event) const noexcept
{
cxx::vector<uint64_t, MAX_SERVICE_DESCRIPTIONS> intersection;

ServiceDescriptionVector_t serviceInstanceResult;
// Find (K1, K2)
// O(log n + log n + max(#PossibleServices + #possiblesInstances) + #intersection)
if (instance && service)
{
cxx::vector<uint64_t, MAX_SERVICE_DESCRIPTIONS> intersection;
cxx::vector<uint64_t, MAX_SERVICE_DESCRIPTIONS> possibleServices;
cxx::vector<uint64_t, MAX_SERVICE_DESCRIPTIONS> possibleInstances;

Expand All @@ -134,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)
Expand All @@ -144,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, *)
Expand All @@ -154,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;
}
}

Expand Down
15 changes: 5 additions & 10 deletions iceoryx_posh/test/integrationtests/test_service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ TEST_F(ServiceDiscovery_test, OfferDifferentServicesWithSameInstanceAndEvent)
EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3));
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceDiscovery_test, DISABLED_FindServiceDoesNotReturnServiceWhenStringsDoNotMatch)
TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnServiceWhenStringsDoNotMatch)
{
::testing::Test::RecordProperty("TEST_ID", "1984e907-e990-48b2-8cbd-eab3f67cd162");
const iox::capro::ServiceDescription SERVICE_DESCRIPTION1("service1", "instance1", "event1");
Expand Down Expand Up @@ -237,8 +236,7 @@ TEST_F(ServiceDiscovery_test, FindServiceWithInstanceAndEventWildcardReturnsAllM
EXPECT_TRUE(serviceContainer.value() == serviceContainerExp);
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceDiscovery_test, DISABLED_FindServiceWithServiceWildcardReturnsCorrectServices)
TEST_F(ServiceDiscovery_test, FindServiceWithServiceWildcardReturnsCorrectServices)
{
::testing::Test::RecordProperty("TEST_ID", "f4731a52-39d8-4d49-b247-008a2e9181f9");
const IdString_t INSTANCE = "instance";
Expand Down Expand Up @@ -286,8 +284,7 @@ TEST_F(ServiceDiscovery_test, FindServiceWithEventWildcardReturnsCorrectServices
EXPECT_TRUE(serviceContainer.value() == serviceContainerExp);
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceDiscovery_test, DISABLED_FindServiceWithInstanceWildcardReturnsCorrectServices)
TEST_F(ServiceDiscovery_test, FindServiceWithInstanceWildcardReturnsCorrectServices)
{
::testing::Test::RecordProperty("TEST_ID", "2ec4b422-3ded-4af3-9e72-3b870c55031c");
const IdString_t SERVICE = "service";
Expand Down Expand Up @@ -342,8 +339,7 @@ TEST_F(ServiceDiscovery_test, OfferSingleServiceMultiInstance)
EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3));
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceDiscovery_test, DISABLED_FindServiceReturnsCorrectServiceInstanceCombinations)
TEST_F(ServiceDiscovery_test, FindServiceReturnsCorrectServiceInstanceCombinations)
{
::testing::Test::RecordProperty("TEST_ID", "360839a7-9309-4e7e-8e89-892097a87f7a");

Expand Down Expand Up @@ -423,8 +419,7 @@ TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnNotOfferedServices)
EXPECT_THAT(serviceContainer.value().size(), Eq(0U));
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceDiscovery_test, DISABLED_NonExistingServicesAreNotFound)
TEST_F(ServiceDiscovery_test, NonExistingServicesAreNotFound)
{
::testing::Test::RecordProperty("TEST_ID", "86b87264-4df4-4d20-9357-06391ca1d57f");
const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event");
Expand Down
15 changes: 7 additions & 8 deletions iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,15 @@ TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithWildcardSearc
EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Foo", "Bar", "Baz")));
}

/// @todo #415 enable once the prefix tree is integrated into the service registry
TEST_F(ServiceRegistry_test, DISABLED_SingleServiceDescriptionCanBeFoundWithEventName)
TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithEventName)
{
::testing::Test::RecordProperty("TEST_ID", "6df8fd7d-e4d1-4c51-8ad7-2fbe82e4ed09");
iox::capro::ServiceDescription service1("a", "b", "c");
ASSERT_FALSE(sut.add(service1).has_error());
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"));

EXPECT_THAT(searchResults.size(), Eq(1));
EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1));
EXPECT_THAT(searchResults[0].serviceDescription, Eq(service));
}

TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithInstanceName)
Expand All @@ -209,12 +208,12 @@ TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithInstanceName)
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());
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));
EXPECT_THAT(searchResults[0].serviceDescription, Eq(service));
}

TEST_F(ServiceRegistry_test, EmptyAndNotEmptyServiceDescriptionsCanAllBeFoundWithWildcardSearch)
Expand Down

0 comments on commit ad69dcf

Please sign in to comment.