00001 /*----------------------------------------------------------------------------- 00002 Name: TestDoubleGlobal.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Testing the Timeout Features 00006 -----------------------------------------------------------------------------*/ 00007 #include <util/qos/ConnectQos.h> 00008 #include <util/qos/ConnectQosFactory.h> 00009 #include <util/XmlBlasterException.h> 00010 #include <util/Global.h> 00011 #include "TestSuite.h" 00012 #include <iostream> 00013 00014 namespace org { namespace xmlBlaster { namespace test { 00015 00016 using namespace std; 00017 using namespace org::xmlBlaster::util; 00018 using namespace org::xmlBlaster::util::qos; 00019 using namespace org::xmlBlaster::util::qos::storage; 00020 using namespace org::xmlBlaster::util::qos::address; 00021 00022 class TestDoubleGlobal 00023 { 00024 private: 00025 string ME; 00026 Global& global_; 00027 I_Log& log_; 00028 Global *global2_; 00029 bool useSessionMarker_; // Remove again at version 2.0 00030 00031 public: 00032 TestDoubleGlobal(Global& glob) 00033 : ME("TestDoubleGlobal"), 00034 global_(glob), 00035 log_(glob.getLog("test")) 00036 { 00037 SessionName sn(global_, "client/dummy"); 00038 useSessionMarker_ = sn.useSessionMarker(); 00039 } 00040 00041 00042 void tearDown() 00043 { 00044 delete global2_; 00045 global2_ = NULL; 00046 } 00047 00048 virtual ~TestDoubleGlobal() 00049 { 00050 } 00051 00052 void setUp() 00053 { 00054 global2_ = new Global(); 00055 global2_->initialize(); 00056 bool overwrite = true; 00057 global2_->getProperty().setProperty("session.name", "pinco/2", overwrite); 00058 } 00059 00060 00061 void sessionQos(Global& glob, const string& shouldSessionName) 00062 { 00063 00064 string me = ME + ".testSessionQos"; 00065 log_.info(me, "testing creation, parsing and output of SessionQos: start"); 00066 00067 string qos = string("<session name='/node/http:/client/ticheta/-3' timeout='86400000' maxSessions='10' \n") + 00068 " clearSessions='false' sessionId='IIOP:01110728321B0222011028'/>\n"; 00069 00070 SessionQosFactory factory(glob); 00071 00072 for (int i=0; i<2; i++) { 00073 SessionQosData data = factory.readObject(qos); 00074 if (useSessionMarker_) 00075 assertEquals(log_, me, string("/node/http:/client/ticheta/session/-3"), data.getAbsoluteName(), "absolute name check"); 00076 else 00077 assertEquals(log_, me, string("/node/http:/client/ticheta/-3"), data.getAbsoluteName(), "absolute name check"); 00078 assertEquals(log_, me, (long)86400000l, data.getTimeout(), "timeout check"); 00079 assertEquals(log_, me, 10, data.getMaxSessions(), "maxSessions check"); 00080 assertEquals(log_, me, false, data.getClearSessions(), "clearSessions check"); 00081 assertEquals(log_, me, string("IIOP:01110728321B0222011028"), data.getSecretSessionId(), "sessionId check"); 00082 SessionQosData ref(glob); 00083 ref.setAbsoluteName("/node/http:/client/ticheta/-3"); 00084 ref.setTimeout(86400000l); 00085 ref.setMaxSessions(10); 00086 ref.setClearSessions(false); 00087 ref.setSecretSessionId("IIOP:01110728321B0222011028"); 00088 string lit1 = data.toXml(); 00089 string lit2 = ref.toXml(); 00090 if (log_.trace()) { 00091 log_.trace(me, string("xml is: ") + lit1); 00092 log_.trace(me, string("xml should be: ") + lit2); 00093 } 00094 assertEquals(log_, me, lit2, lit1, "sessionId check"); 00095 } 00096 00097 // make sure the property 'session.name' has not been set on the command line or on the prop. file 00098 string name = glob.getProperty().getStringProperty("session.name", ""); 00099 assertEquals(log_, me, shouldSessionName, name, "non setting of property 'session.name'"); 00100 SessionQosData data1(glob, "Fritz"); 00101 assertEquals(log_, me, string("client/Fritz"), data1.getAbsoluteName(), "checking constructor with 'user' and 'pubSessionId=0'"); 00102 00103 glob.getProperty().setProperty("user", "PincoPallino"); 00104 name = glob.getProperty().getStringProperty("user", ""); 00105 assertEquals(log_, me, string("PincoPallino"), name, "checking if property 'user' has been set correctly"); 00106 00107 // set the property now 00108 glob.getProperty().setProperty("session.name", "/node/australia/client/Martin/4"); 00109 name = glob.getProperty().getStringProperty("session.name", ""); 00110 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking if property 'session.name' has been set correctly"); 00111 data1 = SessionQosData(glob, "Nisse/3", 0); 00112 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking when 'session.name' is strongest"); 00113 00114 data1 = SessionQosData(glob); 00115 data1.setAbsoluteName("/node/frodo/client/whoMore/3"); 00116 if (useSessionMarker_) 00117 assertEquals(log_, me, string("/node/frodo/client/whoMore/session/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker"); 00118 else 00119 assertEquals(log_, me, string("/node/frodo/client/whoMore/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker"); 00120 log_.info(me, "testing creation, parsing and output of SessionQos: end"); 00121 } 00122 00123 void testSessionQos() { 00124 sessionQos(global_, string("")); 00125 sessionQos(*global2_, string("pinco/2")); 00126 } 00127 00128 00129 }; 00130 00131 }}} // namespace 00132 00133 00134 using namespace org::xmlBlaster::test; 00135 00143 int main(int args, char ** argv) 00144 { 00145 try { 00146 org::xmlBlaster::util::Object_Lifetime_Manager::init(); 00147 Global& glob = Global::getInstance(); 00148 glob.initialize(args, argv); 00149 00150 TestDoubleGlobal testConnectQos(glob); 00151 00152 testConnectQos.setUp(); 00153 testConnectQos.testSessionQos(); 00154 testConnectQos.tearDown(); 00155 00156 org::xmlBlaster::util::Object_Lifetime_Manager::fini(); 00157 } 00158 catch (XmlBlasterException& ex) { 00159 std::cout << ex.toXml() << std::endl; 00160 } 00161 catch (bad_exception& ex) { 00162 cout << "bad_exception: " << ex.what() << endl; 00163 } 00164 catch (exception& ex) { 00165 cout << " exception: " << ex.what() << endl; 00166 } 00167 catch (string& ex) { 00168 cout << "string: " << ex << endl; 00169 } 00170 catch (char* ex) { 00171 cout << "char* : " << ex << endl; 00172 } 00173 00174 catch (...) 00175 { 00176 cout << "unknown exception occured" << endl; 00177 XmlBlasterException e(INTERNAL_UNKNOWN, "main", "main thread"); 00178 cout << e.toXml() << endl; 00179 } 00180 return 0; 00181 }