int AttackClient::run(int, char**) { ObjectPrx routerBase = communicator()->stringToProxy("Glacier2/router:" + getTestEndpoint(communicator(), 10)); Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(routerBase); test(router); communicator()->setDefaultRouter(router); PropertyDict::const_iterator p; PropertyDict badProxies = communicator()->getProperties()->getPropertiesForPrefix("Reject.Proxy."); for(p = badProxies.begin(); p != badProxies.end(); ++p) { try { Glacier2::SessionPrx session = router->createSession("userid", "abc123"); } catch(const Glacier2::CannotCreateSessionException&) { test("Unable to create new session" == 0); } BackendPrx backend = BackendPrx::uncheckedCast(communicator()->stringToProxy(p->second)); try { backend->ice_ping(); cerr << "Test failed on : " << p->second << endl; test("Expected exception" == 0); } catch(const ConnectionLostException&) { // // This is ok. // } catch(const CloseConnectionException&) { // // This is also ok. // } catch(const ObjectNotExistException&) { // // This is ok for non-address filters. // try { router->destroySession(); } catch(...) { } } catch(const LocalException& e) { cerr << e << endl; test("Unexpected local exception" == 0); } } PropertyDict goodProxies = communicator()->getProperties()->getPropertiesForPrefix("Accept.Proxy."); for(p = goodProxies.begin(); p != goodProxies.end(); ++p) { try { Glacier2::SessionPrx session = router->createSession("userid", "abc123"); } catch(const Glacier2::CannotCreateSessionException&) { test("Unable to create new session" == 0); } BackendPrx backend = BackendPrx::uncheckedCast(communicator()->stringToProxy(p->second)); try { backend->ice_ping(); } catch(const LocalException& ex) { cerr << p->second << endl; cerr << ex << endl; test("Unexpected local exception" == 0); } try { router->destroySession(); } catch(const LocalException&) { // // Expected. // } } // // Stop using router and communicate with backend and router directly // to shut things down. // communicator()->setDefaultRouter(0); try { BackendPrx backend = BackendPrx::checkedCast(communicator()->stringToProxy("dummy:tcp -p 12010")); backend->shutdown(); } catch(const Ice::LocalException&) { test(false); } ObjectPrx processBase = communicator()->stringToProxy("Glacier2/admin -f Process:" + getTestEndpoint(communicator(), 11)); Ice::ProcessPrx process = Ice::ProcessPrx::checkedCast(processBase); test(process); process->shutdown(); try { process->ice_ping(); test(false); } catch(const Ice::LocalException&) { cout << "ok" << endl; } return EXIT_SUCCESS; }
int SessionControlClient::run(int argc, char* argv[]) { // // We initialize the controller on a separate port because we want // to bypass the router for test control operations. // cout << "accessing test controller... " << flush; Ice::InitializationData initData; initData.properties = communicator()->getProperties(); Ice::CommunicatorPtr controlComm = Ice::initialize(argc, argv, initData); TestControllerPrx controller = TestControllerPrx::checkedCast( controlComm->stringToProxy("testController:tcp -p 12013")); test(controller); TestToken currentState; TestToken newState; currentState.expectedResult = false; currentState.config = 0; currentState.caseIndex = 0; currentState.code = Initial; controller->step(0, currentState, newState); currentState = newState; cout << "ok" << endl; cout << "getting router... " << flush; ObjectPrx routerBase = communicator()->stringToProxy("Glacier2/router:default -p 12347"); Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(routerBase); test(router); communicator()->setDefaultRouter(router); cout << "ok" << endl; Glacier2::SessionPrx sessionBase = router->createSession("userid", "abc123"); Test::TestSessionPrx currentSession = Test::TestSessionPrx::checkedCast(sessionBase); bool printOk = false; while(currentState.code == Running) { controller->step(currentSession, currentState, newState); currentState = newState; if(currentState.code != Running) { cout << "ok" << endl; break; } // // If we are running the first case for this configuration, print the configuration description. // if(currentState.caseIndex == 0) { if(printOk) { cout << "ok" << endl; } else { printOk = true; } cout << currentState.description << "... " << flush; } if(currentState.expectedResult) { BackendPrx prx = BackendPrx::uncheckedCast(communicator()->stringToProxy(currentState.testReference)); try { prx->check(); } catch(const Exception& ex) { cerr << ex << endl; test(false); } } else { BackendPrx prx = BackendPrx::uncheckedCast(communicator()->stringToProxy(currentState.testReference)); try { prx->check(); test(false); } catch(const ObjectNotExistException&) { } catch(const Exception& ex) { cerr << ex << endl; test(false); } } } // // Cleanup. // router->destroySession(); cout << "testing shutdown... " << flush; try { // // Shut down the test server. // currentSession = Test::TestSessionPrx::uncheckedCast(router->createSession("userid", "abc123")); currentSession->shutdown(); } catch(const Glacier2::CannotCreateSessionException& ex) { cerr << ex.reason << endl; throw ex; } // // Shut down the router. // communicator()->setDefaultRouter(0); ObjectPrx processBase = communicator()->stringToProxy("Glacier2/admin -f Process:tcp -p 12348"); Ice::ProcessPrx process = Ice::ProcessPrx::checkedCast(processBase); test(process); process->shutdown(); try { process->ice_ping(); test(false); } catch(const Ice::LocalException&) { cout << "ok" << endl; } try { controlComm->destroy(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } return EXIT_SUCCESS; }
int AttackClient::run(int argc, char* argv[]) { cout << "getting router... " << flush; ObjectPrx routerBase = communicator()->stringToProxy("Glacier2/router:default -p 12347"); Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(routerBase); test(router); communicator()->setDefaultRouter(router); cout << "ok" << endl; cout << "creating session... " << flush; Glacier2::SessionPrx session = router->createSession("userid", "abc123"); cout << "ok" << endl; cout << "making thousands of invocations on proxies... " << flush; ObjectPrx backendBase = communicator()->stringToProxy("dummy:tcp -p 12010"); BackendPrx backend = BackendPrx::uncheckedCast(backendBase); backend->ice_ping(); set<BackendPrx> backends; string msg; for(int i = 1; i <= 10000; ++i) { if(i % 100 == 0) { if(!msg.empty()) { cout << string(msg.size(), '\b'); } ostringstream s; s << i; msg = s.str(); cout << msg << flush; } Identity ident; string::iterator p; ident.name.resize(1); // 1 + IceUtilInternal::random() % 2); for(p = ident.name.begin(); p != ident.name.end(); ++p) { *p = static_cast<char>('A' + IceUtilInternal::random() % 26); } ident.category.resize(IceUtilInternal::random() % 2); for(p = ident.category.begin(); p != ident.category.end(); ++p) { *p = static_cast<char>('a' + IceUtilInternal::random() % 26); } BackendPrx newBackend = BackendPrx::uncheckedCast(backendBase->ice_identity(ident)); set<BackendPrx>::const_iterator q = backends.find(newBackend); if(q == backends.end()) { backends.insert(newBackend); backend = newBackend; } else { backend = *q; } backend->ice_ping(); } cout << string(msg.size(), '\b') << string(msg.size(), ' ') << string(msg.size(), '\b'); cout << "ok" << endl; cout << "testing server and router shutdown... " << flush; backend->shutdown(); communicator()->setDefaultRouter(0); ObjectPrx adminBase = communicator()->stringToProxy("Glacier2/admin -f Process:tcp -h 127.0.0.1 -p 12348"); Ice::ProcessPrx process = Ice::ProcessPrx::checkedCast(adminBase); test(process); process->shutdown(); try { process->ice_ping(); test(false); } catch(const Ice::LocalException&) { cout << "ok" << endl; } return EXIT_SUCCESS; }