2 //=============================================================================
6 * This class implements a number of test objects to test the
9 * @author Torben Worm <tworm@cs.wustl.edu>
11 //=============================================================================
15 #include "ace/Log_Msg.h"
17 CC_Test::CC_Test (CC_naming_service
*ns
)
27 CosConcurrencyControl::LockSet_ptr
28 CC_Test::create_lock_set ()
30 // Create the lock set and return an obj ref corresponding to the
32 CosConcurrencyControl::LockSet_ptr
lock_set(0);
36 this->naming_service_
->get_lock_set_factory ()->create ();
38 if (CORBA::is_nil (lock_set
))
39 ACE_ERROR_RETURN ((LM_ERROR
,
40 "null lock set objref returned by factory\n"),
43 catch (const CORBA::Exception
& ex
)
45 ex
._tao_print_exception ("CC_Client::create_lock_set");
52 CC_Test::get_lock_mode_name (CosConcurrencyControl::lock_mode mode
)
54 if (mode
==CosConcurrencyControl::read
)
55 return const_cast<char *> ("read");
57 if (mode
==CosConcurrencyControl::write
)
58 return const_cast<char *> ("write");
60 if (mode
==CosConcurrencyControl::upgrade
)
61 return const_cast<char *> ("upgrade");
63 if (mode
==CosConcurrencyControl::intention_read
)
64 return const_cast<char *> ("intension_read");
66 if (mode
==CosConcurrencyControl::intention_write
)
67 return const_cast<char *> ("intension_write");
69 return const_cast<char *> ("unknown lock mode");
72 // ================================
73 // Here the tests start.
75 Test_Single_Lock_With_Mode::Test_Single_Lock_With_Mode (CC_naming_service
*naming_service
,
76 CosConcurrencyControl::lock_mode mode
)
77 : CC_Test (naming_service
),
82 Test_Single_Lock_With_Mode::~Test_Single_Lock_With_Mode ()
87 Test_Single_Lock_With_Mode::run (int /* times_to_run */)
89 CORBA::Boolean lock_not_held
;
91 CosConcurrencyControl::LockSet_ptr cc_lock_set_
= create_lock_set ();
95 cc_lock_set_
->lock (mode_
);
99 get_lock_mode_name (mode_
)));
101 lock_not_held
= cc_lock_set_
->try_lock (mode_
);
105 ACE_DEBUG ((LM_DEBUG
,
106 "%s lock not held\n",
107 get_lock_mode_name (mode_
)));
111 ACE_DEBUG ((LM_DEBUG
,
113 get_lock_mode_name (mode_
)));
115 cc_lock_set_
->unlock (mode_
);
116 ACE_DEBUG ((LM_DEBUG
,
117 "%s lock released\n",
118 get_lock_mode_name (mode_
)));
120 lock_not_held
= cc_lock_set_
->try_lock (mode_
);
123 ACE_DEBUG ((LM_DEBUG
,
124 "%s lock not held\n",
125 get_lock_mode_name (mode_
)));
128 ACE_DEBUG ((LM_DEBUG
,
130 get_lock_mode_name (mode_
)));
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Test_Single_Lock_With_Mode::run");
141 CORBA::release (cc_lock_set_
);
146 // ================================
148 Test_Setup_LockSet::Test_Setup_LockSet (CC_naming_service
*naming_service
,
150 : CC_Test (naming_service
),
155 Test_Setup_LockSet::~Test_Setup_LockSet ()
160 Test_Setup_LockSet::run (int /* times_to_run */)
164 CosConcurrencyControl::LockSet_ptr cc_lock_set_
=
166 this->naming_service_
->bind_name (my_name_
, cc_lock_set_
);
168 ACE_DEBUG ((LM_DEBUG
,
171 cc_lock_set_
->lock (CosConcurrencyControl::read
);
173 ACE_DEBUG ((LM_DEBUG
,
176 catch (const CORBA::Exception
& ex
)
178 ex
._tao_print_exception ("Test_Against_Other_LockSet::run");
185 // ================================
187 Test_Use_Already_Created_LockSet::
188 Test_Use_Already_Created_LockSet (CC_naming_service
*naming_service
,
190 : CC_Test (naming_service
),
195 Test_Use_Already_Created_LockSet::~Test_Use_Already_Created_LockSet ()
200 Test_Use_Already_Created_LockSet::run (int /* times_to_run */)
204 CORBA::Object_var ccls_obj
=
205 this->naming_service_
->get_obj_from_name (const_cast<char *> (""),
208 CosConcurrencyControl::LockSet_var ccls
=
209 CosConcurrencyControl::LockSet::_narrow (ccls_obj
.in ());
211 ccls
->lock (CosConcurrencyControl::read
);
213 catch (const CORBA::Exception
& ex
)
215 ex
._tao_print_exception ("Test_Against_Other_LockSet::run");
222 // ================================
224 Test_Unlock_Already_Created_LockSet::
225 Test_Unlock_Already_Created_LockSet (CC_naming_service
*naming_service
,
227 : CC_Test (naming_service
),
232 Test_Unlock_Already_Created_LockSet::~Test_Unlock_Already_Created_LockSet ()
237 Test_Unlock_Already_Created_LockSet::run (int /* times_to_run */)
241 CORBA::Object_var ccls_obj
=
242 this->naming_service_
->get_obj_from_name (const_cast<char *> (""), my_name_
);
244 CosConcurrencyControl::LockSet_var ccls
=
245 CosConcurrencyControl::LockSet::_narrow (ccls_obj
.in ());
247 ccls
->unlock (CosConcurrencyControl::read
);
249 catch (const CORBA::Exception
& ex
)
251 ex
._tao_print_exception ("Test_Unlock_Already_Created_LockSet::run");
258 // ================================
260 Test_Release_Not_Held_Lock::Test_Release_Not_Held_Lock (CC_naming_service
*naming_service
,
261 CosConcurrencyControl::lock_mode mode
)
262 : CC_Test (naming_service
),
267 Test_Release_Not_Held_Lock::~Test_Release_Not_Held_Lock ()
272 Test_Release_Not_Held_Lock::run (int /* times_to_run */)
274 CORBA::Boolean lock_not_held
;
276 // Create the lock set
277 CosConcurrencyControl::LockSet_ptr cc_lock_set_
= create_lock_set ();
281 cc_lock_set_
->lock (mode_
);
283 ACE_DEBUG ((LM_DEBUG
,
285 get_lock_mode_name (mode_
)));
287 // check to see if the lock is held
288 lock_not_held
= cc_lock_set_
->try_lock (mode_
);
292 ACE_DEBUG ((LM_DEBUG
,
293 "%s lock not held\n",
294 get_lock_mode_name (mode_
)));
298 ACE_DEBUG ((LM_DEBUG
,
300 get_lock_mode_name (mode_
)));
303 cc_lock_set_
->unlock (mode_
);
304 ACE_DEBUG ((LM_DEBUG
,
305 "%s lock released\n",
306 get_lock_mode_name (mode_
)));
308 // release the lock again. this should raise an exception
309 cc_lock_set_
->unlock (mode_
);
311 ACE_DEBUG ((LM_DEBUG
,
312 "attemptet to release %s lock\n",
313 get_lock_mode_name (mode_
)));
315 catch (const CosConcurrencyControl::LockNotHeld
& userex
)
317 // We should end here
318 ACE_UNUSED_ARG (userex
);
319 ACE_DEBUG((LM_DEBUG
, "CosConcurrencyControl::LockNotHeld\n"));
323 catch (const CORBA::Exception
& ex
)
325 ex
._tao_print_exception ("Test_Release_Not_Held_Lock::run");
329 CORBA::release (cc_lock_set_
);