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::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()); 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()); 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& 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); AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways); AdminPrx admin = session->getAdmin(); test(admin); Ice::PropertiesPtr properties = communicator->getProperties(); { ApplicationDescriptor testApp; testApp.name = "TestApp"; admin->addApplication(testApp); ApplicationUpdateDescriptor empty; empty.name = "TestApp"; NodeUpdateDescriptor node; node.name = "localnode"; empty.nodes.push_back(node); ApplicationUpdateDescriptor update = empty; cout << "testing server add... " << flush; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "Server"; server->exe = properties->getProperty("TestDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); AdapterDescriptor adapter; adapter.name = "Server"; adapter.id = "ServerAdapter"; adapter.registerProcess = false; adapter.serverLifetime = false; addProperty(server, "Server.Endpoints", "default"); ObjectDescriptor object; object.id = communicator->stringToIdentity("test"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); update.nodes[0].servers.push_back(server); admin->updateApplication(update); update.nodes[0].servers[0]->id = "Server2"; try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Adapter already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update.nodes[0].servers[0]->adapters[0].id = "ServerAdapter2"; try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Object already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update.nodes[0].servers[0]->adapters[0].objects[0].id = communicator->stringToIdentity("test2"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } TemplateDescriptor templ; templ.parameters.push_back("name"); templ.descriptor = new ServerDescriptor(); server = ServerDescriptorPtr::dynamicCast(templ.descriptor); server->id = "${name}"; server->exe = "${test.dir}/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); adapter = AdapterDescriptor(); adapter.name = "Server"; adapter.id = "${server}"; adapter.registerProcess = false; adapter.serverLifetime = false; addProperty(server, "Server.Endpoints", "default"); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("${server}"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); update = empty; update.serverTemplates["ServerTemplate"] = templ; try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; ServerInstanceDescriptor instance; instance._cpp_template = "ServerTemplate"; update.nodes[0].serverInstances.push_back(instance); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Missing parameter } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; update.variables["test.dir"] = properties->getProperty("TestDir"); update.variables["variable"] = ""; instance = ServerInstanceDescriptor(); instance._cpp_template = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server remove... " << flush; update = empty; update.nodes[0].removeServers.push_back("Server2"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { admin->getServerInfo("Server2"); test(false); } catch(const ServerNotExistException&) { } try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; update.removeServerTemplates.push_back("ServerTemplate"); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Server without template! } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; update.nodes[0].removeServers.push_back("Server1"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { admin->getServerInfo("Server1"); test(false); } catch(const ServerNotExistException&) { } update = empty; update.removeServerTemplates.push_back("ServerTemplate"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing server update... " << flush; ServerInfo info = admin->getServerInfo("Server"); test(info.descriptor); addProperty(info.descriptor, "test", "test"); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); test(getProperty(info.descriptor->propertySet.properties, "test") == "test"); update = empty; update.serverTemplates["ServerTemplate"] = templ; instance = ServerInstanceDescriptor(); instance._cpp_template = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; addProperty(server, "test", "test"); assert(templ.descriptor == server); update.serverTemplates["ServerTemplate"] = templ; try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server1"); test(info.descriptor); test(getProperty(info.descriptor->propertySet.properties, "test") == "test"); info = admin->getServerInfo("Server"); test(info.descriptor); adapter = AdapterDescriptor(); adapter.id = "Server1"; adapter.serverLifetime = false; adapter.registerProcess = false; info.descriptor->adapters.push_back(adapter); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Adapter already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); adapter = AdapterDescriptor(); adapter.id = "ServerX"; adapter.serverLifetime = false; adapter.registerProcess = false; object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test"); adapter.objects.push_back(object); info.descriptor->adapters.push_back(adapter); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Object already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test"); info.descriptor->adapters[0].objects.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Object already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test1"); info.descriptor->adapters[0].allocatables.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(true); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test1"); info.descriptor->adapters[0].allocatables.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Object already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test"); info.descriptor->adapters[0].allocatables.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(true); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test"); info.descriptor->adapters[0].allocatables.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Object already exists } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } admin->removeApplication("TestApp"); cout << "ok" << endl; } { ApplicationDescriptor testApp; testApp.name = "TestApp"; admin->addApplication(testApp); ApplicationUpdateDescriptor empty; empty.name = "TestApp"; NodeUpdateDescriptor node; node.name = "localnode"; empty.nodes.push_back(node); ApplicationUpdateDescriptor update = empty; cout << "testing icebox server add... " << flush; ServiceDescriptorPtr service = new ServiceDescriptor(); service->name = "Service1"; service->entry = "TestService:create"; AdapterDescriptor adapter; adapter.name = "${service}"; adapter.id = "${server}.${service}"; adapter.registerProcess = false; adapter.serverLifetime = false; addProperty(service, "${service}.Endpoints", "default"); service->adapters.push_back(adapter); IceBoxDescriptorPtr server = new IceBoxDescriptor(); server->id = "IceBox"; string iceboxExe = "/icebox"; #if defined(__linux) # if defined(__i386) iceboxExe += "32"; # endif # if defined(ICE_CPP11) iceboxExe += "++11"; # endif #endif #if defined(_WIN32) && !defined(NDEBUG) iceboxExe += "d"; #endif server->exe = properties->getProperty("IceBinDir") + iceboxExe; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); server->services.resize(3); server->services[0].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); service->name = "Service2"; server->services[1].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); service->name = "Service3"; server->services[2].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); update.nodes[0].servers.push_back(server); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing service add... " << flush; service->name = "First"; server->services.resize(4); server->services[3].descriptor = service; try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing service remove... " << flush; server->services.resize(3); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; admin->removeApplication("TestApp"); } { cout << "testing node add... " << flush; ApplicationDescriptor testApp; testApp.name = "TestApp"; NodeDescriptor node; node.variables["nodename"] = "node1"; testApp.nodes["node1"] = node; try { admin->addApplication(testApp); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ApplicationUpdateDescriptor update; update.name = "TestApp"; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node2"; nodeUpdate.variables["nodename"] = "node2"; update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.nodes.size() == 2); test(testApp.nodes["node1"].variables["nodename"] == "node1"); test(testApp.nodes["node2"].variables["nodename"] == "node2"); cout << "ok" << endl; cout << "testing node update... " << flush; nodeUpdate.name = "node2"; nodeUpdate.variables["nodename"] = "node2updated"; update.nodes.back() = nodeUpdate; try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.nodes.size() == 2); test(testApp.nodes["node1"].variables["nodename"] == "node1"); test(testApp.nodes["node2"].variables["nodename"] == "node2updated"); cout << "ok" << endl; cout << "testing node remove... " << flush; update.nodes.clear(); update.removeNodes.push_back("node1"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.nodes.size() == 1); test(testApp.nodes["node2"].variables["nodename"] == "node2updated"); admin->removeApplication("TestApp"); cout << "ok" << endl; } { cout << "testing variable update... " << flush; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "${name}"; server->exe = "server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "ApplicationVar", "${appvar}"); addProperty(server, "NodeVar", "${nodevar}"); addProperty(server, "ServerParamVar", "${serverparamvar}"); TemplateDescriptor templ; templ.parameters.push_back("name"); templ.parameters.push_back("serverparamvar"); templ.descriptor = server; ApplicationDescriptor testApp; testApp.name = "TestApp"; testApp.variables["appvar"] = "AppValue"; testApp.serverTemplates["ServerTemplate"] = templ; NodeDescriptor node; node.variables["nodevar"] = "NodeValue"; ServerInstanceDescriptor serverInstance; serverInstance._cpp_template = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; serverInstance.parameterValues["serverparamvar"] = "ServerParamValue"; node.serverInstances.push_back(serverInstance); testApp.nodes["node1"] = node; try { admin->addApplication(testApp); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ApplicationUpdateDescriptor empty; empty.name = "TestApp"; ApplicationUpdateDescriptor update = empty; update.removeVariables.push_back("appvar"); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Missing app variable //cerr << ex.reason << endl; } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node1"; nodeUpdate.removeVariables.push_back("nodevar"); update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Missing node variable //cerr << ex.reason << endl; } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } update = empty; serverInstance = ServerInstanceDescriptor(); serverInstance._cpp_template = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node1"; nodeUpdate.serverInstances.push_back(serverInstance); update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); test(false); } catch(const DeploymentException&) { // Missing parameter //cerr << ex.reason << endl; } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ServerInfo serverBefore = admin->getServerInfo("Server"); ApplicationDescriptor origApp = admin->getApplicationInfo("TestApp").descriptor; update = empty; update.variables["nodevar"] = "appoverride"; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node1"; nodeUpdate.variables["serverparamvar"] = "nodeoverride"; update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ServerInfo serverAfter = admin->getServerInfo("Server"); test(serverBefore.descriptor->propertySet == serverAfter.descriptor->propertySet); update = empty; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node1"; nodeUpdate.variables["appvar"] = "nodeoverride"; update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } serverAfter = admin->getServerInfo("Server"); PropertyDescriptorSeq newProps = serverAfter.descriptor->propertySet.properties; test(getProperty(serverAfter.descriptor->propertySet.properties, "ApplicationVar") == "nodeoverride"); test(getProperty(serverAfter.descriptor->propertySet.properties, "NodeVar") == "NodeValue"); test(getProperty(serverAfter.descriptor->propertySet.properties, "ServerParamVar") == "ServerParamValue"); admin->removeApplication("TestApp"); cout << "ok" << endl; } { cout << "testing property set update... " << flush; ServiceDescriptorPtr service = new ServiceDescriptor(); service->name = "${name}"; service->entry = "dummy"; addProperty(service, "ServiceProp", "test"); TemplateDescriptor svcTempl; svcTempl.parameters.push_back("name"); svcTempl.descriptor = service; ServiceInstanceDescriptor serviceInstance; serviceInstance._cpp_template = "ServiceTemplate"; serviceInstance.parameterValues["name"] = "Service"; serviceInstance.propertySet.properties.push_back(createProperty("ServiceInstanceProp", "test")); IceBoxDescriptorPtr server = new IceBoxDescriptor(); server->id = "${name}"; server->exe = "server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; server->propertySet.references.push_back("ApplicationPropertySet"); server->propertySet.references.push_back("NodePropertySet"); addProperty(server, "ServerProp", "test"); server->services.push_back(serviceInstance); TemplateDescriptor templ; templ.parameters.push_back("name"); templ.descriptor = server; ApplicationDescriptor testApp; testApp.name = "TestApp"; testApp.variables["appvar"] = "AppValue"; testApp.serverTemplates["ServerTemplate"] = templ; testApp.serviceTemplates["ServiceTemplate"] = svcTempl; testApp.propertySets["ApplicationPropertySet"].properties.push_back(createProperty("ApplicationProp","test")); testApp.propertySets["ApplicationPropertySet1"].properties.push_back(createProperty("ApplicationProp", "d")); NodeDescriptor node; node.variables["nodevar"] = "NodeValue"; node.propertySets["NodePropertySet"].properties.push_back(createProperty("NodeProp", "test")); node.propertySets["NodePropertySet1"].properties.push_back(createProperty("NodeProp", "test")); ServerInstanceDescriptor serverInstance; serverInstance._cpp_template = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; serverInstance.propertySet.properties.push_back(createProperty("ServerInstanceProp", "test")); node.serverInstances.push_back(serverInstance); testApp.nodes["node1"] = node; try { admin->addApplication(testApp); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ServerInfo info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "ServerProp", "test")); test(hasProperty(info.descriptor, "NodeProp", "test")); test(hasProperty(info.descriptor, "ApplicationProp", "test")); test(hasProperty(info.descriptor, "ServerInstanceProp", "test")); ServiceDescriptorPtr svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor; test(hasProperty(svc, "ServiceProp", "test")); ApplicationUpdateDescriptor empty; empty.name = "TestApp"; ApplicationUpdateDescriptor update; update = empty; service->propertySet.properties.clear(); addProperty(service, "ServiceProp", "updated"); svcTempl.descriptor = service; update.serviceTemplates["ServiceTemplate"] = svcTempl; admin->updateApplication(update); info = admin->getServerInfo("Server"); svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor; test(hasProperty(svc, "ServiceProp", "updated")); update = empty; serviceInstance.propertySet.properties.clear(); serviceInstance.propertySet.properties.push_back(createProperty("ServiceInstanceProp", "updated")); server->services.clear(); server->services.push_back(serviceInstance); templ.descriptor = server; update.serverTemplates["ServerTemplate"] = templ; admin->updateApplication(update); info = admin->getServerInfo("Server"); svc = IceBoxDescriptorPtr::dynamicCast(info.descriptor)->services[0].descriptor; test(hasProperty(svc, "ServiceInstanceProp", "updated")); update = empty; server->propertySet.properties.clear(); addProperty(server, "ServerProp", "updated"); templ.descriptor = server; update.serverTemplates["ServerTemplate"] = templ; admin->updateApplication(update); info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "ServerProp", "updated")); update = empty; serverInstance.propertySet.properties.clear(); serverInstance.propertySet.properties.push_back(createProperty("ServerInstanceProp", "updated")); NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node1"; nodeUpdate.serverInstances.push_back(serverInstance); update.nodes.push_back(nodeUpdate); admin->updateApplication(update); info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "ServerInstanceProp", "updated")); update = empty; nodeUpdate.name = "node1"; nodeUpdate.serverInstances.clear(); nodeUpdate.propertySets["NodePropertySet"].properties.clear(); nodeUpdate.propertySets["NodePropertySet"].properties.push_back( createProperty("NodeProp", "updated")); nodeUpdate.removePropertySets.push_back("NodePropertySet1"); update.nodes.push_back(nodeUpdate); admin->updateApplication(update); info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "NodeProp", "updated")); ApplicationDescriptor updatedApplication = admin->getApplicationInfo("TestApp").descriptor; test(updatedApplication.nodes["node1"].propertySets.find("NodePropertySet1") == updatedApplication.nodes["node1"].propertySets.end()); update = empty; update.propertySets["ApplicationPropertySet"].properties.clear(); update.propertySets["ApplicationPropertySet"].properties.push_back( createProperty("ApplicationProp", "updated")); update.removePropertySets.push_back("ApplicationPropertySet1"); admin->updateApplication(update); info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "ApplicationProp", "updated")); updatedApplication = admin->getApplicationInfo("TestApp").descriptor; test(updatedApplication.propertySets.find("ApplicationPropertySet1") == updatedApplication.propertySets.end()); admin->removeApplication("TestApp"); cout << "ok" << endl; } { cout << "testing description update... " << flush; ApplicationDescriptor testApp; testApp.name = "TestApp"; testApp.description = "Description"; try { admin->addApplication(testApp); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.description == "Description"); ApplicationUpdateDescriptor update; update.name = "TestApp"; try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.description == "Description"); update.description = new BoxedString("updatedDescription"); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.description == "updatedDescription"); update.description = new BoxedString(""); try { admin->updateApplication(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } testApp = admin->getApplicationInfo("TestApp").descriptor; test(testApp.description == ""); admin->removeApplication("TestApp"); cout << "ok" << endl; } { cout << "testing server node move... " << flush; ApplicationDescriptor nodeApp; nodeApp.name = "NodeApp"; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "node-${index}"; #if defined(NDEBUG) || !defined(_WIN32) server->exe = properties->getProperty("IceBinDir") + "/icegridnode"; #else server->exe = properties->getProperty("IceBinDir") + "/icegridnoded"; #endif server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; server->options.push_back("--nowarn"); addProperty(server, "IceGrid.Node.Name", "node-${index}"); addProperty(server, "IceGrid.Node.Data", properties->getProperty("TestDir") + "/db/node-${index}"); addProperty(server, "IceGrid.Node.Endpoints", "default"); addProperty(server, "IceGrid.Node.PropertiesOverride", properties->getProperty("NodePropertiesOverride")); addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); nodeApp.serverTemplates["nodeTemplate"].descriptor = server; nodeApp.serverTemplates["nodeTemplate"].parameters.push_back("index"); ServerInstanceDescriptor instance; instance._cpp_template = "nodeTemplate"; instance.parameterValues["index"] = "1"; nodeApp.nodes["localnode"].serverInstances.push_back(instance); instance.parameterValues["index"] = "2"; nodeApp.nodes["localnode"].serverInstances.push_back(instance); try { admin->addApplication(nodeApp); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } admin->startServer("node-1"); admin->startServer("node-2"); // // We need to wait because the node might not be fully started // here (the node adapter isn't indirect, so we can't use the // wait-for-activation feature here.) // int retry = 0; while(retry < 20) { try { if(admin->pingNode("node-1") && admin->pingNode("node-2")) { break; } } catch(const NodeNotExistException&) { } IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); ++retry; } test(admin->pingNode("node-1")); test(admin->pingNode("node-2")); ApplicationDescriptor testApp; testApp.name = "TestApp"; server = new ServerDescriptor(); server->id = "Server"; server->exe = properties->getProperty("TestDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); AdapterDescriptor adapter; adapter.name = "Server"; adapter.id = "ServerAdapter"; adapter.registerProcess = false; adapter.serverLifetime = true; server->adapters.push_back(adapter); addProperty(server, "Server.Endpoints", "default"); testApp.nodes["node-1"].servers.push_back(server); try { admin->addApplication(testApp); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } try { admin->startServer("Server"); test(admin->getServerState("Server") == Active); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ApplicationUpdateDescriptor update; update.name = "TestApp"; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node-1"; nodeUpdate.removeServers.push_back("Server"); update.nodes.push_back(nodeUpdate); nodeUpdate.name = "node-2"; nodeUpdate.servers.push_back(server); nodeUpdate.removeServers.clear(); update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } while(true) { try { test(admin->getServerInfo("Server").node == "node-2" && admin->getServerState("Server") == Inactive); admin->startServer("Server"); test(admin->getServerState("Server") == Active); break; } catch(const DeploymentException&) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(200)); } } IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1)); update = ApplicationUpdateDescriptor(); update.name = "TestApp"; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node-2"; nodeUpdate.removeServers.push_back("Server"); update.nodes.push_back(nodeUpdate); nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "unknownNode"; nodeUpdate.servers.push_back(server); update.nodes.push_back(nodeUpdate); try { admin->updateApplication(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } try { admin->getServerState("Server"); test(false); } catch(const NodeUnreachableException&) { } try { admin->removeApplication("TestApp"); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } admin->stopServer("node-1"); admin->stopServer("node-2"); try { admin->removeApplication("NodeApp"); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; } 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 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::HeartbeatAlways); AdminPrx admin = session->getAdmin(); test(admin); Ice::PropertiesPtr properties = communicator->getProperties(); { ApplicationDescriptor testApp; testApp.name = "TestApp"; admin->addApplication(testApp); ApplicationUpdateDescriptor empty; empty.name = "TestApp"; NodeUpdateDescriptor node; node.name = "localnode"; empty.nodes.push_back(node); ApplicationUpdateDescriptor update = empty; cout << "testing server add... " << flush; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "Server"; server->exe = properties->getProperty("ServerDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; server->activation = "on-demand"; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); AdapterDescriptor adapter; adapter.name = "Server"; adapter.id = "ServerAdapter"; adapter.registerProcess = false; adapter.serverLifetime = true; addProperty(server, "Server.Endpoints", "default"); ObjectDescriptor object; object.id = communicator->stringToIdentity("${server}"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); update.nodes[0].servers.push_back(server); admin->updateApplicationWithoutRestart(update); admin->startServer("Server"); int serverPid = admin->getServerPid("Server"); update.nodes[0].servers[0]->id = "Server2"; update.nodes[0].servers[0]->adapters[0].id = "ServerAdapter2"; update.nodes[0].servers[0]->adapters[0].objects[0].id = communicator->stringToIdentity("test2"); try { admin->updateApplicationWithoutRestart(update); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } admin->startServer("Server2"); int server2Pid = admin->getServerPid("Server2"); TemplateDescriptor templ; templ.parameters.push_back("name"); templ.descriptor = new ServerDescriptor(); server = ServerDescriptorPtr::dynamicCast(templ.descriptor); server->id = "${name}"; server->exe = "${server.dir}/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; server->activation = "on-demand"; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); adapter = AdapterDescriptor(); adapter.name = "Server"; adapter.id = "${server}"; adapter.registerProcess = false; adapter.serverLifetime = true; addProperty(server, "Server.Endpoints", "default"); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("${server}"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); update = empty; update.serverTemplates["ServerTemplate"] = templ; try { admin->updateApplicationWithoutRestart(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } test(serverPid == admin->getServerPid("Server")); test(server2Pid == admin->getServerPid("Server2")); ServerInstanceDescriptor instance; update = empty; update.variables["server.dir"] = properties->getProperty("ServerDir"); update.variables["variable"] = ""; instance = ServerInstanceDescriptor(); instance._cpp_template = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try { admin->updateApplicationWithoutRestart(update); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } admin->startServer("Server1"); int server1Pid = admin->getServerPid("Server1"); test(serverPid == admin->getServerPid("Server")); test(server2Pid == admin->getServerPid("Server2")); cout << "ok" << endl; cout << "testing server remove... " << flush; update = empty; update.nodes[0].removeServers.push_back("Server2"); try { admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } test(server2Pid == admin->getServerPid("Server2")); update = empty; update.nodes[0].removeServers.push_back("Server1"); try { admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } test(server1Pid == admin->getServerPid("Server1")); admin->stopServer("Server2"); update.nodes[0].removeServers.clear(); update.nodes[0].removeServers.push_back("Server2"); try { admin->updateApplicationWithoutRestart(update); } catch(const DeploymentException&) { test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { admin->getServerPid("Server2"); test(false); } catch(const ServerNotExistException&) { } cout << "ok" << endl; cout << "testing server update... " << flush; ServerInfo info = admin->getServerInfo("Server"); test(info.descriptor); addProperty(info.descriptor, "test", "test"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test") == ""); updateServerRuntimeProperties(admin, "Server", info.descriptor); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test") == "test"); test(serverPid == admin->getServerPid("Server")); admin->stopServer("Server"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test") == "test"); test((serverPid = admin->getServerPid("Server")) > 0); test(hasProperty(admin->getServerInfo("Server").descriptor, "test", "test")); addProperty(info.descriptor, "test2", "test2"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test2") == ""); updateServerRuntimeProperties(admin, "Server", info.descriptor); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test2") == "test2"); test(serverPid == admin->getServerPid("Server")); test(hasProperty(admin->getServerInfo("Server").descriptor, "test2", "test2")); removeProperty(info.descriptor, "test2"); updateServerRuntimeProperties(admin, "Server", info.descriptor); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test2") == ""); test(serverPid == admin->getServerPid("Server")); test(!hasProperty(admin->getServerInfo("Server").descriptor, "test2", "test2")); addProperty(info.descriptor, "test3", "test3"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test3") == ""); updateServerRuntimeProperties(admin, "Server", info.descriptor); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test3") == "test3"); test(serverPid == admin->getServerPid("Server")); test(hasProperty(admin->getServerInfo("Server").descriptor, "test3", "test3")); admin->stopServer("Server"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test") == "test"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test2") == ""); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server"))->getProperty("test3") == "test3"); test((serverPid = admin->getServerPid("Server")) > 0); test(hasProperty(admin->getServerInfo("Server").descriptor, "test", "test")); test(!hasProperty(admin->getServerInfo("Server").descriptor, "test2", "")); test(hasProperty(admin->getServerInfo("Server").descriptor, "test3", "test3")); try { update = empty; update.serverTemplates["ServerTemplate"] = templ; instance = ServerInstanceDescriptor(); instance._cpp_template = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); admin->updateApplicationWithoutRestart(update); test(server1Pid == admin->getServerPid("Server1")); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { update = empty; addProperty(server, "test", "test"); assert(templ.descriptor == server); update.serverTemplates["ServerTemplate"] = templ; test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server1"))->getProperty("test") == ""); admin->updateApplicationWithoutRestart(update); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server1"))->getProperty("test") == "test"); test(server1Pid == admin->getServerPid("Server1")); admin->stopServer("Server1"); test(TestIntfPrx::uncheckedCast(communicator->stringToProxy("Server1"))->getProperty("test") == "test"); server1Pid = admin->getServerPid("Server1"); test(hasProperty(admin->getServerInfo("Server1").descriptor, "test", "test")); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { info = admin->getServerInfo("Server"); test(info.descriptor); adapter = AdapterDescriptor(); adapter.id = "ServerFoo"; adapter.serverLifetime = false; adapter.registerProcess = false; info.descriptor->adapters.push_back(adapter); update = empty; update.nodes[0].servers.push_back(info.descriptor); admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // Can't update server adapters without restart } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { info = admin->getServerInfo("Server"); test(info.descriptor); test(info.descriptor->adapters.size() == 1); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("testfoo"); info.descriptor->adapters[0].objects.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // Can't update server objects without restart } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } try { info = admin->getServerInfo("Server"); test(info.descriptor); object = ObjectDescriptor(); object.id = communicator->stringToIdentity("test"); info.descriptor->adapters[0].allocatables.push_back(object); update = empty; update.nodes[0].servers.push_back(info.descriptor); admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // Can't update server allocatables without restart } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } test(serverPid == admin->getServerPid("Server")); try { info = admin->getServerInfo("Server"); test(info.descriptor); DbEnvDescriptor dbEnv = DbEnvDescriptor(); dbEnv.name = "foo"; info.descriptor->dbEnvs.push_back(dbEnv); update = empty; update.nodes[0].servers.push_back(info.descriptor); admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // Can't update server dbenvs without restart } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } test(serverPid == admin->getServerPid("Server")); cout << "ok" << endl; cout << "testing icebox server add... " << flush; ServiceDescriptorPtr service = new ServiceDescriptor(); addProperty(service, "Ice.Warn.UnknownProperties", "0"); //addProperty(service, "Ice.Trace.Admin.Properties", "1"); service->name = "Service1"; service->entry = "./TestService:create"; adapter = AdapterDescriptor(); adapter.name = "${service}"; adapter.id = "${server}.${service}"; adapter.registerProcess = false; adapter.serverLifetime = false; addProperty(service, "${service}.Endpoints", "default"); object.id = communicator->stringToIdentity("${server}.${service}"); addProperty(service, "${service}.Identity", "${server}.${service}"); adapter.objects.push_back(object); service->adapters.push_back(adapter); string iceboxExe = "/icebox"; #if defined(__linux) # if defined(__i386) iceboxExe += "32"; # endif # if defined(ICE_CPP11_COMPILER) iceboxExe += "++11"; # endif #endif IceBoxDescriptorPtr icebox = new IceBoxDescriptor(); icebox->id = "IceBox"; icebox->exe = properties->getProperty("IceBinDir") + iceboxExe; icebox->activation = "on-demand"; icebox->applicationDistrib = false; icebox->allocatable = false; addProperty(icebox, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); icebox->services.resize(3); icebox->services[0].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); service->name = "Service2"; icebox->services[1].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); service->name = "Service3"; icebox->services[2].descriptor = ServiceDescriptorPtr::dynamicCast(service->ice_clone()); try { update = empty; update.nodes[0].servers.push_back(icebox); admin->updateApplicationWithoutRestart(update); test(serverPid == admin->getServerPid("Server")); test(server1Pid == admin->getServerPid("Server1")); admin->startServer("IceBox"); } catch(const DeploymentException& ex) { cerr << ex.reason << endl; test(false); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } int iceBoxPid = admin->getServerPid("IceBox"); cout << "ok" << endl; cout << "testing service add... " << flush; try { service->name = "First"; icebox->services.resize(4); icebox->services[3].descriptor = service; admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // can't add service without restart test(iceBoxPid == admin->getServerPid("IceBox")); icebox = IceBoxDescriptorPtr::dynamicCast(admin->getServerInfo("IceBox").descriptor); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing service remove... " << flush; try { icebox->services.resize(2); admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // can't remove service without restart test(iceBoxPid == admin->getServerPid("IceBox")); icebox = IceBoxDescriptorPtr::dynamicCast(admin->getServerInfo("IceBox").descriptor); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing service update... " << flush; try { icebox->services[0].descriptor->entry = "TestService:create2"; admin->updateApplicationWithoutRestart(update); test(false); } catch(const DeploymentException&) { // can't update service entry point without restart test(iceBoxPid == admin->getServerPid("IceBox")); icebox = IceBoxDescriptorPtr::dynamicCast(admin->getServerInfo("IceBox").descriptor); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } ServiceDescriptorPtr svc1 = icebox->services[0].descriptor; TestIntfPrx svc1Prx = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox.Service1")); ServiceDescriptorPtr svc2 = icebox->services[1].descriptor; TestIntfPrx svc2Prx = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox.Service2")); ServiceDescriptorPtr svc3 = icebox->services[2].descriptor; TestIntfPrx svc3Prx = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox.Service3")); addProperty(svc1, "test", "test"); test(svc1Prx->getProperty("test") == ""); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc1Prx->getProperty("test") == "test"); test(iceBoxPid == admin->getServerPid("IceBox")); admin->stopServer("IceBox"); admin->startServer("IceBox"); test((iceBoxPid = admin->getServerPid("IceBox")) > 0); test(svc1Prx->getProperty("test") == "test"); test(hasProperty(getServiceDescriptor(admin, "Service1"), "test", "test")); addProperty(svc1, "test2", "test2"); test(svc1Prx->getProperty("test2") == ""); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc1Prx->getProperty("test2") == "test2"); test(iceBoxPid == admin->getServerPid("IceBox")); test(hasProperty(getServiceDescriptor(admin, "Service1"), "test2", "test2")); removeProperty(svc1, "test2"); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc1Prx->getProperty("test2") == ""); test(iceBoxPid == admin->getServerPid("IceBox")); test(!hasProperty(getServiceDescriptor(admin, "Service1"), "test2", "test2")); addProperty(svc1, "test3", "test3"); test(svc1Prx->getProperty("test3") == ""); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc1Prx->getProperty("test3") == "test3"); test(iceBoxPid == admin->getServerPid("IceBox")); test(hasProperty(getServiceDescriptor(admin, "Service1"), "test3", "test3")); admin->stopServer("IceBox"); test(svc1Prx->getProperty("test") == "test"); test(svc1Prx->getProperty("test2") == ""); test(svc1Prx->getProperty("test3") == "test3"); test((iceBoxPid = admin->getServerPid("IceBox")) > 0); // Wait for the server to be active to have the guarantee that // the property update will return once the properties are // updated. while(admin->getServerState("IceBox") != IceGrid::Active) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100)); } test(hasProperty(getServiceDescriptor(admin, "Service1"), "test", "test")); test(!hasProperty(getServiceDescriptor(admin, "Service1"), "test2", "")); test(hasProperty(getServiceDescriptor(admin, "Service1"), "test3", "test3")); addProperty(svc2, "test22", "test22"); addProperty(svc3, "test32", "test32"); test(svc2Prx->getProperty("test22") == ""); test(svc3Prx->getProperty("test32") == ""); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc2Prx->getProperty("test22") == "test22"); test(svc3Prx->getProperty("test32") == "test32"); test(iceBoxPid == admin->getServerPid("IceBox")); test(hasProperty(getServiceDescriptor(admin, "Service2"), "test22", "test22")); test(hasProperty(getServiceDescriptor(admin, "Service3"), "test32", "test32")); removeProperty(svc2, "test22"); addProperty(svc3, "test33", "test33"); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc2Prx->getProperty("test22") == ""); test(svc3Prx->getProperty("test33") == "test33"); test(iceBoxPid == admin->getServerPid("IceBox")); test(!hasProperty(getServiceDescriptor(admin, "Service2"), "test22", "test22")); test(hasProperty(getServiceDescriptor(admin, "Service3"), "test33", "test33")); addProperty(svc2, "test24", "test24"); removeProperty(svc3, "test33"); addProperty(svc3, "test34", "test34"); updateServerRuntimeProperties(admin, "IceBox", icebox); test(svc2Prx->getProperty("test24") == "test24"); test(svc3Prx->getProperty("test33") == ""); test(svc3Prx->getProperty("test34") == "test34"); test(iceBoxPid == admin->getServerPid("IceBox")); test(hasProperty(getServiceDescriptor(admin, "Service2"), "test24", "test24")); test(!hasProperty(getServiceDescriptor(admin, "Service3"), "test33", "test33")); test(hasProperty(getServiceDescriptor(admin, "Service3"), "test34", "test34")); cout << "ok" << endl; admin->removeApplication("TestApp"); } // // TODO: Add more tests. // 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& comm) { IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( comm->stringToProxy(comm->getDefaultLocator()->ice_getIdentity().category + "/Registry")); AdminSessionPrx session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways); AdminPrx admin = session->getAdmin(); test(admin); map<string, string> params; params.clear(); params["id"] = "Master"; params["replicaName"] = ""; params["port"] = "12050"; instantiateServer(admin, "IceGridRegistry", params); params.clear(); params["id"] = "Slave1"; params["replicaName"] = "Slave1"; params["port"] = "12051"; instantiateServer(admin, "IceGridRegistry", params); params.clear(); params["id"] = "Slave2"; params["replicaName"] = "Slave2"; params["port"] = "12052"; instantiateServer(admin, "IceGridRegistry", params); Ice::LocatorPrx masterLocator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator-Master:default -p 12050")); Ice::LocatorPrx slave1Locator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator-Slave1:default -p 12051")); Ice::LocatorPrx slave2Locator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator-Slave2:default -p 12052")); Ice::LocatorPrx replicatedLocator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator:default -p 12050:default -p 12051")); AdminPrx masterAdmin, slave1Admin, slave2Admin; admin->startServer("Master"); masterAdmin = createAdminSession(masterLocator, ""); admin->startServer("Slave1"); slave1Admin = createAdminSession(slave1Locator, "Slave1"); // // Test replication and well-known objects: // // - Locator interface // - Query interface // // - Registry object // - RegistryUserAccountMapper // - SessionManager/SSLSessionManager // - AdminSessionManager/AdminSSLSessionManager // cout << "testing replicated locator and query interface... " << flush; { Ice::EndpointSeq endpoints; ObjectInfo info; info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")); ObjectInfo info1 = slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")); test(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")) == info); test(info.type == Ice::Locator::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 2); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")); test(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")) == info); test(info.type == IceGrid::Query::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 2); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")); // We eventually need to wait here for the update of the replicated objects to propagate to the replica. int nRetry = 0; while(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")) != info && nRetry < maxRetry) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(sleepTime)); ++nRetry; } test(slave2Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")) == info); test(info.type == Ice::Locator::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 3); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); test(endpoints[2]->toString().find("-p 12052") != string::npos); info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")); // We eventually need to wait here for the update of the replicated objects to propagate to the replica. nRetry = 0; while(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")) != info && nRetry < maxRetry) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(sleepTime)); ++nRetry; } test(slave2Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")) == info); test(info.type == IceGrid::Query::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 3); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); test(endpoints[2]->toString().find("-p 12052") != string::npos); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")); // We eventually need to wait here for the update of the replicated objects to propagate to the replica. nRetry = 0; while(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")) != info && nRetry < maxRetry) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(sleepTime)); ++nRetry; } test(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Locator")) == info); test(info.type == Ice::Locator::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 2); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); info = masterAdmin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")); nRetry = 0; while(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")) != info && nRetry < maxRetry) { IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(sleepTime)); ++nRetry; } test(slave1Admin->getObjectInfo(Ice::stringToIdentity("RepTestIceGrid/Query")) == info); test(info.type == IceGrid::Query::ice_staticId()); endpoints = info.proxy->ice_getEndpoints(); test(endpoints.size() == 2); test(endpoints[0]->toString().find("-p 12050") != string::npos); test(endpoints[1]->toString().find("-p 12051") != string::npos); QueryPrx query; query = QueryPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Query:" + endpoints[0]->toString())); Ice::ObjectProxySeq objs = query->findAllObjectsByType("::IceGrid::Registry"); test(objs.size() == 2); query = QueryPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Query:" + endpoints[1]->toString())); test(objs == query->findAllObjectsByType("::IceGrid::Registry")); } cout << "ok" << endl; cout << "testing well-known IceGrid objects... " << flush; { // // Test Registry well-known object (we have already tested // admin session creation for the creation of the admin // session above!) // RegistryPrx masterRegistry = RegistryPrx::checkedCast( comm->stringToProxy("RepTestIceGrid/Registry")->ice_locator(replicatedLocator)); RegistryPrx slave1Registry = RegistryPrx::checkedCast( comm->stringToProxy("RepTestIceGrid/Registry-Slave1")->ice_locator(replicatedLocator)); SessionPrx session = masterRegistry->createSession("dummy", "dummy"); session->destroy(); if(comm->getProperties()->getProperty("Ice.Default.Protocol") == "ssl") { session = masterRegistry->createSessionFromSecureConnection(); session->destroy(); } else { try { masterRegistry->createSessionFromSecureConnection(); } catch(const PermissionDeniedException&) { } } try { slave1Registry->createSession("dummy", ""); } catch(const PermissionDeniedException&) { } try { slave1Registry->createSessionFromSecureConnection(); } catch(const PermissionDeniedException&) { } // // Test registry user-account mapper. // UserAccountMapperPrx masterMapper = UserAccountMapperPrx::checkedCast( comm->stringToProxy("RepTestIceGrid/RegistryUserAccountMapper")->ice_locator(replicatedLocator)); UserAccountMapperPrx slave1Mapper = UserAccountMapperPrx::checkedCast( comm->stringToProxy("RepTestIceGrid/RegistryUserAccountMapper-Slave1")->ice_locator(replicatedLocator)); test(masterMapper->getUserAccount("Dummy User Account1") == "dummy1"); test(masterMapper->getUserAccount("Dummy User Account2") == "dummy2"); test(slave1Mapper->getUserAccount("Dummy User Account1") == "dummy1"); test(slave1Mapper->getUserAccount("Dummy User Account2") == "dummy2"); try { masterMapper->getUserAccount("unknown"); test(false); } catch(const UserAccountNotFoundException&) { } try { slave1Mapper->getUserAccount("unknown"); test(false); } catch(const UserAccountNotFoundException&) { } // // Test SessionManager, SSLSessionManager, // AdminSessionManager, AdminSSLSessionManager // comm->stringToProxy("RepTestIceGrid/SessionManager")->ice_locator(replicatedLocator)->ice_ping(); comm->stringToProxy("RepTestIceGrid/SSLSessionManager")->ice_locator(replicatedLocator)->ice_ping(); try { comm->stringToProxy("RepTestIceGrid/SessionManager-Slave1")->ice_locator(replicatedLocator)->ice_ping(); test(false); } catch(const Ice::NotRegisteredException&) { } try { comm->stringToProxy("RepTestIceGrid/SSLSessionManager-Slave1")->ice_locator(replicatedLocator)->ice_ping(); test(false); } catch(const Ice::NotRegisteredException&) { } comm->stringToProxy("RepTestIceGrid/AdminSessionManager")->ice_locator(replicatedLocator)->ice_ping(); comm->stringToProxy("RepTestIceGrid/AdminSSLSessionManager")->ice_locator(replicatedLocator)->ice_ping(); comm->stringToProxy("RepTestIceGrid/AdminSessionManager-Slave1")->ice_locator(replicatedLocator)->ice_ping(); comm->stringToProxy("RepTestIceGrid/AdminSSLSessionManager-Slave1")->ice_locator(replicatedLocator)->ice_ping(); } cout << "ok" << endl; // // Registry update test: // // - start master // - start slave1: keep slave1 up for each update // - start slave2: shutdown slave2 for each update // - ensure updates are correctly replicated // - updates to test: application/adapter/object // cout << "testing registry updates... " << flush; { ApplicationDescriptor app; app.name = "TestApp"; app.description = "added application"; AdapterInfo adpt; adpt.id = "TestAdpt"; adpt.proxy = comm->stringToProxy("dummy:tcp -p 12345 -h 127.0.0.1"); ObjectInfo obj; obj.proxy = comm->stringToProxy("dummy:tcp -p 12345 -h 127.0.0.1"); obj.type = "::Hello"; // // We use the locator registry from Slave1 to ensure that the // forwarding to the master work (the slave locator registry // forwards everything to the master). // Ice::LocatorRegistryPrx locatorRegistry = slave1Locator->getRegistry(); // // Test addition of application, adapter, object. // try { slave1Admin->addApplication(app); test(false); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->addApplication(app); locatorRegistry->setAdapterDirectProxy(adpt.id, adpt.proxy); try { slave1Admin->addObjectWithType(obj.proxy, obj.type); test(false); } catch(const DeploymentException&) { // Slave can't modify the database } masterAdmin->addObjectWithType(obj.proxy, obj.type); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); test(masterAdmin->getApplicationInfo("TestApp").descriptor.description == "added application"); test(slave1Admin->getApplicationInfo("TestApp").descriptor.description == "added application"); test(slave2Admin->getApplicationInfo("TestApp").descriptor.description == "added application"); test(masterAdmin->getAdapterInfo("TestAdpt")[0] == adpt); test(slave1Admin->getAdapterInfo("TestAdpt")[0] == adpt); test(slave2Admin->getAdapterInfo("TestAdpt")[0] == adpt); test(masterAdmin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); test(slave1Admin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); test(slave2Admin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); // // Test sync of application. // app.description = "updated1 application"; try { slave1Admin->syncApplication(app); test(false); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->syncApplication(app); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); test(masterAdmin->getApplicationInfo("TestApp").descriptor.description == "updated1 application"); test(slave1Admin->getApplicationInfo("TestApp").descriptor.description == "updated1 application"); test(slave2Admin->getApplicationInfo("TestApp").descriptor.description == "updated1 application"); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); // // Test update of application, adapter, object. // ApplicationUpdateDescriptor appUpdate; appUpdate.name = "TestApp"; appUpdate.description = new BoxedString("updated2 application"); try { slave1Admin->updateApplication(appUpdate); test(false); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->updateApplication(appUpdate); adpt.replicaGroupId = "TestReplicaGroup"; locatorRegistry->setReplicatedAdapterDirectProxy(adpt.id, adpt.replicaGroupId, adpt.proxy); obj.proxy = comm->stringToProxy("dummy:tcp -p 12346 -h 127.0.0.1"); try { slave1Admin->updateObject(obj.proxy); test(false); } catch(const DeploymentException&) { // Slave can't modify the database } masterAdmin->updateObject(obj.proxy); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); test(masterAdmin->getApplicationInfo("TestApp").descriptor.description == "updated2 application"); test(slave1Admin->getApplicationInfo("TestApp").descriptor.description == "updated2 application"); test(slave2Admin->getApplicationInfo("TestApp").descriptor.description == "updated2 application"); test(masterAdmin->getAdapterInfo("TestAdpt")[0] == adpt); test(slave1Admin->getAdapterInfo("TestAdpt")[0] == adpt); test(slave2Admin->getAdapterInfo("TestAdpt")[0] == adpt); test(masterAdmin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); test(slave1Admin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); test(slave2Admin->getObjectInfo(obj.proxy->ice_getIdentity()) == obj); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); // // Test removal of application, adapter and object. try { slave1Admin->removeApplication("TestApp"); test(false); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->removeApplication("TestApp"); try { slave1Admin->removeAdapter("TestAdpt"); test(false); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->removeAdapter("TestAdpt"); try { slave1Admin->removeObject(obj.proxy->ice_getIdentity()); } catch(const DeploymentException&) { // Slave can't modify the database. } masterAdmin->removeObject(obj.proxy->ice_getIdentity()); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); try { masterAdmin->getApplicationInfo("TestApp"); test(false); } catch(const ApplicationNotExistException&) { } try { slave1Admin->getApplicationInfo("TestApp"); test(false); } catch(const ApplicationNotExistException&) { } try { slave2Admin->getApplicationInfo("TestApp"); test(false); } catch(const ApplicationNotExistException&) { } try { masterAdmin->getAdapterInfo("TestAdpt"); test(false); } catch(const AdapterNotExistException&) { } try { slave1Admin->getAdapterInfo("TestAdpt"); test(false); } catch(const AdapterNotExistException&) { } try { slave2Admin->getAdapterInfo("TestAdpt"); test(false); } catch(const AdapterNotExistException&) { } try { masterAdmin->getObjectInfo(obj.proxy->ice_getIdentity()); test(false); } catch(const ObjectNotRegisteredException&) { } try { slave1Admin->getObjectInfo(obj.proxy->ice_getIdentity()); test(false); } catch(const ObjectNotRegisteredException&) { } try { slave2Admin->getObjectInfo(obj.proxy->ice_getIdentity()); test(false); } catch(const ObjectNotRegisteredException&) { } slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); } cout << "ok" << endl; params.clear(); params["id"] = "Node1"; instantiateServer(admin, "IceGridNode", params); // // Add an application which is using Node1. Otherwise, when a // registry restarts it would throw aways the proxy of the nodes // because the node isn't used by any application. // ApplicationDescriptor app; app.name = "DummyApp"; app.nodes["Node1"].description = "dummy node"; try { masterAdmin->addApplication(app); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } // // Test node session establishment. // // - start master, start slave1, start node, start slave2 // - shutdown slave1, start slave1 -> node should re-connect // - shutdown master // - shutdown slave2, start slave2 -> node should re-connect // - shutdown slave1 // - start master -> node connects to master // - start slave1 -> node connects to slave1 // cout << "testing node session establishment... " << flush; { admin->startServer("Node1"); waitForNodeState(masterAdmin, "Node1", true); waitForNodeState(slave1Admin, "Node1", true); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); waitForNodeState(slave2Admin, "Node1", true); // Node should connect. slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); admin->startServer("Slave1"); slave1Admin = createAdminSession(slave1Locator, "Slave1"); try { test(slave1Admin->pingNode("Node1")); // Node should be re-connected. } catch(const NodeNotExistException&) { test(false); } masterAdmin->shutdown(); waitForServerState(admin, "Master", false); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); try { // // On slow environments, it can take a bit for the node to // re-establish the connection so we ping it twice. The // second should succeed. // slave2Admin->pingNode("Node1"); test(slave2Admin->pingNode("Node1")); // Node should be re-connected even if the master is down. } catch(const NodeNotExistException&) { test(false); } slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); admin->startServer("Master"); masterAdmin = createAdminSession(masterLocator, ""); try { test(masterAdmin->pingNode("Node1")); // Node should be re-connected. } catch(const NodeNotExistException&) { test(false); } admin->startServer("Slave1"); slave1Admin = createAdminSession(slave1Locator, "Slave1"); try { test(slave1Admin->pingNode("Node1")); // Node should be re-connected. } catch(const NodeNotExistException&) { test(false); } try { test(masterAdmin->pingNode("Node1")); } catch(const NodeNotExistException&) { test(false); } try { test(slave2Admin->pingNode("Node1")); } catch(const NodeNotExistException&) { test(false); } slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); try { test(slave2Admin->pingNode("Node1")); } catch(const NodeNotExistException&) { test(false); } } cout << "ok" << endl; // // Testing updates with out-of-date replicas. // cout << "testing out-of-date replicas... " << flush; { ApplicationDescriptor app; app.name = "TestApp"; app.description = "added application"; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "Server"; server->exe = comm->getProperties()->getProperty("ServerDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); server->activation = "on-demand"; AdapterDescriptor adapter; adapter.name = "TestAdapter"; adapter.id = "TestAdapter.Server"; adapter.registerProcess = false; adapter.serverLifetime = true; PropertyDescriptor property; property.name = "TestAdapter.Endpoints"; property.value = "default"; server->propertySet.properties.push_back(property); property.name = "Identity"; property.value = "test"; server->propertySet.properties.push_back(property); ObjectDescriptor object; object.id = Ice::stringToIdentity("test"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); app.nodes["Node1"].servers.push_back(server); masterAdmin->addApplication(app); try { comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } masterAdmin->stopServer("Server"); // // Shutdown Slave2 and update application. // slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); ApplicationUpdateDescriptor update; update.name = "TestApp"; NodeUpdateDescriptor node; node.name = "Node1"; node.servers.push_back(server); update.nodes.push_back(node); property.name = "Dummy"; property.value = "val"; server->propertySet.properties.push_back(property); masterAdmin->updateApplication(update); try { comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } masterAdmin->shutdown(); waitForServerState(admin, "Master", false); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); waitForNodeState(slave2Admin, "Node1", true); // Node should connect. try { slave2Admin->startServer("Server"); test(false); } catch(const DeploymentException&) { } try { comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } admin->startServer("Master"); masterAdmin = createAdminSession(masterLocator, ""); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); try { comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } // // Shutdown Node1 and update the application, then, shutdown // the master. // slave1Admin->shutdownNode("Node1"); waitForServerState(admin, "Node1", false); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); property.name = "Dummy2"; property.value = "val"; server->propertySet.properties.push_back(property); masterAdmin->updateApplication(update); masterAdmin->shutdown(); waitForServerState(admin, "Master", false); // // Restart Node1 and Slave2, Slave2 still has the old version // of the server so it should be able to load it. Slave1 has // a more recent version, so it can't load it. // admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); admin->startServer("Node1"); waitForNodeState(slave2Admin, "Node1", true); slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); try { comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } admin->startServer("Slave1"); slave1Admin = createAdminSession(slave1Locator, "Slave1"); try { comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::NoEndpointException&) { } try { comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } slave2Admin->stopServer("Server"); // // Start the master. This will re-load the server on the node // and update the out-of-date replicas. // admin->startServer("Master"); masterAdmin = createAdminSession(masterLocator, ""); slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); admin->startServer("Slave1"); slave1Admin = createAdminSession(slave1Locator, "Slave1"); slave2Admin->shutdownNode("Node1"); waitForServerState(admin, "Node1", false); admin->startServer("Node1"); slave2Admin->shutdown(); waitForServerState(admin, "Slave2", false); admin->startServer("Slave2"); slave2Admin = createAdminSession(slave2Locator, "Slave2"); waitForNodeState(masterAdmin, "Node1", true); waitForNodeState(slave1Admin, "Node1", true); waitForNodeState(slave2Admin, "Node1", true); try { comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } slave2Admin->stopServer("Server"); masterAdmin->removeApplication("TestApp"); } cout << "ok" << endl; cout << "testing master upgrade... " << flush; { ApplicationDescriptor app; app.name = "TestApp"; app.description = "added application"; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "Server"; server->exe = comm->getProperties()->getProperty("ServerDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); server->activation = "on-demand"; AdapterDescriptor adapter; adapter.name = "TestAdapter"; adapter.id = "TestAdapter.Server"; adapter.serverLifetime = true; adapter.registerProcess = false; PropertyDescriptor property; property.name = "TestAdapter.Endpoints"; property.value = "default"; server->propertySet.properties.push_back(property); property.name = "Identity"; property.value = "test"; server->propertySet.properties.push_back(property); ObjectDescriptor object; object.id = Ice::stringToIdentity("test"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); app.nodes["Node1"].servers.push_back(server); masterAdmin->addApplication(app); comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); masterAdmin->stopServer("Server"); // // Shutdown the Master, update Slave1 to be the Master. // masterAdmin->shutdown(); waitForServerState(admin, "Master", false); slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); params.clear(); params["id"] = "Slave1"; params["port"] = "12051"; params["replicaName"] = "Master"; instantiateServer(admin, "IceGridRegistry", params); admin->startServer("Slave1"); slave1Locator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator-Master:default -p 12051")); slave1Admin = createAdminSession(slave1Locator, ""); waitForReplicaState(slave1Admin, "Slave2", true); ApplicationUpdateDescriptor update; update.name = "TestApp"; NodeUpdateDescriptor node; node.name = "Node1"; node.servers.push_back(server); update.nodes.push_back(node); property.name = "Dummy"; property.value = "val"; server->propertySet.properties.push_back(property); slave1Admin->updateApplication(update); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); slave1Admin->shutdown(); waitForServerState(admin, "Slave1", false); params.clear(); params["id"] = "Slave1"; params["replicaName"] = "Slave1"; params["port"] = "12051"; instantiateServer(admin, "IceGridRegistry", params); params.clear(); params["id"] = "Master"; params["replicaName"] = ""; params["port"] = "12050"; params["arg"] = "--initdb-from-replica=Slave2"; instantiateServer(admin, "IceGridRegistry", params); admin->startServer("Master"); masterAdmin = createAdminSession(masterLocator, ""); admin->startServer("Slave1"); slave1Locator = Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("RepTestIceGrid/Locator-Slave1:default -p 12051")); slave1Admin = createAdminSession(slave1Locator, "Slave1"); comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping(); masterAdmin->stopServer("Server"); waitForReplicaState(masterAdmin, "Slave1", true); waitForReplicaState(masterAdmin, "Slave2", true); ApplicationInfo info = masterAdmin->getApplicationInfo("TestApp"); test(info.revision == 2); masterAdmin->removeApplication("TestApp"); } cout << "ok" << endl; cout << "testing interop with registry and node using the 1.0 encoding... " << flush; { params.clear(); params["id"] = "Slave3"; params["replicaName"] = "Slave3"; params["port"] = "12053"; params["encoding"] = "1.0"; instantiateServer(admin, "IceGridRegistry", params); params.clear(); params["id"] = "Node2"; params["encoding"] = "1.0"; instantiateServer(admin, "IceGridNode", params); admin->startServer("Slave3"); waitForServerState(admin, "Slave3", true); waitForReplicaState(masterAdmin, "Slave3", true); admin->startServer("Node2"); waitForNodeState(masterAdmin, "Node2", true); Ice::LocatorPrx slave3Locator = Ice::LocatorPrx::uncheckedCast( comm->stringToProxy("RepTestIceGrid/Locator-Slave3 -e 1.0:default -p 12053")); IceGrid::AdminPrx slave3Admin = createAdminSession(slave3Locator, "Slave3"); waitForNodeState(slave3Admin, "Node2", true); ApplicationDescriptor app; app.name = "TestApp"; app.description = "added application"; ServerDescriptorPtr server = new ServerDescriptor(); server->id = "Server"; server->exe = comm->getProperties()->getProperty("ServerDir") + "/server"; server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); server->activation = "on-demand"; AdapterDescriptor adapter; adapter.name = "TestAdapter"; adapter.id = "TestAdapter.Server"; adapter.serverLifetime = true; adapter.registerProcess = false; PropertyDescriptor property; property.name = "TestAdapter.Endpoints"; property.value = "default"; server->propertySet.properties.push_back(property); property.name = "Identity"; property.value = "test"; server->propertySet.properties.push_back(property); ObjectDescriptor object; object.id = Ice::stringToIdentity("test"); object.type = "::Test::TestIntf"; adapter.objects.push_back(object); server->adapters.push_back(adapter); app.nodes["Node2"].servers.push_back(server); masterAdmin->addApplication(app); comm->stringToProxy("test -e 1.0")->ice_locator( masterLocator->ice_encodingVersion(Ice::Encoding_1_0))->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test -e 1.0")->ice_locator( slave1Locator->ice_encodingVersion(Ice::Encoding_1_0))->ice_locatorCacheTimeout(0)->ice_ping(); comm->stringToProxy("test -e 1.0")->ice_locator(slave3Locator)->ice_locatorCacheTimeout(0)->ice_ping(); masterAdmin->stopServer("Server"); } cout << "ok" << endl; slave1Admin->shutdownNode("Node1"); removeServer(admin, "Node1"); removeServer(admin, "Slave2"); slave1Admin->shutdown(); removeServer(admin, "Slave1"); masterAdmin->shutdown(); removeServer(admin, "Master"); }
void allTests(const Ice::CommunicatorPtr& communicator) { { cout << "Testing Glacier2 stub... " << flush; char** argv = 0; int argc = 0; SessionHelperClient client; client.run(argc, argv); cout << "ok" << endl; } { cout << "Testing IceStorm stub... " << flush; IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::uncheckedCast(communicator->stringToProxy("test:default -p 12010")); IceStorm::QoS qos; IceStorm::TopicPrx topic; string topicName = "time"; try { topic = manager->retrieve(topicName); test(false); } catch(const IceStorm::NoSuchTopic&) { test(false); } catch(const Ice::LocalException&) { } Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("subscriber" ,"tcp"); Ice::ObjectPrx subscriber = adapter->addWithUUID(new ClockI); adapter->activate(); try { topic->subscribeAndGetPublisher(qos, subscriber); test(false); } catch(const IceStorm::AlreadySubscribed&) { test(false); } catch(const IceUtil::NullHandleException&) { } cout << "ok" << endl; } { cout << "Testing IceGrid stub... " << flush; Ice::ObjectPrx base = communicator->stringToProxy("test:default -p 12010"); IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::uncheckedCast(base); IceGrid::AdminSessionPrx session; IceGrid::AdminPrx admin; try { session = registry->createAdminSession("username", "password"); test(false); } catch(const IceGrid::PermissionDeniedException&) { test(false); } catch(const Ice::LocalException&) { } try { admin = session->getAdmin(); test(false); } catch(const IceUtil::NullHandleException&) { } 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); cout << "testing server registration... " << flush; Ice::StringSeq serverIds = admin->getAllServerIds(); test(find(serverIds.begin(), serverIds.end(), "Server1") != serverIds.end()); test(find(serverIds.begin(), serverIds.end(), "Server2") != serverIds.end()); test(find(serverIds.begin(), serverIds.end(), "IceBox1") != serverIds.end()); test(find(serverIds.begin(), serverIds.end(), "IceBox2") != serverIds.end()); test(find(serverIds.begin(), serverIds.end(), "SimpleServer") != serverIds.end()); test(find(serverIds.begin(), serverIds.end(), "SimpleIceBox") != serverIds.end()); cout << "ok" << endl; cout << "testing adapter registration... " << flush; Ice::StringSeq adapterIds = admin->getAllAdapterIds(); test(find(adapterIds.begin(), adapterIds.end(), "Server1.Server") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "Server2.Server") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "SimpleServer.Server") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "IceBox1.Service1.Service1") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "IceBox1Service2Adapter") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "IceBox2.Service1.Service1") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "IceBox2Service2Adapter") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "SimpleIceBox.SimpleService.SimpleService") != adapterIds.end()); test(find(adapterIds.begin(), adapterIds.end(), "ReplicatedAdapter") != adapterIds.end()); cout << "ok" << endl; cout << "testing object registration... " << flush; Ice::ObjectProxySeq objs = query->findAllObjectsByType("::Test"); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"Server1")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"Server2")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"SimpleServer")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox1-Service1")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox1-Service2")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox2-Service1")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox2-Service2")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"SimpleIceBox-SimpleService")) != objs.end()); test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"ReplicatedObject")) != objs.end()); { test(identityToString(query->findObjectByType("::TestId1")->ice_getIdentity()) == "cat/name1"); test(identityToString(query->findObjectByType("::TestId2")->ice_getIdentity()) == "cat1/name1"); test(identityToString(query->findObjectByType("::TestId3")->ice_getIdentity()) == "cat1/name1-bis"); test(identityToString(query->findObjectByType("::TestId4")->ice_getIdentity()) == "c2\\/c2/n2\\/n2"); test(identityToString(query->findObjectByType("::TestId5")->ice_getIdentity()) == "n2\\/n2"); } { Ice::ObjectPrx obj = query->findObjectByType("::Test"); string id = identityToString(obj->ice_getIdentity()); test(id == "Server1" || id == "Server2" || id == "SimpleServer" || id == "IceBox1-Service1" || id == "IceBox1-Service2" || id == "IceBox2-Service1" || id == "IceBox2-Service2" || id == "SimpleIceBox-SimpleService" || "ReplicatedObject"); } { Ice::ObjectPrx obj = query->findObjectByTypeOnLeastLoadedNode("::Test", LoadSample5); string id = identityToString(obj->ice_getIdentity()); test(id == "Server1" || id == "Server2" || id == "SimpleServer" || id == "IceBox1-Service1" || id == "IceBox1-Service2" || id == "IceBox2-Service1" || id == "IceBox2-Service2" || id == "SimpleIceBox-SimpleService" || "ReplicatedObject"); } { Ice::ObjectPrx obj = query->findObjectByType("::Foo"); test(!obj); obj = query->findObjectByTypeOnLeastLoadedNode("::Foo", LoadSample15); test(!obj); } Ice::Identity encoding10_oneway; encoding10_oneway.name = "encoding10-oneway"; test(query->findObjectById(encoding10_oneway)->ice_getEncodingVersion() == Ice::Encoding_1_0); test(query->findObjectById(encoding10_oneway)->ice_isOneway()); Ice::Identity encoding10_secure; encoding10_secure.name = "encoding10-secure"; test(query->findObjectById(encoding10_secure)->ice_getEncodingVersion() == Ice::Encoding_1_0); test(query->findObjectById(encoding10_secure)->ice_isSecure()); Ice::Identity oaoptions; oaoptions.name = "oaoptions"; test(query->findObjectById(oaoptions)->ice_getEncodingVersion() == Ice::stringToEncodingVersion("1.2")); test(query->findObjectById(oaoptions)->ice_isTwoway()); Ice::Identity comoptions; comoptions.name = "communicatoroptions"; test(query->findObjectById(comoptions)->ice_getEncodingVersion() == Ice::stringToEncodingVersion("1.3")); test(query->findObjectById(comoptions)->ice_isTwoway()); Ice::Identity options34; options34.name = "34options"; test(query->findObjectById(options34)->ice_getEncodingVersion() == Ice::Encoding_1_0); Ice::Identity simpleServer; simpleServer.name = "SimpleServer"; test(query->findObjectById(simpleServer)->ice_getEncodingVersion() == Ice::Encoding_1_1); Ice::Identity replicated15; replicated15.name = "ReplicatedObject15"; test(query->findObjectById(replicated15)->ice_getEncodingVersion() == Ice::stringToEncodingVersion("1.5")); Ice::Identity replicated14; replicated14.name = "ReplicatedObject14"; test(query->findObjectById(replicated14)->ice_getEncodingVersion() == Ice::stringToEncodingVersion("1.4")); Ice::LocatorPrx locator = comm->getDefaultLocator(); test(query->findObjectById(encoding10_oneway) == locator->findObjectById(encoding10_oneway)); test(query->findObjectById(encoding10_secure) == locator->findObjectById(encoding10_secure)); test(query->findObjectById(oaoptions) == locator->findObjectById(oaoptions)); test(query->findObjectById(comoptions) == locator->findObjectById(comoptions)); test(query->findObjectById(options34) == locator->findObjectById(options34)); test(query->findObjectById(simpleServer) == locator->findObjectById(simpleServer)); test(query->findObjectById(replicated15) == locator->findObjectById(replicated15)); test(query->findObjectById(replicated14) == locator->findObjectById(replicated14)); cout << "ok" << endl; // // Ensure that all server and service objects are reachable. // // The identity for the test object in deployed server or services // is the name of the service or server. The object adapter name // is Adapter prefixed with the name of the service or // server. Ensure we can reach each object. // cout << "pinging server objects... " << flush; TestIntfPrx obj; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); obj = TestIntfPrx::checkedCast( comm->stringToProxy("*****@*****.**")); cout << "ok" << endl; cout << "testing server configuration... " << flush; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("Type") == "Server"); test(obj->getProperty("Name") == "Server1"); test(obj->getProperty("NameName") == "Server1Server1"); test(obj->getProperty("NameEscaped") == "${name}"); test(obj->getProperty("NameEscapeEscaped") == "$Server1"); test(obj->getProperty("NameEscapedEscapeEscaped") == "$${name}"); test(obj->getProperty("ManyEscape") == "$$$${name}"); test(obj->getProperty("TestServer1Identity") == "Server1"); test(obj->getProperty("LogFilePath") == "test-Server1.log"); test(obj->getProperty("LogFilePath-Server1") == "test.log"); test(obj->getProperty("PropertyWithSpaces") == " test "); // \ is escaped in C++ string literals test(obj->getProperty("WindowsPath") == "C:\\Program Files (x86)\\ZeroC\\"); test(obj->getProperty("UNCPath") == "\\\\server\\foo bar\\file"); test(obj->getProperty("PropertyWith=") == "foo=bar"); test(obj->getProperty("PropertyWithHash") == "foo#bar"); test(obj->getProperty("PropertyWithTab") == "foo\tbar"); test(obj->getProperty("PropertyWithEscapeSpace") == "foo\\ "); test(obj->getProperty("PropertyWithProperty") == "Plugin.EntryPoint=foo:bar --Ice.Config=\\\\\\server\\foo bar\\file.cfg"); cout << "ok" << endl; cout << "testing service configuration... " << flush; obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("Service1.Type") == "standard"); test(obj->getProperty("Service1.ServiceName") == "Service1"); test(obj->getProperty("TestService1Identity") == "IceBox1-Service1"); test(obj->getProperty("LogFilePath") == "test-Service1.log"); test(obj->getProperty("LogFilePath-Service1") == "test.log"); test(obj->getProperty("PropertyWithSpaces") == " test "); // \ is escaped in C++ string literals test(obj->getProperty("WindowsPath") == "C:\\Program Files (x86)\\ZeroC\\"); test(obj->getProperty("UNCPath") == "\\\\server\\foo bar\\file"); test(obj->getProperty("PropertyWith=") == "foo=bar"); test(obj->getProperty("PropertyWithHash") == "foo#bar"); test(obj->getProperty("PropertyWithTab") == "foo\tbar"); test(obj->getProperty("PropertyWithEscapeSpace") == "foo\\ "); test(obj->getProperty("PropertyWithProperty") == "Plugin.EntryPoint=foo:bar --Ice.Config=\\\\\\server\\foo bar\\file.cfg"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); test(obj->getProperty("Service2.Type") == "nonstandard"); test(obj->getProperty("Service2.ServiceName") == "Service2"); test(obj->getProperty("Service2.DebugProperty") == ""); test(obj->getProperty("Service1.DebugProperty") == ""); cout << "ok" << endl; cout << "testing server options... " << flush; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("Test.Test") == "2"); test(obj->getProperty("Test.Test1") == "0"); cout << "ok" << endl; cout << "testing variables... " << flush; vector<TestIntfPrx> proxies; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); proxies.push_back(obj); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); proxies.push_back(obj); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); proxies.push_back(obj); obj = TestIntfPrx::checkedCast( comm->stringToProxy("*****@*****.**")); proxies.push_back(obj); for(vector<TestIntfPrx>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) { test((*p)->getProperty("AppVarProp") == "AppVar"); test((*p)->getProperty("NodeVarProp") == "NodeVar"); test((*p)->getProperty("RecursiveAppVarProp") == "Test"); test((*p)->getProperty("AppVarOverridedProp") == "OverridedInNode"); test((*p)->getProperty("AppVarDefinedInNodeProp") == "localnode"); test((*p)->getProperty("EscapedAppVarProp") == "${escaped}"); test((*p)->getProperty("RecursiveEscapedAppVarProp") == "${escaped}"); test((*p)->getProperty("Recursive2EscapedAppVarProp") == "${escaped}"); test((*p)->getProperty("RecursiveNodeVarProp") == "localnode"); test((*p)->getProperty("TestDirProp") != "NotThisValue"); } cout << "ok" << endl; cout << "testing parameters... " << flush; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("Param1Prop") == "Param1"); test(obj->getProperty("Param2Prop") == "AppVar"); test(obj->getProperty("ParamEscapedProp") == "${escaped}"); test(obj->getProperty("ParamDoubleEscapedProp") == "$escapedvalue"); test(obj->getProperty("AppVarOverridedByParamProp") == "Overrided"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Test"); test(obj->getProperty("DefaultParamProp") == "VALUE"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("Param1Prop") == "Param12"); test(obj->getProperty("Param2Prop") == "OverridedInNode"); test(obj->getProperty("ParamEscapedProp") == "${escaped}"); test(obj->getProperty("ParamDoubleEscapedProp") == "$escapedvalue"); test(obj->getProperty("AppVarOverridedByParamProp") == "Overrided"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Test"); test(obj->getProperty("DefaultParamProp") == "OTHERVALUE"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("AppVarOverridedByParamProp") == "Test"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Overrided"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter")); test(obj->getProperty("AppVarOverridedByParamProp") == "Test"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Test"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("AppVarOverridedByParamProp") == "Test"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Overrided"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); test(obj->getProperty("AppVarOverridedByParamProp") == "Test"); test(obj->getProperty("NodeVarOverridedByParamProp") == "Test"); cout << "ok" << endl; cout << "testing descriptions... " << flush; // // NOTE: We can't test the following since // getApplicationDescriptor doesn't return the instantiated // application descriptor... // // ApplicationDescriptor desc = admin->getApplicationDescriptor("test"); // test(desc.description == "APP AppVar"); // test(desc.nodes["localnode"].description == "NODE NodeVar"); // test(desc.replicaGroups[0].description == "REPLICA GROUP AppVar"); // test(desc.nodes["localnode"].servers.size() == 2); // const int idx = desc.nodes["localnode"].servers[0]->id == "SimpleServer" ? 0 : 1; ServerInfo info = admin->getServerInfo("SimpleServer"); test(info.descriptor->id == "SimpleServer"); test(info.descriptor->description == "SERVER NodeVar"); test(info.descriptor->adapters[0].description == "ADAPTER NodeVar"); test(info.descriptor->dbEnvs[0].description == "DBENV NodeVar"); cout << "ok" << endl; cout << "testing property sets..." << flush; obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("AppProperty") == "AppVar"); test(obj->getProperty("AppProperty2") == "OverrideMe"); test(obj->getProperty("AppProperty21") == "Override"); test(obj->getProperty("NodeProperty") == "NodeVar"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("AppProperty") == "AppVar"); test(obj->getProperty("AppProperty2") == "OverrideMe"); test(obj->getProperty("AppProperty21") == "Override"); test(obj->getProperty("NodeProperty") == "NodeVar"); test(obj->getProperty("ServerInstanceProperty") == "Server2"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("AppProperty") == ""); // IceBox server properties aren't inherited for IceBox1 test(obj->getProperty("AppProperty2") == ""); test(obj->getProperty("AppProperty21") == ""); test(obj->getProperty("NodeProperty") == ""); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("AppProperty") == "AppVar"); test(obj->getProperty("AppProperty2") == "OverrideMe"); test(obj->getProperty("AppProperty21") == "Override"); test(obj->getProperty("NodeProperty") == "NodeVar"); test(obj->getProperty("IceBoxInstanceProperty") == "IceBox2"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); test(obj->getProperty("AppProperty") == "AppVar"); test(obj->getProperty("AppProperty2") == "OverrideMe"); test(obj->getProperty("AppProperty21") == "Override"); test(obj->getProperty("NodeProperty") == "NodeVar"); test(obj->getProperty("IceBoxInstanceProperty") == "IceBox2"); test(obj->getProperty("ServiceInstanceProperty") == "Service2"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("*****@*****.**")); test(obj->getProperty("AppProperty") == "AppVar"); test(obj->getProperty("AppProperty2") == "OverrideMe"); test(obj->getProperty("AppProperty21") == "Override"); test(obj->getProperty("NodeProperty") == "NodeVar"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("ServerInstanceServiceProperty") == "service1"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("ServerInstanceServiceProperty") == "service4"); obj = TestIntfPrx::checkedCast(comm->stringToProxy("[email protected]")); test(obj->getProperty("IceBoxInstanceProperty") == "overriden"); cout << "ok" << endl; cout << "testing validation... " << flush; TemplateDescriptor templ; templ.parameters.push_back("name"); templ.parameters.push_back("nam3"); templ.parameters.push_back("nam2"); templ.parameters.push_back("nam3"); templ.descriptor = new ServerDescriptor(); ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(templ.descriptor); server->id = "test"; server->exe = "${test.dir}/server"; server->applicationDistrib = false; server->allocatable = false; ApplicationDescriptor desc; desc.name = "App"; desc.serverTemplates["ServerTemplate"] = templ; try { admin->addApplication(desc); test(false); } catch(const DeploymentException& ex) { test(ex.reason.find("duplicate parameters") != string::npos); } catch(const Ice::Exception& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; logTests(comm, session); 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(); }
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 << "testing distributions... " << flush; { admin->startServer("Test.IcePatch2"); admin->startServer("IcePatch2-Direct"); TestIntfPrx test; test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all")); test(test->getServerFile("rootfile") == ""); try { admin->patchServer("server-all", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test(test->getServerFile("rootfile") == "rootfile"); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == "dummy-file3"); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == ""); test(test->getServerFile("dir1/file2") == ""); test(test->getServerFile("dir2/file3") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); try { admin->patchServer("server-all-direct", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test(test->getServerFile("rootfile") == "rootfile"); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == "dummy-file3"); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); try { admin->patchApplication("Test", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); admin->stopServer("Test.IcePatch2"); admin->stopServer("IcePatch2-Direct"); } cout << "ok" << endl; cout << "testing distributions after update... " << flush; { ApplicationUpdateDescriptor update; update.name = "Test"; update.variables["icepatch.directory"] = "${test.dir}/data/updated"; admin->updateApplication(update); admin->startServer("Test.IcePatch2"); admin->startServer("IcePatch2-Direct"); TestIntfPrx test; test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all")); test(test->getServerFile("rootfile") == "rootfile"); try { admin->patchServer("server-all", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test(test->getServerFile("rootfile") == "rootfile-updated!"); test(test->getServerFile("dir1/file1") == ""); test(test->getServerFile("dir1/file2") == "dummy-file2-updated!"); test(test->getServerFile("dir2/file3") == "dummy-file3"); test(test->getServerFile("dir2/file4") == "dummy-file4"); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); test(test->getApplicationFile("dir2/file4") == "dummy-file4"); try { admin->patchServer("server-all-direct", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all-direct")); test(test->getServerFile("rootfile") == "rootfile-updated!"); test(test->getServerFile("dir1/file1") == ""); test(test->getServerFile("dir1/file2") == "dummy-file2-updated!"); test(test->getServerFile("dir2/file3") == "dummy-file3"); test(test->getServerFile("dir2/file4") == "dummy-file4"); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); test(test->getApplicationFile("dir2/file4") == "dummy-file4"); try { admin->patchApplication("Test", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == ""); test(test->getServerFile("dir1/file2") == "dummy-file2-updated!"); test(test->getServerFile("dir2/file3") == ""); test(test->getServerFile("dir2/file4") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); test(test->getApplicationFile("dir2/file4") == "dummy-file4"); admin->stopServer("Test.IcePatch2"); admin->stopServer("IcePatch2-Direct"); } cout << "ok" << endl; cout << "testing application distrib configuration... " << flush; try { ApplicationDescriptor app = admin->getApplicationInfo("Test").descriptor; admin->removeApplication("Test"); app.variables["icepatch.directory"] = "${test.dir}/data/original"; test(app.nodes["localnode"].servers[2]->id == "server-dir1"); app.nodes["localnode"].servers[2]->applicationDistrib = false; admin->addApplication(app); admin->startServer("Test.IcePatch2"); try { admin->patchServer("server-dir1", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } TestIntfPrx test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == ""); admin->removeApplication("Test"); admin->addApplication(app); admin->startServer("Test.IcePatch2"); admin->startServer("IcePatch2-Direct"); try { admin->patchApplication("Test", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == "dummy-file3"); admin->removeApplication("Test"); app.distrib.icepatch = ""; admin->addApplication(app); admin->startServer("Test.IcePatch2"); admin->startServer("IcePatch2-Direct"); try { admin->patchServer("server-dir1", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-dir1")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == ""); test(test->getApplicationFile("rootfile") == ""); test(test->getApplicationFile("dir1/file1") == ""); test(test->getApplicationFile("dir1/file2") == ""); test(test->getApplicationFile("dir2/file3") == ""); test = TestIntfPrx::uncheckedCast(communicator->stringToProxy("server-all")); test(test->getServerFile("rootfile") == ""); test(test->getServerFile("dir1/file1") == ""); test(test->getServerFile("dir1/file2") == ""); test(test->getServerFile("dir2/file3") == ""); try { admin->patchApplication("Test", true); } catch(const PatchException& ex) { copy(ex.reasons.begin(), ex.reasons.end(), ostream_iterator<string>(cerr, "\n")); test(false); } test(test->getServerFile("rootfile") == "rootfile"); test(test->getServerFile("dir1/file1") == "dummy-file1"); test(test->getServerFile("dir1/file2") == "dummy-file2"); test(test->getServerFile("dir2/file3") == "dummy-file3"); } catch(const DeploymentException& ex) { cerr << ex << ":\n" << ex.reason << endl; test(false); } cout << "ok" << endl; session->destroy(); }