void removeServer(const AdminPrx& admin, const string& id) { try { admin->enableServer(id, false); // Makes sure the server isn't activated on-demand after the stop. admin->stopServer(id); } catch(const ServerStopException&) { } catch(const NodeUnreachableException&) { } catch(const Ice::UserException& ex) { cerr << ex << endl; test(false); } ServerInfo info = admin->getServerInfo(id); NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = info.node; nodeUpdate.removeServers.push_back(id); ApplicationUpdateDescriptor update; update.name = info.application; update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } }
void allTests(const Ice::CommunicatorPtr& communicator) { IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::ICE_ENUM(ACMHeartbeat, HeartbeatAlways)); 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; const int allocationTimeout = 5000; Ice::ObjectPrx obj; Ice::ObjectPrx dummy; try { cout << "testing create session... " << flush; SessionPrx session1 = registry->createSession("Client1", ""); SessionPrx session2 = registry->createSession("Client2", ""); cout << "ok" << endl; cout << "testing allocate object by identity... " << flush; Ice::Identity allocatable = Ice::stringToIdentity("allocatable"); Ice::Identity allocatablebis = Ice::stringToIdentity("allocatablebis"); try { session1->allocateObjectById(Ice::stringToIdentity("dummy")); } catch(const ObjectNotRegisteredException&) { } try { session1->releaseObject(Ice::stringToIdentity("dummy")); } catch(const ObjectNotRegisteredException&) { } try { session1->allocateObjectById(Ice::stringToIdentity("nonallocatable")); test(false); } catch(const AllocationException&) { test(false); } catch(const ObjectNotRegisteredException&) { } try { session2->allocateObjectById(Ice::stringToIdentity("nonallocatable")); test(false); } catch(const AllocationException&) { test(false); } catch(const ObjectNotRegisteredException&) { } try { session1->releaseObject(Ice::stringToIdentity("nonallocatable")); test(false); } catch(const AllocationException&) { test(false); } catch(const ObjectNotRegisteredException&) { } try { session2->releaseObject(Ice::stringToIdentity("nonallocatable")); test(false); } catch(const AllocationException&) { test(false); } catch(const ObjectNotRegisteredException&) { } session1->allocateObjectById(allocatable); try { session1->allocateObjectById(allocatable); test(false); } catch(const AllocationException&) { } session1->setAllocationTimeout(0); session2->setAllocationTimeout(0); try { session2->allocateObjectById(allocatable); test(false); } catch(const AllocationTimeoutException&) { } try { session2->releaseObject(allocatable); test(false); } catch(const AllocationException&) { } session1->allocateObjectById(allocatablebis); try { session2->allocateObjectById(allocatablebis); test(false); } catch(const AllocationTimeoutException&) { } session1->releaseObject(allocatablebis); session2->allocateObjectById(allocatablebis); try { session1->allocateObjectById(allocatablebis); test(false); } catch(const AllocationTimeoutException&) { } session2->releaseObject(allocatablebis); session2->setAllocationTimeout(allocationTimeout); CallbackPtr asyncCB1 = new Callback(); IceGrid::Callback_Session_allocateObjectByIdPtr cb1 = IceGrid::newCallback_Session_allocateObjectById(asyncCB1, &Callback::response, &Callback::exception); session2->begin_allocateObjectById(allocatable, cb1); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB1->hasResponse(dummy)); session1->releaseObject(allocatable); asyncCB1->waitResponse(__FILE__, __LINE__); test(asyncCB1->hasResponse(dummy)); session1->setAllocationTimeout(0); try { session1->allocateObjectById(allocatable); test(false); } catch(const AllocationTimeoutException&) { } try { session1->releaseObject(allocatable); test(false); } catch(const AllocationException&) { } session1->setAllocationTimeout(allocationTimeout); asyncCB1 = new Callback(); cb1 = IceGrid::newCallback_Session_allocateObjectById(asyncCB1, &Callback::response, &Callback::exception); session1->begin_allocateObjectById(allocatable, cb1); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB1->hasResponse(dummy)); session2->releaseObject(allocatable); asyncCB1->waitResponse(__FILE__, __LINE__); test(asyncCB1->hasResponse(dummy)); session1->releaseObject(allocatable); cout << "ok" << endl; cout << "testing allocate object by type... " << flush; session1->setAllocationTimeout(0); session2->setAllocationTimeout(0); try { obj = session1->allocateObjectByType("::Unknown"); test(false); } catch(const AllocationTimeoutException&) { test(false); } catch(const AllocationException&) { } try { obj = session1->allocateObjectByType("::NotAllocatable"); test(false); } catch(const AllocationTimeoutException&) { test(false); } catch(const AllocationException&) { } obj = session1->allocateObjectByType("::Test"); test(obj && obj->ice_getIdentity().name == "allocatable"); try { session1->allocateObjectByType("::Test"); test(false); } catch(const AllocationException&) { } try { session2->allocateObjectByType("::Test"); test(false); } catch(const AllocationTimeoutException&) { } try { session2->releaseObject(obj->ice_getIdentity()); } catch(const AllocationException&) { } session1->releaseObject(obj->ice_getIdentity()); try { session1->releaseObject(obj->ice_getIdentity()); } catch(const AllocationException&) { } obj = session2->allocateObjectByType("::Test"); // Allocate the object test(obj && obj->ice_getIdentity().name == "allocatable"); try { session2->allocateObjectByType("::Test"); test(false); } catch(const AllocationException&) { } try { session1->allocateObjectByType("::Test"); test(false); } catch(const AllocationTimeoutException&) { } session1->allocateObjectByType("::TestBis"); try { session2->allocateObjectByType("::TestBis"); test(false); } catch(const AllocationTimeoutException&) { } session1->releaseObject(allocatablebis); session2->allocateObjectByType("::TestBis"); try { session1->allocateObjectByType("::TestBis"); test(false); } catch(const AllocationTimeoutException&) { } session2->releaseObject(allocatablebis); session1->setAllocationTimeout(allocationTimeout); CallbackPtr asyncCB3 = new Callback(); IceGrid::Callback_Session_allocateObjectByTypePtr cb3 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB3, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::Test", cb3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB3->hasResponse(dummy)); session2->releaseObject(obj->ice_getIdentity()); asyncCB3->waitResponse(__FILE__, __LINE__); test(asyncCB3->hasResponse(obj)); session1->releaseObject(obj->ice_getIdentity()); admin->enableServer("ObjectAllocation", false); try { while(true) { // The notification of the server being disabled is asynchronous and might // not be visible to the allocation system immediately. session1->allocateObjectByType("::Test"); session1->releaseObject(obj->ice_getIdentity()); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100)); } test(false); } catch(const AllocationException&) { } admin->enableServer("ObjectAllocation", true); cout << "ok" << endl; cout << "testing object allocation timeout... " << flush; session1->allocateObjectById(allocatable); IceUtil::Time time = IceUtil::Time::now(); session2->setAllocationTimeout(500); try { session2->allocateObjectById(allocatable); test(false); } catch(const AllocationTimeoutException&) { test(time + IceUtil::Time::milliSeconds(100) < IceUtil::Time::now()); } time = IceUtil::Time::now(); try { session2->allocateObjectById(allocatable); test(false); } catch(const AllocationTimeoutException&) { } test(time + IceUtil::Time::milliSeconds(100) < IceUtil::Time::now()); time = IceUtil::Time::now(); try { session2->allocateObjectByType("::Test"); test(false); } catch(const AllocationTimeoutException&) { } test(time + IceUtil::Time::milliSeconds(100) < IceUtil::Time::now()); session1->releaseObject(allocatable); session2->setAllocationTimeout(0); cout << "ok" << endl; cout << "testing server allocation... " << flush; session1->setAllocationTimeout(0); session2->setAllocationTimeout(0); Ice::Identity allocatable3 = Ice::stringToIdentity("allocatable3"); Ice::Identity allocatable4 = Ice::stringToIdentity("allocatable4"); session1->allocateObjectById(allocatable3); try { session2->allocateObjectById(allocatable3); test(false); } catch(const AllocationTimeoutException&) { } try { session2->allocateObjectById(allocatable4); test(false); } catch(const AllocationTimeoutException&) { } session1->allocateObjectById(allocatable4); session1->releaseObject(allocatable3); try { session2->allocateObjectById(allocatable3); test(false); } catch(const AllocationTimeoutException&) { } session1->releaseObject(allocatable4); session2->allocateObjectById(allocatable3); try { session1->allocateObjectById(allocatable3); test(false); } catch(const AllocationTimeoutException&) { } try { session1->allocateObjectById(allocatable4); test(false); } catch(const AllocationTimeoutException&) { } session2->allocateObjectById(allocatable4); session2->releaseObject(allocatable3); try { session1->allocateObjectById(allocatable3); test(false); } catch(const AllocationTimeoutException&) { } try { session1->allocateObjectByType("::TestServer1"); test(false); } catch(const AllocationException&) { } try { session1->allocateObjectByType("::TestServer2"); test(false); } catch(const AllocationException&) { } test(session2->allocateObjectByType("::TestServer1")); try { session2->allocateObjectByType("::TestServer1"); test(false); } catch(const AllocationException&) { } try { session2->allocateObjectByType("::TestServer2"); test(false); } catch(const AllocationException&) { } session2->releaseObject(allocatable3); session2->releaseObject(allocatable4); session1->allocateObjectById(allocatable3); session1->allocateObjectById(allocatable4); session2->setAllocationTimeout(allocationTimeout); asyncCB1 = new Callback(); cb1 = IceGrid::newCallback_Session_allocateObjectById(asyncCB1, &Callback::response, &Callback::exception); session2->begin_allocateObjectById(allocatable3, cb1); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB1->hasResponse(dummy)); session1->releaseObject(allocatable3); test(!asyncCB1->hasResponse(dummy)); session1->releaseObject(allocatable4); asyncCB1->waitResponse(__FILE__, __LINE__); test(asyncCB1->hasResponse(dummy)); session2->releaseObject(allocatable3); session1->setAllocationTimeout(allocationTimeout); test(session2->allocateObjectByType("::TestServer1")); asyncCB3 = new Callback(); cb3 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB3, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::TestServer2", cb3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB3->hasResponse(dummy)); session2->releaseObject(allocatable3); asyncCB3->waitResponse(__FILE__, __LINE__); test(asyncCB3->hasResponse(dummy)); session1->releaseObject(allocatable4); session1->setAllocationTimeout(0); session2->setAllocationTimeout(0); test(session1->allocateObjectByType("::TestMultipleByServer")); try { session2->allocateObjectByType("::TestMultipleByServer"); test(false); } catch(const AllocationException&) { } test(session1->allocateObjectByType("::TestMultipleByServer")); session1->releaseObject(Ice::stringToIdentity("allocatable31")); session1->releaseObject(Ice::stringToIdentity("allocatable41")); test(session2->allocateObjectByType("::TestMultipleByServer")); try { session1->allocateObjectByType("::TestMultipleByServer"); test(false); } catch(const AllocationException&) { } test(session2->allocateObjectByType("::TestMultipleByServer")); session2->releaseObject(Ice::stringToIdentity("allocatable31")); session2->releaseObject(Ice::stringToIdentity("allocatable41")); Ice::ObjectPrx obj1 = session1->allocateObjectByType("::TestMultipleServer"); test(obj1); Ice::ObjectPrx obj2 = session2->allocateObjectByType("::TestMultipleServer"); test(obj2); try { session1->allocateObjectByType("::TestMultipleServer"); test(false); } catch(const AllocationTimeoutException&) { } try { session2->allocateObjectByType("::TestMultipleServer"); test(false); } catch(const AllocationTimeoutException&) { } session1->releaseObject(obj1->ice_getIdentity()); obj1 = session2->allocateObjectByType("::TestMultipleServer"); session2->releaseObject(obj1->ice_getIdentity()); session2->releaseObject(obj2->ice_getIdentity()); admin->enableServer("ServerAllocation", false); try { while(true) { // The notification of the server being disabled is asynchronous and might // not be visible to the allocation system immediately. session1->allocateObjectByType("::TestServer1"); session1->releaseObject(allocatable3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100)); } test(false); } catch(const AllocationException&) { } admin->enableServer("ServerAllocation", true); cout << "ok" << endl; cout << "testing concurrent allocations... " << flush; session1->setAllocationTimeout(allocationTimeout); session2->setAllocationTimeout(allocationTimeout); session2->allocateObjectById(allocatable); CallbackPtr asyncCB11 = new Callback(); IceGrid::Callback_Session_allocateObjectByIdPtr cb11 = IceGrid::newCallback_Session_allocateObjectById(asyncCB11, &Callback::response, &Callback::exception); CallbackPtr asyncCB12 = new Callback(); IceGrid::Callback_Session_allocateObjectByIdPtr cb12 = IceGrid::newCallback_Session_allocateObjectById(asyncCB12, &Callback::response, &Callback::exception); session1->begin_allocateObjectById(allocatable, cb11); session1->begin_allocateObjectById(allocatable, cb12); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB11->hasResponse(dummy)); test(!asyncCB12->hasResponse(dummy)); session2->releaseObject(allocatable); asyncCB11->waitResponse(__FILE__, __LINE__); asyncCB12->waitResponse(__FILE__, __LINE__); test(asyncCB11->hasResponse(dummy) ? asyncCB12->hasException() : asyncCB12->hasResponse(dummy)); test(asyncCB12->hasResponse(dummy) ? asyncCB11->hasException() : asyncCB11->hasResponse(dummy)); session1->releaseObject(allocatable); session2->allocateObjectById(allocatable); CallbackPtr asyncCB31 = new Callback(); IceGrid::Callback_Session_allocateObjectByTypePtr cb31 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB31, &Callback::response, &Callback::exception); CallbackPtr asyncCB32 = new Callback(); IceGrid::Callback_Session_allocateObjectByTypePtr cb32 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB32, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::Test", cb31); session1->begin_allocateObjectByType("::Test", cb32); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB31->hasResponse(dummy)); test(!asyncCB32->hasResponse(dummy)); session2->releaseObject(allocatable); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); do { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } while(!asyncCB31->hasResponse(dummy) && !asyncCB32->hasResponse(dummy)); test((asyncCB31->hasResponse(dummy) && dummy && !asyncCB32->hasResponse(dummy)) || (asyncCB32->hasResponse(dummy) && dummy && !asyncCB31->hasResponse(dummy))); session1->releaseObject(allocatable); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); CallbackPtr asyncCB33 = asyncCB31->hasResponse(dummy) ? asyncCB32 : asyncCB31; asyncCB33->waitResponse(__FILE__, __LINE__); test(asyncCB33->hasResponse(dummy) && dummy); session1->releaseObject(allocatable); session2->allocateObjectById(allocatable3); asyncCB11 = new Callback(); cb11 = IceGrid::newCallback_Session_allocateObjectById(asyncCB11, &Callback::response, &Callback::exception); asyncCB12 = new Callback(); cb12 = IceGrid::newCallback_Session_allocateObjectById(asyncCB12, &Callback::response, &Callback::exception); session1->begin_allocateObjectById(allocatable3, cb11); session1->begin_allocateObjectById(allocatable3, cb12); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB11->hasResponse(dummy)); test(!asyncCB12->hasResponse(dummy)); session2->releaseObject(allocatable3); asyncCB11->waitResponse(__FILE__, __LINE__); asyncCB12->waitResponse(__FILE__, __LINE__); test(asyncCB11->hasResponse(dummy) ? asyncCB12->hasException() : asyncCB12->hasResponse(dummy)); test(asyncCB12->hasResponse(dummy) ? asyncCB11->hasException() : asyncCB11->hasResponse(dummy)); session1->releaseObject(allocatable3); session2->allocateObjectById(allocatable3); asyncCB31 = new Callback(); cb31 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB31, &Callback::response, &Callback::exception); asyncCB32 = new Callback(); cb32 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB32, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::TestServer1", cb31); session1->begin_allocateObjectByType("::TestServer1", cb32); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB31->hasResponse(dummy)); test(!asyncCB32->hasResponse(dummy)); session2->releaseObject(allocatable3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); do { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } while(!asyncCB31->hasResponse(dummy) && !asyncCB32->hasResponse(dummy)); test((asyncCB31->hasResponse(dummy) && dummy && !asyncCB32->hasResponse(dummy)) || (asyncCB32->hasResponse(dummy) && dummy && !asyncCB31->hasResponse(dummy))); session1->releaseObject(allocatable3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); asyncCB33 = asyncCB31->hasResponse(dummy) ? asyncCB32 : asyncCB31; asyncCB33->waitResponse(__FILE__, __LINE__); test(asyncCB33->hasResponse(dummy) && dummy); session1->releaseObject(allocatable3); session1->allocateObjectById(allocatable3); asyncCB31 = new Callback(); cb31 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB31, &Callback::response, &Callback::exception); asyncCB32 = new Callback(); cb32 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB32, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::TestServer1", cb31); session1->begin_allocateObjectByType("::TestServer1", cb32); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB31->hasResponse(dummy)); test(!asyncCB32->hasResponse(dummy)); session1->releaseObject(allocatable3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); do { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } while(!asyncCB31->hasResponse(dummy) && !asyncCB32->hasResponse(dummy)); test((asyncCB31->hasResponse(dummy) && dummy && !asyncCB32->hasResponse(dummy)) || (asyncCB32->hasResponse(dummy) && dummy && !asyncCB31->hasResponse(dummy))); session1->releaseObject(allocatable3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(300)); asyncCB33 = asyncCB31->hasResponse(dummy) ? asyncCB32 : asyncCB31; asyncCB33->waitResponse(__FILE__, __LINE__); test(asyncCB33->hasResponse(dummy) && dummy); session1->releaseObject(allocatable3); cout << "ok" << endl; cout << "testing session destroy... " << flush; obj = session2->allocateObjectByType("::Test"); // Allocate the object test(obj && obj->ice_getIdentity().name == "allocatable"); session1->setAllocationTimeout(allocationTimeout); asyncCB3 = new Callback(); cb3 = IceGrid::newCallback_Session_allocateObjectByType(asyncCB3, &Callback::response, &Callback::exception); session1->begin_allocateObjectByType("::Test", cb3); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); test(!asyncCB3->hasResponse(dummy)); session2->destroy(); asyncCB3->waitResponse(__FILE__, __LINE__); test(asyncCB3->hasResponse(obj)); session1->destroy(); session2 = SessionPrx::uncheckedCast(registry->createSession("Client2", "")); session2->setAllocationTimeout(0); session2->allocateObjectById(allocatable); session2->destroy(); cout << "ok" << endl; cout << "testing application updates with allocated objects... " << flush; { SessionPrx session1 = registry->createSession("Client1", ""); SessionPrx session2 = registry->createSession("Client2", ""); ServerDescriptorPtr objectAllocOriginal = admin->getServerInfo("ObjectAllocation").descriptor; ServerDescriptorPtr objectAllocUpdate = ServerDescriptorPtr::dynamicCast(objectAllocOriginal->ice_clone()); ServerDescriptorPtr serverAllocOriginal = admin->getServerInfo("ServerAllocation").descriptor; ServerDescriptorPtr serverAllocUpdate = ServerDescriptorPtr::dynamicCast(serverAllocOriginal->ice_clone()); NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "localnode"; nodeUpdate.servers.push_back(objectAllocUpdate); nodeUpdate.servers.push_back(serverAllocUpdate); ApplicationUpdateDescriptor appUpdate; appUpdate.name = "Test"; appUpdate.nodes.push_back(nodeUpdate); { session1->allocateObjectById(allocatable3); Ice::AsyncResultPtr r2 = session2->begin_allocateObjectById(allocatable4); session1->allocateObjectById(allocatable4); session1->releaseObject(allocatable4); test(!r2->isCompleted()); serverAllocUpdate->allocatable = false; admin->updateApplication(appUpdate); test(!r2->isCompleted()); session1->releaseObject(allocatable3); session2->end_allocateObjectById(r2); session2->releaseObject(allocatable4); serverAllocUpdate->allocatable = true; admin->updateApplication(appUpdate); } { session1->allocateObjectById(allocatable); Ice::AsyncResultPtr r2 = session2->begin_allocateObjectById(allocatable); objectAllocUpdate->deactivationTimeout = "23"; admin->updateApplication(appUpdate); session1->releaseObject(allocatable); session2->end_allocateObjectById(r2); session2->releaseObject(allocatable); } { session1->allocateObjectById(allocatable); Ice::AsyncResultPtr r2 = session2->begin_allocateObjectById(allocatable); vector<ObjectDescriptor> allocatables = objectAllocUpdate->adapters[0].allocatables; objectAllocUpdate->adapters[0].allocatables.clear(); // Remove the allocatable object admin->updateApplication(appUpdate); try { session2->end_allocateObjectById(r2); test(false); } catch(const ObjectNotRegisteredException&) { } try { session1->releaseObject(allocatable); test(false); } catch(const ObjectNotRegisteredException&) { } objectAllocUpdate->adapters[0].allocatables = allocatables; admin->updateApplication(appUpdate); } session1->destroy(); session2->destroy(); } cout << "ok" << endl; cout << "testing allocation with Glacier2 session... " << flush; Ice::ObjectPrx routerBase = communicator->stringToProxy("Glacier2/router:default -p 12347"); Glacier2::RouterPrx router1 = Glacier2::RouterPrx::checkedCast(routerBase->ice_connectionId("client1")); test(router1); Glacier2::SessionPrx sessionBase = router1->createSession("test1", "abc123"); try { session1 = IceGrid::SessionPrx::checkedCast(sessionBase->ice_connectionId("client1")->ice_router(router1)); test(session1); session1->ice_ping(); Ice::ObjectPrx obj; obj = session1->allocateObjectById(allocatable)->ice_connectionId("client1")->ice_router(router1); obj->ice_ping(); session1->releaseObject(allocatable); try { obj->ice_ping(); } catch(const Ice::ObjectNotExistException&) { } obj = session1->allocateObjectById(allocatable3)->ice_connectionId("client1")->ice_router(router1); obj->ice_ping(); obj2 = communicator->stringToProxy("allocatable4")->ice_connectionId("client1")->ice_router(router1); obj2->ice_ping(); session1->releaseObject(allocatable3); try { obj->ice_ping(); } catch(const Ice::ObjectNotExistException&) { } try { obj2->ice_ping(); } catch(const Ice::ObjectNotExistException&) { } session1->destroy(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "stress test... " << flush; SessionPrx stressSession = registry->createSession("StressSession", ""); const int nClients = 10; int i; vector<StressClientPtr> clients; for(i = 0; i < nClients - 2; ++i) { if(IceUtilInternal::random(2) == 1) { clients.push_back(new StressClient(i, registry, false)); } else { clients.push_back(new StressClient(i, stressSession)); } clients.back()->start(); } clients.push_back(new StressClient(i++, registry, true)); clients.back()->start(); clients.push_back(new StressClient(i++, registry, true)); clients.back()->start(); for(vector<StressClientPtr>::const_iterator p = clients.begin(); p != clients.end(); ++p) { (*p)->notifyThread(); } // // Let the stress client run for a bit. // IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(8)); // // Terminate the stress clients. // for(vector<StressClientPtr>::const_iterator q = clients.begin(); q != clients.end(); ++q) { (*q)->terminate(); (*q)->getThreadControl().join(); } stressSession->destroy(); cout << "ok" << endl; } catch(const AllocationTimeoutException& ex) { cerr << ex << endl; test(false); } catch(const AllocationException& ex) { cerr << ex.reason << endl; test(false); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } cout << "shutting down router... " << flush; admin->stopServer("Glacier2"); cout << "ok" << endl; 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(); }