summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Event/Basic/Reconnect.cpp
blob: 7bb4b36492fe83e019bc2a978dfb501f9a03cc7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// $Id$

#include "Reconnect.h"
#include "Consumer.h"
#include "Supplier.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "ace/Get_Opt.h"
#include "ace/High_Res_Timer.h"

ACE_RCSID (EC_Tests_Basic, 
           Reconnect, 
           "$Id$")

int
main (int argc, char *argv [])
{
  EC_Reconnect driver;
  return driver.run (argc, argv);
}

// ****************************************************************

EC_Reconnect::EC_Reconnect (void)
  : allow_consumer_reconnect_ (0),
    allow_supplier_reconnect_ (0),
    disconnections_ (1000)
{
}

int
EC_Reconnect::parse_args (int& argc, char* argv[])
{
  if (this->EC_Driver::parse_args (argc, argv) != 0)
    return -1;

  ACE_Get_Opt get_opt (argc, argv, "scd:");
  int opt;

  while ((opt = get_opt ()) != EOF)
    {
      switch (opt)
        {
        case 'c':
          this->allow_consumer_reconnect_ = 1;
          break;
        case 's':
          this->allow_supplier_reconnect_ = 1;
          break;
        case 'd':
          this->disconnections_ = ACE_OS::atoi (get_opt.opt_arg ());
          break;

        case '?':
        default:
          this->print_usage ();
          return -1;
        }
    }

  return 0;
}

void
EC_Reconnect::print_args (void) const
{
  this->EC_Driver::print_args ();

  ACE_DEBUG ((LM_DEBUG, "EC_Reconnect: \n"
              " consumer_reconnect = %d\n"
              " supplier_reconnect = %d\n"
              " disconnect_count = %d\n",
              this->allow_consumer_reconnect_,
              this->allow_supplier_reconnect_,
              this->disconnections_));
}

void
EC_Reconnect::print_usage (void)
{
  this->EC_Driver::print_usage ();

  ACE_DEBUG ((LM_DEBUG, "EC_Reconnect usage: [-s] [-c] [-d disc]\n"));
}

void
EC_Reconnect::modify_attributes (TAO_EC_Event_Channel_Attributes& attr)
{
  attr.consumer_reconnect = this->allow_consumer_reconnect_;
  attr.supplier_reconnect = this->allow_supplier_reconnect_;
}

void
EC_Reconnect::execute_test (ACE_ENV_SINGLE_ARG_DECL)
{
  this->execute_consumer_test (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;
  this->execute_supplier_test (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor ();
  this->consumer_reconnect_.dump_results ("Reconnect/consumer", gsf);
  this->supplier_reconnect_.dump_results ("Reconnect/supplier", gsf);

  // this->EC_Driver::execute_test (ACE_ENV_SINGLE_ARG_PARAMETER);
}

void
EC_Reconnect::dump_results (void)
{
}

void
EC_Reconnect::execute_consumer_test (ACE_ENV_SINGLE_ARG_DECL)
{
  RtecEventChannelAdmin::ConsumerQOS qos;
  int shutdown_event_type;
  this->build_consumer_qos (0, qos, shutdown_event_type ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (this->allow_consumer_reconnect_)
    {
      ACE_hrtime_t start_time = ACE_OS::gethrtime ();
      for (int i = 0; i < this->disconnections_; ++i)
        {
          ACE_hrtime_t start = ACE_OS::gethrtime ();
          this->consumers_[0]->connect (qos,
                                        shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_CHECK;
          ACE_hrtime_t stop = ACE_OS::gethrtime ();
          this->consumer_reconnect_.sample (stop - start_time,
                                            stop - start);
        }
    }
  else
    {
      ACE_TRY
        {
          this->consumers_[0]->connect (qos,
                                        shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_DEBUG ((LM_ERROR, "Expected exception\n"));
        }
      ACE_CATCH (RtecEventChannelAdmin::AlreadyConnected, ex)
        {
          /* do nothing */
        }
      ACE_CATCHANY
        {
          ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                               "Expected AlreadyConnected exception");
        }
      ACE_ENDTRY;

      RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
        this->event_channel_->for_consumers (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      ACE_hrtime_t start_time = ACE_OS::gethrtime ();
      for (int i = 0; i < this->disconnections_; ++i)
        {
          ACE_hrtime_t start = ACE_OS::gethrtime ();
          this->consumers_[0]->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
          ACE_CHECK;
          this->consumers_[0]->connect (consumer_admin.in (),
                                        qos,
                                        shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_CHECK;
          ACE_hrtime_t stop = ACE_OS::gethrtime ();
          this->consumer_reconnect_.sample (stop - start_time,
                                            stop - start);
        }
    }
}

void
EC_Reconnect::execute_supplier_test (ACE_ENV_SINGLE_ARG_DECL)
{
  RtecEventChannelAdmin::SupplierQOS qos;
  int shutdown_event_type;
  this->build_supplier_qos (0, qos, shutdown_event_type ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (this->allow_supplier_reconnect_)
    {
      ACE_hrtime_t start_time = ACE_OS::gethrtime ();
      for (int i = 0; i < this->disconnections_; ++i)
        {
          ACE_hrtime_t start = ACE_OS::gethrtime ();
          this->suppliers_[0]->connect (qos, shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_CHECK;
          ACE_hrtime_t stop = ACE_OS::gethrtime ();
          this->supplier_reconnect_.sample (stop - start_time,
                                            stop - start);
        }
    }
  else
    {
      ACE_TRY
        {
          this->suppliers_[0]->connect (qos, shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_DEBUG ((LM_ERROR, "Expected exception\n"));
        }
      ACE_CATCH (RtecEventChannelAdmin::AlreadyConnected, ex)
        {
          /* do nothing */
        }
      ACE_CATCHANY
        {
          ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                               "Expected AlreadyConnected exception");
        }
      ACE_ENDTRY;

      RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
        this->event_channel_->for_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      ACE_hrtime_t start_time = ACE_OS::gethrtime ();
      for (int i = 0; i < this->disconnections_; ++i)
        {
          ACE_hrtime_t start = ACE_OS::gethrtime ();
          this->suppliers_[0]->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
          ACE_CHECK;
          this->suppliers_[0]->connect (supplier_admin.in (),
                                        qos,
                                        shutdown_event_type
                                        ACE_ENV_ARG_PARAMETER);
          ACE_CHECK;
          ACE_hrtime_t stop = ACE_OS::gethrtime ();
          this->supplier_reconnect_.sample (stop - start_time,
                                            stop - start);
        }
    }
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */