📄 alltests.cpp
字号:
this->nodes.erase(name); updated("node `" + name + "' down"); } virtual void updateServer(const string& node, const ServerDynamicInfo& info, const Ice::Current& current) { if(info.id == "Glacier2" || info.id == "Glacier2Admin" || info.id == "PermissionsVerifierServer") { return; } Lock sync(*this); //cerr << node << " " << info.id << " " << info.state << " " << info.pid << endl; ServerDynamicInfoSeq& servers = this->nodes[node].servers; ServerDynamicInfoSeq::iterator p; for(p = servers.begin(); p != servers.end(); ++p) { if(p->id == info.id) { if(info.state == Destroyed) { servers.erase(p); } else { *p = info; } break; } } if(info.state != Destroyed && p == servers.end()) { servers.push_back(info); } ostringstream os; os << "server `" << info.id << "' on node `" << node << "' state updated: " << info.state << " (pid = " << info.pid << ")"; updated(os.str()); } virtual void updateAdapter(const string& node, const AdapterDynamicInfo& info, const Ice::Current& current) { if(info.id == "PermissionsVerifierServer.Server") { return; } Lock sync(*this); //cerr << "update adapter: " << info.id << " " << (info.proxy ? "active" : "inactive") << endl; AdapterDynamicInfoSeq& adapters = this->nodes[node].adapters; AdapterDynamicInfoSeq::iterator p; for(p = adapters.begin(); p != adapters.end(); ++p) { if(p->id == info.id) { if(info.proxy) { *p = info; } else { adapters.erase(p); } break; } } if(info.proxy && p == adapters.end()) { adapters.push_back(info); } ostringstream os; os << "adapter `" << info.id << " on node `" << node << "' state updated: " << (info.proxy ? "active" : "inactive"); updated(os.str()); } NodeDynamicInfo filter(const NodeDynamicInfo& info) { if(info.info.name != "localnode") { return info; } NodeDynamicInfo filtered; filtered.info = info.info; for(ServerDynamicInfoSeq::const_iterator p = info.servers.begin(); p != info.servers.end(); ++p) { if(p->id == "Glacier2" || p->id == "Glacier2Admin" || p->id == "PermissionsVerifierServer") { continue; } filtered.servers.push_back(*p); } for(AdapterDynamicInfoSeq::const_iterator a = info.adapters.begin(); a != info.adapters.end(); ++a) { if(a->id == "PermissionsVerifierServer.Server") { continue; } filtered.adapters.push_back(*a); } return filtered; } map<string, NodeDynamicInfo> nodes;};typedef IceUtil::Handle<NodeObserverI> NodeObserverIPtr;class RegistryObserverI : public RegistryObserver, public ObserverBase{public: RegistryObserverI(const string& name) : ObserverBase(name) { } virtual void registryInit(const RegistryInfoSeq& info, const Ice::Current& current) { Lock sync(*this); for(RegistryInfoSeq::const_iterator p = info.begin(); p != info.end(); ++p) { this->registries[p->name] = *p; } updated("init"); } virtual void registryUp(const RegistryInfo& info, const Ice::Current& current) { Lock sync(*this); this->registries[info.name] = info; updated("registry `" + info.name + "' up"); } virtual void registryDown(const string& name, const Ice::Current& current) { Lock sync(*this); this->registries.erase(name); updated("registry `" + name + "' down"); } map<string, RegistryInfo> registries;};typedef IceUtil::Handle<RegistryObserverI> RegistryObserverIPtr;voidtestFailedAndPrintObservers(const char* expr, const char* file, unsigned int line){ ObserverBase::printStack(); testFailed(expr, file, line);}#undef test#define test(ex) ((ex) ? ((void)0) : testFailedAndPrintObservers(#ex, __FILE__, __LINE__))void allTests(const Ice::CommunicatorPtr& communicator){ SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread( communicator->getLogger(), IceUtil::Time::seconds(5)); keepAlive->start(); RegistryPrx registry = RegistryPrx::checkedCast(communicator->stringToProxy("IceGrid/Registry")); test(registry); AdminSessionPrx session = registry->createAdminSession("admin3", "test3"); keepAlive->add(session); AdminPrx admin = session->getAdmin(); test(admin); cout << "starting router... " << flush; try { admin->startServer("Glacier2"); } catch(const ServerStartException& ex) { cerr << ex.reason << endl; test(false); } cout << "ok" << endl; cout << "starting admin router... " << flush; try { admin->startServer("Glacier2Admin"); } catch(const ServerStartException& ex) { cerr << ex.reason << endl; test(false); } cout << "ok" << endl; Ice::PropertiesPtr properties = communicator->getProperties(); IceGrid::RegistryPrx registry1 = IceGrid::RegistryPrx::uncheckedCast(registry->ice_connectionId("reg1")); IceGrid::RegistryPrx registry2 = IceGrid::RegistryPrx::uncheckedCast(registry->ice_connectionId("reg2")); Ice::ObjectPrx router = communicator->stringToProxy("Glacier2/router:default -p 12347 -h 127.0.0.1"); Ice::ObjectPrx adminRouter = communicator->stringToProxy("Glacier2/router:default -p 12348 -h 127.0.0.1"); Glacier2::RouterPrx router1 = Glacier2::RouterPrx::uncheckedCast(router->ice_connectionId("router1")); Glacier2::RouterPrx router2 = Glacier2::RouterPrx::uncheckedCast(router->ice_connectionId("router2")); Glacier2::RouterPrx adminRouter1 = Glacier2::RouterPrx::uncheckedCast(adminRouter->ice_connectionId("admRouter1")); Glacier2::RouterPrx adminRouter2 = Glacier2::RouterPrx::uncheckedCast(adminRouter->ice_connectionId("admRouter2")); // // TODO: Find a better way to wait for the Glacier2 router to be // fully started... // while(true) { try { router1->ice_ping(); adminRouter1->ice_ping(); break; } catch(const Ice::LocalException&) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100)); } } { cout << "testing username/password sessions... " << flush; SessionPrx session1, session2; session1 = SessionPrx::uncheckedCast(registry1->createSession("client1", "test1")->ice_connectionId("reg1")); session2 = SessionPrx::uncheckedCast(registry2->createSession("client2", "test2")->ice_connectionId("reg2")); try { registry1->createSession("client3", "test1"); test(false); } catch(const IceGrid::PermissionDeniedException&) { } session1->ice_ping(); session2->ice_ping(); try { session1->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { session2->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { session1->ice_connectionId("reg2")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { session2->ice_connectionId("reg1")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } session1->destroy(); session2->destroy(); AdminSessionPrx adminSession1, adminSession2; adminSession1 = AdminSessionPrx::uncheckedCast( registry1->createAdminSession("admin1", "test1")->ice_connectionId("reg1")); adminSession2 = AdminSessionPrx::uncheckedCast( registry2->createAdminSession("admin2", "test2")->ice_connectionId("reg2")); try { registry1->createAdminSession("admin3", "test1"); test(false); } catch(const IceGrid::PermissionDeniedException&) { } adminSession1->ice_ping(); adminSession2->ice_ping(); try { adminSession1->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { adminSession2->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } adminSession1->getAdmin()->ice_connectionId("reg1")->ice_ping(); adminSession2->getAdmin()->ice_connectionId("reg2")->ice_ping(); try { adminSession1->getAdmin()->ice_connectionId("reg2")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { adminSession2->getAdmin()->ice_connectionId("reg1")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } adminSession1->destroy(); adminSession2->destroy(); cout << "ok" << endl; } if(properties->getProperty("Ice.Default.Protocol") == "ssl") { cout << "testing sessions from secure connection... " << flush; SessionPrx session1, session2; session1 = SessionPrx::uncheckedCast(registry1->createSessionFromSecureConnection()->ice_connectionId("reg1")); session2 = SessionPrx::uncheckedCast(registry2->createSessionFromSecureConnection()->ice_connectionId("reg2")); session1->ice_ping(); session2->ice_ping(); try { session1->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } try { session2->ice_connectionId("")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } session1->destroy(); session2->destroy(); AdminSessionPrx adminSession1, adminSession2; adminSession1 = AdminSessionPrx::uncheckedCast(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -