3 #include "tao/Messaging/Messaging.h"
5 #include "tao/Transport_Cache_Manager.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Thread_Lane_Resources.h"
8 #include "tao/Base_Transport_Property.h"
10 #include "tao/Profile.h"
11 #include "tao/Transport.h"
13 #include "ace/Get_Opt.h"
15 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
16 bool level_obj
= false;
17 bool level_thread
= false;
18 bool level_orb
= false;
20 bool synch_none
= false;
21 bool synch_delayed
= false;
24 parse_args (int argc
, ACE_TCHAR
*argv
[])
26 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:l:s:"));
28 level_obj
= true; //default
29 synch_none
= true; //default
31 while ((c
= get_opts ()) != -1)
35 ior
= get_opts
.opt_arg ();
39 ACE_TCHAR
*level
= get_opts
.opt_arg ();
42 if (ACE_OS::strcmp (level
, ACE_TEXT("orb")) == 0) {
45 else if (ACE_OS::strcmp (level
, ACE_TEXT("thread")) == 0) {
55 ACE_TCHAR
*synch
= get_opts
.opt_arg ();
58 if (ACE_OS::strcmp (synch
, ACE_TEXT("delayed")) == 0) {
69 ACE_ERROR_RETURN ((LM_ERROR
,
72 "-l <obj|orb|thread> "
78 // Indicates successful parsing of the command line
83 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
88 CORBA::ORB_init (argc
, argv
, "test");
90 if (parse_args (argc
, argv
) != 0)
93 CORBA::Object_var tmp
= orb
->string_to_object(ior
);
95 if (CORBA::is_nil (tmp
.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid IOR.\n")
102 // Set the Synch Scopes
104 CORBA::Any scope_as_any
;
106 if (synch_none
== true)
108 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Applying SYNC_NONE.\n"));
109 scope_as_any
<<= Messaging::SYNC_NONE
;
111 else if (synch_delayed
== true)
113 ACE_DEBUG ((LM_DEBUG
,
114 "(%P|%t) - Applying SYNC_DELAYED_BUFFERING.\n"));
115 scope_as_any
<<= TAO::SYNC_DELAYED_BUFFERING
;
118 CORBA::PolicyList
policies (1);
121 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
124 if (level_thread
== true)
126 ACE_DEBUG ((LM_DEBUG
,
127 "(%P|%t) - Applying Synch Scope at thread level.\n"));
129 CORBA::Object_var object
=
130 orb
->resolve_initial_references ("PolicyCurrent");
131 CORBA::PolicyCurrent_var policy_current
=
132 CORBA::PolicyCurrent::_narrow (object
.in ());
134 policy_current
->set_policy_overrides (policies
,
135 CORBA::ADD_OVERRIDE
);
137 else if (level_orb
== true)
139 ACE_DEBUG ((LM_DEBUG
,
140 "(%P|%t) - Applying Synch Scope at orb level.\n"));
142 CORBA::Object_var obj
=
143 orb
->resolve_initial_references("ORBPolicyManager");
144 CORBA::PolicyManager_var policy_manager
=
145 CORBA::PolicyManager::_narrow(obj
.in());
147 policy_manager
->set_policy_overrides (policies
,
148 CORBA::ADD_OVERRIDE
);
150 else if (level_obj
== true)
152 ACE_DEBUG ((LM_DEBUG
,
153 "(%P|%t) - Applying Synch Scope at Object level.\n"));
155 tmp
= tmp
->_set_policy_overrides (policies
, CORBA::SET_OVERRIDE
);
158 policies
[0]->destroy ();
161 Test::Hello_var hello
=
162 Test::Hello::_unchecked_narrow(tmp
.in ());
164 if (CORBA::is_nil (hello
.in ()))
166 ACE_ERROR_RETURN ((LM_ERROR
,
167 "Nil Test::Hello reference <%s>\n",
172 // If a blocking connection is initiated in the next step
173 // the test will get an exception indicating test failure.
174 // Be sure you IOR is for the localhost endpoint, else
175 // grab a book and wait around for timeout.
176 hello
->get_string ();
178 TAO::Transport_Cache_Manager
&tcm
=
179 hello
->orb_core ()->lane_resources ().transport_cache ();
181 TAO_Base_Transport_Property
desc (hello
->_stubobj ()->profile_in_use ()->endpoint ());
183 if (tcm
.current_size() == 0)
185 ACE_ERROR_RETURN ((LM_ERROR
,
186 "The Transport Cache shouldn't be empty here.\n"),
190 size_t busy_count
= 0;
191 TAO_Transport
*transport
= 0;
192 TAO::Transport_Cache_Manager::Find_Result find_result
=
193 tcm
.find_transport (&desc
, transport
, busy_count
);
194 // We don't need this transport any more. Release the ownership.
195 transport
->remove_reference ();
197 switch (find_result
){
198 case TAO::Transport_Cache_Manager::CACHE_FOUND_NONE
:
200 ACE_ERROR_RETURN ((LM_ERROR
,
201 ACE_TEXT("Expected to find a transport in the cache.\n")
204 case TAO::Transport_Cache_Manager::CACHE_FOUND_CONNECTING
:
206 ACE_DEBUG (( LM_DEBUG
,
207 ACE_TEXT ("Transport Cache contains connecting entry as expected.\n")
209 break; // that's what we expected
211 case TAO::Transport_Cache_Manager::CACHE_FOUND_BUSY
:
213 ACE_ERROR_RETURN ((LM_ERROR
,
214 ACE_TEXT("Cached Transport is busy. Should not happen because there's no server.\n")
217 case TAO::Transport_Cache_Manager::CACHE_FOUND_AVAILABLE
:
219 ACE_ERROR_RETURN ((LM_ERROR
,
220 ACE_TEXT("Cached Transport is available. Should not happen because there's no server.\n")
225 ACE_ERROR_RETURN ((LM_ERROR
,
226 ACE_TEXT("Transport_Cache::find returned unknown status.\n")
233 catch (const CORBA::Exception
&ex
)
235 ACE_ERROR ((LM_ERROR
, "ERROR: Exception caught: %s\"%s\"\n"
236 , ex
._name(), ex
._rep_id ()));