From 45a02347625d48d7dd10dbc76706a2d1742a73cf Mon Sep 17 00:00:00 2001 From: juanlofer-eprosima <88179026+juanlofer-eprosima@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:57:17 +0200 Subject: [PATCH] Remove DiscoveryServerConnectionAdress (#131) Signed-off-by: Juan Lopez Fernandez --- ...iscoveryServerParticipantConfiguration.hpp | 3 +- .../InitialPeersParticipantConfiguration.hpp | 1 - .../testing/random_values.hpp | 6 - .../DiscoveryServerConnectionAddress.hpp | 84 -------------- ...iscoveryServerParticipantConfiguration.cpp | 3 +- .../rtps/DiscoveryServerParticipant.cpp | 83 ++++++------- .../src/cpp/testing/random_values.cpp | 16 --- .../DiscoveryServerConnectionAddress.cpp | 74 ------------ .../include/ddspipe_yaml/YamlReader.hpp | 1 + .../ddspipe_yaml/testing/generate_yaml.hpp | 1 - .../ddspipe_yaml/yaml_configuration_tags.hpp | 1 - ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 1 - .../src/cpp/YamlReader_participants.cpp | 3 +- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 39 ------- .../unittest/entities/address/CMakeLists.txt | 33 ------ ...amlGetEntityDiscoveryServerAddressTest.cpp | 30 ----- ...coveryServerAddressTest_get_ds_address.ipp | 109 ------------------ ...verAddressTest_get_ds_address_negative.ipp | 94 --------------- 18 files changed, 39 insertions(+), 543 deletions(-) delete mode 100644 ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp delete mode 100644 ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp delete mode 100644 ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp index 14ecf1d7..f07a8a80 100644 --- a/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -56,7 +55,7 @@ struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigu std::set listening_addresses {}; - std::set connection_addresses {}; + std::set connection_addresses {}; types::TlsConfiguration tls_configuration {}; }; diff --git a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp index a62d352f..99178d89 100644 --- a/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp +++ b/ddspipe_participants/include/ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp index ff32ffdd..7d8c29bf 100644 --- a/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp +++ b/ddspipe_participants/include/ddspipe_participants/testing/random_values.hpp @@ -16,7 +16,6 @@ #include #include -#include namespace eprosima { namespace ddspipe { @@ -27,11 +26,6 @@ DDSPIPE_PARTICIPANTS_DllAPI types::Address random_address( unsigned int seed = 0); -DDSPIPE_PARTICIPANTS_DllAPI -types::DiscoveryServerConnectionAddress random_connection_address( - unsigned int seed = 0, - unsigned int size = 1); - } /* namespace testing */ } /* namespace participants */ } /* namespace ddspipe */ diff --git a/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp b/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp deleted file mode 100644 index 0391acf0..00000000 --- a/ddspipe_participants/include/ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed 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, -// See the License for the specific language governing permissions and -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// limitations under the License. - -#pragma once - -#include -#include - -#include -#include - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -/** - * @brief Collection of Addresses to connect with a remote Disovery Server. - * - * An address will remain in an IP and a Port, IP version and Transport Protocol. - * This class has several address in order to connect with a remote Discovery Server. - */ -class DiscoveryServerConnectionAddress -{ -public: - - /** - * @brief Construct a new \c DiscoveryServerConnectionAddress object with all the parameters - * - * @param addresses_ collection of addresses - */ - DDSPIPE_PARTICIPANTS_DllAPI - DiscoveryServerConnectionAddress( - std::set
addresses); - - //! Addresses getter - DDSPIPE_PARTICIPANTS_DllAPI - std::set
addresses() const noexcept; - - /** - * @brief Whether the address is correct - * - * Checks if it has at least one correct address. - */ - DDSPIPE_PARTICIPANTS_DllAPI - virtual bool is_valid() const noexcept; - - //! Minor operator - DDSPIPE_PARTICIPANTS_DllAPI - bool operator <( - const DiscoveryServerConnectionAddress& other) const noexcept; - - //! Equal operator - DDSPIPE_PARTICIPANTS_DllAPI - bool operator ==( - const DiscoveryServerConnectionAddress& other) const noexcept; - -protected: - - //! Internal Addresses object - std::set
addresses_; -}; - -//! \c DiscoveryServerConnectionAddress to stream serializator -DDSPIPE_PARTICIPANTS_DllAPI -std::ostream& operator <<( - std::ostream& output, - const DiscoveryServerConnectionAddress& address); - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp b/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp index 65308bf2..3d503adb 100644 --- a/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp +++ b/ddspipe_participants/src/cpp/configuration/DiscoveryServerParticipantConfiguration.cpp @@ -18,7 +18,6 @@ #include #include #include -#include namespace eprosima { namespace ddspipe { @@ -44,7 +43,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check connection addresses - for (types::DiscoveryServerConnectionAddress address : connection_addresses) + for (types::Address address : connection_addresses) { if (!address.is_valid()) { diff --git a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp index 24ee2f96..fba2ad17 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp @@ -208,10 +208,10 @@ DiscoveryServerParticipant::reckon_participant_attributes_() const ///// // Set connection addresses - for (types::DiscoveryServerConnectionAddress connection_address : + for (types::Address address : discovery_server_configuration->connection_addresses) { - if (!connection_address.is_valid()) + if (!address.is_valid()) { // Invalid connection address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, @@ -220,59 +220,46 @@ DiscoveryServerParticipant::reckon_participant_attributes_() const continue; } - for (types::Address address : connection_address.addresses()) - { - if (!address.is_valid()) - { - // Invalid ip address, continue with next one - EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Discard connection address with remote server due to invalid ip address " << - address.ip() << " in Participant " << discovery_server_configuration->id << - " initialization."); - continue; - } - - has_connection_addresses = true; + has_connection_addresses = true; - eprosima::fastdds::rtps::Locator_t locator; + eprosima::fastdds::rtps::Locator_t locator; - // KIND - locator.kind = address.get_locator_kind(); + // KIND + locator.kind = address.get_locator_kind(); - // In case it is TCP mark has_connection_tcp as true - if (address.is_tcp()) - { - has_connection_tcp_ipv4 = address.is_ipv4(); - has_connection_tcp_ipv6 = !address.is_ipv4(); - } - else - { - has_udp_ipv4 = address.is_ipv4(); - has_udp_ipv6 = !address.is_ipv4(); - } + // In case it is TCP mark has_connection_tcp as true + if (address.is_tcp()) + { + has_connection_tcp_ipv4 = address.is_ipv4(); + has_connection_tcp_ipv6 = !address.is_ipv4(); + } + else + { + has_udp_ipv4 = address.is_ipv4(); + has_udp_ipv6 = !address.is_ipv4(); + } - // IP - if (address.is_ipv4()) - { - eprosima::fastdds::rtps::IPLocator::setIPv4(locator, address.ip()); - } - else - { - eprosima::fastdds::rtps::IPLocator::setIPv6(locator, address.ip()); - } + // IP + if (address.is_ipv4()) + { + eprosima::fastdds::rtps::IPLocator::setIPv4(locator, address.ip()); + } + else + { + eprosima::fastdds::rtps::IPLocator::setIPv6(locator, address.ip()); + } - // PORT - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(locator, address.port()); - eprosima::fastdds::rtps::IPLocator::setLogicalPort(locator, address.port()); - // Warning: Logical port is not needed unless domain could change + // PORT + eprosima::fastdds::rtps::IPLocator::setPhysicalPort(locator, address.port()); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(locator, address.port()); + // Warning: Logical port is not needed unless domain could change - // Add as remote server and add it to builtin - params.builtin.discovery_config.m_DiscoveryServers.push_back(locator); + // Add as remote server and add it to builtin + params.builtin.discovery_config.m_DiscoveryServers.push_back(locator); - logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Add connection address " << address << " to Server Participant " << - discovery_server_configuration->id << "."); - } + logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, + "Add connection address " << address << " to Server Participant " << + discovery_server_configuration->id << "."); } ///// diff --git a/ddspipe_participants/src/cpp/testing/random_values.cpp b/ddspipe_participants/src/cpp/testing/random_values.cpp index 12e4f8c0..866db7a2 100644 --- a/ddspipe_participants/src/cpp/testing/random_values.cpp +++ b/ddspipe_participants/src/cpp/testing/random_values.cpp @@ -29,22 +29,6 @@ Address random_address( return Address("127.0.0.1", 10000 + seed, 10000 + seed, TransportProtocol::udp); } -DiscoveryServerConnectionAddress random_connection_address( - unsigned int seed /* = 0 */, - unsigned int size /* = 1 */) -{ - std::set
addresses; - for (unsigned int i = 0; i < size; ++i) - { - addresses.insert( - random_address((seed + i))); - } - - return DiscoveryServerConnectionAddress( - addresses - ); -} - } /* namespace testing */ } /* namespace participants */ } /* namespace ddspipe */ diff --git a/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp b/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp deleted file mode 100644 index 550ea9e9..00000000 --- a/ddspipe_participants/src/cpp/types/address/DiscoveryServerConnectionAddress.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed 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 - -namespace eprosima { -namespace ddspipe { -namespace participants { -namespace types { - -DiscoveryServerConnectionAddress::DiscoveryServerConnectionAddress( - std::set
addresses) - : addresses_(addresses) -{ -} - -std::set
DiscoveryServerConnectionAddress::addresses() const noexcept -{ - return addresses_; -} - -bool DiscoveryServerConnectionAddress::is_valid() const noexcept -{ - for (auto address : addresses_) - { - if (address.is_valid()) - { - return true; - } - } - - return false; -} - -bool DiscoveryServerConnectionAddress::operator <( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - return this->addresses() < other.addresses(); -} - -bool DiscoveryServerConnectionAddress::operator ==( - const DiscoveryServerConnectionAddress& other) const noexcept -{ - return (this->addresses() == other.addresses()); -} - -std::ostream& operator <<( - std::ostream& output, - const DiscoveryServerConnectionAddress& address) -{ - output << "{["; - for (auto a : address.addresses()) - { - output << a << ","; - } - output << "]}"; - return output; -} - -} /* namespace types */ -} /* namespace participants */ -} /* namespace ddspipe */ -} /* namespace eprosima */ diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp index 467b1fe0..a1c65dec 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp @@ -108,6 +108,7 @@ enum YamlReaderVersion * * - Make discovery server's guid prefix optional. * - Remove server's guid prefix from discovery server clients' connection addresses. + * - Remove 'addresses' tag from discovery server clients' connection addresses (now it's just a list of addresses). */ V_5_0, diff --git a/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp b/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp index fb68838d..2794807e 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/testing/generate_yaml.hpp @@ -24,7 +24,6 @@ #include #include -#include #include #include diff --git a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp index cd84c6f0..7332d381 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/yaml_configuration_tags.hpp @@ -101,7 +101,6 @@ constexpr const char* DOMAIN_ID_TAG("domain"); //! Domain Id of the participant constexpr const char* DISCOVERY_SERVER_GUID_PREFIX_TAG("discovery-server-guid"); //! TODO: add comment constexpr const char* LISTENING_ADDRESSES_TAG("listening-addresses"); //! TODO: add comment constexpr const char* CONNECTION_ADDRESSES_TAG("connection-addresses"); //! TODO: add comment -constexpr const char* COLLECTION_ADDRESSES_TAG("addresses"); //! TODO: add comment // TLS related tags constexpr const char* TLS_TAG("tls"); //! TLS configuration tag diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index dbdbc1fb..eabc3d4b 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index 8cce876b..6c52ed31 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -208,7 +207,7 @@ void YamlReader::fill( // Optional connection addresses if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) { - object.connection_addresses = YamlReader::get_set( + object.connection_addresses = YamlReader::get_set
( yml, CONNECTION_ADDRESSES_TAG, version); diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index cbadb8ef..1d54c607 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -303,44 +302,6 @@ Address YamlReader::get
( } } -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(addresses); -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( - const Yaml& yml, - const YamlReaderVersion version) -{ - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(addresses); -} - -template <> -DDSPIPE_YAML_DllAPI -DiscoveryServerConnectionAddress YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - switch (version) - { - case V_1_0: - return _get_discovery_server_connection_address_v1(yml, version); - - default: - return _get_discovery_server_connection_address_latest(yml, version); - } -} - template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( diff --git a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt index 9983c0c1..30f991d6 100644 --- a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt @@ -50,36 +50,3 @@ add_unittest_executable( "${TEST_SOURCES}" "${TEST_LIST}" "${TEST_EXTRA_LIBRARIES}") - -################################################ -# Yaml GetEntities DiscoveryServerAddress Test # -################################################ - -set(TEST_NAME YamlGetEntityDiscoveryServerAddressTest) - -set(TEST_SOURCES - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp - YamlGetEntityDiscoveryServerAddressTest.cpp - ) - -set(TEST_LIST - get_ds_address - get_ds_address_negative - ) - -set(TEST_EXTRA_LIBRARIES - yaml-cpp - fastcdr - fastdds - cpp_utils - ddspipe_core - ddspipe_participants - ) - -add_unittest_executable( - "${TEST_NAME}" - "${TEST_SOURCES}" - "${TEST_LIST}" - "${TEST_EXTRA_LIBRARIES}") diff --git a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp b/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp deleted file mode 100644 index 0b1c3ac1..00000000 --- a/ddspipe_yaml/test/unittest/entities/address/YamlGetEntityDiscoveryServerAddressTest.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed 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 -#include - -// In order to not create an enormous terrible file, each unit test has been implemented in different and independent -// files in folder "test_units", and all these files are included only from here, so they are compilated and tested. - -#include "test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp" -#include "test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp" - -int main( - int argc, - char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp deleted file mode 100644 index 1eaec143..00000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address.ipp +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed 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 -#include -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::participants::testing; -using namespace eprosima::ddspipe::yaml::testing; - -const constexpr unsigned int TEST_ADDRESSES_NUMBER = 5; - -/** - * Test read a discovery server - * - * POSITIVE CASES: - * - one address - * - several addresses - */ -TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address) -{ - // one address - { - Yaml yml_ds_address; - - // Get random address and add it to yaml - participants::types::Address address = random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - - yml_addresses.push_back(yml_address); - - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Generate overall yaml - Yaml yml; - yml["ds-address"] = yml_ds_address; - - // Create object DiscoveryServerAddress from yaml - participants::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); - - // Check result - ASSERT_EQ(result.addresses().size(), 1u); - ASSERT_EQ(address, *result.addresses().begin()); - } - - // several addresses - { - Yaml yml_ds_address; - - // Get random address and add it to yaml - Yaml yml_addresses; - std::vector addresses; - for (unsigned int i = 0; i < TEST_ADDRESSES_NUMBER; i++) - { - // Create new address and add it to already created addresses and to yaml - Yaml yml_address; - participants::types::Address address = random_address(i); - - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - - addresses.push_back(address); - yml_addresses.push_back(yml_address); - } - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Generate overall yaml - Yaml yml; - yml["ds-address"] = yml_ds_address; - - // Create object DiscoveryServerAddress from yaml - participants::types::DiscoveryServerConnectionAddress result = - YamlReader::get(yml, "ds-address", LATEST); - - // Check result - ASSERT_EQ(result.addresses().size(), TEST_ADDRESSES_NUMBER); - - // Check every address introduced in yaml is in result - for (participants::types::Address address : addresses) - { - // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses = result.addresses(); - ASSERT_NE(addresses.find(address), addresses.end()); - } - } -} diff --git a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp b/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp deleted file mode 100644 index b0da4e83..00000000 --- a/ddspipe_yaml/test/unittest/entities/address/test_units/YamlGetEntityDiscoveryServerAddressTest_get_ds_address_negative.ipp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed 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 -#include - -#include -#include -#include - -#include - -using namespace eprosima; -using namespace eprosima::ddspipe; -using namespace eprosima::ddspipe::yaml; -using namespace eprosima::ddspipe::core::testing; -using namespace eprosima::ddspipe::yaml::testing; - -/** - * Test read a discovery server connection address that fails - * - * NEGATIVE CASES: - * - empty - * - no guid prefix - * - no addresses - * - error format in guid prefix - * - error format in addresses - */ -TEST(YamlGetEntityDiscoveryServerAddressTest, get_ds_address_negative) -{ - // empty - { - Yaml yml_empty; - Yaml yml; - yml["connection-address"] = yml_empty; - - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // no addresses - { - Yaml yml_ds_address; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } - - // error format in addresses - { - Yaml yml_ds_address; - - // Address error (in map instead of sequence) - participants::types::Address address = eprosima::ddspipe::participants::testing::random_address(); - Yaml yml_addresses; - Yaml yml_address; - ddspipe::yaml::testing::address_to_yaml(yml_address, address); - yml_addresses["address1"] = yml_address; - yml_ds_address[COLLECTION_ADDRESSES_TAG] = yml_addresses; - - // Get random guid prefix and add it to yaml - core::types::GuidPrefix guid_prefix = eprosima::ddspipe::core::testing::random_guid_prefix(); - Yaml yml_guid; - guid_prefix_to_yaml(yml_guid, guid_prefix); - yml_ds_address[DISCOVERY_SERVER_GUID_PREFIX_TAG] = yml_guid; - - Yaml yml; - yml["connection-address"] = yml_ds_address; - ASSERT_THROW( - YamlReader::get(yml, "connection-address", LATEST), - eprosima::utils::ConfigurationException); - } -}