00001 /*----------------------------------------------------------------------------- 00002 Name: TestCorbaDriver.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Testing the Timeout Features 00006 -----------------------------------------------------------------------------*/ 00007 #ifdef COMPILE_CORBA_PLUGIN 00008 00009 #include <client/protocol/corba/CorbaDriverFactory.h> 00010 #include "TestSuite.h" 00011 #include <iostream> 00012 00013 using namespace std; 00014 using namespace org::xmlBlaster::util; 00015 using namespace org::xmlBlaster::util::thread; 00016 using namespace org::xmlBlaster::client::protocol::corba; 00017 00018 00019 namespace org { namespace xmlBlaster { namespace test { 00020 00021 class TestCorbaDriver 00022 { 00023 private: 00024 string ME; 00025 Global& global_; 00026 I_Log& log_; 00027 Mutex updateMutex_; 00028 int numOfUpdates_; 00029 CorbaDriverFactory& factory_; 00030 00031 public: 00032 00033 TestCorbaDriver(Global& glob) 00034 : ME("TestCorbaDriver"), 00035 global_(glob), 00036 log_(glob.getLog()), 00037 updateMutex_(), 00038 factory_(CorbaDriverFactory::getFactory(glob)) 00039 { 00040 } 00041 00042 00043 void tearDown() 00044 { 00045 } 00046 00047 virtual ~TestCorbaDriver() 00048 { 00049 } 00050 00051 void setUp() 00052 { 00053 } 00054 00055 void testSingleDriver() 00056 { 00057 log_.info(ME, "testing single driver: start"); 00058 CorbaDriver& driver1 = factory_.getDriverInstance(&global_); 00059 CorbaDriver& driver2 = factory_.getDriverInstance(&global_); 00060 CorbaDriver& driver3 = factory_.getDriverInstance(&global_); 00061 // should be three instances with the name 'one' now ... 00062 00063 assertEquals(log_, ME, &driver1, &driver2, "Both 'one' drivers should share the same address"); 00064 assertEquals(log_, ME, &driver2, &driver3, "Both 'one' drivers should share the same address"); 00065 assertEquals(log_, ME, 2, factory_.killDriverInstance(&global_), "number of 'one' instances should be 2 (after deletion)"); 00066 Thread::sleepSecs(1); 00067 assertEquals(log_, ME, 1, factory_.killDriverInstance(&global_), "number of 'one' instances should be 1 (after deletion)"); 00068 Thread::sleepSecs(1); 00069 assertEquals(log_, ME, 0, factory_.killDriverInstance(&global_), "number of 'one' instances should be 0 (after deletion)"); 00070 Thread::sleepSecs(1); 00071 assertEquals(log_, ME, -1, factory_.killDriverInstance(&global_), "number of 'one' instances should be -1 (after deletion)"); 00072 Thread::sleepSecs(1); 00073 assertEquals(log_, ME, -1, factory_.killDriverInstance(&global_), "number of 'one' instances should be -1 (after deletion)"); 00074 log_.info(ME, "testing single driver: end"); 00075 } 00076 00077 void testMultipleDrivers() 00078 { 00079 log_.info(ME, "testing multiple drivers: start"); 00080 Global glob2; 00081 Global glob3; 00082 CorbaDriver& driver1 = factory_.getDriverInstance(&global_); 00083 CorbaDriver& driver2 = factory_.getDriverInstance(&glob2); 00084 CorbaDriver& driver3 = factory_.getDriverInstance(&glob3); 00085 factory_.getDriverInstance(&glob2); 00086 factory_.getDriverInstance(&glob3); 00087 // should be three instances with the name 'one' now ... 00088 00089 assertDifferes(log_, ME, &driver1, &driver2, "'one' and 'two' should NOT share the same address"); 00090 assertDifferes(log_, ME, &driver2, &driver3, "Both 'one' drivers should share the same address"); 00091 00092 Thread::sleepSecs(1); 00093 assertEquals(log_, ME, 0, factory_.killDriverInstance(&global_), "number of 'one' instances should be 0 (after deletion)"); 00094 Thread::sleepSecs(1); 00095 assertEquals(log_, ME, -1, factory_.killDriverInstance(&global_), "number of 'one' instances should be -1 (after deletion)"); 00096 Thread::sleepSecs(1); 00097 assertEquals(log_, ME, 1, factory_.killDriverInstance(&glob2), "number of 'two' instances should be 1 (after deletion)"); 00098 Thread::sleepSecs(1); 00099 assertEquals(log_, ME, 1, factory_.killDriverInstance(&glob3), "number of 'three' instances should be 1 (after deletion)"); 00100 Thread::sleepSecs(1); 00101 assertEquals(log_, ME, 0, factory_.killDriverInstance(&glob3), "number of 'three' instances should be 0 (after deletion)"); 00102 // here the thread still should be running ... 00103 Thread::sleepSecs(2); 00104 assertEquals(log_, ME, 0, factory_.killDriverInstance(&glob2), "number of 'two' instances should be 0 (after deletion)"); 00105 log_.info(ME, "testing multiple drivers: end"); 00106 } 00107 00108 }; 00109 00110 }}} 00111 00119 using namespace org::xmlBlaster::test; 00120 00121 int main(int args, char ** argv) 00122 { 00123 try { 00124 org::xmlBlaster::util::Object_Lifetime_Manager::init(); 00125 Global& glob = Global::getInstance(); 00126 glob.initialize(args, argv); 00127 00128 TestCorbaDriver test(glob); 00129 test.setUp(); 00130 test.testSingleDriver(); 00131 test.tearDown(); 00132 00133 test.setUp(); 00134 test.testMultipleDrivers(); 00135 test.tearDown(); 00136 org::xmlBlaster::util::Object_Lifetime_Manager::fini(); 00137 } 00138 catch (XmlBlasterException& ex) { 00139 std::cout << ex.toXml() << std::endl; 00140 } 00141 catch (bad_exception& ex) { 00142 cout << "bad_exception: " << ex.what() << endl; 00143 } 00144 catch (exception& ex) { 00145 cout << " exception: " << ex.what() << endl; 00146 } 00147 catch (string& ex) { 00148 cout << "string: " << ex << endl; 00149 } 00150 catch (char* ex) { 00151 cout << "char* : " << ex << endl; 00152 } 00153 00154 catch (...) 00155 { 00156 cout << "unknown exception occured" << endl; 00157 XmlBlasterException e(INTERNAL_UNKNOWN, "main", "main thread"); 00158 cout << e.toXml() << endl; 00159 } 00160 00161 return 0; 00162 } 00163 00164 #else // COMPILE_CORBA_PLUGIN 00165 #include <iostream> 00166 int main(int args, char ** argv) 00167 { 00168 ::std::cout << "TestCorbaDriver: COMPILE_CORBA_PLUGIN is not defined, nothing to do" << ::std::endl; 00169 return 0; 00170 } 00171 #endif // COMPILE_CORBA_PLUGIN 00172