Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2128 Add segmentName to publisher/client/server o…
Browse files Browse the repository at this point in the history
…ptions
  • Loading branch information
Graham Palmer committed Jan 12, 2024
1 parent 84481de commit 47a49c3
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 17 deletions.
4 changes: 4 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/popo/client_options.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -41,6 +42,9 @@ struct ClientOptions
/// @brief The option whether the client shall try to connect when creating it
bool connectOnCreate{true};

/// @brief The name of the shared memory segment in which to create requests.
iox::ShmName_t requestSegmentName{""};

/// @brief The option whether the server should block when the response queue is full
/// @note Corresponds with ServerOptions::clientTooSlowPolicy
QueueFullPolicy responseQueueFullPolicy{QueueFullPolicy::DISCARD_OLDEST_DATA};
Expand Down
4 changes: 4 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/popo/publisher_options.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -41,6 +42,9 @@ struct PublisherOptions
/// @brief The option whether the publisher should already be offered when creating it
bool offerOnCreate{true};

/// @brief The name of the shared memory segment in which to publish messages.
iox::ShmName_t segmentName{""};

/// @brief The option whether the publisher should block when the subscriber queue is full
ConsumerTooSlowPolicy subscriberTooSlowPolicy{ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};

Expand Down
4 changes: 4 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/popo/server_options.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -41,6 +42,9 @@ struct ServerOptions
/// @brief The option whether the server should already be offered when creating it
bool offerOnCreate{true};

/// @brief The name of the shared memory segment in which to create responses.
iox::ShmName_t responseSegmentName{""};

/// @brief The option whether the client should block when the request queue is full
/// @note Corresponds with ClientOptions::serverTooSlowPolicy
QueueFullPolicy requestQueueFullPolicy{QueueFullPolicy::DISCARD_OLDEST_DATA};
Expand Down
6 changes: 5 additions & 1 deletion iceoryx_posh/source/popo/client_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -26,6 +27,7 @@ Serialization ClientOptions::serialize() const noexcept
return Serialization::create(responseQueueCapacity,
nodeName,
connectOnCreate,
requestSegmentName,
static_cast<std::underlying_type_t<QueueFullPolicy>>(responseQueueFullPolicy),
static_cast<std::underlying_type_t<ConsumerTooSlowPolicy>>(serverTooSlowPolicy));
}
Expand All @@ -42,6 +44,7 @@ expected<ClientOptions, Serialization::Error> ClientOptions::deserialize(const S
auto deserializationSuccessful = serialized.extract(clientOptions.responseQueueCapacity,
clientOptions.nodeName,
clientOptions.connectOnCreate,
clientOptions.requestSegmentName,
responseQueueFullPolicy,
serverTooSlowPolicy);

Expand All @@ -60,7 +63,8 @@ expected<ClientOptions, Serialization::Error> ClientOptions::deserialize(const S
bool ClientOptions::operator==(const ClientOptions& rhs) const noexcept
{
return responseQueueCapacity == rhs.responseQueueCapacity && nodeName == rhs.nodeName
&& connectOnCreate == rhs.connectOnCreate && responseQueueFullPolicy == rhs.responseQueueFullPolicy
&& connectOnCreate == rhs.connectOnCreate && requestSegmentName == rhs.requestSegmentName
&& responseQueueFullPolicy == rhs.responseQueueFullPolicy
&& serverTooSlowPolicy == rhs.serverTooSlowPolicy;
}
} // namespace popo
Expand Down
3 changes: 3 additions & 0 deletions iceoryx_posh/source/popo/publisher_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -26,6 +27,7 @@ Serialization PublisherOptions::serialize() const noexcept
return Serialization::create(historyCapacity,
nodeName,
offerOnCreate,
segmentName,
static_cast<std::underlying_type_t<ConsumerTooSlowPolicy>>(subscriberTooSlowPolicy));
}

