MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / test

Method test

tests/DCPS/SharedTransport/TestCase.cpp:83–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83int
84TestCase::test()
85{
86 wait_for_subscribers(); // wait for association
87
88 // As there are no fully association establishment between pub and sub for UDP
89 // transport, a delay is required for the test to receive all messages.
90 ACE_OS::sleep (3);
91
92 // Write test data to exercise the data paths:
93 for (int i = 0; i < num_messages; ++i) {
94 int pind = 0;
95 for (TestPublisherVector::iterator pub = publishers_.begin();
96 pub != publishers_.end(); ++pub) {
97 TestMessage message = { (100*pind) + i, "Testing!" };
98 if ((*pub)->write_message(message)) {
99 return -1;
100 }
101 ++pind;
102 }
103 }
104
105 // wait for delivery
106 for (TestSubscriberVector::iterator sub = subscribers_.begin();
107 sub != subscribers_.end(); ++sub) {
108 size_t read = 0;
109 DDS::WaitSet_var ws = new DDS::WaitSet;
110 DDS::ReadCondition_var rc =
111 (*sub)->create_readcondition(DDS::NOT_READ_SAMPLE_STATE,
112 DDS::NEW_VIEW_STATE,
113 DDS::ALIVE_INSTANCE_STATE);
114 ws->attach_condition(rc);
115 const OpenDDS::DCPS::MonotonicTimePoint start = OpenDDS::DCPS::MonotonicTimePoint::now();
116 const OpenDDS::DCPS::TimeDuration timeout(30, 0);
117 const DDS::Duration_t one_sec = {1, 0};
118 const size_t num_expected = num_messages * publishers_.size();
119 do {
120 TestMessageSeq data_values;
121 DDS::SampleInfoSeq sample_infos;
122 const CORBA::Long expected = static_cast<CORBA::Long>(num_expected);
123 (*sub)->read_w_condition(data_values, sample_infos, expected, rc);
124 read += data_values.length();
125 if (read != num_expected) {
126 DDS::ConditionSeq active;
127 DDS::ReturnCode_t ret = ws->wait(active, one_sec);
128 if (ret != DDS::RETCODE_OK && ret != DDS::RETCODE_TIMEOUT) {
129 ACE_ERROR_RETURN((LM_ERROR,
130 ACE_TEXT("%N:%l: wait()")
131 ACE_TEXT(" ERROR: wait for samples failed: %d\n"),
132 ret), -1);
133 }
134 }
135 } while (read != num_expected && (OpenDDS::DCPS::MonotonicTimePoint::now() - start < timeout));
136
137 ws->detach_condition(rc);
138
139 // Only check the number read if the transport is reliable
140 if (!best_effort && read < num_expected) {

Callers

nothing calls this directly

Calls 12

write_messageMethod · 0.80
attach_conditionMethod · 0.80
detach_conditionMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
create_readconditionMethod · 0.45
sizeMethod · 0.45
read_w_conditionMethod · 0.45
lengthMethod · 0.45
waitMethod · 0.45
take_w_conditionMethod · 0.45
inMethod · 0.45

Tested by

no test coverage detected