diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-22 18:53:42 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-22 18:53:42 +0000 |
commit | d5c89c0858f351389dabe7b3ee55f1a1c36ef14b (patch) | |
tree | 71017a3db937722354222eb80ff5f06a962f731a /tests/Timer_Cancellation_Test.cpp | |
parent | 85a5337fdd6ad331b82536f934edc5c091444f28 (diff) | |
download | ATCD-Reactor_RefCount_1.tar.gz |
ChangeLogTag: Thu May 22 14:13:37 2003 Irfan Pyarali <irfan@oomworks.com>Reactor_RefCount_1
Diffstat (limited to 'tests/Timer_Cancellation_Test.cpp')
-rw-r--r-- | tests/Timer_Cancellation_Test.cpp | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/tests/Timer_Cancellation_Test.cpp b/tests/Timer_Cancellation_Test.cpp new file mode 100644 index 00000000000..6ba4c794535 --- /dev/null +++ b/tests/Timer_Cancellation_Test.cpp @@ -0,0 +1,160 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests +// +// = FILENAME +// Timer_Cancellation_Test.cpp +// +// = DESCRIPTION +// A test to ensure the timer cancellation works correctly. +// +// = AUTHOR +// Irfan Pyarali <irfan@oomworks.com> +// +// ============================================================================ + +#include "tests/test_config.h" +#include "ace/TP_Reactor.h" +#include "ace/Task.h" + +ACE_RCSID(tests, Timer_Cancellation_Test, "$Id$") + +#if defined (ACE_HAS_THREADS) + +class Deadlock : public ACE_Task_Base +{ +public: + + int svc (void); + + int handle_timeout (const ACE_Time_Value ¤t_time, + const void *act); +}; + +int +Deadlock::svc (void) +{ + ACE_DEBUG ((LM_DEBUG, + "Deadlock starts accessing Reactor and Timer Queue....\n")); + + this->reactor ()->schedule_timer (this, + 0, + ACE_Time_Value (1)); + + ACE_DEBUG ((LM_DEBUG, + "Deadlock completes accessing Reactor and Timer Queue....\n")); + + return 0; +} + +int +Deadlock::handle_timeout (const ACE_Time_Value &, + const void *) +{ + ACE_DEBUG ((LM_DEBUG, + "Deadlock timeout\n")); + + return 0; +} + +class Event_Handler : public ACE_Event_Handler +{ +public: + + Event_Handler (Deadlock &deadlock); + + int handle_timeout (const ACE_Time_Value ¤t_time, + const void *act); + + int handle_close (ACE_HANDLE handle, + ACE_Reactor_Mask close_mask); + + Deadlock &deadlock_; +}; + +Event_Handler::Event_Handler (Deadlock &deadlock) + : deadlock_ (deadlock) +{ +} + +int +Event_Handler::handle_timeout (const ACE_Time_Value &, + const void *) +{ + ACE_DEBUG ((LM_DEBUG, + "Event_Handler timeout\n")); + + return -1; +} + +int +Event_Handler::handle_close (ACE_HANDLE, + ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, + "Event_Handler closed\n")); + + // Activate Deadlock. + this->deadlock_.activate (); + + // Give Deadlock a chance to deadlock... ;-) + ACE_OS::sleep (1); + + ACE_DEBUG ((LM_DEBUG, + "Event Handler starts accessing Reactor....\n")); + + // This is a superfluous call to the Reactor to acquire its lock. + this->reactor ()->max_notify_iterations (); + + ACE_DEBUG ((LM_DEBUG, + "Event Handler completes accessing Reactor....\n")); + + return 0; +} + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test")); + + ACE_Reactor reactor (new ACE_TP_Reactor, + 1); + + Deadlock deadlock; + deadlock.reactor (&reactor); + + Event_Handler handler (deadlock); + + // Scheduler a timer to kick things off. + reactor.schedule_timer (&handler, + 0, + ACE_Time_Value (1)); + + // Run the event loop for a while. + ACE_Time_Value timeout (4); + reactor.run_reactor_event_loop (timeout); + + ACE_END_TEST; + + return 0; +} + +#else /* ACE_HAS_THREADS */ + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test")); + + ACE_ERROR ((LM_INFO, + ACE_TEXT ("threads not supported on this platform\n"))); + + ACE_END_TEST; + + return 0; +} + +#endif /* ACE_HAS_THREADS */ |