virtual void runTestCase(const RemoteObjectAdapterPrx& adapter, const TestIntfPrx& proxy) { for(int i = 0; i < 12; ++i) { proxy->ice_ping(); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } Lock sync(*this); test(_heartbeat >= 3); }
void allTests(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); cout << "ok" << endl; cout << "pinging server... " << flush; obj->ice_ping(); cout << "ok" << endl; cout << "shutting down server... " << flush; obj->shutdown(); cout << "ok" << endl; }
void allTests(const Ice::CommunicatorPtr& communicator) { IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(communicator->stringToProxy("IceGrid/Registry")); test(registry); IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout()/2); keepAlive->start(); IceGrid::AdminPrx admin = session->getAdmin(); test(admin); admin->startServer("node-1"); admin->startServer("node-2"); int nRetry = 0; while(!admin->pingNode("node-1") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); ++nRetry; } nRetry = 0; while(!admin->pingNode("node-2") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); ++nRetry; } cout << "testing on-demand activation... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server")); waitForServerState(admin, "server", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server", IceGrid::Inactive); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } waitForServerState(admin, "server", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing manual activation... " << flush; try { test(admin->getServerState("server-manual") == IceGrid::Inactive); TestIntfPrx obj; try { obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-manual")); test(false); } catch(const Ice::NoEndpointException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->startServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-manual")); test(admin->getServerState("server-manual") == IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-manual", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing always activation... " << flush; try { waitForServerState(admin, "server-always", IceGrid::Active); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-always")); admin->stopServer("server-always"); waitForServerState(admin, "server-always", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-always", IceGrid::Active); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } waitForServerState(admin, "server-always", IceGrid::Active); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing session activation... " << flush; try { IceGrid::SessionPrx session = registry->createSession("test", ""); test(admin->getServerState("server-session") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-session")); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } session->allocateObjectById(obj->ice_getIdentity()); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-session", IceGrid::Inactive); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); session->releaseObject(obj->ice_getIdentity()); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } waitForServerState(admin, "server-session", IceGrid::Inactive); session->allocateObjectById(obj->ice_getIdentity()); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); session->destroy(); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } waitForServerState(admin, "server-session", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server disable... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); admin->enableServer("server", false); try { communicator->stringToProxy("server")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server") == IceGrid::Inactive); test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->enableServer("server-manual", false); try { communicator->stringToProxy("server-manual")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server-manual"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); test(admin->getServerState("server-always") == IceGrid::Active); admin->enableServer("server-always", false); admin->stopServer("server-always"); test(admin->getServerState("server-always") == IceGrid::Inactive); try { communicator->stringToProxy("server-always")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server-always"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-always") == IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server enable... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); admin->enableServer("server", true); communicator->stringToProxy("server")->ice_ping(); admin->stopServer("server"); test(admin->getServerState("server") == IceGrid::Inactive); admin->startServer("server"); test(admin->getServerState("server") == IceGrid::Active); admin->stopServer("server"); test(admin->getServerState("server") == IceGrid::Inactive); test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->enableServer("server-manual", true); try { communicator->stringToProxy("server-manual")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->startServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Active); admin->stopServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Inactive); test(admin->getServerState("server-always") == IceGrid::Inactive); admin->enableServer("server-always", true); waitForServerState(admin, "server-always", IceGrid::Active); admin->stopServer("server-always"); try { admin->startServer("server-always"); // test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-always") == IceGrid::Active); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing activation failure... " << flush; try { int i; const int nThreads = 3; Ice::ObjectPrx invalid = communicator->stringToProxy("invalid-exe"); vector<PingThreadPtr> threads; threads.reserve(nThreads); vector<PingThreadPtr>::const_iterator p; for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 10)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { auto_ptr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); invalid = communicator->stringToProxy("invalid-pwd"); for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 10)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { auto_ptr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); invalid = communicator->stringToProxy("fail-on-startup"); for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 5)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { auto_ptr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing activation timeout... " << flush; try { test(admin->getServerState("server-activation-timeout") == IceGrid::Inactive); const int nThreads = 5; Ice::ObjectPrx proxy = communicator->stringToProxy("server-activation-timeout"); vector<PingThreadPtr> threads; threads.reserve(nThreads); vector<PingThreadPtr>::const_iterator p; int i; for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(proxy, 1)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { auto_ptr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } admin->stopServer("server-activation-timeout"); } catch(const IceGrid::ServerStopException& ex) { cerr << ex << ": " << ex.reason << endl; test(false); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing deactivation timeout... " << flush; try { test(admin->getServerState("server-deactivation-timeout") == IceGrid::Inactive); communicator->stringToProxy("server-deactivation-timeout")->ice_ping(); admin->stopServer("server-deactivation-timeout"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing permanent disable on failure... " << flush; try { test(admin->getServerState("server1") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1")); waitForServerState(admin, "server1", IceGrid::Active); obj->fail(); waitForServerState(admin, "server1", IceGrid::Inactive); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(!admin->isServerEnabled("server1")); test(admin->getServerState("server1-manual") == IceGrid::Inactive); admin->startServer("server1-manual"); test(admin->getServerState("server1-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1-manual")); test(admin->getServerState("server1-manual") == IceGrid::Active); obj->fail(); waitForServerState(admin, "server1-manual", IceGrid::Inactive); test(!admin->isServerEnabled("server1-manual")); test(admin->getServerState("server1-always") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1-always")); obj->fail(); waitForServerState(admin, "server1-always", IceGrid::Inactive); test(!admin->isServerEnabled("server1-always")); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing temporary disable on failure... " << flush; try { test(admin->getServerState("server2") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2")); waitForServerState(admin, "server2", IceGrid::Active); obj->fail(); waitForServerState(admin, "server2", IceGrid::Inactive); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(!admin->isServerEnabled("server2")); nRetry = 0; while(!admin->isServerEnabled("server2") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); ++nRetry; try { obj->ice_ping(); } catch(const Ice::NoEndpointException&) { } } test(admin->isServerEnabled("server2")); waitForServerState(admin, "server2", IceGrid::Active); obj->ice_ping(); admin->stopServer("server2"); test(admin->getServerState("server2-manual") == IceGrid::Inactive); admin->startServer("server2-manual"); test(admin->getServerState("server2-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2-manual")); obj->fail(); waitForServerState(admin, "server2-manual", IceGrid::Inactive); test(!admin->isServerEnabled("server2-manual")); admin->startServer("server2-manual"); test(admin->isServerEnabled("server2-manual")); test(admin->getServerState("server2-manual") == IceGrid::Active); admin->stopServer("server2-manual"); test(admin->getServerState("server2-always") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2-always")); obj->fail(); waitForServerState(admin, "server2-always", IceGrid::Inactive); test(!admin->isServerEnabled("server2-always")); nRetry = 0; while((!admin->isServerEnabled("server2-always") || admin->getServerState("server2-always") != IceGrid::Active) && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); ++nRetry; } test(admin->isServerEnabled("server2-always") && admin->getServerState("server2-always") == IceGrid::Active); obj->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; admin->stopServer("node-1"); admin->stopServer("node-2"); keepAlive->destroy(); keepAlive->getThreadControl().join(); keepAlive = 0; session->destroy(); }
void allTests(const Ice::CommunicatorPtr& communicator) { IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways); IceGrid::AdminPrx admin = session->getAdmin(); test(admin); admin->startServer("node-1"); admin->startServer("node-2"); int nRetry = 0; while(!admin->pingNode("node-1") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); ++nRetry; } nRetry = 0; while(!admin->pingNode("node-2") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); ++nRetry; } cout << "testing on-demand activation... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server")); waitForServerState(admin, "server", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server", IceGrid::Inactive); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } waitForServerState(admin, "server", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing manual activation... " << flush; try { test(admin->getServerState("server-manual") == IceGrid::Inactive); TestIntfPrx obj; try { obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-manual")); test(false); } catch(const Ice::NoEndpointException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->startServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-manual")); test(admin->getServerState("server-manual") == IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-manual", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing always activation... " << flush; try { waitForServerState(admin, "server-always", IceGrid::Active); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server-always")); admin->stopServer("server-always"); waitForServerState(admin, "server-always", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-always", IceGrid::Active); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } waitForServerState(admin, "server-always", IceGrid::Active); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing session activation... " << flush; try { IceGrid::SessionPrx session = registry->createSession("test", ""); test(admin->getServerState("server-session") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-session")); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } session->allocateObjectById(obj->ice_getIdentity()); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); obj->shutdown(); waitForServerState(admin, "server-session", IceGrid::Inactive); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); nRetry = 4; while(--nRetry > 0) { obj->shutdown(); } obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); session->releaseObject(obj->ice_getIdentity()); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } waitForServerState(admin, "server-session", IceGrid::Inactive); session->allocateObjectById(obj->ice_getIdentity()); obj->ice_ping(); waitForServerState(admin, "server-session", IceGrid::Active); session->destroy(); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } waitForServerState(admin, "server-session", IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server disable... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); admin->enableServer("server", false); try { communicator->stringToProxy("server")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server") == IceGrid::Inactive); test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->enableServer("server-manual", false); try { communicator->stringToProxy("server-manual")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server-manual"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); test(admin->getServerState("server-always") == IceGrid::Active); admin->enableServer("server-always", false); admin->stopServer("server-always"); test(admin->getServerState("server-always") == IceGrid::Inactive); try { communicator->stringToProxy("server-always")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { admin->startServer("server-always"); test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-always") == IceGrid::Inactive); test(admin->getServerState("server") == IceGrid::Inactive); admin->enableServer("server", true); communicator->stringToProxy("server")->ice_locatorCacheTimeout(0)->ice_ping(); int pid = admin->getServerPid("server"); admin->enableServer("server", false); test(admin->getServerState("server") == IceGrid::Active); try { communicator->stringToProxy("server")->ice_locatorCacheTimeout(0)->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } admin->enableServer("server", true); communicator->stringToProxy("server")->ice_locatorCacheTimeout(0)->ice_ping(); test(admin->getServerPid("server") == pid); admin->stopServer("server"); test(admin->getServerState("server") == IceGrid::Inactive); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server enable... " << flush; try { test(admin->getServerState("server") == IceGrid::Inactive); admin->enableServer("server", true); communicator->stringToProxy("server")->ice_ping(); admin->stopServer("server"); test(admin->getServerState("server") == IceGrid::Inactive); admin->startServer("server"); test(admin->getServerState("server") == IceGrid::Active); admin->stopServer("server"); test(admin->getServerState("server") == IceGrid::Inactive); test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->enableServer("server-manual", true); try { communicator->stringToProxy("server-manual")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(admin->getServerState("server-manual") == IceGrid::Inactive); admin->startServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Active); admin->stopServer("server-manual"); test(admin->getServerState("server-manual") == IceGrid::Inactive); test(admin->getServerState("server-always") == IceGrid::Inactive); admin->enableServer("server-always", true); waitForServerState(admin, "server-always", IceGrid::Active); admin->stopServer("server-always"); try { admin->startServer("server-always"); // test(false); } catch(const IceGrid::ServerStartException&) { } test(admin->getServerState("server-always") == IceGrid::Active); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing activation failure... " << flush; try { int i; const int nThreads = 3; Ice::ObjectPrx invalid = communicator->stringToProxy("invalid-exe"); vector<PingThreadPtr> threads; threads.reserve(nThreads); vector<PingThreadPtr>::const_iterator p; for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 10)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { IceUtil::UniquePtr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); invalid = communicator->stringToProxy("invalid-pwd"); for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 10)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { IceUtil::UniquePtr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); invalid = communicator->stringToProxy("fail-on-startup"); for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(invalid, 5)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { IceUtil::UniquePtr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } threads.resize(0); try { admin->startServer("invalid-pwd-no-oa"); test(false); } catch(const IceGrid::ServerStartException& ex) { test(!ex.reason.empty()); } try { admin->startServer("invalid-exe-no-oa"); test(false); } catch(const IceGrid::ServerStartException& ex) { test(!ex.reason.empty()); } } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing activation timeout... " << flush; try { test(admin->getServerState("server-activation-timeout") == IceGrid::Inactive); const int nThreads = 5; Ice::ObjectPrx proxy = communicator->stringToProxy("server-activation-timeout"); vector<PingThreadPtr> threads; threads.reserve(nThreads); vector<PingThreadPtr>::const_iterator p; int i; for(i = 0; i < nThreads; i++) { threads.push_back(new PingThread(proxy, 1)); } for(p = threads.begin(); p != threads.end(); ++p) { (*p)->start(); } for(p = threads.begin(); p != threads.end(); ++p) { IceUtil::UniquePtr<Ice::LocalException> ex((*p)->waitUntilFinished()); test(dynamic_cast<Ice::NoEndpointException*>(ex.get())); } admin->stopServer("server-activation-timeout"); } catch(const IceGrid::ServerStopException& ex) { cerr << ex << ": " << ex.reason << endl; test(false); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing deactivation timeout... " << flush; try { test(admin->getServerState("server-deactivation-timeout") == IceGrid::Inactive); communicator->stringToProxy("server-deactivation-timeout")->ice_ping(); admin->stopServer("server-deactivation-timeout"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing permanent disable on failure... " << flush; try { test(admin->getServerState("server1") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1")); waitForServerState(admin, "server1", IceGrid::Active); obj->fail(); waitForServerState(admin, "server1", IceGrid::Inactive); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(!admin->isServerEnabled("server1")); test(admin->getServerState("server1-manual") == IceGrid::Inactive); admin->startServer("server1-manual"); test(admin->getServerState("server1-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1-manual")); test(admin->getServerState("server1-manual") == IceGrid::Active); obj->fail(); waitForServerState(admin, "server1-manual", IceGrid::Inactive); test(!admin->isServerEnabled("server1-manual")); test(admin->getServerState("server1-always") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server1-always")); obj->fail(); waitForServerState(admin, "server1-always", IceGrid::Inactive); test(!admin->isServerEnabled("server1-always")); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing temporary disable on failure... " << flush; try { test(admin->getServerState("server2") == IceGrid::Inactive); TestIntfPrx obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2")); waitForServerState(admin, "server2", IceGrid::Active); obj->fail(); waitForServerState(admin, "server2", IceGrid::Inactive); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } test(!admin->isServerEnabled("server2")); nRetry = 0; while(!admin->isServerEnabled("server2") && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); ++nRetry; try { obj->ice_ping(); } catch(const Ice::NoEndpointException&) { } } test(admin->isServerEnabled("server2")); waitForServerState(admin, "server2", IceGrid::Active); obj->ice_ping(); admin->stopServer("server2"); test(admin->getServerState("server2-manual") == IceGrid::Inactive); admin->startServer("server2-manual"); test(admin->getServerState("server2-manual") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2-manual")); obj->fail(); waitForServerState(admin, "server2-manual", IceGrid::Inactive); test(!admin->isServerEnabled("server2-manual")); admin->startServer("server2-manual"); test(admin->isServerEnabled("server2-manual")); test(admin->getServerState("server2-manual") == IceGrid::Active); admin->stopServer("server2-manual"); test(admin->getServerState("server2-always") == IceGrid::Active); obj = TestIntfPrx::checkedCast(communicator->stringToProxy("server2-always")); obj->fail(); waitForServerState(admin, "server2-always", IceGrid::Inactive); test(!admin->isServerEnabled("server2-always")); nRetry = 0; while((!admin->isServerEnabled("server2-always") || admin->getServerState("server2-always") != IceGrid::Active) && nRetry < 15) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); ++nRetry; } test(admin->isServerEnabled("server2-always") && admin->getServerState("server2-always") == IceGrid::Active); obj->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing large number of servers... " << flush; { IceGrid::ApplicationInfo info = admin->getApplicationInfo("Test"); IceGrid::ApplicationDescriptor testApp; testApp.name = "TestApp"; testApp.serverTemplates = info.descriptor.serverTemplates; testApp.variables = info.descriptor.variables; const int nServers = 75; for(int i = 0; i < nServers; ++i) { ostringstream id; id << "server-" << i; IceGrid::ServerInstanceDescriptor server; server._cpp_template = "Server"; server.parameterValues["id"] = id.str(); testApp.nodes["localnode"].serverInstances.push_back(server); } try { admin->addApplication(testApp); } catch(const IceGrid::DeploymentException& ex) { cerr << ex.reason << endl; test(false); } for(int i = 0; i < nServers; ++i) { ostringstream id; id << "server-" << i; admin->startServer(id.str()); } for(int i = 0; i < nServers; ++i) { ostringstream id; id << "server-" << i; admin->stopServer(id.str()); } admin->removeApplication("TestApp"); } cout << "ok" << endl; admin->stopServer("node-1"); admin->stopServer("node-2"); session->destroy(); }
void allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); test(base); Ice::ObjectPrx base2 = communicator->stringToProxy("test"); test(base2); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); TestIntfPrx obj2 = TestIntfPrx::checkedCast(base2); test(obj2); test(obj2 == base2); cout << "ok" << endl; cout << "pinging server... " << flush; obj->ice_ping(); obj2->ice_ping(); cout << "ok" << endl; cout << "testing reference with unknown identity... " << flush; try { communicator->stringToProxy("unknown/unknown")->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object"); test(ex.id == "unknown/unknown"); } cout << "ok" << endl; cout << "testing reference with unknown adapter... " << flush; try { communicator->stringToProxy("test @ TestAdapterUnknown")->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object adapter"); test(ex.id == "TestAdapterUnknown"); } cout << "ok" << endl; IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( communicator->stringToProxy("IceGrid/Registry")); test(registry); IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout()/2); keepAlive->start(); IceGrid::AdminPrx admin = session->getAdmin(); test(admin); admin->enableServer("server", false); admin->stopServer("server"); cout << "testing whether server is still reachable... " << flush; try { obj = TestIntfPrx::checkedCast(base); test(false); } catch(const Ice::NoEndpointException&) { } try { obj2 = TestIntfPrx::checkedCast(base2); test(false); } catch(const Ice::NoEndpointException&) { } admin->enableServer("server", true); try { obj = TestIntfPrx::checkedCast(base); } catch(const Ice::NoEndpointException&) { test(false); } try { obj2 = TestIntfPrx::checkedCast(base2); } catch(const Ice::NoEndpointException&) { test(false); } cout << "ok" << endl; admin->stopServer("server"); keepAlive->destroy(); keepAlive->getThreadControl().join(); keepAlive = 0; session->destroy(); }
void allTests(const Ice::CommunicatorPtr& communicator, const vector<int>& ports) { cout << "testing stringToProxy... " << flush; ostringstream ref; ref << "test"; for(vector<int>::const_iterator p = ports.begin(); p != ports.end(); ++p) { ref << ":default -p " << *p; } Ice::ObjectPrx base = communicator->stringToProxy(ref.str()); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); cout << "ok" << endl; int oldPid = 0; bool ami = false; for(unsigned int i = 1, j = 0; i <= ports.size(); ++i, ++j) { if(j > 3) { j = 0; ami = !ami; } if(!ami) { cout << "testing server #" << i << "... " << flush; int pid = obj->pid(); test(pid != oldPid); cout << "ok" << endl; oldPid = pid; } else { cout << "testing server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback(); obj->begin_pid(newCallback_TestIntf_pid(cb, &Callback::opPidI, &Callback::exception)); cb->check(); int pid = cb->pid(); test(pid != oldPid); cout << "ok" << endl; oldPid = pid; } if(j == 0) { if(!ami) { cout << "shutting down server #" << i << "... " << flush; obj->shutdown(); cout << "ok" << endl; } else { cout << "shutting down server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback; obj->begin_shutdown(newCallback_TestIntf_shutdown(cb, &Callback::opShutdownI, &Callback::exception)); cb->check(); cout << "ok" << endl; } } else if(j == 1 || i + 1 > ports.size()) { if(!ami) { cout << "aborting server #" << i << "... " << flush; try { obj->abort(); test(false); } catch(const Ice::ConnectionLostException&) { cout << "ok" << endl; } catch(const Ice::ConnectFailedException&) { cout << "ok" << endl; } } else { cout << "aborting server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback; obj->begin_abort(newCallback_TestIntf_abort(cb, &Callback::response, &Callback::exceptAbortI)); cb->check(); cout << "ok" << endl; } } else if(j == 2 || j == 3) { if(!ami) { cout << "aborting server #" << i << " and #" << i + 1 << " with idempotent call... " << flush; try { obj->idempotentAbort(); test(false); } catch(const Ice::ConnectionLostException&) { cout << "ok" << endl; } catch(const Ice::ConnectFailedException&) { cout << "ok" << endl; } } else { cout << "aborting server #" << i << " and #" << i + 1 << " with idempotent AMI call... " << flush; CallbackPtr cb = new Callback; obj->begin_idempotentAbort(newCallback_TestIntf_idempotentAbort(cb, &Callback::response, &Callback::exceptAbortI)); cb->check(); cout << "ok" << endl; } ++i; } else { assert(false); } } cout << "testing whether all servers are gone... " << flush; try { obj->ice_ping(); test(false); } catch(const Ice::LocalException&) { cout << "ok" << endl; } }
void allTests(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); test(base); cout << "ok" << endl; cout << "testing IceGrid.Locator is present... " << flush; IceGrid::LocatorPrx locator = IceGrid::LocatorPrx::uncheckedCast(base); test(locator); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); cout << "ok" << endl; cout << "pinging server... " << flush; obj->ice_ping(); cout << "ok" << endl; cout << "testing locator finder... " << flush; Ice::Identity finderId; finderId.category = "Ice"; finderId.name = "LocatorFinder"; Ice::LocatorFinderPrx finder = Ice::LocatorFinderPrx::checkedCast( communicator->getDefaultLocator()->ice_identity(finderId)); test(finder->getLocator()); cout << "ok" << endl; cout << "testing discovery... " << flush; { // Add test well-known object IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->getAdmin()->addObjectWithType(base, "::Test"); session->destroy(); // // Ensure the IceGrid discovery locator can discover the // registries and make sure locator requests are forwarded. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Default.Locator", ""); initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:createIceLocatorDiscovery"); #ifdef __APPLE__ if(initData.properties->getPropertyAsInt("Ice.PreferIPv6Address") > 0) { initData.properties->setProperty("IceLocatorDiscovery.Interface", "::1"); } #endif initData.properties->setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter"); initData.properties->setProperty("AdapterForDiscoveryTest.Endpoints", "default"); Ice::CommunicatorPtr com = Ice::initialize(initData); test(com->getDefaultLocator()); com->stringToProxy("test @ TestAdapter")->ice_ping(); com->stringToProxy("test")->ice_ping(); test(com->getDefaultLocator()->getRegistry()); test(IceGrid::LocatorPrx::checkedCast(com->getDefaultLocator())); test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalRegistry()); test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalQuery()); Ice::ObjectAdapterPtr adapter = com->createObjectAdapter("AdapterForDiscoveryTest"); adapter->activate(); adapter->deactivate(); com->destroy(); // // Now, ensure that the IceGrid discovery locator correctly // handles failure to find a locator. Also test // Ice::registerIceLocatorDiscovery() // Ice::registerIceLocatorDiscovery(); initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", ""); initData.properties->setProperty("IceLocatorDiscovery.InstanceName", "unknown"); initData.properties->setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties->setProperty("IceLocatorDiscovery.Timeout", "100"); com = Ice::initialize(initData); test(com->getDefaultLocator()); try { com->stringToProxy("test @ TestAdapter")->ice_ping(); } catch(const Ice::NoEndpointException&) { } try { com->stringToProxy("test")->ice_ping(); } catch(const Ice::NoEndpointException&) { } test(!com->getDefaultLocator()->getRegistry()); test(!IceGrid::LocatorPrx::checkedCast(com->getDefaultLocator())); try { test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalQuery()); } catch(const Ice::OperationNotExistException&) { } adapter = com->createObjectAdapter("AdapterForDiscoveryTest"); adapter->activate(); adapter->deactivate(); com->destroy(); } cout << "ok" << endl; cout << "shutting down server... " << flush; obj->shutdown(); cout << "ok" << endl; }
void allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); test(base); Ice::ObjectPrx base2 = communicator->stringToProxy("test"); test(base2); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); TestIntfPrx obj2 = TestIntfPrx::checkedCast(base2); test(obj2); test(obj2 == base2); cout << "ok" << endl; cout << "pinging server... " << flush; obj->ice_ping(); obj2->ice_ping(); cout << "ok" << endl; cout << "testing encoding versioning... " << flush; Ice::ObjectPrx base10 = communicator->stringToProxy("test10 @ TestAdapter10"); test(base10); Ice::ObjectPrx base102 = communicator->stringToProxy("test10"); test(base102); try { base10->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } try { base102->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } base10 = base10->ice_encodingVersion(Ice::Encoding_1_0); base102 = base102->ice_encodingVersion(Ice::Encoding_1_0); base10->ice_ping(); base102->ice_ping(); cout << "ok" << endl; cout << "testing reference with unknown identity... " << flush; try { communicator->stringToProxy("unknown/unknown")->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object"); test(ex.id == "unknown/unknown"); } cout << "ok" << endl; cout << "testing reference with unknown adapter... " << flush; try { communicator->stringToProxy("test @ TestAdapterUnknown")->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object adapter"); test(ex.id == "TestAdapterUnknown"); } cout << "ok" << endl; IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways); IceGrid::AdminPrx admin = session->getAdmin(); test(admin); admin->enableServer("server", false); admin->stopServer("server"); cout << "testing whether server is still reachable... " << flush; try { obj = TestIntfPrx::checkedCast(base); test(false); } catch(const Ice::NoEndpointException&) { } try { obj2 = TestIntfPrx::checkedCast(base2); test(false); } catch(const Ice::NoEndpointException&) { } admin->enableServer("server", true); try { obj = TestIntfPrx::checkedCast(base); } catch(const Ice::NoEndpointException&) { test(false); } try { obj2 = TestIntfPrx::checkedCast(base2); } catch(const Ice::NoEndpointException&) { test(false); } cout << "ok" << endl; admin->stopServer("server"); session->destroy(); }
void allTests(const Ice::CommunicatorPtr& comm) { IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( comm->stringToProxy(comm->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); IceGrid::QueryPrx query = IceGrid::QueryPrx::checkedCast( comm->stringToProxy(comm->getDefaultLocator()->ice_getIdentity().category + "/Query")); test(query); AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways); AdminPrx admin = session->getAdmin(); test(admin); set<string> serverReplicaIds; serverReplicaIds.insert("Server1.ReplicatedAdapter"); serverReplicaIds.insert("Server2.ReplicatedAdapter"); serverReplicaIds.insert("Server3.ReplicatedAdapter"); set<string> svcReplicaIds; svcReplicaIds.insert("IceBox1.Service1.Service1"); svcReplicaIds.insert("IceBox1.Service2.Service2"); svcReplicaIds.insert("IceBox1.Service3.Service3"); cout << "testing Query::findAllReplicas... " << flush; { map<string, string> params; params["replicaGroup"] = "RoundRobin"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("dummy@RoundRobin")); Ice::ObjectProxySeq objs = query->findAllReplicas(obj); test(objs.size() == 3); test(serverReplicaIds.find(objs[0]->ice_getAdapterId()) != serverReplicaIds.end()); test(serverReplicaIds.find(objs[1]->ice_getAdapterId()) != serverReplicaIds.end()); test(serverReplicaIds.find(objs[2]->ice_getAdapterId()) != serverReplicaIds.end()); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin")); objs = query->findAllReplicas(obj); test(objs.size() == 3); test(serverReplicaIds.find(objs[0]->ice_getAdapterId()) != serverReplicaIds.end()); test(serverReplicaIds.find(objs[1]->ice_getAdapterId()) != serverReplicaIds.end()); test(serverReplicaIds.find(objs[2]->ice_getAdapterId()) != serverReplicaIds.end()); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("dummy@dummy")); objs = query->findAllReplicas(obj); test(objs.empty()); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("*****@*****.**")); objs = query->findAllReplicas(obj); test(objs.empty()); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("dummy:tcp")); objs = query->findAllReplicas(obj); test(objs.empty()); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("dummy@Ordered")); objs = query->findAllReplicas(obj); test(objs.empty()); removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } cout << "ok" << endl; cout << "testing replication with round-robin load balancing... " << flush; { map<string, string> params; params["replicaGroup"] = "RoundRobin"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); try { test(obj->getReplicaIdAndShutdown() == "Server1.ReplicatedAdapter"); test(obj->getReplicaIdAndShutdown() == "Server2.ReplicatedAdapter"); test(obj->getReplicaIdAndShutdown() == "Server3.ReplicatedAdapter"); admin->enableServer("Server1", false); admin->enableServer("Server2", false); admin->enableServer("Server3", false); try { obj->getReplicaId(); test(false); } catch(const Ice::NoEndpointException&) { } admin->enableServer("Server1", true); admin->enableServer("Server2", true); admin->enableServer("Server3", true); set<string> adapterIds; string previousId; while(adapterIds.size() != 3) { string id = obj->getReplicaId(); adapterIds.insert(id); if(adapterIds.size() == 1) { previousId = id; } else { test(previousId != id); previousId = id; } } int i; for(i = 0; i < 3; i++) { if(obj->getReplicaId() == "Server3.ReplicatedAdapter") { break; } } test(i != 3); test(obj->getReplicaId() == "Server1.ReplicatedAdapter"); test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); test(obj->getReplicaId() == "Server3.ReplicatedAdapter"); test(obj->getReplicaIdAndShutdown() == "Server1.ReplicatedAdapter"); test(obj->getReplicaIdAndShutdown() == "Server2.ReplicatedAdapter"); test(obj->getReplicaIdAndShutdown() == "Server3.ReplicatedAdapter"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { map<string, string> params; params["replicaGroup"] = "RoundRobin"; params["id"] = "IceBox1"; instantiateServer(admin, "IceBox", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin")); try { test(obj->getReplicaIdAndShutdown() == "IceBox1.Service1.Service1"); test(obj->getReplicaIdAndShutdown() == "IceBox1.Service2.Service2"); test(obj->getReplicaIdAndShutdown() == "IceBox1.Service3.Service3"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "IceBox1"); } cout << "ok" << endl; cout << "testing replication with ordered load balancing... " << flush; { map<string, string> params; params["replicaGroup"] = "Ordered"; params["id"] = "Server1"; params["priority"] = "3"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; params["priority"] = "1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; params["priority"] = "2"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Ordered")); try { test(obj->getReplicaIdAndShutdown() == "Server2.ReplicatedAdapter"); admin->enableServer("Server2", false); test(obj->getReplicaIdAndShutdown() == "Server3.ReplicatedAdapter"); admin->enableServer("Server3", false); test(obj->getReplicaIdAndShutdown() == "Server1.ReplicatedAdapter"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { map<string, string> params; params["replicaGroup"] = "Ordered"; params["id"] = "IceBox1"; instantiateServer(admin, "IceBox", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Ordered")); try { test(obj->getReplicaIdAndShutdown() == "IceBox1.Service3.Service3"); test(obj->getReplicaIdAndShutdown() == "IceBox1.Service2.Service2"); test(obj->getReplicaIdAndShutdown() == "IceBox1.Service1.Service1"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "IceBox1"); } cout << "ok" << endl; cout << "testing replication with random load balancing... " << flush; { map<string, string> params; params["replicaGroup"] = "Random"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Random")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); set<string> replicaIds = serverReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } admin->stopServer("Server1"); admin->stopServer("Server2"); admin->stopServer("Server3"); admin->enableServer("Server1", false); admin->enableServer("Server2", false); admin->enableServer("Server3", false); try { obj->getReplicaId(); test(false); } catch(const Ice::NoEndpointException&) { } admin->enableServer("Server1", true); admin->enableServer("Server2", true); admin->enableServer("Server3", true); replicaIds = serverReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaIdAndShutdown()); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { map<string, string> params; params["replicaGroup"] = "Random"; params["id"] = "IceBox1"; instantiateServer(admin, "IceBox", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Random")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); set<string> replicaIds = svcReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::ConnectionRefusedException&) { } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "IceBox1"); } cout << "ok" << endl; cout << "testing replication with adaptive load balancing... " << flush; { map<string, string> params; params["replicaGroup"] = "Adaptive"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Adaptive")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); set<string> replicaIds = serverReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { map<string, string> params; params["replicaGroup"] = "Adaptive"; params["id"] = "IceBox1"; instantiateServer(admin, "IceBox", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Adaptive")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); set<string> replicaIds = svcReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::ConnectionRefusedException&) { } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "IceBox1"); } cout << "ok" << endl; cout << "testing filters... " << flush; { map<string, string> params; params["replicaGroup"] = "Ordered-Filtered"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "IceBox1", "localnode", params); Ice::LocatorPrx locator = comm->getDefaultLocator(); Ice::Context ctx; ctx["server"] = "Server3"; locator->ice_context(ctx); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Ordered-Filtered")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); try { ctx["server"] = "Server3"; test(obj->ice_locator(locator->ice_context(ctx))->getReplicaId() == "Server3.Service.Service"); ctx["server"] = "Server1"; test(obj->ice_locator(locator->ice_context(ctx))->getReplicaId() == "Server1.ReplicatedAdapter"); ctx["server"] = "Server2"; test(obj->ice_locator(locator->ice_context(ctx))->getReplicaId() == "Server2.ReplicatedAdapter"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } try { ctx["server"] = "Server3"; test(query->ice_context(ctx)->findAllReplicas(obj)[0]->ice_getAdapterId() == "Server3.Service.Service"); ctx["server"] = "Server1"; test(query->ice_context(ctx)->findAllReplicas(obj)[0]->ice_getAdapterId() == "Server1.ReplicatedAdapter"); ctx["server"] = "Server2"; test(query->ice_context(ctx)->findAllReplicas(obj)[0]->ice_getAdapterId() == "Server2.ReplicatedAdapter"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } try { ctx["server"] = "Server3"; test(query->ice_context(ctx)->findObjectByType("::Test::TestIntf2")->ice_getAdapterId() == "Server3.Service.Service"); ctx["server"] = "Server1"; test(query->ice_context(ctx)->findObjectByType("::Test::TestIntf2")->ice_getAdapterId() == "Server1.ReplicatedAdapter"); ctx["server"] = "Server2"; test(query->ice_context(ctx)->findObjectByType("::Test::TestIntf2")->ice_getAdapterId() == "Server2.ReplicatedAdapter"); ctx["server"] = "Server3"; test(query->ice_context(ctx)->findObjectByTypeOnLeastLoadedNode( "::Test::TestIntf2", LoadSample5)->ice_getAdapterId() == "Server3.Service.Service"); ctx["server"] = "Server1"; test(query->ice_context(ctx)->findObjectByTypeOnLeastLoadedNode( "::Test::TestIntf2", LoadSample5)->ice_getAdapterId() == "Server1.ReplicatedAdapter"); ctx["server"] = "Server2"; test(query->ice_context(ctx)->findObjectByTypeOnLeastLoadedNode( "::Test::TestIntf2", LoadSample5)->ice_getAdapterId() == "Server2.ReplicatedAdapter"); ctx["server"] = "Server3"; test(query->ice_context(ctx)->findAllObjectsByType("::Test::TestIntf2")[0]->ice_getAdapterId() == "Server3.Service.Service"); ctx["server"] = "Server1"; test(query->ice_context(ctx)->findAllObjectsByType("::Test::TestIntf2")[0]->ice_getAdapterId() == "Server1.ReplicatedAdapter"); ctx["server"] = "Server2"; test(query->ice_context(ctx)->findAllObjectsByType("::Test::TestIntf2")[0]->ice_getAdapterId() == "Server2.ReplicatedAdapter"); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { map<string, string> params; params["replicaGroup"] = "Unknown"; params["id"] = "UnknownServer"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Unknown")); obj->getReplicaId(); removeServer(admin, "UnknownServer"); } { map<string, string> params; params["replicaGroup"] = "Exclude"; params["id"] = "ExcludeServer"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Exclude")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); try { obj->getReplicaId(); test(false); } catch(const Ice::NoEndpointException&) { } Ice::LocatorPrx locator = comm->getDefaultLocator(); try { Ice::Context ctx; ctx["server"] = "Server2"; obj->ice_locator(locator->ice_context(ctx))->getReplicaId(); test(false); } catch(const Ice::NoEndpointException&) { } try { Ice::Context ctx; ctx["server"] = "Server3"; obj->ice_locator(locator->ice_context(ctx))->getReplicaId(); test(false); } catch(const Ice::NoEndpointException&) { } Ice::Context ctx; ctx["server"] = "Server1"; string id = obj->ice_locator(locator->ice_context(ctx))->getReplicaId(); removeServer(admin, "ExcludeServer"); } cout << "ok" << endl; cout << "testing load balancing n-replicas... " << flush; { TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin-2")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(-1)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } map<string, string> params; params["replicaGroup"] = "RoundRobin-2"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); try { set<string> replicaIds; set<string> expected; replicaIds.insert("Server1.ReplicatedAdapter"); replicaIds.insert("Server2.ReplicatedAdapter"); expected = replicaIds; while(!replicaIds.empty()) { string replicaId = obj->getReplicaId(); test(expected.find(replicaId) != expected.end()); replicaIds.erase(replicaId); } obj->ice_locatorCacheTimeout(0)->ice_ping(); replicaIds.insert("Server2.ReplicatedAdapter"); replicaIds.insert("Server3.ReplicatedAdapter"); expected = replicaIds; while(!replicaIds.empty()) { string replicaId = obj->getReplicaId(); test(expected.find(replicaId) != expected.end()); replicaIds.erase(replicaId); } obj->ice_locatorCacheTimeout(0)->ice_ping(); replicaIds.insert("Server3.ReplicatedAdapter"); replicaIds.insert("Server1.ReplicatedAdapter"); expected = replicaIds; while(!replicaIds.empty()) { string replicaId = obj->getReplicaId(); test(expected.find(replicaId) != expected.end()); replicaIds.erase(replicaId); } admin->stopServer("Server1"); admin->stopServer("Server2"); admin->stopServer("Server3"); obj->ice_locatorCacheTimeout(0)->ice_ping(); int nRetry = 500; while(replicaIds.size() != 2 && --nRetry > 0) { replicaIds.insert(obj->getReplicaId()); } test(replicaIds.size() == 2); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } { TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin-All")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(-1)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); try { obj->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } map<string, string> params; params["replicaGroup"] = "RoundRobin-All"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; instantiateServer(admin, "Server", "localnode", params); try { set<string> replicaIds; set<string> expected; replicaIds.insert("Server1.ReplicatedAdapter"); replicaIds.insert("Server2.ReplicatedAdapter"); replicaIds.insert("Server3.ReplicatedAdapter"); expected = replicaIds; while(!replicaIds.empty()) { string replicaId = obj->getReplicaId(); test(expected.find(replicaId) != expected.end()); replicaIds.erase(replicaId); } obj->ice_locatorCacheTimeout(0)->ice_ping(); replicaIds.insert("Server1.ReplicatedAdapter"); replicaIds.insert("Server2.ReplicatedAdapter"); replicaIds.insert("Server3.ReplicatedAdapter"); expected = replicaIds; while(!replicaIds.empty()) { string replicaId = obj->getReplicaId(); test(expected.find(replicaId) != expected.end()); replicaIds.erase(replicaId); } } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } cout << "ok" << endl; cout << "testing replication with inactive nodes... " << flush; { map<string, string> params; params["replicaGroup"] = "Random"; params["id"] = "Server1"; instantiateServer(admin, "Server", "inactivenode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Random")); test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); // // Also make sure that findObjectByTypeOnLeastLoadedNode still work. // obj = TestIntfPrx::uncheckedCast(query->findObjectByTypeOnLeastLoadedNode("::Test::TestIntf", LoadSample1)); test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); removeServer(admin, "Server1"); removeServer(admin, "Server2"); params["replicaGroup"] = "RoundRobin"; params["id"] = "Server1"; instantiateServer(admin, "Server", "inactivenode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("RoundRobin")); test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); removeServer(admin, "Server1"); removeServer(admin, "Server2"); params["replicaGroup"] = "Adaptive"; params["id"] = "Server1"; instantiateServer(admin, "Server", "inactivenode", params); params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Adaptive")); test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); removeServer(admin, "Server1"); removeServer(admin, "Server2"); params["replicaGroup"] = "Random"; params["id"] = "IceBox1"; instantiateServer(admin, "IceBox", "localnode", params); params["id"] = "Server1"; instantiateServer(admin, "Server", "inactivenode", params); obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Random")); test(svcReplicaIds.find(obj->getReplicaId()) != svcReplicaIds.end()); removeServer(admin, "IceBox1"); removeServer(admin, "Server1"); }; cout << "ok" << endl; cout << "testing replica group from different applications... " << flush; { map<string, string> params; params["replicaGroup"] = "Random"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); ApplicationUpdateDescriptor update; update.name = "Test"; update.removeReplicaGroups.push_back("Random"); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // The Random replica goup is used by Server1! } // // Add an application Test1 without replica groups and a // server that uses the Random replica group. // ApplicationInfo app = admin->getApplicationInfo("Test"); app.descriptor.name = "Test1"; app.descriptor.replicaGroups.clear(); app.descriptor.nodes.clear(); try { admin->addApplication(app.descriptor); } catch(const DeploymentException& ex) { cerr << ex << endl; test(false); } params["id"] = "Server2"; instantiateServer(admin, "Server", "localnode", params, "Test1"); try { admin->removeApplication("Test"); test(false); } catch(const DeploymentException&) { // Test has a replica group referenced by the Test1 application. } TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy("Random")); obj = TestIntfPrx::uncheckedCast(obj->ice_locatorCacheTimeout(0)); obj = TestIntfPrx::uncheckedCast(obj->ice_connectionCached(false)); set<string> replicaIds; replicaIds.insert("Server1.ReplicatedAdapter"); replicaIds.insert("Server2.ReplicatedAdapter"); while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "Server2"); removeServer(admin, "Server1"); ReplicaGroupDescriptor replicaGroup; replicaGroup.id = "ReplicatedAdapterFromTest1"; replicaGroup.loadBalancing = new RandomLoadBalancingPolicy(); replicaGroup.loadBalancing->nReplicas = "0"; update = ApplicationUpdateDescriptor(); update.name = "Test1"; update.replicaGroups.push_back(replicaGroup); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } params["replicaGroup"] = "ReplicatedAdapterFromTest1"; params["id"] = "Server1"; instantiateServer(admin, "Server", "localnode", params); try { admin->removeApplication("Test1"); test(false); } catch(const DeploymentException&) { // ReplicatedAdapterFromTest1 used by server from Test } update = ApplicationUpdateDescriptor(); update.name = "Test1"; update.removeReplicaGroups.push_back("ReplicatedAdapterFromTest1"); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // ReplicatedAdapterFromTest1 used by server from Test } removeServer(admin, "Server1"); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex << endl; test(false); } admin->removeApplication("Test1"); }; cout << "ok" << endl; cout << "testing replica group with different server encoding support... " << flush; { vector<string> loadBalancings; loadBalancings.push_back("Random"); loadBalancings.push_back("RoundRobin"); loadBalancings.push_back("RoundRobin-All"); for(vector<string>::const_iterator p = loadBalancings.begin(); p != loadBalancings.end(); ++p) { map<string, string> params; params["replicaGroup"] = *p; params["id"] = "Server1"; params["encoding"] = "1.0"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server2"; params["encoding"] = "1.1"; instantiateServer(admin, "Server", "localnode", params); params["id"] = "Server3"; params["encoding"] = "1.0"; instantiateServer(admin, "Server", "localnode", params); TestIntfPrx obj = TestIntfPrx::uncheckedCast(comm->stringToProxy(*p)); obj = obj->ice_locatorCacheTimeout(0); obj = obj->ice_connectionCached(false); for(int i = 0; i < 30; ++i) { test(obj->getReplicaId() == "Server2.ReplicatedAdapter"); } obj = obj->ice_encodingVersion(Ice::Encoding_1_0); set<string> replicaIds = serverReplicaIds; while(!replicaIds.empty()) { try { replicaIds.erase(obj->getReplicaId()); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } } removeServer(admin, "Server1"); removeServer(admin, "Server2"); removeServer(admin, "Server3"); } }; cout << "ok" << endl; session->destroy(); }
TestIntfPrx allTests(const CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; ObjectPrx base = communicator->stringToProxy("test:default -p 12010"); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); cout << "ok" << endl; { cout << "creating/destroying/recreating object adapter... " << flush; ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch(const AlreadyRegisteredException&) { } adapter->destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter->destroy(); cout << "ok" << endl; } cout << "creating/activating/deactivating object adapter in one operation... " << flush; obj->transient(); cout << "ok" << endl; { cout << "testing connection closure... " << flush; for(int i = 0; i < 10; ++i) { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); Ice::CommunicatorPtr comm = Ice::initialize(initData); comm->stringToProxy("test:default -p 12010")->begin_ice_ping(); comm->destroy(); } cout << "ok" << endl; } cout << "deactivating object adapter in the server... " << flush; obj->deactivate(); cout << "ok" << endl; cout << "testing whether server is gone... " << flush; try { obj->ice_ping(); test(false); } catch(const LocalException&) { cout << "ok" << endl; } return obj; }