Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Blocking_Sync_None / client.cpp
blob3d1285e6cf507bfcb795df8604211d377bb0e816
1 #include "TestC.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_sys_time.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
8 int iterations = 1000;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
23 case 'i':
24 iterations = ACE_OS::atoi (get_opts.opt_arg ());
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-k <ior> "
32 "-i <iterations> "
33 "\n",
34 argv [0]),
35 -1);
37 // Indicates successful parsing of the command line
38 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 CORBA::ORB_var orb =
47 CORBA::ORB_init (argc, argv);
49 if (parse_args (argc, argv) != 0)
50 return 1;
52 CORBA::Object_var tmp =
53 orb->string_to_object(ior);
55 Test::Blocking_Sync_None_var blocking_sync_none =
56 Test::Blocking_Sync_None::_narrow(tmp.in ());
58 if (CORBA::is_nil (blocking_sync_none.in ()))
59 ACE_ERROR_RETURN ((LM_DEBUG,
60 "ERROR: Nil reference in Blocking_Sync_None reference <%s>\n",
61 ior),
62 1);
64 CORBA::Object_var object =
65 orb->resolve_initial_references ("PolicyCurrent");
67 CORBA::PolicyCurrent_var policy_current =
68 CORBA::PolicyCurrent::_narrow (object.in ());
70 if (CORBA::is_nil (policy_current.in ()))
72 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
73 return 1;
75 CORBA::Any scope_as_any;
76 scope_as_any <<= Messaging::SYNC_NONE;
78 CORBA::PolicyList policies(1); policies.length (1);
79 policies[0] =
80 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
81 scope_as_any);
83 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
85 policies[0]->destroy ();
87 const int payload_length = 65536;
88 const unsigned int sleep_milliseconds = 20;
89 const unsigned int sleep_microseconds = sleep_milliseconds * 1000;
91 Test::Payload payload(payload_length);
92 payload.length (payload_length);
94 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test running . . .\n"));
95 int blocked_calls = 0;
96 for (int i = 0; i != iterations; ++i)
98 ACE_Time_Value start = ACE_OS::gettimeofday ();
100 blocking_sync_none->slow_operation (payload,
101 sleep_microseconds);
103 ACE_Time_Value elapsed = ACE_OS::gettimeofday ();
104 elapsed -= start;
106 if (elapsed.msec () >= sleep_milliseconds)
108 blocked_calls++;
112 blocking_sync_none->shutdown ();
114 orb->destroy ();
116 if (blocked_calls > iterations / 20)
118 ACE_ERROR ((LM_ERROR,
119 "ERROR: More than 5% (%d) of the calls blocked\n",
120 blocked_calls));
121 return 1;
124 if (blocked_calls != 0)
126 ACE_ERROR ((LM_ERROR,
127 "Warning: Some (%d) SYNC_NONE calls blocked\n",
128 blocked_calls));
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("Exception caught:");
134 return 1;
137 return 0;