Expand All @@ -39,6 +41,7 @@ expected<PublisherOptions, Serialization::Error> PublisherOptions::deserialize(c
auto deserializationSuccessful = serialized.extract(publisherOptions.historyCapacity,
publisherOptions.nodeName,
publisherOptions.offerOnCreate,
publisherOptions.segmentName,
subscriberTooSlowPolicy);

if (!deserializationSuccessful
Expand Down
6 changes: 5 additions & 1 deletion iceoryx_posh/source/popo/server_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -26,6 +27,7 @@ Serialization ServerOptions::serialize() const noexcept
return Serialization::create(requestQueueCapacity,
nodeName,
offerOnCreate,
responseSegmentName,
static_cast<std::underlying_type_t<QueueFullPolicy>>(requestQueueFullPolicy),
static_cast<std::underlying_type_t<ConsumerTooSlowPolicy>>(clientTooSlowPolicy));
}
Expand All @@ -42,6 +44,7 @@ expected<ServerOptions, Serialization::Error> ServerOptions::deserialize(const S
auto deserializationSuccessful = serialized.extract(serverOptions.requestQueueCapacity,
serverOptions.nodeName,
serverOptions.offerOnCreate,
serverOptions.responseSegmentName,
requestQueueFullPolicy,
clientTooSlowPolicy);

Expand All @@ -61,7 +64,8 @@ expected<ServerOptions, Serialization::Error> ServerOptions::deserialize(const S
bool ServerOptions::operator==(const ServerOptions& rhs) const noexcept
{
return requestQueueCapacity == rhs.requestQueueCapacity && nodeName == rhs.nodeName
&& offerOnCreate == rhs.offerOnCreate && requestQueueFullPolicy == rhs.requestQueueFullPolicy
&& offerOnCreate == rhs.offerOnCreate && responseSegmentName == rhs.responseSegmentName
&& requestQueueFullPolicy == rhs.requestQueueFullPolicy
&& clientTooSlowPolicy == rhs.clientTooSlowPolicy;
}
} // namespace popo
Expand Down
20 changes: 19 additions & 1 deletion iceoryx_posh/test/moduletests/test_popo_client_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -32,6 +33,7 @@ TEST(ClientOptions_test, SerializationRoundTripIsSuccessful)
testOptions.responseQueueCapacity = 42;
testOptions.nodeName = "hypnotoad";
testOptions.connectOnCreate = false;
testOptions.requestSegmentName = "gdpr-noncompliant-data";
testOptions.responseQueueFullPolicy = iox::popo::QueueFullPolicy::BLOCK_PRODUCER;
testOptions.serverTooSlowPolicy = iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER;

Expand All @@ -46,6 +48,9 @@ TEST(ClientOptions_test, SerializationRoundTripIsSuccessful)
EXPECT_THAT(roundTripOptions.connectOnCreate, Ne(defaultOptions.connectOnCreate));
EXPECT_THAT(roundTripOptions.connectOnCreate, Eq(testOptions.connectOnCreate));

EXPECT_THAT(roundTripOptions.requestSegmentName, Ne(defaultOptions.requestSegmentName));
EXPECT_THAT(roundTripOptions.requestSegmentName, Eq(testOptions.requestSegmentName));

EXPECT_THAT(roundTripOptions.responseQueueFullPolicy, Ne(defaultOptions.responseQueueFullPolicy));
EXPECT_THAT(roundTripOptions.responseQueueFullPolicy, Eq(testOptions.responseQueueFullPolicy));

Expand Down Expand Up @@ -81,9 +86,10 @@ iox::Serialization enumSerialization(QueueFullPolicyUT responseQueueFullPolicy,
constexpr uint64_t RESPONSE_QUEUE_CAPACITY{42U};
const iox::NodeName_t NODE_NAME{"harr-harr"};
constexpr bool CONNECT_ON_CREATE{true};
const iox::ShmName_t SEGMENT_NAME{"ho-ho"};

return iox::Serialization::create(
RESPONSE_QUEUE_CAPACITY, NODE_NAME, CONNECT_ON_CREATE, responseQueueFullPolicy, serverTooSlowPolicy);
RESPONSE_QUEUE_CAPACITY, NODE_NAME, CONNECT_ON_CREATE, SEGMENT_NAME, responseQueueFullPolicy, serverTooSlowPolicy);
}

TEST(ClientOptions_test, DeserializingValidResponseQueueFullAndServerTooSlowPolicyIsSuccessful)
Expand Down Expand Up @@ -191,6 +197,18 @@ TEST(ClientOptions_test, ComparisonOperatorReturnsFalseWhenConnectOnCreateDoesNo
EXPECT_FALSE(options2 == options1);
}

TEST(ClientOptions_test, ComparisonOperatorReturnsFalseWhenSegmentNameDoesNotMatch)
{
::testing::Test::RecordProperty("TEST_ID", "f5434f77-2490-4fc1-9ca7-87fdd26379b7");
ClientOptions options1;
options1.requestSegmentName= "🙂";
ClientOptions options2;
options2.requestSegmentName = "🙃";

EXPECT_FALSE(options1 == options2);
EXPECT_FALSE(options2 == options1);
}

TEST(ClientOptions_test, ComparisonOperatorReturnsFalseResponseQueueFullPolicyDoesNotMatch)
{
::testing::Test::RecordProperty("TEST_ID", "9ab2afdd-f75f-4340-8ac0-2288fec030fa");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -31,6 +32,7 @@ TEST(PublisherOptions_test, SerializationRoundTripIsSuccessful)
testOptions.historyCapacity = 42;
testOptions.nodeName = "hypnotoad";
testOptions.offerOnCreate = false;
testOptions.segmentName = "nsa_top_secret_data";
testOptions.subscriberTooSlowPolicy = iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER;

iox::popo::PublisherOptions::deserialize(testOptions.serialize())
Expand All @@ -44,6 +46,9 @@ TEST(PublisherOptions_test, SerializationRoundTripIsSuccessful)
EXPECT_THAT(roundTripOptions.offerOnCreate, Ne(defaultOptions.offerOnCreate));
EXPECT_THAT(roundTripOptions.offerOnCreate, Eq(testOptions.offerOnCreate));

EXPECT_THAT(roundTripOptions.segmentName, Ne(defaultOptions.segmentName));
EXPECT_THAT(roundTripOptions.segmentName, Eq(testOptions.segmentName));

EXPECT_THAT(roundTripOptions.subscriberTooSlowPolicy, Ne(defaultOptions.subscriberTooSlowPolicy));
EXPECT_THAT(roundTripOptions.subscriberTooSlowPolicy, Eq(testOptions.subscriberTooSlowPolicy));
})
Expand All @@ -65,10 +70,11 @@ TEST(PublisherOptions_test, DeserializingInvalidSubscriberTooSlowPolicyFails)
constexpr uint64_t HISTORY_CAPACITY{42U};
const iox::NodeName_t NODE_NAME{"harr-harr"};
constexpr bool OFFER_ON_CREATE{true};
const iox::ShmName_t SEGMENT_NAME{"ho-ho"};
constexpr std::underlying_type_t<iox::popo::ConsumerTooSlowPolicy> SUBSCRIBER_TOO_SLOW_POLICY{111};

