Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / Basic / Reconnect.cpp
blob2fdb2af44b5b52ddde9b68e38eb6367edefda579
1 #include "Reconnect.h"
2 #include "Consumer.h"
3 #include "Supplier.h"
4 #include "orbsvcs/Event/EC_Event_Channel.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/High_Res_Timer.h"
8 int
9 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
11 EC_Reconnect driver;
12 return driver.run (argc, argv);
15 // ****************************************************************
17 EC_Reconnect::EC_Reconnect (void)
18 : allow_consumer_reconnect_ (0),
19 allow_supplier_reconnect_ (0),
20 disconnections_ (1000)
24 int
25 EC_Reconnect::parse_args (int& argc, ACE_TCHAR* argv[])
27 if (this->EC_Driver::parse_args (argc, argv) != 0)
28 return -1;
30 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("scd:"));
31 int opt;
33 while ((opt = get_opt ()) != EOF)
35 switch (opt)
37 case 'c':
38 this->allow_consumer_reconnect_ = 1;
39 break;
40 case 's':
41 this->allow_supplier_reconnect_ = 1;
42 break;
43 case 'd':
44 this->disconnections_ = ACE_OS::atoi (get_opt.opt_arg ());
45 break;
47 case '?':
48 default:
49 this->print_usage ();
50 return -1;
54 return 0;
57 void
58 EC_Reconnect::print_args (void) const
60 this->EC_Driver::print_args ();
62 ACE_DEBUG ((LM_DEBUG, "EC_Reconnect:\n"
63 " consumer_reconnect = %d\n"
64 " supplier_reconnect = %d\n"
65 " disconnect_count = %d\n",
66 this->allow_consumer_reconnect_,
67 this->allow_supplier_reconnect_,
68 this->disconnections_));
71 void
72 EC_Reconnect::print_usage (void)
74 this->EC_Driver::print_usage ();
76 ACE_DEBUG ((LM_DEBUG, "EC_Reconnect usage: [-s] [-c] [-d disc]\n"));
79 void
80 EC_Reconnect::modify_attributes (TAO_EC_Event_Channel_Attributes& attr)
82 attr.consumer_reconnect = this->allow_consumer_reconnect_;
83 attr.supplier_reconnect = this->allow_supplier_reconnect_;
86 void
87 EC_Reconnect::execute_test (void)
89 this->execute_consumer_test ();
90 this->execute_supplier_test ();
92 ACE_High_Res_Timer::global_scale_factor_type gsf =
93 ACE_High_Res_Timer::global_scale_factor ();
94 this->consumer_reconnect_.dump_results (ACE_TEXT("Reconnect/consumer"), gsf);
95 this->supplier_reconnect_.dump_results (ACE_TEXT("Reconnect/supplier"), gsf);
97 // this->EC_Driver::execute_test ();
100 void
101 EC_Reconnect::dump_results (void)
105 void
106 EC_Reconnect::execute_consumer_test (void)
108 RtecEventChannelAdmin::ConsumerQOS qos;
109 int shutdown_event_type;
110 this->build_consumer_qos (0, qos, shutdown_event_type);
112 if (this->allow_consumer_reconnect_)
114 ACE_hrtime_t start_time = ACE_OS::gethrtime ();
115 for (int i = 0; i < this->disconnections_; ++i)
117 ACE_hrtime_t start = ACE_OS::gethrtime ();
118 this->consumers_[0]->connect (qos,
119 shutdown_event_type);
120 ACE_hrtime_t stop = ACE_OS::gethrtime ();
121 this->consumer_reconnect_.sample (stop - start_time,
122 stop - start);
125 else
129 this->consumers_[0]->connect (qos,
130 shutdown_event_type);
132 ACE_DEBUG ((LM_ERROR, "Expected exception\n"));
134 catch (const RtecEventChannelAdmin::AlreadyConnected&)
136 /* do nothing */
138 catch (const CORBA::Exception& ex)
140 ex._tao_print_exception ("Expected AlreadyConnected exception");
143 RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
144 this->event_channel_->for_consumers ();
146 ACE_hrtime_t start_time = ACE_OS::gethrtime ();
147 for (int i = 0; i < this->disconnections_; ++i)
149 ACE_hrtime_t start = ACE_OS::gethrtime ();
150 this->consumers_[0]->disconnect ();
151 this->consumers_[0]->connect (consumer_admin.in (),
152 qos,
153 shutdown_event_type);
154 ACE_hrtime_t stop = ACE_OS::gethrtime ();
155 this->consumer_reconnect_.sample (stop - start_time,
156 stop - start);
161 void
162 EC_Reconnect::execute_supplier_test (void)
164 RtecEventChannelAdmin::SupplierQOS qos;
165 int shutdown_event_type;
166 this->build_supplier_qos (0, qos, shutdown_event_type);
168 if (this->allow_supplier_reconnect_)
170 ACE_hrtime_t start_time = ACE_OS::gethrtime ();
171 for (int i = 0; i < this->disconnections_; ++i)
173 ACE_hrtime_t start = ACE_OS::gethrtime ();
174 this->suppliers_[0]->connect (qos, shutdown_event_type);
175 ACE_hrtime_t stop = ACE_OS::gethrtime ();
176 this->supplier_reconnect_.sample (stop - start_time,
177 stop - start);
180 else
184 this->suppliers_[0]->connect (qos, shutdown_event_type);
186 ACE_DEBUG ((LM_ERROR, "Expected exception\n"));
188 catch (const RtecEventChannelAdmin::AlreadyConnected&)
190 /* do nothing */
192 catch (const CORBA::Exception& ex)
194 ex._tao_print_exception ("Expected AlreadyConnected exception");
197 RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
198 this->event_channel_->for_suppliers ();
200 ACE_hrtime_t start_time = ACE_OS::gethrtime ();
201 for (int i = 0; i < this->disconnections_; ++i)
203 ACE_hrtime_t start = ACE_OS::gethrtime ();
204 this->suppliers_[0]->disconnect ();
205 this->suppliers_[0]->connect (supplier_admin.in (),
206 qos,
207 shutdown_event_type);
208 ACE_hrtime_t stop = ACE_OS::gethrtime ();
209 this->supplier_reconnect_.sample (stop - start_time,
210 stop - start);