2 #include "tao/AnyTypeCode/Any.h"
3 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_unistd.h"
7 const ACE_TCHAR
*ior_input_file
= ACE_TEXT ("file://serverA.ior");
8 int test_duration_sec
= 15;
9 bool expect_object_not_exist
= false;
11 class Client_Task
: public ACE_Task_Base
14 Client_Task (taoimrtest::reconnectserver::TimeSrv_ptr obj
)
15 : test_ (taoimrtest::reconnectserver::TimeSrv::_duplicate (obj
)),
16 communication_failed_ (false),
18 caught_object_not_exist_ (false)
23 ACE_Time_Value start
= ACE_OS::gettimeofday ();
24 ACE_Time_Value elapsed
;
25 for (int i
= 0; elapsed
< ACE_Time_Value (test_duration_sec
); i
++)
29 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t)Request %d\n"), i
));
30 test_
->current_time();
31 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t)Done request %d\n"), i
));
32 if (communication_failed_
)
34 communication_failed_
= false;
38 catch (const CORBA::OBJECT_NOT_EXIST
&)
40 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t)caught OBJECT_NOT_EXIST exception for request %d\n"), i
));
41 caught_object_not_exist_
= true;
43 catch (const CORBA::Exception
& /*ex*/)
45 communication_failed_
= true;
48 elapsed
= ACE_OS::gettimeofday () - start
;
51 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t)Client thread exit \n")));
55 bool test_passed () const
57 bool conn_test
= communication_failed_
!= reconnected_
;
58 bool one_test
= expect_object_not_exist
== caught_object_not_exist_
;
59 bool success
= (conn_test
&& one_test
);
63 ACE_TEXT ("(%P|%t)Client results, cf = %d, r = %d, ")
64 ACE_TEXT ("eone = %d, cone = %d\n"),
65 communication_failed_
, reconnected_
,
66 expect_object_not_exist
, caught_object_not_exist_
));
72 taoimrtest::reconnectserver::TimeSrv_var test_
;
73 bool communication_failed_
;
75 bool caught_object_not_exist_
;
80 parse_args (int argc
, ACE_TCHAR
* argv
[])
82 ACE_Get_Opt
get_opts (argc
, argv
, "i:t:e:");
86 while ((c
= get_opts ()) != -1)
90 ior_input_file
= get_opts
.opt_arg ();
93 test_duration_sec
= ACE_OS::atoi (get_opts
.opt_arg ());
96 expect_object_not_exist
= ACE_OS::atoi (get_opts
.opt_arg ());
100 ACE_ERROR_RETURN ((LM_ERROR
,
102 "-i <iorfile> -t <test_duration>"
107 // Indicates successful parsing of the command line
112 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
116 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
118 if (parse_args (argc
, argv
) != 0)
123 CORBA::Object_var object
= orb
->resolve_initial_references ("RootPOA");
125 object
= orb
->string_to_object(ior_input_file
);
127 taoimrtest::reconnectserver::TimeSrv_var test
=
128 taoimrtest::reconnectserver::TimeSrv::_narrow(object
.in ());
130 if (CORBA::is_nil(test
.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR
,
133 "(%P|%t) Object reference is nil \n"),
137 Client_Task
task (test
.in ());
138 task
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1, 1);
140 ACE_Time_Value
tv(test_duration_sec
);
147 if (task
.test_passed ())
149 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Client test passed \n")));
153 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("(%P|%t) Client test failed.\n")), 1);
156 catch (const CORBA::Exception
&ex
)
158 ex
._tao_print_exception ("Exception caught by client:");