const auto serialized =
iox::Serialization::create(HISTORY_CAPACITY, NODE_NAME, OFFER_ON_CREATE, SUBSCRIBER_TOO_SLOW_POLICY);
iox::Serialization::create(HISTORY_CAPACITY, NODE_NAME, OFFER_ON_CREATE, SEGMENT_NAME, SUBSCRIBER_TOO_SLOW_POLICY);
iox::popo::PublisherOptions::deserialize(serialized)
.and_then([&](auto&) { GTEST_FAIL() << "Deserialization is expected to fail!"; })
.or_else([&](auto&) { GTEST_SUCCEED(); });
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ class PublisherPort_test : public Test

// publisher port w/o offer on create
iox::popo::PublisherOptions m_noOfferOnCreatePublisherOptions{
0U, iox::NodeName_t{""}, false, iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};
0U, iox::NodeName_t{""}, false, "", iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};
iox::popo::PublisherPortData m_publisherPortDataNoOfferOnCreate{
iox::capro::ServiceDescription("a", "b", "c"), "myApp", &m_memoryManager, m_noOfferOnCreatePublisherOptions};
iox::popo::PublisherPortRouDi m_sutNoOfferOnCreateRouDiSide{&m_publisherPortDataNoOfferOnCreate};
iox::popo::PublisherPortUser m_sutNoOfferOnCreateUserSide{&m_publisherPortDataNoOfferOnCreate};

// publisher port that waits for subscriber when queue is full
iox::popo::PublisherOptions m_waitForSubscriberPublisherOptions{
0U, iox::NodeName_t{""}, false, iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER};
0U, iox::NodeName_t{""}, false, "", iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER};
iox::popo::PublisherPortData m_publisherPortDataWaitForSubscriber{
iox::capro::ServiceDescription("a", "b", "c"), "myApp", &m_memoryManager, m_waitForSubscriberPublisherOptions};
iox::popo::PublisherPortRouDi m_sutWaitForSubscriberRouDiSide{&m_publisherPortDataWaitForSubscriber};
iox::popo::PublisherPortUser m_sutWaitForSubscriberUserSide{&m_publisherPortDataWaitForSubscriber};

