00001 /*----------------------------------------------------------------------------- 00002 Name: TestConnectQos.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 TestConnectQos 00023 { 00024 private: 00025 string ME; 00026 Global& global_; 00027 I_Log& log_; 00028 bool useSessionMarker_; // Remove again at version 2.0 00029 00030 public: 00031 TestConnectQos(Global& glob) 00032 : ME("TestConnectQos"), 00033 global_(glob), 00034 log_(glob.getLog("test")) 00035 { 00036 SessionName sn(global_, "client/dummy"); 00037 useSessionMarker_ = sn.useSessionMarker(); 00038 //useSessionMarker_ = global_.getProperty().getBoolProperty("xmlBlaster/useSessionMarker", true); 00039 } 00040 00041 00042 void tearDown() 00043 { 00044 } 00045 00046 virtual ~TestConnectQos() 00047 { 00048 } 00049 00050 void setUp() 00051 { 00052 } 00053 00054 00055 void testSessionQos() 00056 { 00057 00058 string me = ME + ".testSessionQos"; 00059 log_.info(me, "testing creation, parsing and output of SessionQos: start"); 00060 log_.info(me, "useSessionMarker=" + lexical_cast<std::string>(useSessionMarker_)); 00061 00062 string qos = string("<session name='/node/http:/client/ticheta/-3' timeout='86400000' maxSessions='10' \n") + 00063 " clearSessions='false' sessionId='IIOP:01110728321B0222011028'/>\n"; 00064 00065 SessionQosFactory factory(global_); 00066 00067 for (int i=0; i<2; i++) { 00068 SessionQosData data = factory.readObject(qos); 00069 if (useSessionMarker_) 00070 assertEquals(log_, me, string("/node/http:/client/ticheta/session/-3"), data.getAbsoluteName(), "absolute name check"); 00071 else 00072 assertEquals(log_, me, string("/node/http:/client/ticheta/-3"), data.getAbsoluteName(), "absolute name check"); 00073 assertEquals(log_, me, (long)86400000l, data.getTimeout(), "timeout check"); 00074 assertEquals(log_, me, 10, data.getMaxSessions(), "maxSessions check"); 00075 assertEquals(log_, me, false, data.getClearSessions(), "clearSessions check"); 00076 assertEquals(log_, me, string("IIOP:01110728321B0222011028"), data.getSecretSessionId(), "sessionId check"); 00077 SessionQosData ref(global_); 00078 ref.setAbsoluteName("/node/http:/client/ticheta/-3"); 00079 ref.setTimeout(86400000l); 00080 ref.setMaxSessions(10); 00081 ref.setClearSessions(false); 00082 ref.setSecretSessionId("IIOP:01110728321B0222011028"); 00083 string lit1 = data.toXml(); 00084 string lit2 = ref.toXml(); 00085 if (log_.trace()) { 00086 log_.trace(me, string("xml is: ") + lit1); 00087 log_.trace(me, string("xml should be: ") + lit2); 00088 } 00089 assertEquals(log_, me, lit2, lit1, "sessionId check"); 00090 } 00091 00092 // make sure the property 'session.name' has not been set on the command line or on the prop. file 00093 string name = global_.getProperty().getStringProperty("session.name", ""); 00094 assertEquals(log_, me, string(""), name, "non setting of property 'session.name'"); 00095 SessionQosData data1(global_, "Fritz", 0); 00096 assertEquals(log_, me, string("client/Fritz"), data1.getAbsoluteName(), "checking constructor with 'user' and 'pubSessionId=0'"); 00097 data1 = SessionQosData(global_, "Franz", -3); 00098 if (useSessionMarker_) 00099 assertEquals(log_, me, string("client/Franz/session/-3"), data1.getAbsoluteName(), "checking constructor with relative name"); 00100 else 00101 assertEquals(log_, me, string("client/Franz/-3"), data1.getAbsoluteName(), "checking constructor with relative name"); 00102 00103 global_.getProperty().setProperty("user.name", "PincoPallino"); 00104 name = global_.getProperty().getStringProperty("user.name", ""); 00105 assertEquals(log_, me, string("PincoPallino"), name, "checking if property 'user' has been set correctly"); 00106 00107 data1 = SessionQosData(global_, "", 6); 00108 if (useSessionMarker_) 00109 assertEquals(log_, me, string("client/PincoPallino/session/6"), data1.getAbsoluteName(), "checking constructor with empty defaultUserName when 'user' set"); 00110 else 00111 assertEquals(log_, me, string("client/PincoPallino/6"), data1.getAbsoluteName(), "checking constructor with empty defaultUserName when 'user' set"); 00112 00113 data1 = SessionQosData(global_, "Nisse", 0); 00114 assertEquals(log_, me, string("client/Nisse"), data1.getAbsoluteName(), "checking constructor with set defaultUserName when 'user' set"); 00115 00116 00117 // set the property now 00118 global_.getProperty().setProperty("session.name", "/node/australia/client/Martin/4"); 00119 name = global_.getProperty().getStringProperty("session.name", ""); 00120 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking if property 'session.name' has been set correctly"); 00121 data1 = SessionQosData(global_, "Nisse/3", 0); 00122 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking when 'session.name' is strongest"); 00123 00124 data1 = SessionQosData(global_); 00125 data1.setAbsoluteName("/node/frodo/client/whoMore/3"); 00126 if (useSessionMarker_) 00127 assertEquals(log_, me, string("/node/frodo/client/whoMore/session/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker"); 00128 else 00129 assertEquals(log_, me, string("/node/frodo/client/whoMore/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker"); 00130 log_.info(me, "testing creation, parsing and output of SessionQos: end"); 00131 } 00132 00133 00134 void testQueueProperty() 00135 { 00136 string me = ME + "::testQueueProperty"; 00137 log_.info(me, "testing queue properties parsing: start"); 00138 00139 string qos = string("<queue relating='connection' storeSwapLevel='1468006' storeSwapBytes='524288' ") + 00140 string(" reloadSwapLevel='629145' reloadSwapBytes='524288'>\n") + 00141 string(" <address type='IOR' bootstrapHostname='127.0.0.2' dispatchPlugin='undef'>") + 00142 string(" <burstMode collectTime='400' maxEntries='20' maxBytes='3900' />") + 00143 string(" http://127.0.0.2:3412\n") + 00144 string(" <attribute name='corrId' type='int'>120001</attribute>\n") + 00145 string(" </address>\n") + 00146 string("</queue>\n"); 00147 00148 QueuePropertyFactory factory(global_); 00149 for (int i=0; i < 2; i++) { 00150 QueuePropertyBase propBase = factory.readObject(qos); 00151 ClientQueueProperty prop(propBase); 00152 assertEquals(log_, me, string("connection"), prop.getRelating(), "relating check"); 00153 assertEquals(log_, me, 1468006L, prop.getStoreSwapLevel(), "storeSwapLevel check"); 00154 assertEquals(log_, me, 524288L, prop.getStoreSwapBytes(), "storeSwapBytes check"); 00155 assertEquals(log_, me, 629145L, prop.getReloadSwapLevel(), "reloadSwapLevel check"); 00156 assertEquals(log_, me, 524288L, prop.getReloadSwapBytes(), "reloadSwapBytes check"); 00157 00158 AddressBaseRef address = prop.getCurrentAddress(); 00159 assertEquals(log_, me, string("IOR"), address->getType(), "address type check"); 00160 assertEquals(log_, me, string("127.0.0.2"), address->getHostname(), "address hostname check"); 00161 assertEquals(log_, me, string("undef"), address->getDispatchPlugin(), "address dispatch Plugin check"); 00162 assertEquals(log_, me, 400L, address->getCollectTime(), "collectTime check"); 00163 assertEquals(log_, me, 20, address->getBurstModeMaxEntries(), "getBurstModeMaxEntries check"); 00164 assertEquals(log_, me, 3900L, address->getBurstModeMaxBytes(), "getBurstModeMaxBytes check"); 00165 org::xmlBlaster::util::qos::address::AddressBase::ClientPropertyMap map = address->getAttributes(); 00166 assertEquals(log_, me, 1L, map.size(), "no attribute"); 00167 00168 if (log_.trace()) log_.trace(me, string("the queue property literal: ") + prop.toXml()); 00169 } 00170 log_.info(me, "testing queue properties parsing: end"); 00171 } 00172 00173 00174 void testConnectQos() 00175 { 00176 string me = ME + "::testConnectQos"; 00177 log_.info(me, "testing parsing of a return connect qos: start"); 00178 string defaultBoolStr[2] = { "true", "false" }; 00179 for (int jj=0; jj<2; jj++) { 00180 bool defaultBool = lexical_cast<bool>(defaultBoolStr[jj]); 00181 string qos = 00182 string("<qos>\n") + 00183 string(" <securityService type='htpasswd' version='1.0'><![CDATA[\n") + 00184 string(" <user>Tim</user>\n") + 00185 string(" <passwd>secret</passwd>\n") + 00186 string(" ]]></securityService>\n") + 00187 string(" <ptp>")+defaultBoolStr[jj]+string("</ptp>\n") + 00188 string(" <clusterNode>")+defaultBoolStr[jj]+string("</clusterNode>\n") + 00189 string(" <instanceId>/xmlBlaster/node/heron/client/Tim/session/-3/instanceId/123445</instanceId>\n") + 00190 string(" <reconnected>")+defaultBoolStr[jj]+string("</reconnected>\n") + 00191 string(" <refreshSession>")+defaultBoolStr[jj]+string("</refreshSession>\n") + 00192 string(" <duplicateUpdates>")+defaultBoolStr[jj]+string("</duplicateUpdates>\n") + 00193 string(" <duplicateUpdates>")+defaultBoolStr[jj]+string("</duplicateUpdates>\n") + 00194 string(" <session name='/node/http_127_0_0_2_3412/client/Tim/-3' timeout='86400000' maxSessions='10' clearSessions='")+defaultBoolStr[jj]+string("' sessionId='IIOP:01110C332A141532012A0F'/>\n") + 00195 string(" <queue relating='connection' storeSwapLevel='1468006' storeSwapBytes='524288' reloadSwapLevel='629145' reloadSwapBytes='524288'>\n") + 00196 string(" <address type='IOR' bootstrapHostname='127.0.0.2' dispatchPlugin='undef'>\n") + 00197 string(" http://127.0.0.2:3412\n") + 00198 string(" <attribute name='someConnectFloat' size='3' type='float'>1.5</attribute>\n") + 00199 string(" </address>\n") + 00200 string(" </queue>\n") + 00201 string(" <queue relating='callback' type='CACHE' version='1.0' maxEntries='10000000' storeSwapLevel='1468006' storeSwapBytes='524288' reloadSwapLevel='629145' reloadSwapBytes='524288'>\n") + 00202 string(" <callback type='IOR' bootstrapHostname='127.0.0.1' dispatchPlugin='undef'>\n") + 00203 string(" IOR:010000004000000049444c3a6f72672e786d6c426c61737465722e70726f746f636f6c2e636f7262612f636c69656e7449646c2f426c617374657243616c6c6261636b3a312e300002000000000000002f000000010100000c0000006c696e75782e6c6f63616c00a6820000130000002f353936372f313034323232363530392f5f30000100000024000000010000000100000001000000140000000100000001000100000000000901010000000000\n") + 00204 string(" <burstMode collectTime='400' maxEntries='20' maxBytes='-1' />\n") + 00205 string(" <attribute name='someString'>BlaBla</attribute>\n") + 00206 string(" <attribute name='someString2'>BlaBla2</attribute>\n") + 00207 string(" </callback>\n") + 00208 string(" </queue>\n") + 00209 string(" <serverRef type='IOR'>\n") + 00210 string(" IOR:000000000000003749444c3a6f72672e786d6c426c61737465722e70726f746f636f6c2e636f7262612f73657276657249646c2f5365727665723a312e300000000000030000000000000043000100000000000a3132372e302e302e320082980000002b5374616e64617264496d706c4e616d652f786d6c426c61737465722d504f412f01110c332a141532012a0f000000000000000048000101000000000a3132372e302e302e320082980000002b5374616e64617264496d706c4e616d652f786d6c426c61737465722d504f412f01110c332a141532012a0f0000000000000000010000002c0000000000000001000000010000001c00000000000100010000000105010001000101090000000105010001\n") + 00211 string(" </serverRef>\n") + 00212 string(" <clientProperty name='intKey' type='int'>123</clientProperty>\n") + 00213 string(" <clientProperty name='StringKey' type='String' encoding='") + Constants::ENCODING_BASE64 + string("'>QmxhQmxhQmxh</clientProperty>\n") + 00214 string(" <persistent>")+defaultBoolStr[jj]+string("</persistent>\n") + 00215 string(" </qos>\n"); 00216 00217 ConnectQosFactory factory(global_); 00218 for (int i=0; i < 2; i++) { 00219 ConnectQosRef connQos = factory.readObject(qos); 00220 string qos2 = connQos->toXml(); 00221 connQos = factory.readObject(qos2); // round trip: parse -> dump -> parse again -> check 00222 assertEquals(log_, me, "/xmlBlaster/node/heron/client/Tim/session/-3/instanceId/123445", connQos->getInstanceId(), "check 'instanceId' flag"); 00223 assertEquals(log_, me, defaultBool, connQos->getPtp(), "check 'ptp' flag"); 00224 assertEquals(log_, me, defaultBool, connQos->isClusterNode(), "check 'clusterNode' flag"); 00225 assertEquals(log_, me, defaultBool, connQos->isRefreshSession(), "check 'refreshSession' flag"); 00226 assertEquals(log_, me, defaultBool, connQos->isDuplicateUpdates(), "check 'duplicateUpdates' flag"); 00227 assertEquals(log_, me, defaultBool, connQos->isPersistent(), "check 'persistent' flag"); 00228 assertEquals(log_, me, 123, connQos->getClientProperty("intKey", 0), "check 'intKey' flag"); 00229 // Base64: QmxhQmxhQmxh -> BlaBlaBla 00230 assertEquals(log_, me, string("BlaBlaBla"), connQos->getClientProperty("StringKey", string("wrong")), "check 'StringKey' flag"); 00231 assertEquals(log_, me, "IIOP:01110C332A141532012A0F", connQos->getSecretSessionId(), "check 'secretSessionId' flag"); 00232 assertEquals(log_, me, 20, connQos->getCbAddress()->getBurstModeMaxEntries(), "getBurstModeMaxEntries check"); 00233 // TODO: other checks! 00234 00235 log_.info(me, string("connect qos: ") + connQos->toXml()); 00236 } 00237 } 00238 } 00239 }; 00240 00241 }}} // namespace 00242 00243 00244 using namespace org::xmlBlaster::test; 00245 00253 int main(int args, char ** argv) 00254 { 00255 try { 00256 org::xmlBlaster::util::Object_Lifetime_Manager::init(); 00257 Global& glob = Global::getInstance(); 00258 glob.initialize(args, argv); 00259 00260 TestConnectQos testConnectQos(glob); 00261 00262 testConnectQos.setUp(); 00263 testConnectQos.testSessionQos(); 00264 testConnectQos.tearDown(); 00265 testConnectQos.setUp(); 00266 testConnectQos.testQueueProperty(); 00267 testConnectQos.tearDown(); 00268 testConnectQos.setUp(); 00269 testConnectQos.testConnectQos(); 00270 testConnectQos.tearDown(); 00271 org::xmlBlaster::util::Object_Lifetime_Manager::fini(); 00272 } 00273 catch (XmlBlasterException& ex) { 00274 std::cout << ex.toXml() << std::endl; 00275 } 00276 catch (bad_exception& ex) { 00277 cout << "bad_exception: " << ex.what() << endl; 00278 } 00279 catch (exception& ex) { 00280 cout << " exception: " << ex.what() << endl; 00281 } 00282 catch (string& ex) { 00283 cout << "string: " << ex << endl; 00284 } 00285 catch (char* ex) { 00286 cout << "char* : " << ex << endl; 00287 } 00288 00289 catch (...) 00290 { 00291 cout << "unknown exception occured" << endl; 00292 XmlBlasterException e(INTERNAL_UNKNOWN, "main", "main thread"); 00293 cout << e.toXml() << endl; 00294 } 00295 return 0; 00296 }