Skip to content

Commit 7f00d83

Browse files
committed
Refs 23573 Adding tests for original writer parameter
Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
1 parent 7adaeba commit 7f00d83

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,65 @@ void test_local_communication(
206206
router.stop();
207207
}
208208

209+
template <class MsgStruct, class MsgStructType>
210+
void test_original_writer_forwarding(
211+
DdsRouterConfiguration ddsrouter_configuration)
212+
{
213+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
214+
215+
uint32_t samples_sent = 0;
216+
std::atomic<uint32_t> samples_received(0);
217+
std::atomic<uint32_t> samples_to_receive(1);
218+
219+
MsgStruct sent_msg;
220+
MsgStruct recv_msg;
221+
MsgStructType type;
222+
std::string msg_str;
223+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
224+
sent_msg.message(msg_str);
225+
// Create DDS Publisher in domain 0
226+
TestPublisher<MsgStruct> publisher(type.is_compute_key_provided);
227+
228+
ASSERT_TRUE(publisher.init(0));
229+
230+
// Create DDS Subscriber in domain 1
231+
TestSubscriber<MsgStruct> subscriber(type.is_compute_key_provided);
232+
ASSERT_TRUE(subscriber.init(1, &recv_msg, &samples_received));
233+
234+
// Create DdsRouter entity
235+
DdsRouter router(ddsrouter_configuration);
236+
router.start();
237+
238+
// CASE 1: Send message without original_writer_param, should be set to writers guid
239+
sent_msg.index(samples_sent);
240+
ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK);
241+
// Watiting for the message to be received
242+
while(samples_received.load() < 1){};
243+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
244+
245+
// CASE 2: Send message with original_writer_param set to unknown, should be set to other value
246+
sent_msg.index(samples_sent);
247+
eprosima::fastdds::rtps::WriteParams params;
248+
params.original_writer_guid(eprosima::fastdds::rtps::GUID_t::unknown());
249+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK);
250+
// Watiting for the message to be received
251+
while(samples_received.load() < 2){};
252+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
253+
254+
// CASE 3: Send message with original_writer_param set to some value, value must be kept
255+
sent_msg.index(samples_sent);
256+
eprosima::fastdds::rtps::WriteParams params_with_og_writer;
257+
eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678);
258+
params_with_og_writer.original_writer_guid(guid);
259+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK);
260+
// Watiting for the message to be received
261+
while(samples_received.load() < 2){};
262+
ASSERT_EQ(subscriber.original_writer_guid(), guid);
263+
264+
router.stop();
265+
}
266+
267+
209268
} /* namespace test */
210269

211270
/**
@@ -322,6 +381,19 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami
322381
true);
323382
}
324383

384+
385+
/**
386+
* Test original writer forwarding in HelloWorld topic between two DDS participants created in different domains,
387+
* by using a router with two Simple Participants at each domain.
388+
*/
389+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding)
390+
{
391+
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
392+
test::dds_test_simple_configuration());
393+
}
394+
395+
396+
325397
int main(
326398
int argc,
327399
char** argv)

ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ class TestPublisher
152152
return writer_->write(&hello_);
153153
}
154154

155+
//! Publish a sample with parameters
156+
eprosima::fastdds::dds::ReturnCode_t publish_with_params(
157+
MsgStruct msg, eprosima::fastdds::rtps::WriteParams params)
158+
{
159+
hello_.index(msg.index());
160+
hello_.message(msg.message());
161+
162+
163+
return writer_->write(&hello_, params);
164+
}
165+
155166
//! Dispose instance
156167
eprosima::fastdds::dds::ReturnCode_t dispose_key(
157168
MsgStruct msg);
@@ -162,6 +173,11 @@ class TestPublisher
162173
listener_.wait_discovery(n_subscribers);
163174
}
164175

176+
eprosima::fastdds::rtps::GUID_t original_writer_guid() const
177+
{
178+
return writer_->guid();
179+
}
180+
165181
private:
166182

167183
MsgStruct hello_;
@@ -213,6 +229,7 @@ class TestPublisher
213229
}
214230
}
215231

232+
216233
private:
217234

218235
//! Number of DataReaders discovered
@@ -357,6 +374,11 @@ class TestSubscriber
357374
return listener_.n_key_disposed;
358375
}
359376

377+
eprosima::fastdds::rtps::GUID_t original_writer_guid() const
378+
{
379+
return listener_.original_writer_guid;
380+
}
381+
360382
private:
361383

362384
eprosima::fastdds::dds::DomainParticipant* participant_;
@@ -424,6 +446,8 @@ class TestSubscriber
424446
{
425447
n_key_disposed++;
426448
}
449+
450+
original_writer_guid = iHandle2GUID(info.original_publication_handle);
427451
}
428452
}
429453

@@ -445,6 +469,9 @@ class TestSubscriber
445469
//! Placeholder where received data is stored
446470
MsgStruct msg_received;
447471

472+
//! Placeholder where original writer GUID is stored
473+
eprosima::fastdds::rtps::GUID_t original_writer_guid;
474+
448475
std::atomic<std::uint32_t> n_key_disposed;
449476

450477
//! Reference to the sample sent by the publisher

0 commit comments

Comments
 (0)