1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
7 Updates_StructuredPushConsumer::Updates_StructuredPushConsumer (Updates
*test_client
)
8 : test_client_ (test_client
)
13 Updates_StructuredPushConsumer::offer_change (
14 const CosNotification::EventTypeSeq
& added
,
15 const CosNotification::EventTypeSeq
& removed
19 ACE_DEBUG ((LM_DEBUG
, "StructuredPushConsumer::offer_change invoked:\n"));
20 this->test_client_
->types_changed (added
, removed
);
23 /***************************************************************************/
25 Updates_StructuredPushSupplier::Updates_StructuredPushSupplier (Updates
* test_client
)
26 :test_client_ (test_client
)
30 Updates_StructuredPushSupplier::~Updates_StructuredPushSupplier ()
35 Updates_StructuredPushSupplier::subscription_change (
36 const CosNotification::EventTypeSeq
& added
,
37 const CosNotification::EventTypeSeq
& removed
41 ACE_DEBUG ((LM_DEBUG
, "StructuredPushSupplier::subscription_change invoked:\n"));
42 this->test_client_
->types_changed (added
, removed
);
45 /***************************************************************************/
48 : added_count_ (0), removed_count_ (0)
57 Updates::init (int argc
,
60 // Initialize base class.
61 Notify_Test_Client::init (argc
,
64 // Create all participents.
67 CosNotifyChannelAdmin::AdminID adminid
;
70 ec_
->new_for_suppliers (this->ifgop_
,
73 ACE_ASSERT (!CORBA::is_nil (supplier_admin_
.in ()));
76 ec_
->new_for_consumers (this->ifgop_
,
79 ACE_ASSERT (!CORBA::is_nil (consumer_admin_
.in ()));
81 ACE_NEW_RETURN (consumer_
,
82 Updates_StructuredPushConsumer (this),
84 consumer_
->init (root_poa_
.in ());
86 consumer_
->connect (this->consumer_admin_
.in ());
88 ACE_NEW_RETURN (supplier_
,
89 Updates_StructuredPushSupplier (this),
91 supplier_
->init (root_poa_
.in ());
93 supplier_
->connect (this->supplier_admin_
.in ());
101 CosNotifyChannelAdmin::ChannelID id
;
103 ec_
= notify_factory_
->create_channel (initial_qos_
,
107 ACE_ASSERT (!CORBA::is_nil (ec_
.in ()));
111 Updates::types_changed (const CosNotification::EventTypeSeq
& added
,
112 const CosNotification::EventTypeSeq
& removed
)
116 ACE_DEBUG ((LM_DEBUG
, "Added Types..\n"));
117 this->print_event_types (added
);
119 ACE_DEBUG ((LM_DEBUG
, "Removed Types..\n"));
120 this->print_event_types (removed
);
123 ACE_GUARD (TAO_SYNCH_MUTEX
, mon
, this->lock_
);
125 this->added_count_
+= added
.length ();
126 this->removed_count_
+= removed
.length ();
130 Updates::print_event_types (const CosNotification::EventTypeSeq
&types
)
132 for (CORBA::ULong i
= 0; i
< types
.length (); ++i
)
134 ACE_DEBUG ((LM_DEBUG
, "(%s, %s)\n", types
[i
].domain_name
.in (), types
[i
].type_name
. in()));
139 Updates::add_type (CosNotification::EventTypeSeq
& type_seq
, const char* type
)
142 int index
= type_seq
.length ();
143 type_seq
.length (index
+ 1);
145 type_seq
[index
].domain_name
= CORBA::string_dup (type
);
146 type_seq
[index
].type_name
= CORBA::string_dup (type
);
150 Updates::wait_for_updates (int expected_added
, int expected_removed
)
154 if (added_count_
== expected_added
&&
155 removed_count_
== expected_removed
)
158 ACE_Time_Value
tv(0, 100 * 1000);
164 Updates::reset_counts ()
166 ACE_GUARD (TAO_SYNCH_MUTEX
, mon
, this->lock_
);
167 this->added_count_
= 0;
168 this->removed_count_
= 0;
174 this->test_subscription_change ();
177 ACE_DEBUG ((LM_DEBUG
, "Finished testing subscription_change!\n"));
179 this->test_offer_change ();
181 ACE_DEBUG ((LM_DEBUG
, "Updates test has run successfully!\n"));
185 Updates::test_subscription_change ()
189 this->reset_counts ();
191 /// Currently we're subscribed for "*"
192 /// Add RED, GREEN and BLUE
193 /// Remove ORANGE and PINK
195 CosNotification::EventTypeSeq added
, removed
;
197 this->add_type (added
, "RED");
198 this->add_type (added
, "GREEN");
199 this->add_type (added
, "BLUE");
201 this->add_type (removed
, "ORANGE");
202 this->add_type (removed
, "PINK");
206 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with added types:\n"));
207 this->print_event_types (added
);
208 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with removed types:\n"));
209 this->print_event_types (removed
);
212 this->consumer_
->get_proxy_supplier ()->subscription_change (added
, removed
);
214 this->wait_for_updates (3, 0); // The supplier should receive Added (RED, GREEN, BLUE)
216 // Get the subscriptions visible to the supplier.
217 CosNotification::EventTypeSeq_var obtained
=
218 this->supplier_
->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
222 ACE_DEBUG ((LM_DEBUG
, "obtain_subscription_types\n"));
223 this->print_event_types (obtained
.in ());
229 this->reset_counts ();
231 // Now, add PURPLE, RED and GREEN
232 CosNotification::EventTypeSeq added
, removed
;
234 this->add_type (added
, "PURPLE");
235 this->add_type (added
, "GREEN");
236 this->add_type (added
, "BLUE");
240 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with added types:\n"));
241 this->print_event_types (added
);
242 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with removed types:\n"));
243 this->print_event_types (removed
);
246 this->consumer_
->get_proxy_supplier ()->subscription_change (added
, removed
);
248 this->wait_for_updates (1, 0); // The supplier should receive Added (PURPLE).
250 // Get the subscriptions visible to the supplier.
251 CosNotification::EventTypeSeq_var obtained
=
252 this->supplier_
->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
256 ACE_DEBUG ((LM_DEBUG
, "obtain_subscription_types\n"));
257 this->print_event_types (obtained
.in ());
263 this->reset_counts ();
265 // Next, Remove everything by subcribing to "*"
266 CosNotification::EventTypeSeq added
, removed
;
268 this->add_type (added
, "*");
272 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with added types:\n"));
273 this->print_event_types (added
);
274 ACE_DEBUG ((LM_DEBUG
, "Calling subscription_change with removed types:\n"));
275 this->print_event_types (removed
);
278 this->consumer_
->get_proxy_supplier ()->subscription_change (added
, removed
);
280 this->wait_for_updates (0, 4);
281 // The supplier should receive Remove {RED, GREEN} out of the 4 actally removed (RED, GREEN, BLUE, PURPLE) becaue that whats it offered for.
283 // Get the subscriptions visible to the supplier.
284 CosNotification::EventTypeSeq_var obtained
=
285 this->supplier_
->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
289 ACE_DEBUG ((LM_DEBUG
, "obtain_subscription_types\n"));
290 this->print_event_types (obtained
.in ());
297 Updates::test_offer_change ()
301 this->reset_counts ();
303 /// Currently we're subscribed for "*"
304 /// Add RED, GREEN and BLUE
305 /// Remove ORANGE and PINK
307 CosNotification::EventTypeSeq added
, removed
;
309 this->add_type (added
, "RED");
310 this->add_type (added
, "GREEN");
311 this->add_type (added
, "BLUE");
313 this->add_type (removed
, "ORANGE");
314 this->add_type (removed
, "PINK");
318 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with added types:\n"));
319 this->print_event_types (added
);
320 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with removed types:\n"));
321 this->print_event_types (removed
);
324 this->supplier_
->get_proxy_consumer ()->offer_change (added
, removed
);
326 this->wait_for_updates (3, 0); // The consumer should receive Added (RED, GREEN, BLUE)
328 // Get the offers visible to the supplier.
329 CosNotification::EventTypeSeq_var obtained
=
330 this->consumer_
->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
334 ACE_DEBUG ((LM_DEBUG
, "obtain_offer_types\n"));
335 this->print_event_types (obtained
.in ());
341 this->reset_counts ();
343 // Now, add PURPLE, RED and GREEN
344 CosNotification::EventTypeSeq added
, removed
;
346 this->add_type (added
, "PURPLE");
347 this->add_type (added
, "GREEN");
348 this->add_type (added
, "BLUE");
352 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with added types:\n"));
353 this->print_event_types (added
);
354 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with removed types:\n"));
355 this->print_event_types (removed
);
358 this->supplier_
->get_proxy_consumer ()->offer_change (added
, removed
);
360 this->wait_for_updates (1, 0); // The consumer should receive Added (PURPLE).
362 // Get the offers visible to the consumer.
363 CosNotification::EventTypeSeq_var obtained
=
364 this->consumer_
->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
368 ACE_DEBUG ((LM_DEBUG
, "obtain_offer_types\n"));
369 this->print_event_types (obtained
.in ());
375 this->reset_counts ();
377 // Next, Remove everything by subcribing to "*"
378 CosNotification::EventTypeSeq added
, removed
;
380 this->add_type (added
, "*");
384 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with added types:\n"));
385 this->print_event_types (added
);
386 ACE_DEBUG ((LM_DEBUG
, "Calling offer_change with removed types:\n"));
387 this->print_event_types (removed
);
390 this->supplier_
->get_proxy_consumer ()->offer_change (added
, removed
);
392 this->wait_for_updates (0, 4);
393 // The consumer should receive Remove {RED, GREEN} out of the 4 actally removed (RED, GREEN, BLUE, PURPLE) becaue that whats it offered for.
395 // Get the offers visible to the consumer.
396 CosNotification::EventTypeSeq_var obtained
=
397 this->consumer_
->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON
);
401 ACE_DEBUG ((LM_DEBUG
, "obtain_offer_types\n"));
402 this->print_event_types (obtained
.in ());
408 /***************************************************************************/
411 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
422 catch (const CORBA::SystemException
& se
)
424 se
._tao_print_exception ("Error: ");