Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application properties to participants [19865] #408

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ddsrouter_core/src/cpp/core/ParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ generic_create_participant(
const std::shared_ptr<ddspipe::participants::ParticipantConfiguration>& participant_configuration,
Args... args)
{
participant_configuration->app_id = "DDS_ROUTER";
participant_configuration->app_metadata = "";

std::shared_ptr<ConfigurationT> conf_ =
std::dynamic_pointer_cast<ConfigurationT>(
participant_configuration);
Expand Down
1 change: 1 addition & 0 deletions ddsrouter_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ add_subdirectory(labels)

# Add subdirectory with tests
add_subdirectory(blackbox)
add_subdirectory(unittest)
4 changes: 4 additions & 0 deletions ddsrouter_core/test/labels/XTSAN.list
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ ImplementationsTest.pair_implementation
ImplementationsTest.pair_implementation_with_topic
ImplementationsTest.all_implementations
ImplementationsTest.duplicated_ids_negative
ParticipantFactoryTest.create_simple_participant
ParticipantFactoryTest.create_discovery_server_participant
ParticipantFactoryTest.create_initial_peers_participant
ParticipantFactoryTest.create_xml_participant
47 changes: 47 additions & 0 deletions ddsrouter_core/test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 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.

############################
# Participant Factory Test #
############################

set(TEST_NAME ParticipantFactoryTest)

set(TEST_SOURCES
ParticipantFactoryTest.cpp
${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantFactory.cpp
)

set(TEST_LIST
create_echo_participant
create_simple_participant
create_discovery_server_participant
create_initial_peers_participant
create_xml_participant
)

set(TEST_EXTRA_LIBRARIES
fastcdr
fastrtps
cpp_utils
ddspipe_core
ddspipe_participants
)

add_unittest_executable(
"${TEST_NAME}"
"${TEST_SOURCES}"
"${TEST_LIST}"
"${TEST_EXTRA_LIBRARIES}"
)
252 changes: 252 additions & 0 deletions ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
// Copyright 2023 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.

/**
* @file ParticipantFactoryTest.cpp
*
*/

#include <cpp_utils/testing/gtest_aux.hpp>
#include <gtest/gtest.h>

#include <ddspipe_core/dynamic/DiscoveryDatabase.hpp>
#include <ddspipe_core/efficiency/payload/PayloadPool.hpp>
#include <ddspipe_core/efficiency/payload/FastPayloadPool.hpp>

#include <ddspipe_participants/configuration/EchoParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/XmlParticipantConfiguration.hpp>

#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_participants/participant/auxiliar/EchoParticipant.hpp>
#include <ddspipe_participants/participant/rtps/SimpleParticipant.hpp>
#include <ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp>
#include <ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp>
#include <ddspipe_participants/participant/dds/XmlParticipant.hpp>

#include <ddspipe_participants/testing/random_values.hpp>

#include <ddsrouter_core/core/ParticipantFactory.hpp>

using namespace eprosima;
using namespace eprosima::ddsrouter::core;

/**
* This class is a subclass of ddspipe::participants::EchoParticipant.
* It provides public access to the protected member 'configuration_' from its base class
* ddspipe::participants::EchoParticipant.
*/
class EchoTestClass : public ddspipe::participants::EchoParticipant
{
public:

using ddspipe::participants::EchoParticipant::configuration_; // Make protected member accessible
};

/**
* This class is a subclass of ddspipe::participants::SimpleParticipant.
* It provides public access to the protected member 'configuration_' from its base class
* ddspipe::participants::SimpleParticipant.
*/
class SimpleTestClass : public ddspipe::participants::rtps::SimpleParticipant
{
public:

using ddspipe::participants::rtps::SimpleParticipant::configuration_; // Make protected member accessible
};

/**
* This class is a subclass of ddspipe::participants::DiscoveryServerParticipant.
* It provides public access to the protected member 'configuration_' from its base class
* ddspipe::participants::DiscoveryServerParticipant.
*/
class DiscoveryServerTestClass : public ddspipe::participants::rtps::DiscoveryServerParticipant
{
public:

using ddspipe::participants::rtps::DiscoveryServerParticipant::configuration_; // Make protected member accessible
};

/**
* This class is a subclass of ddspipe::participants::InitialPeersParticipant.
* It provides public access to the protected member 'configuration_' from its base class
* ddspipe::participants::InitialPeersParticipant.
*/
class InitialPeersTestClass : public ddspipe::participants::rtps::InitialPeersParticipant
{
public:

using ddspipe::participants::rtps::InitialPeersParticipant::configuration_; // Make protected member accessible
};

/**
* This class is a subclass of ddspipe::participants::XmlParticipant.
* It provides public access to the protected member 'configuration_' from its base class
* ddspipe::participants::XmlParticipant.
*/
class XMLTestClass : public ddspipe::participants::dds::XmlParticipant
{
public:

using ddspipe::participants::dds::XmlParticipant::configuration_; // Make protected member accessible
};

/**
* This test case is for the ParticipantFactory class, specifically testing the creation
* of an EchoParticipant. The test checks whether the created EchoParticipant has the
* expected configuration values.
*/
TEST(ParticipantFactoryTest, create_echo_participant)
{
{
ParticipantFactory participant_factory;

auto configuration = std::make_shared<ddspipe::participants::EchoParticipantConfiguration>();
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool(new ddspipe::core::FastPayloadPool());
std::shared_ptr<ddspipe::core::DiscoveryDatabase> discovery_database(new ddspipe::core::DiscoveryDatabase());

std::shared_ptr<eprosima::ddspipe::core::IParticipant> i_participant = participant_factory.create_participant(
types::ParticipantKind::echo, configuration, payload_pool, discovery_database);

ASSERT_TRUE(i_participant) << "Failed to create I Participant";

std::shared_ptr<EchoTestClass> echo_participant =
std::static_pointer_cast<EchoTestClass>(i_participant);

ASSERT_TRUE(echo_participant) << "Failed to create Echo Participant";

ASSERT_EQ(echo_participant->configuration_->app_id, "DDS_ROUTER");
ASSERT_EQ(echo_participant->configuration_->app_metadata, "");
}
}

/**
* This test case is for the ParticipantFactory class, specifically testing the creation
* of an SimpleParticipant. The test checks whether the created SimpleParticipant has the
* expected configuration values.
*/
TEST(ParticipantFactoryTest, create_simple_participant)
{
{
ParticipantFactory participant_factory;

auto configuration = std::make_shared<ddspipe::participants::SimpleParticipantConfiguration>();
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool(new ddspipe::core::FastPayloadPool());
std::shared_ptr<ddspipe::core::DiscoveryDatabase> discovery_database(new ddspipe::core::DiscoveryDatabase());

std::shared_ptr<eprosima::ddspipe::core::IParticipant> i_participant = participant_factory.create_participant(
types::ParticipantKind::simple, configuration, payload_pool, discovery_database);

std::shared_ptr<SimpleTestClass> simple_participant =
std::static_pointer_cast<SimpleTestClass>(i_participant);

ASSERT_TRUE(simple_participant) << "Failed to create Simple Participant";

ASSERT_EQ(simple_participant->configuration_->app_id, "DDS_ROUTER");
ASSERT_EQ(simple_participant->configuration_->app_metadata, "");
}
}

/**
* This test case is for the ParticipantFactory class, specifically testing the creation
* of an DiscoveryServerParticipant. The test checks whether the created DiscoveryServerParticipant has the
* expected configuration values.
*/
TEST(ParticipantFactoryTest, create_discovery_server_participant)
{
{
ParticipantFactory participant_factory;

auto configuration = std::make_shared<ddspipe::participants::DiscoveryServerParticipantConfiguration>();
configuration->listening_addresses.insert(ddspipe::participants::testing::random_address());
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool(new ddspipe::core::FastPayloadPool());
std::shared_ptr<ddspipe::core::DiscoveryDatabase> discovery_database(new ddspipe::core::DiscoveryDatabase());

std::shared_ptr<eprosima::ddspipe::core::IParticipant> i_participant = participant_factory.create_participant(
types::ParticipantKind::discovery_server, configuration, payload_pool, discovery_database);

std::shared_ptr<DiscoveryServerTestClass> discovery_server_participant =
std::static_pointer_cast<DiscoveryServerTestClass>(i_participant);

ASSERT_TRUE(discovery_server_participant) << "Failed to create Discovery Server Participant";

ASSERT_EQ(discovery_server_participant->configuration_->app_id, "DDS_ROUTER");
ASSERT_EQ(discovery_server_participant->configuration_->app_metadata, "");
}
}

/**
* This test case is for the ParticipantFactory class, specifically testing the creation
* of an InitialPeersParticipant. The test checks whether the created InitialPeersParticipant has the
* expected configuration values.
*/
TEST(ParticipantFactoryTest, create_initial_peers_participant)
{
{
ParticipantFactory participant_factory;

auto configuration = std::make_shared<ddspipe::participants::InitialPeersParticipantConfiguration>();
configuration->listening_addresses.insert(ddspipe::participants::testing::random_address());
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool(new ddspipe::core::FastPayloadPool());
std::shared_ptr<ddspipe::core::DiscoveryDatabase> discovery_database(new ddspipe::core::DiscoveryDatabase());

std::shared_ptr<eprosima::ddspipe::core::IParticipant> i_participant = participant_factory.create_participant(
types::ParticipantKind::initial_peers, configuration, payload_pool, discovery_database);

std::shared_ptr<InitialPeersTestClass> initial_peers_participant =
std::static_pointer_cast<InitialPeersTestClass>(i_participant);

ASSERT_TRUE(initial_peers_participant) << "Failed to create Initial Peers Participant";

ASSERT_EQ(initial_peers_participant->configuration_->app_id, "DDS_ROUTER");
ASSERT_EQ(initial_peers_participant->configuration_->app_metadata, "");
}
}

/**
* This test case is for the ParticipantFactory class, specifically testing the creation
* of an XmlParticipant. The test checks whether the created XmlParticipant has the
* expected configuration values.
*/
TEST(ParticipantFactoryTest, create_xml_participant)
{
{
ParticipantFactory participant_factory;

auto configuration = std::make_shared<ddspipe::participants::XmlParticipantConfiguration>();
std::shared_ptr<ddspipe::core::PayloadPool> payload_pool(new ddspipe::core::FastPayloadPool());
std::shared_ptr<ddspipe::core::DiscoveryDatabase> discovery_database(new ddspipe::core::DiscoveryDatabase());

std::shared_ptr<eprosima::ddspipe::core::IParticipant> i_participant = participant_factory.create_participant(
types::ParticipantKind::xml, configuration, payload_pool, discovery_database);

std::shared_ptr<XMLTestClass> xml_participant =
std::static_pointer_cast<XMLTestClass>(i_participant);

ASSERT_TRUE(xml_participant) << "Failed to create XML Participant";

ASSERT_EQ(xml_participant->configuration_->app_id, "DDS_ROUTER");
ASSERT_EQ(xml_participant->configuration_->app_metadata, "");
}
}

int main(
int argc,
char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions docs/rst/notes/forthcoming_version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The next release will include the following **Features**:
* :ref:`Downsampling <user_manual_configuration_downsampling>`.
* :ref:`Discovery Trigger <user_manual_configuration_discovery_trigger>`.
* Rename the `max-depth` under the `specs` tag to `history-depth`.
* Set `app_id` and `app_metadata` attributes in *eProsima DDS Router* participants.

The next release will include the following **Bugfixes**:

Expand Down