// publisher port w/ history
iox::popo::PublisherOptions m_withHistoryPublisherOptions{
iox::MAX_PUBLISHER_HISTORY, iox::NodeName_t{""}, true, iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};
iox::MAX_PUBLISHER_HISTORY, iox::NodeName_t{""}, true, "", iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};
iox::popo::PublisherPortData m_publisherPortDataHistory{
iox::capro::ServiceDescription("x", "y", "z"), "myApp", &m_memoryManager, m_withHistoryPublisherOptions};
iox::popo::PublisherPortUser m_sutWithHistoryUserSide{&m_publisherPortDataHistory};
Expand Down
20 changes: 19 additions & 1 deletion iceoryx_posh/test/moduletests/test_popo_server_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude 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.
Expand Down Expand Up @@ -32,6 +33,7 @@ TEST(ServerOptions_test, SerializationRoundTripIsSuccessful)
testOptions.requestQueueCapacity = 42;
testOptions.nodeName = "hypnotoad";
testOptions.offerOnCreate = false;
testOptions.responseSegmentName = "rejected-cookies";
testOptions.requestQueueFullPolicy = iox::popo::QueueFullPolicy::BLOCK_PRODUCER;
testOptions.clientTooSlowPolicy = iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER;

Expand All @@ -46,6 +48,9 @@ TEST(ServerOptions_test, SerializationRoundTripIsSuccessful)
EXPECT_THAT(roundTripOptions.offerOnCreate, Ne(defaultOptions.offerOnCreate));
EXPECT_THAT(roundTripOptions.offerOnCreate, Eq(testOptions.offerOnCreate));

EXPECT_THAT(roundTripOptions.responseSegmentName, Ne(defaultOptions.responseSegmentName));
EXPECT_THAT(roundTripOptions.responseSegmentName, Eq(testOptions.responseSegmentName));

EXPECT_THAT(roundTripOptions.requestQueueFullPolicy, Ne(defaultOptions.requestQueueFullPolicy));
EXPECT_THAT(roundTripOptions.requestQueueFullPolicy, Eq(testOptions.requestQueueFullPolicy));

Expand All @@ -72,9 +77,10 @@ iox::Serialization enumSerialization(QueueFullPolicyUT requsetQueueFullPolicy,
constexpr uint64_t REQUEST_QUEUE_CAPACITY{42U};
const iox::NodeName_t NODE_NAME{"harr-harr"};
constexpr bool OFFER_ON_CREATE{true};
const iox::ShmName_t SEGMENT_NAME{"ho-ho"};

return iox::Serialization::create(
REQUEST_QUEUE_CAPACITY, NODE_NAME, OFFER_ON_CREATE, requsetQueueFullPolicy, clientTooSlowPolicy);
REQUEST_QUEUE_CAPACITY, NODE_NAME, OFFER_ON_CREATE, SEGMENT_NAME, requsetQueueFullPolicy, clientTooSlowPolicy);
}

TEST(ServerOptions_test, DeserializingValidRequestQueueFullPolicyAndClientTooSlowPolicyIsSuccessful)
Expand Down Expand Up @@ -164,6 +170,18 @@ TEST(ServerOptions_test, ComparisonOperatorReturnsFalseWhenOfferOnCreateDoesNotM
EXPECT_FALSE(options2 == options1);
}

TEST(ServerOptions_test, ComparisonOperatorReturnsFalseWhenResponseSegmentNameDoesNotMatch)
{
::testing::Test::RecordProperty("TEST_ID", "692b602d-b60b-4ab7-ac33-9467e2604a10");
ServerOptions options1;
options1.responseSegmentName= "(╯°□°)╯︵ ┻━┻";
ServerOptions options2;
options2.responseSegmentName = "┬─┬ノ( º _ ºノ)";

EXPECT_FALSE(options1 == options2);
EXPECT_FALSE(options2 == options1);
}

TEST(ServerOptions_test, ComparisonOperatorReturnsFalseRequestQueueFullPolicyDoesNotMatch)
{
::testing::Test::RecordProperty("TEST_ID", "cc97e01c-94f7-41a9-8fac-19db1fd2d20e");
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_posh/test/moduletests/test_posh_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ TEST_F(PoshRuntime_test, ShutdownUnblocksBlockingPublisher)
iox::capro::ServiceDescription serviceDescription{"don't", "stop", "me"};

iox::popo::PublisherOptions publisherOptions{
0U, iox::NodeName_t("node"), true, iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER};
0U, iox::NodeName_t("node"), true, "", iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER};
iox::popo::SubscriberOptions subscriberOptions{
1U, 0U, iox::NodeName_t("node"), true, iox::popo::QueueFullPolicy::BLOCK_PRODUCER};

Expand Down
Loading

0 comments on commit 47a49c3

Please sign in to comment.