// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::FH_ZipFileSystem::fileExistsSuceeded( const std::string& path, const std::string& testPath, CallbackPtr callback, const PropertyList& userData ) { FileManager::getInstancePtr()->_existSuccess( path, this ); FileExistsCallbackParameters params( path, true, testPath, getName(), userData ); callback->invoke( (void*)¶ms ); }
// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::FH_StandardFileSystem::readFile( const std::string& path, CallbackPtr callback, const PropertyList& userData ) { // try this as a fully qualified path first... std::string testPath = path; std::multimap<unsigned int, std::string>::iterator testBase = mBasePaths.begin(); do { if ( FileManager::getInstancePtr()->fileExistsInFileMappedCache( testPath ) ) { std::fstream str( testPath.c_str(), std::ios::in | std::ios::binary ); if (str.is_open()) { str.seekg( 0, std::ios::end ); size_t length = str.tellg(); str.seekg( 0, std::ios::beg ); char* buffer = new char[ length ]; str.read( buffer, length ); str.close(); FileManager::getInstancePtr()->_readSuccess(path, this); ReadFileCallbackParameters params(path, buffer, length, testPath, getName(), userData); callback->invoke( (void *)¶ms ); return; } else { // Failed to open a file that should have existed... // This should only happen if files were removed from the base paths after // startup. assert( false ); } } else { if (testBase != mBasePaths.end()) { testPath = StringHelper::addPathComponent(testBase->second, path); testBase++; } else { // no more paths to test... we're done! break; } } } while (true); // fail! FileManager::getInstancePtr()->_readFail( path, this, callback, userData ); }
// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::FH_ZipFileSystem::readFileSucceeded( const std::string& path, const std::string& testPath, CallbackPtr callback, const PropertyList& userData ) { mZipReader->openFile(testPath); unsigned long length = mZipReader->getCurrentFileSize(); char* buffer = new char[ length ]; mZipReader->readCurrentFile(buffer); FileManager::getInstancePtr()->_readSuccess(path, this); ReadFileCallbackParameters params(path, buffer, length, testPath, getName(), userData); callback->invoke( (void *)¶ms ); }
// ---------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------- void ProgrammaticTexture2D::reload( CallbackPtr ptr, FileManager::PlatformPolicy policy ) { if (name_ == NO_TEXTURE) { // rebuild! initWithSize(width_, height_, settings_.getColorspace()); setData(imageBuffer_); } if (ptr) { TextureLoadedCallbackParameters params( fileName_, ResultCode_OK ); ptr->invoke((void*)¶ms); } }
// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::FH_StandardFileSystem::fileExists( const std::string& path, CallbackPtr callback, const PropertyList& userData ) { // try this as a fully qualified path first... std::string testPath = path; std::multimap<unsigned int, std::string>::iterator testBase = mBasePaths.begin(); do { bool exists = FileManager::getInstancePtr()->fileExistsInFileMappedCache( testPath ); if (exists) { FileManager::getInstancePtr()->_existSuccess( path, this ); FileExistsCallbackParameters params( path, exists, testPath, getName(), userData ); callback->invoke( (void*)¶ms ); return; } else { if (testBase != mBasePaths.end()) { testPath = testBase->second + path; testBase++; } else { // no more paths to test... we're done! break; } } } while (true); // fail! FileManager::getInstancePtr()->_existFail( path, this, callback, userData ); }
void allTests(const Ice::CommunicatorPtr& communicator) { string sref = "test:" + getTestEndpoint(communicator, 0); Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref); test(obj); Test::TestIntfPrxPtr p = ICE_UNCHECKED_CAST(Test::TestIntfPrx, obj); sref = "testController:" + getTestEndpoint(communicator, 1, "tcp"); obj = communicator->stringToProxy(sref); test(obj); Test::TestIntfControllerPrxPtr testController = ICE_UNCHECKED_CAST(Test::TestIntfControllerPrx, obj); cout << "testing dispatcher... " << flush; { p->op(); CallbackPtr cb = ICE_MAKE_SHARED(Callback); #ifdef ICE_CPP11_MAPPING p->opAsync( [cb]() { cb->response(); }, [cb](exception_ptr err) { try { rethrow_exception(err); } catch(const Ice::Exception& ex) { cb->exception(ex); } }); cb->check(); auto i = p->ice_adapterId("dummy"); i->opAsync( [cb]() { cb->response(); }, [cb](exception_ptr err) { try { rethrow_exception(err); } catch(const Ice::Exception& ex) { cb->exception(ex); } }); cb->check(); { // // Expect InvocationTimeoutException. // auto to = p->ice_invocationTimeout(250); to->sleepAsync(500, [cb]() { cb->responseEx(); }, [cb](exception_ptr err) { try { rethrow_exception(err); } catch(const Ice::Exception& ex) { cb->exceptionEx(ex); } }); cb->check(); } testController->holdAdapter(); Ice::ByteSeq seq; seq.resize(1024); // Make sure the request doesn't compress too well. for(Ice::ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) { *q = static_cast<Ice::Byte>(IceUtilInternal::random(255)); } vector<shared_ptr<promise<void>>> completed; while(true) { auto s = make_shared<promise<bool>>(); auto fs = s->get_future(); auto c = make_shared<promise<void>>(); p->opWithPayloadAsync(seq, [=]() { c->set_value(); }, [=](exception_ptr) { c->set_value(); }, [=](bool sent) { s->set_value(sent); }); completed.push_back(c); if(fs.wait_for(chrono::milliseconds(0)) != future_status::ready || !fs.get()) { break; } } testController->resumeAdapter(); for(auto& c : completed) { c->get_future().get(); } #else Test::Callback_TestIntf_opPtr callback = Test::newCallback_TestIntf_op(cb, &Callback::response, &Callback::exception); p->begin_op(callback); cb->check(); Test::TestIntfPrx i = p->ice_adapterId("dummy"); i->begin_op(callback); cb->check(); { // // Expect InvocationTimeoutException. // Test::TestIntfPrx to = p->ice_invocationTimeout(250); to->begin_sleep(500, Test::newCallback_TestIntf_sleep(cb, &Callback::responseEx, &Callback::exceptionEx)); cb->check(); } testController->holdAdapter(); Test::Callback_TestIntf_opWithPayloadPtr callback2 = Test::newCallback_TestIntf_opWithPayload(cb, &Callback::payload, &Callback::ignoreEx, &Callback::sent); Ice::ByteSeq seq; seq.resize(1024); // Make sure the request doesn't compress too well. for(Ice::ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) { *q = static_cast<Ice::Byte>(IceUtilInternal::random(255)); } Ice::AsyncResultPtr result; while((result = p->begin_opWithPayload(seq, callback2))->sentSynchronously()); testController->resumeAdapter(); result->waitForCompleted(); #endif } cout << "ok" << endl; p->shutdown(); }
ThrowerPrxPtr allTests(const Ice::CommunicatorPtr& communicator) { cout << "testing ice_print()/what()... " << flush; { A a; string aMsg = "Test::A"; Ice::UnknownLocalException ule("thisFile", 99); string uleMsg = "thisFile:99: Ice::UnknownLocalException:\nunknown local exception"; // // Test ice_print(). // { stringstream str; a.ice_print(str); test(str.str() == aMsg); } { stringstream str; ule.ice_print(str); test(str.str() == uleMsg); } // // Test operator<<(). // { stringstream str; str << a; test(str.str() == aMsg); } { stringstream str; str << ule; test(str.str() == uleMsg); } // // Test what(). (Called twice because of lazy initialization in what().) // test(aMsg == a.what()); test(aMsg == a.what()); test(uleMsg == ule.what()); test(uleMsg == ule.what()); { E ex("E"); ostringstream os; ex.ice_print(os); test(os.str() == "Test::E"); test(ex.data == "E"); } // // Test custom ice_print // { F ex("F"); ostringstream os; ex.ice_print(os); test(os.str() == "Test::F data:'F'"); test(ex.data == "F"); } { G ex(__FILE__, __LINE__, "G"); ostringstream os; ex.ice_print(os); test(endsWith(os.str(), "Test::G")); test(ex.data == "G"); } { H ex(__FILE__, __LINE__, "H"); ostringstream os; ex.ice_print(os); test(endsWith(os.str(), "Test::H data:'H'")); test(ex.data == "H"); } } cout << "ok" << endl; string localOAEndpoint; { ostringstream ostr; if(communicator->getProperties()->getProperty("Ice.Default.Protocol") == "bt") { ostr << "default -a *"; } else { ostr << "default -h *"; } localOAEndpoint = ostr.str(); } cout << "testing object adapter registration exceptions... " << flush; { Ice::ObjectAdapterPtr first; try { first = communicator->createObjectAdapter("TestAdapter0"); test(false); } catch(const Ice::InitializationException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected } communicator->getProperties()->setProperty("TestAdapter0.Endpoints", localOAEndpoint); first = communicator->createObjectAdapter("TestAdapter0"); try { Ice::ObjectAdapterPtr second = communicator->createObjectAdapter("TestAdapter0"); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected } try { Ice::ObjectAdapterPtr second = communicator->createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected. } first->deactivate(); } cout << "ok" << endl; cout << "testing servant registration exceptions... " << flush; { communicator->getProperties()->setProperty("TestAdapter1.Endpoints", localOAEndpoint); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter1"); Ice::ObjectPtr obj = ICE_MAKE_SHARED(EmptyI); adapter->add(obj, communicator->stringToIdentity("x")); try { adapter->add(obj, communicator->stringToIdentity("x")); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } try { adapter->add(obj, communicator->stringToIdentity("")); } catch(const Ice::IllegalIdentityException& ex) { test(ex.id.name == ""); if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } try { adapter->add(0, communicator->stringToIdentity("x")); } catch(const Ice::IllegalServantException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } adapter->remove(communicator->stringToIdentity("x")); try { adapter->remove(communicator->stringToIdentity("x")); test(false); } catch(const Ice::NotRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } adapter->deactivate(); } cout << "ok" << endl; cout << "testing servant locator registrations exceptions... " << flush; { communicator->getProperties()->setProperty("TestAdapter2.Endpoints", localOAEndpoint); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter2"); Ice::ServantLocatorPtr loc = ICE_MAKE_SHARED(ServantLocatorI); adapter->addServantLocator(loc, "x"); try { adapter->addServantLocator(loc, "x"); test(false); } catch(const Ice::AlreadyRegisteredException&) { } adapter->deactivate(); } cout << "ok" << endl; cout << "testing value factory registration exception... " << flush; { #ifdef ICE_CPP11_MAPPING communicator->addValueFactory( [](const std::string&) { return nullptr; }, "x"); try { communicator->addValueFactory( [](const std::string&) { return nullptr; }, "x"); test(false); } catch(const Ice::AlreadyRegisteredException&) { } #else Ice::ValueFactoryPtr vf = new ValueFactoryI; communicator->addValueFactory(vf, "x"); try { communicator->addValueFactory(vf, "x"); test(false); } catch(const Ice::AlreadyRegisteredException&) { } #endif } cout << "ok" << endl; cout << "testing stringToProxy... " << flush; string ref = "thrower:" + getTestEndpoint(communicator, 0); Ice::ObjectPrxPtr base = communicator->stringToProxy(ref); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; ThrowerPrxPtr thrower = ICE_CHECKED_CAST(ThrowerPrx, base); test(thrower); #ifdef ICE_CPP11_MAPPING test(Ice::targetEquals(thrower, base)); #else test(thrower == base); #endif cout << "ok" << endl; cout << "catching exact types... " << flush; try { thrower->throwAasA(1); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::Exception& ex) { cout << ex << endl; test(false); } catch(...) { test(false); } try { thrower->throwAorDasAorD(1); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(...) { test(false); } try { thrower->throwAorDasAorD(-1); test(false); } catch(const D& ex) { test(ex.dMem == -1); } catch(...) { test(false); } try { thrower->throwBasB(1, 2); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwCasC(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } try { thrower->throwModA(1, 2); test(false); } catch(const Mod::A& ex) { test(ex.aMem == 1); test(ex.a2Mem == 2); } catch(const Ice::OperationNotExistException&) { // // This operation is not supported in Java. // } catch(...) { test(false); } cout << "ok" << endl; cout << "catching base types... " << flush; try { thrower->throwBasB(1, 2); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(...) { test(false); } try { thrower->throwCasC(1, 2, 3); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwModA(1, 2); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::OperationNotExistException&) { // // This operation is not supported in Java. // } catch(...) { test(false); } cout << "ok" << endl; cout << "catching derived types... " << flush; try { thrower->throwBasA(1, 2); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwCasA(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } try { thrower->throwCasB(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } cout << "ok" << endl; if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception... " << flush; try { thrower->throwUndeclaredA(1); test(false); } catch(const Ice::UnknownUserException&) { } catch(const Ice::Exception& ex) { cout << ex << endl; cout << ex.ice_stackTrace() << endl; test(false); } catch(...) { test(false); } try { thrower->throwUndeclaredB(1, 2); test(false); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } try { thrower->throwUndeclaredC(1, 2, 3); test(false); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } cout << "ok" << endl; } if(thrower->ice_getConnection()) { cout << "testing memory limit marshal exception..." << flush; try { thrower->throwMemoryLimitException(Ice::ByteSeq()); test(false); } catch(const Ice::MemoryLimitException&) { } catch(...) { test(false); } try { thrower->throwMemoryLimitException(Ice::ByteSeq(20 * 1024)); // 20KB test(false); } catch(const Ice::ConnectionLostException&) { } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } ThrowerPrxPtr thrower2 = ICE_UNCHECKED_CAST(ThrowerPrx, communicator->stringToProxy("thrower:" + getTestEndpoint(communicator, 1))); try { thrower2->throwMemoryLimitException(Ice::ByteSeq(2 * 1024 * 1024)); // 2MB (no limits) } catch(const Ice::MemoryLimitException&) { } ThrowerPrxPtr thrower3 = ICE_UNCHECKED_CAST(ThrowerPrx, communicator->stringToProxy("thrower:" + getTestEndpoint(communicator, 2))); try { thrower3->throwMemoryLimitException(Ice::ByteSeq(1024)); // 1KB limit test(false); } catch(const Ice::ConnectionLostException&) { } cout << "ok" << endl; } cout << "catching object not exist exception... " << flush; Ice::Identity id = communicator->stringToIdentity("does not exist"); try { ThrowerPrxPtr thrower2 = ICE_UNCHECKED_CAST(ThrowerPrx, thrower->ice_identity(id)); thrower2->throwAasA(1); // thrower2->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException& ex) { test(ex.id == id); } catch(...) { test(false); } cout << "ok" << endl; cout << "catching facet not exist exception... " << flush; try { #ifdef ICE_CPP11_MAPPING ThrowerPrxPtr thrower2 = Ice::uncheckedCast<ThrowerPrx>(thrower, "no such facet"); #else ThrowerPrxPtr thrower2 = ThrowerPrx::uncheckedCast(thrower, "no such facet"); #endif try { thrower2->ice_ping(); test(false); } catch(const Ice::FacetNotExistException& ex) { test(ex.facet == "no such facet"); } } catch(...) { test(false); } cout << "ok" << endl; cout << "catching operation not exist exception... " << flush; try { WrongOperationPrxPtr thrower2 = ICE_UNCHECKED_CAST(WrongOperationPrx, thrower); thrower2->noSuchOperation(); test(false); } catch(const Ice::OperationNotExistException& ex) { test(ex.operation == "noSuchOperation"); } catch(...) { test(false); } cout << "ok" << endl; cout << "catching unknown local exception... " << flush; try { thrower->throwLocalException(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(...) { test(false); } try { thrower->throwLocalExceptionIdempotent(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "catching unknown non-Ice exception... " << flush; try { thrower->throwNonIceException(); test(false); } catch(const Ice::UnknownException&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "testing asynchronous exceptions... " << flush; try { thrower->throwAfterResponse(); } catch(...) { test(false); } try { thrower->throwAfterException(); } catch(const A&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "catching exact types with new AMI mapping... " << flush; #ifdef ICE_CPP11_MAPPING { auto f = thrower->throwAasA_async(1); try { f.get(); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::Exception&) { test(false); } catch(...) { test(false); } } { auto f = thrower->throwAorDasAorD_async(1); try { f.get(); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(...) { test(false); } } { auto f = thrower->throwAorDasAorD_async(-1); try { f.get(); test(false); } catch(const D& ex) { test(ex.dMem == -1); } catch(...) { test(false); } } { auto f = thrower->throwBasB_async(1, 2); try { f.get(); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } } { auto f = thrower->throwCasC_async(1, 2, 3); try { f.get(); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } } { auto f = thrower->throwModA_async(1, 2); try { f.get(); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::OperationNotExistException&) { // // This operation is not supported in Java. // } catch(...) { test(false); } } // // repeat with callback API and no exception callback // { promise<bool> sent; thrower->throwAasA_async(1, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } { promise<bool> sent; thrower->throwAorDasAorD_async(1, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } { promise<bool> sent; thrower->throwAorDasAorD_async(-1, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } { promise<bool> sent; thrower->throwBasB_async(1, 2, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } { promise<bool> sent; thrower->throwCasC_async(1, 2, 3, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } { promise<bool> sent; thrower->throwModA_async(1, 2, []() { test(false); }, nullptr, [&](bool value) { sent.set_value(value); }); sent.get_future().get(); // Wait for sent } #else { CallbackPtr cb = new Callback; Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasA); thrower->begin_throwAasA(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwAorDasAorDPtr callback = newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); thrower->begin_throwAorDasAorD(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwAorDasAorDPtr callback = newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); thrower->begin_throwAorDasAorD(-1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwBasBPtr callback = newCallback_Thrower_throwBasB(cb, &Callback::response, &Callback::exception_BasB); thrower->begin_throwBasB(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasCPtr callback = newCallback_Thrower_throwCasC(cb, &Callback::response, &Callback::exception_CasC); thrower->begin_throwCasC(1, 2, 3, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwModAPtr callback = newCallback_Thrower_throwModA(cb, &Callback::response, &Callback::exception_ModA); thrower->begin_throwModA(1, 2, callback); cb->check(); } #endif cout << "ok" << endl; cout << "catching derived types with new AMI mapping... " << flush; #ifdef ICE_CPP11_MAPPING { auto f = thrower->throwBasA_async(1, 2); try { f.get(); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } } { auto f = thrower->throwCasA_async(1, 2, 3); try { f.get(); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } } { auto f = thrower->throwCasB_async(1, 2, 3); try { f.get(); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } } #else { CallbackPtr cb = new Callback; Callback_Thrower_throwBasAPtr callback = newCallback_Thrower_throwBasA(cb, &Callback::response, &Callback::exception_BasA); thrower->begin_throwBasA(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasAPtr callback = newCallback_Thrower_throwCasA(cb, &Callback::response, &Callback::exception_CasA); thrower->begin_throwCasA(1, 2, 3, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasBPtr callback = newCallback_Thrower_throwCasB(cb, &Callback::response, &Callback::exception_CasB); thrower->begin_throwCasB(1, 2, 3, callback); cb->check(); } #endif cout << "ok" << endl; if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception with new AMI mapping... " << flush; #ifdef ICE_CPP11_MAPPING { auto f = thrower->throwUndeclaredA_async(1); try { f.get(); test(false); } catch(const Ice::UnknownUserException&) { } catch(const Ice::Exception& ex) { cout << ex << endl; cout << ex.ice_stackTrace() << endl; test(false); } catch(...) { test(false); } } { auto f = thrower->throwUndeclaredB_async(1, 2); try { f.get(); test(false); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } } { auto f = thrower->throwUndeclaredC_async(1, 2, 3); try { f.get(); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } } #else { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredAPtr callback = newCallback_Thrower_throwUndeclaredA(cb, &Callback::response, &Callback::exception_UndeclaredA); thrower->begin_throwUndeclaredA(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredBPtr callback = newCallback_Thrower_throwUndeclaredB(cb, &Callback::response, &Callback::exception_UndeclaredB); thrower->begin_throwUndeclaredB(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredCPtr callback = newCallback_Thrower_throwUndeclaredC(cb, &Callback::response, &Callback::exception_UndeclaredC); thrower->begin_throwUndeclaredC(1, 2, 3, callback); cb->check(); } #endif cout << "ok" << endl; } cout << "catching object not exist exception with new AMI mapping... " << flush; { #ifdef ICE_CPP11_MAPPING id = communicator->stringToIdentity("does not exist"); shared_ptr<ThrowerPrx> thrower2 = Ice::uncheckedCast<ThrowerPrx>(thrower->ice_identity(id)); auto f = thrower2->throwAasA_async(1); try { f.get(); } catch(const Ice::ObjectNotExistException& ex) { test(ex.id == id); } catch(...) { test(false); } #else id = communicator->stringToIdentity("does not exist"); ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower->ice_identity(id)); CallbackPtr cb = new Callback(communicator); Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAObjectNotExist); thrower2->begin_throwAasA(1, callback); cb->check(); #endif } cout << "ok" << endl; cout << "catching facet not exist exception with new AMI mapping... " << flush; { #ifdef ICE_CPP11_MAPPING shared_ptr<ThrowerPrx> thrower2 = Ice::uncheckedCast<ThrowerPrx>(thrower, "no such facet"); auto f = thrower2->throwAasA_async(1); try { f.get(); } catch(const Ice::FacetNotExistException& ex) { test(ex.facet == "no such facet"); } #else ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower, "no such facet"); CallbackPtr cb = new Callback; Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAFacetNotExist); thrower2->begin_throwAasA(1, callback); cb->check(); #endif } cout << "ok" << endl; cout << "catching operation not exist exception with new AMI mapping... " << flush; { #ifdef ICE_CPP11_MAPPING shared_ptr<WrongOperationPrx> thrower4 = Ice::uncheckedCast<WrongOperationPrx>(thrower); auto f = thrower4->noSuchOperation_async(); try { f.get(); } catch(const Ice::OperationNotExistException& ex) { test(ex.operation == "noSuchOperation"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; Callback_WrongOperation_noSuchOperationPtr callback = newCallback_WrongOperation_noSuchOperation(cb, &Callback::response, &Callback::exception_noSuchOperation); WrongOperationPrx thrower4 = WrongOperationPrx::uncheckedCast(thrower); thrower4->begin_noSuchOperation(callback); cb->check(); #endif } cout << "ok" << endl; cout << "catching unknown local exception with new AMI mapping... " << flush; #ifdef ICE_CPP11_MAPPING { auto f = thrower->throwLocalException_async(); try { f.get(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(...) { test(false); } } { auto f = thrower->throwLocalExceptionIdempotent_async(); try { f.get(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } } #else { CallbackPtr cb = new Callback; Callback_Thrower_throwLocalExceptionPtr callback = newCallback_Thrower_throwLocalException(cb, &Callback::response, &Callback::exception_LocalException); thrower->begin_throwLocalException(callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwLocalExceptionIdempotentPtr callback = newCallback_Thrower_throwLocalExceptionIdempotent(cb, &Callback::response, &Callback::exception_LocalException); thrower->begin_throwLocalExceptionIdempotent(callback); cb->check(); } #endif cout << "ok" << endl; cout << "catching unknown non-Ice exception with new AMI mapping... " << flush; { #ifdef ICE_CPP11_MAPPING auto f = thrower->throwNonIceException_async(); try { f.get(); test(false); } catch(const Ice::UnknownException&) { } catch(...) { test(false); } #else CallbackPtr cb = new Callback; Callback_Thrower_throwNonIceExceptionPtr callback = newCallback_Thrower_throwNonIceException(cb, &Callback::response, &Callback::exception_NonIceException); thrower->begin_throwNonIceException(callback); cb->check(); #endif } cout << "ok" << endl; return thrower; }
void batchOnewaysAMI(const Test::MyClassPrx& p) { const Test::ByteS bs1(10 * 1024); const Test::ByteS bs2(99 * 1024); const Test::ByteS bs3(100 * 1024); CallbackPtr cb = new Callback(); p->begin_opByteSOneway(bs1, Test::newCallback_MyClass_opByteSOneway(new Callback_ByteSOneway1(cb), &Callback_ByteSOneway1::response, &Callback_ByteSOneway1::exception)); cb->check(); p->begin_opByteSOneway(bs2, Test::newCallback_MyClass_opByteSOneway(new Callback_ByteSOneway1(cb), &Callback_ByteSOneway1::response, &Callback_ByteSOneway1::exception)); cb->check(); Test::MyClassPrx batch = Test::MyClassPrx::uncheckedCast(p->ice_batchOneway()); batch->end_ice_flushBatchRequests(batch->begin_ice_flushBatchRequests()); int i; for(i = 0 ; i < 30 ; ++i) { p->begin_opByteSOneway(bs1, Test::newCallback_MyClass_opByteSOneway(new Callback_ByteSOneway3(), &Callback_ByteSOneway3::response, &Callback_ByteSOneway3::exception)); } if(batch->ice_getConnection()) { batch->ice_getConnection()->end_flushBatchRequests(batch->ice_getConnection()->begin_flushBatchRequests()); Test::MyClassPrx batch2 = Test::MyClassPrx::uncheckedCast(p->ice_batchOneway()); batch->begin_ice_ping(); batch2->begin_ice_ping(); batch->end_ice_flushBatchRequests(batch->begin_ice_flushBatchRequests()); batch->ice_getConnection()->close(false); batch->begin_ice_ping(); batch2->begin_ice_ping(); batch->ice_getConnection(); batch2->ice_getConnection(); batch->begin_ice_ping(); batch->ice_getConnection()->close(false); batch->begin_ice_ping(Ice::newCallback_Object_ice_ping(new Callback_ping(cb), &Callback_ping::response, &Callback_ping::exception)); cb->check(); batch2->begin_ice_ping(Ice::newCallback_Object_ice_ping(new Callback_ping(cb), &Callback_ping::response, &Callback_ping::exception)); cb->check(); batch->begin_ice_ping(); batch2->begin_ice_ping(); } Ice::Identity identity; identity.name = "invalid"; Ice::ObjectPrx batch3 = batch->ice_identity(identity); batch3->begin_ice_ping(); batch3->end_ice_flushBatchRequests(batch3->begin_ice_flushBatchRequests()); // Make sure that a bogus batch request doesn't cause troubles to other ones. batch3->begin_ice_ping(); batch->begin_ice_ping(); batch->end_ice_flushBatchRequests(batch->begin_ice_flushBatchRequests()); batch->begin_ice_ping(); }
TimeoutPrxPtr allTests(const Ice::CommunicatorPtr& communicator) { string sref = "timeout:" + getTestEndpoint(communicator, 0); Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref); test(obj); TimeoutPrxPtr timeout = ICE_CHECKED_CAST(TimeoutPrx, obj); test(timeout); cout << "testing connect timeout... " << flush; { // // Expect ConnectTimeoutException. // TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(100)); timeout->holdAdapter(500); try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000)); timeout->holdAdapter(500); try { to->op(); } catch(const Ice::ConnectTimeoutException&) { test(false); } } cout << "ok" << endl; // The sequence needs to be large enough to fill the write/recv buffers ByteSeq seq(2000000); cout << "testing connection timeout... " << flush; { // // Expect TimeoutException. // TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(100)); timeout->holdAdapter(500); try { to->sendData(seq); test(false); } catch(const Ice::TimeoutException&) { // Expected. } } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000)); timeout->holdAdapter(500); try { ByteSeq seq(1000000); to->sendData(seq); } catch(const Ice::TimeoutException&) { test(false); } } cout << "ok" << endl; cout << "testing invocation timeout... " << flush; { Ice::ConnectionPtr connection = obj->ice_getConnection(); TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(100)); test(connection == to->ice_getConnection()); try { to->sleep(750); test(false); } catch(const Ice::InvocationTimeoutException&) { } obj->ice_ping(); to = ICE_CHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(500)); test(connection == to->ice_getConnection()); try { to->sleep(250); } catch(const Ice::InvocationTimeoutException&) { test(false); } test(connection == to->ice_getConnection()); } { // // Expect InvocationTimeoutException. // TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(100)); #ifdef ICE_CPP11_MAPPING auto f = to->sleep_async(750); try { f.get(); test(false); } catch(const Ice::InvocationTimeoutException&) { } catch(...) { test(false); } #else CallbackPtr cb = new Callback(); to->begin_sleep(750, newCallback_Timeout_sleep(cb, &Callback::responseEx, &Callback::exceptionEx)); cb->check(); #endif obj->ice_ping(); } { // // Expect success. // TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(500)); #ifdef ICE_CPP11_MAPPING auto f = to->sleep_async(250); try { f.get(); } catch(...) { test(false); } #else CallbackPtr cb = new Callback(); to->begin_sleep(250, newCallback_Timeout_sleep(cb, &Callback::response, &Callback::exception)); cb->check(); #endif } { // // Backward compatible connection timeouts // TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(-2)->ice_timeout(250)); Ice::ConnectionPtr con; try { con = to->ice_getConnection(); to->sleep(750); test(false); } catch(const Ice::TimeoutException&) { try { con->getInfo(); test(false); } catch(const Ice::TimeoutException&) { // Connection got closed as well. } } obj->ice_ping(); try { con = to->ice_getConnection(); #ifdef ICE_CPP11_MAPPING to->sleep_async(750).get(); #else to->end_sleep(to->begin_sleep(750)); #endif test(false); } catch(const Ice::TimeoutException&) { try { con->getInfo(); test(false); } catch(const Ice::TimeoutException&) { // Connection got closed as well. } } obj->ice_ping(); } cout << "ok" << endl; cout << "testing close timeout... " << flush; { TimeoutPrxPtr to = ICE_CHECKED_CAST(TimeoutPrx, obj->ice_timeout(250)); Ice::ConnectionPtr connection = to->ice_getConnection(); timeout->holdAdapter(600); connection->close(false); try { connection->getInfo(); // getInfo() doesn't throw in the closing state. } catch(const Ice::LocalException&) { test(false); } IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(650)); try { connection->getInfo(); test(false); } catch(const Ice::CloseConnectionException&) { // Expected. } timeout->op(); // Ensure adapter is active. } cout << "ok" << endl; cout << "testing timeout overrides... " << flush; { // // Test Ice.Override.Timeout. This property overrides all // endpoint timeouts. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.Timeout", "250"); Ice::CommunicatorPtr comm = Ice::initialize(initData); TimeoutPrxPtr to = ICE_CHECKED_CAST(TimeoutPrx, comm->stringToProxy(sref)); timeout->holdAdapter(700); try { to->sendData(seq); test(false); } catch(const Ice::TimeoutException&) { // Expected. } // // Calling ice_timeout() should have no effect. // timeout->op(); // Ensure adapter is active. to = ICE_CHECKED_CAST(TimeoutPrx, to->ice_timeout(1000)); timeout->holdAdapter(500); try { to->sendData(seq); test(false); } catch(const Ice::TimeoutException&) { // Expected. } comm->destroy(); } { // // Test Ice.Override.ConnectTimeout. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.ConnectTimeout", "250"); Ice::CommunicatorPtr comm = Ice::initialize(initData); timeout->holdAdapter(750); TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, comm->stringToProxy(sref)); try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } // // Calling ice_timeout() should have no effect on the connect timeout. // timeout->op(); // Ensure adapter is active. timeout->holdAdapter(750); to = ICE_UNCHECKED_CAST(TimeoutPrx, to->ice_timeout(1000)); try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } // // Verify that timeout set via ice_timeout() is still used for requests. // timeout->op(); // Ensure adapter is active. to = ICE_UNCHECKED_CAST(TimeoutPrx, to->ice_timeout(250)); to->ice_getConnection(); // Establish connection timeout->holdAdapter(750); try { to->sendData(seq); test(false); } catch(const Ice::TimeoutException&) { // Expected. } comm->destroy(); } { // // Test Ice.Override.CloseTimeout. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.CloseTimeout", "250"); Ice::CommunicatorPtr comm = Ice::initialize(initData); Ice::ConnectionPtr connection = comm->stringToProxy(sref)->ice_getConnection(); timeout->holdAdapter(500); IceUtil::Time now = IceUtil::Time::now(); comm->destroy(); test(IceUtil::Time::now() - now < IceUtil::Time::milliSeconds(400)); } cout << "ok" << endl; cout << "testing invocation timeouts with collocated calls... " << flush; { communicator->getProperties()->setProperty("TimeoutCollocated.AdapterId", "timeoutAdapter"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TimeoutCollocated"); adapter->activate(); TimeoutPrxPtr timeout = ICE_UNCHECKED_CAST(TimeoutPrx, adapter->addWithUUID(ICE_MAKE_SHARED(TimeoutI))); timeout = timeout->ice_invocationTimeout(100); try { timeout->sleep(300); test(false); } catch(const Ice::InvocationTimeoutException&) { } try { #ifdef ICE_CPP11_MAPPING timeout->sleep_async(300).get(); #else timeout->end_sleep(timeout->begin_sleep(300)); #endif test(false); } catch(const Ice::InvocationTimeoutException&) { } TimeoutPrxPtr batchTimeout = timeout->ice_batchOneway(); batchTimeout->ice_ping(); batchTimeout->ice_ping(); batchTimeout->ice_ping(); // Keep the server thread pool busy. #ifdef ICE_CPP11_MAPPING timeout->ice_invocationTimeout(-1)->sleep_async(300); #else timeout->ice_invocationTimeout(-1)->begin_sleep(300); #endif try { batchTimeout->ice_flushBatchRequests(); test(false); } catch(const Ice::InvocationTimeoutException&) { } batchTimeout->ice_ping(); batchTimeout->ice_ping(); batchTimeout->ice_ping(); // Keep the server thread pool busy. #ifdef ICE_CPP11_MAPPING timeout->ice_invocationTimeout(-1)->sleep_async(300); #else timeout->ice_invocationTimeout(-1)->begin_sleep(300); #endif try { #ifdef ICE_CPP11_MAPPING batchTimeout->ice_flushBatchRequests_async().get(); #else batchTimeout->end_ice_flushBatchRequests(batchTimeout->begin_ice_flushBatchRequests()); #endif test(false); } catch(const Ice::InvocationTimeoutException&) { } adapter->destroy(); } cout << "ok" << endl; return timeout; }
TestIntfPrxPtr allTests(const Ice::CommunicatorPtr& communicator) { Ice::ObjectPrxPtr obj = communicator->stringToProxy("Test:" + getTestEndpoint(communicator, 0)); TestIntfPrxPtr test = ICE_CHECKED_CAST(TestIntfPrx, obj); cout << "base... " << flush; { try { test->baseAsBase(); test(false); } catch(const Base& b) { test(b.b == "Base.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->baseAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "Base.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_baseAsBase( newCallback_TestIntf_baseAsBase(cb, &Callback::response, &Callback::exception_baseAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown derived... " << flush; { try { test->unknownDerivedAsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownDerived.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownDerivedAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownDerived.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownDerivedAsBase( newCallback_TestIntf_unknownDerivedAsBase(cb, &Callback::response, &Callback::exception_unknownDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known derived as base... " << flush; { try { test->knownDerivedAsBase(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known derived as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownDerivedAsBase_async(); try { result.get(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownDerivedAsBase( newCallback_TestIntf_knownDerivedAsBase(cb, &Callback::response, &Callback::exception_knownDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known derived as derived... " << flush; { try { test->knownDerivedAsKnownDerived(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known derived as derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownDerivedAsKnownDerived_async(); try { result.get(); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownDerivedAsKnownDerived( newCallback_TestIntf_knownDerivedAsKnownDerived(cb, &Callback::response, &Callback::exception_knownDerivedAsKnownDerived)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown intermediate as base... " << flush; { try { test->unknownIntermediateAsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownIntermediate.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownIntermediateAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownIntermediate.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownIntermediateAsBase( newCallback_TestIntf_unknownIntermediateAsBase(cb, &Callback::response, &Callback::exception_unknownIntermediateAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of known intermediate as base... " << flush; { try { test->knownIntermediateAsBase(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of known intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownIntermediateAsBase_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownIntermediateAsBase( newCallback_TestIntf_knownIntermediateAsBase(cb, &Callback::response, &Callback::exception_knownIntermediateAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of known most derived as base... " << flush; { try { test->knownMostDerivedAsBase(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of known most derived as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsBase_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsBase( newCallback_TestIntf_knownMostDerivedAsBase(cb, &Callback::response, &Callback::exception_knownMostDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known intermediate as intermediate... " << flush; { try { test->knownIntermediateAsKnownIntermediate(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known intermediate as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownIntermediateAsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownIntermediateAsKnownIntermediate( newCallback_TestIntf_knownIntermediateAsKnownIntermediate(cb, &Callback::response, &Callback::exception_knownIntermediateAsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known most derived exception as intermediate... " << flush; { try { test->knownMostDerivedAsKnownIntermediate(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known most derived as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsKnownIntermediate( newCallback_TestIntf_knownMostDerivedAsKnownIntermediate(cb, &Callback::response, &Callback::exception_knownMostDerivedAsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known most derived as most derived... " << flush; { try { test->knownMostDerivedAsKnownMostDerived(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known most derived as most derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsKnownMostDerived_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsKnownMostDerived( newCallback_TestIntf_knownMostDerivedAsKnownMostDerived(cb, &Callback::response, &Callback::exception_knownMostDerivedAsKnownMostDerived)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as base... " << flush; { try { test->unknownMostDerived1AsBase(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived1AsBase_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived1AsBase( newCallback_TestIntf_unknownMostDerived1AsBase(cb, &Callback::response, &Callback::exception_unknownMostDerived1AsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as intermediate... " << flush; { try { test->unknownMostDerived1AsKnownIntermediate(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived1AsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived1AsKnownIntermediate( newCallback_TestIntf_unknownMostDerived1AsKnownIntermediate(cb, &Callback::response, &Callback::exception_unknownMostDerived1AsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, unknown intermediate as base... " << flush; { try { test->unknownMostDerived2AsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownMostDerived2.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, unknown intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived2AsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownMostDerived2.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived2AsBase( newCallback_TestIntf_unknownMostDerived2AsBase(cb, &Callback::response, &Callback::exception_unknownMostDerived2AsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "unknown most derived in compact format... " << flush; { try { test->unknownMostDerived2AsBaseCompact(); test(false); } catch(const Base&) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); } catch(const Ice::UnknownUserException&) { // // An UnknownUserException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(test->ice_getEncodingVersion() != Ice::Encoding_1_0); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } } cout << "ok" << endl; cout << "preserved exceptions... " << flush; string localOAEndpoint; { ostringstream ostr; if(communicator->getProperties()->getProperty("Ice.Default.Protocol") == "bt") { ostr << "default -a *"; } else { ostr << "default -h *"; } localOAEndpoint = ostr.str(); } { Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Relay", localOAEndpoint); RelayPrxPtr relay = ICE_UNCHECKED_CAST(RelayPrx, adapter->addWithUUID(ICE_MAKE_SHARED(RelayI))); adapter->activate(); try { test->relayKnownPreservedAsBase(relay); test(false); } catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(const Ice::OperationNotExistException&) { } catch(const Ice::LocalException& ex) { cout << endl << "** OOPS" << endl << ex << endl; test(false); } catch(...) { test(false); } try { test->relayKnownPreservedAsKnownPreserved(relay); test(false); } catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } try { test->relayUnknownPreservedAsBase(relay); test(false); } catch(const Preserved2& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = ICE_DYNAMIC_CAST(PreservedClass, ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } catch(const Ice::OperationNotExistException&) { } catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(...) { test(false); } try { test->relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch(const Ice::OperationNotExistException&) { } catch(const Preserved2& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = ICE_DYNAMIC_CAST(PreservedClass, ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(...) { test(false); } adapter->destroy(); } cout << "ok" << endl; return test; }
// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::_readFail( const std::string& path, FileHandler* h, CallbackPtr callback, const PropertyList& userData ) { // failed, see if we have another platform string to try... FileRecordMap::iterator r_it = mPendingReads.find( path ); // this must be in the map! if(r_it == mPendingReads.end()) { if (callback) { ReadFileCallbackParameters params(path, NULL, 0, path, "NOT_FOUND", userData); params.result = ResultCode_ErrorFileNotFound; callback->invoke( (void *)¶ms ); } return; } FileRecord fr = r_it->second; mPendingReads.erase( r_it ); std::string newPath; if (fr.policy == PP_AllowAbstraction && _appendNextPlatformTag( fr.originalPath, newPath, fr.pathTagIndex, fr.pathTagIndex )) { // try reading this next platform-tag before failing through to next handler... mPendingReads[ newPath ] = fr; h->readFile( newPath, callback, userData ); } else { // failed, see if we have another handler after this one, and try it if we do... FileHandlerMap::iterator it; for (it = mFileHandlers.begin(); it != mFileHandlers.end(); it++) { if (it->second == h) { it++; break; } } if (it != mFileHandlers.end()) { Logger::printf("Walaber", Logger::SV_DEBUG, "FileManager::_readFail - trying next handler\n"); if(fr.policy == PP_AllowAbstraction) { _appendNextPlatformTag(fr.originalPath, newPath, -1, fr.pathTagIndex); } else { newPath = fr.originalPath; } mPendingReads[ newPath ] = fr; it->second->readFile( newPath, callback, userData ); } else { // compete failure! Logger::printf("Walaber", Logger::SV_DEBUG, "FileManager::_readFail - complete fail [%s]\n", path.c_str()); if (callback) { ReadFileCallbackParameters params(path, NULL, 0, path, "NOT_FOUND", userData); params.result = ResultCode_ErrorFileNotFound; callback->invoke( (void *)¶ms ); } } } }
// ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm // ---------fm---------fm---------fm---------fm---------fm---------fm---------fm---------fm void FileManager::_existFail( const std::string& path, FileHandler* h, CallbackPtr callback, const PropertyList& userData ) { // failed, see if we have another platform string to try... FileRecordMap::iterator r_it = mPendingExists.find( path ); // this must be in the map! assert(r_it != mPendingExists.end()); FileRecord fr = r_it->second; // remove old pending record... mPendingExists.erase( r_it ); std::string newPath; if (fr.policy == PP_AllowAbstraction && _appendNextPlatformTag( fr.originalPath, newPath, fr.pathTagIndex, fr.pathTagIndex )) { // we can try this new one before failing through to another file handler... // store new record... mPendingExists[ newPath ] = fr; // query file. h->fileExists(newPath, callback, userData); } else { // failed, see if we have another handler after this one, and try it if we do... FileHandlerMap::iterator it; for (it = mFileHandlers.begin(); it != mFileHandlers.end(); it++) { if (it->second == h) { it++; break; } } if (it != mFileHandlers.end()) { Logger::printf("Walaber", Logger::SV_DEBUG, "FileManager::_existFail - trying next handler...\n"); // trying from scratch again... if(fr.policy == PP_AllowAbstraction) { _appendNextPlatformTag(fr.originalPath, newPath, -1, fr.pathTagIndex); } else { newPath = fr.originalPath; } mPendingExists[ newPath ] = fr; it->second->fileExists( newPath, callback, userData ); } else { // compete failure! Logger::printf("Walaber", Logger::SV_DEBUG, "FileManager::_existFail - total failure...\n"); if (callback) { FileExistsCallbackParameters params( path, false, path, "NOT_FOUND", userData ); callback->invoke( (void *)¶ms ); } } } }
void allTests(const Ice::CommunicatorPtr& communicator, const vector<int>& ports) { cout << "testing stringToProxy... " << flush; ostringstream ref; ref << "test"; for(vector<int>::const_iterator p = ports.begin(); p != ports.end(); ++p) { ref << ":default -p " << *p; } Ice::ObjectPrx base = communicator->stringToProxy(ref.str()); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrx obj = TestIntfPrx::checkedCast(base); test(obj); test(obj == base); cout << "ok" << endl; int oldPid = 0; bool ami = false; for(unsigned int i = 1, j = 0; i <= ports.size(); ++i, ++j) { if(j > 3) { j = 0; ami = !ami; } if(!ami) { cout << "testing server #" << i << "... " << flush; int pid = obj->pid(); test(pid != oldPid); cout << "ok" << endl; oldPid = pid; } else { cout << "testing server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback(); obj->begin_pid(newCallback_TestIntf_pid(cb, &Callback::opPidI, &Callback::exception)); cb->check(); int pid = cb->pid(); test(pid != oldPid); cout << "ok" << endl; oldPid = pid; } if(j == 0) { if(!ami) { cout << "shutting down server #" << i << "... " << flush; obj->shutdown(); cout << "ok" << endl; } else { cout << "shutting down server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback; obj->begin_shutdown(newCallback_TestIntf_shutdown(cb, &Callback::opShutdownI, &Callback::exception)); cb->check(); cout << "ok" << endl; } } else if(j == 1 || i + 1 > ports.size()) { if(!ami) { cout << "aborting server #" << i << "... " << flush; try { obj->abort(); test(false); } catch(const Ice::ConnectionLostException&) { cout << "ok" << endl; } catch(const Ice::ConnectFailedException&) { cout << "ok" << endl; } } else { cout << "aborting server #" << i << " with AMI... " << flush; CallbackPtr cb = new Callback; obj->begin_abort(newCallback_TestIntf_abort(cb, &Callback::response, &Callback::exceptAbortI)); cb->check(); cout << "ok" << endl; } } else if(j == 2 || j == 3) { if(!ami) { cout << "aborting server #" << i << " and #" << i + 1 << " with idempotent call... " << flush; try { obj->idempotentAbort(); test(false); } catch(const Ice::ConnectionLostException&) { cout << "ok" << endl; } catch(const Ice::ConnectFailedException&) { cout << "ok" << endl; } } else { cout << "aborting server #" << i << " and #" << i + 1 << " with idempotent AMI call... " << flush; CallbackPtr cb = new Callback; obj->begin_idempotentAbort(newCallback_TestIntf_idempotentAbort(cb, &Callback::response, &Callback::exceptAbortI)); cb->check(); cout << "ok" << endl; } ++i; } else { assert(false); } } cout << "testing whether all servers are gone... " << flush; try { obj->ice_ping(); test(false); } catch(const Ice::LocalException&) { cout << "ok" << endl; } }
MetricsPrx allTests(const Ice::CommunicatorPtr& communicator, const CommunicatorObserverIPtr& obsv) { MetricsPrx metrics = MetricsPrx::checkedCast(communicator->stringToProxy("metrics:default -p 12010")); cout << "testing metrics admin facet checkedCast... " << flush; Ice::ObjectPrx admin = communicator->getAdmin()->ice_collocationOptimized(false); Ice::PropertiesAdminPrx clientProps = Ice::PropertiesAdminPrx::checkedCast(admin, "Properties"); IceMX::MetricsAdminPrx clientMetrics = IceMX::MetricsAdminPrx::checkedCast(admin, "Metrics"); test(clientProps && clientMetrics); admin = metrics->getAdmin(); Ice::PropertiesAdminPrx serverProps = Ice::PropertiesAdminPrx::checkedCast(admin, "Properties"); IceMX::MetricsAdminPrx serverMetrics = IceMX::MetricsAdminPrx::checkedCast(admin, "Metrics"); test(serverProps && serverMetrics); UpdateCallbackI* update = new UpdateCallbackI(serverProps); Ice::NativePropertiesAdminPtr::dynamicCast(communicator->findAdminFacet("Properties"))->addUpdateCallback(update); cout << "ok" << endl; Ice::PropertyDict props; cout << "testing group by none..." << flush; props["IceMX.Metrics.View.GroupBy"] = "none"; updateProps(clientProps, serverProps, update, props); #ifndef ICE_OS_WINRT int threadCount = 4; #else int threadCount = 3; // No endpoint host resolver thread with WinRT. #endif Ice::Long timestamp; IceMX::MetricsView view = clientMetrics->getMetricsView("View", timestamp); test(view["Connection"].size() == 1 && view["Connection"][0]->current == 1 && view["Connection"][0]->total == 1); test(view["Thread"].size() == 1 && view["Thread"][0]->current == threadCount && view["Thread"][0]->total == threadCount); cout << "ok" << endl; cout << "testing group by id..." << flush; props["IceMX.Metrics.View.GroupBy"] = "id"; updateProps(clientProps, serverProps, update, props); metrics->ice_ping(); metrics->ice_ping(); metrics->ice_connectionId("Con1")->ice_ping(); metrics->ice_connectionId("Con1")->ice_ping(); metrics->ice_connectionId("Con1")->ice_ping(); view = clientMetrics->getMetricsView("View", timestamp); test(static_cast<int>(view["Thread"].size()) == threadCount); test(view["Connection"].size() == 2); test(view["Invocation"].size() == 1); IceMX::InvocationMetricsPtr invoke = IceMX::InvocationMetricsPtr::dynamicCast(view["Invocation"][0]); test(invoke->id.find("[ice_ping]") > 0 && invoke->current == 0 && invoke->total == 5); test(invoke->remotes.size() == 2); test(invoke->remotes[0]->total = 2); test(invoke->remotes[1]->total = 3); view = serverMetrics->getMetricsView("View", timestamp); test(view["Thread"].size() > 4); test(view["Connection"].size() == 2); test(view["Dispatch"].size() == 1); test(view["Dispatch"][0]->current <= 1 && view["Dispatch"][0]->total == 5); test(view["Dispatch"][0]->id.find("[ice_ping]") > 0); metrics->ice_getConnection()->close(false); metrics->ice_connectionId("Con1")->ice_getConnection()->close(false); waitForCurrent(clientMetrics, "View", "Connection", 0); waitForCurrent(serverMetrics, "View", "Connection", 0); clearView(clientProps, serverProps, update); cout << "ok" << endl; cout << "testing connection metrics... " << flush; props["IceMX.Metrics.View.Map.Connection.GroupBy"] = "none"; updateProps(clientProps, serverProps, update, props, "Connection"); test(clientMetrics->getMetricsView("View", timestamp)["Connection"].empty()); test(serverMetrics->getMetricsView("View", timestamp)["Connection"].empty()); metrics->ice_ping(); IceMX::ConnectionMetricsPtr cm1, sm1, cm2, sm2; cm1 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm1 = IceMX::ConnectionMetricsPtr::dynamicCast(serverMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm1 = getServerConnectionMetrics(serverMetrics, 25); test(cm1->total == 1 && sm1->total == 1); metrics->ice_ping(); cm2 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm2 = getServerConnectionMetrics(serverMetrics, 50); test(cm2->sentBytes - cm1->sentBytes == 45); // 45 for ice_ping request test(cm2->receivedBytes - cm1->receivedBytes == 25); // 25 bytes for ice_ping response test(sm2->receivedBytes - sm1->receivedBytes == 45); test(sm2->sentBytes - sm1->sentBytes == 25); cm1 = cm2; sm1 = sm2; Test::ByteSeq bs; metrics->opByteS(bs); cm2 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm2 = getServerConnectionMetrics(serverMetrics, sm1->sentBytes + cm2->receivedBytes - cm1->receivedBytes); Ice::Long requestSz = cm2->sentBytes - cm1->sentBytes; Ice::Long replySz = cm2->receivedBytes - cm1->receivedBytes; cm1 = cm2; sm1 = sm2; bs.resize(456); metrics->opByteS(bs); cm2 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm2 = getServerConnectionMetrics(serverMetrics, sm1->sentBytes + replySz); // 4 is for the seq variable size test(cm2->sentBytes - cm1->sentBytes == requestSz + static_cast<int>(bs.size()) + 4); test(cm2->receivedBytes - cm1->receivedBytes == replySz); test(sm2->receivedBytes - sm1->receivedBytes == requestSz + static_cast<int>(bs.size()) + 4); test(sm2->sentBytes - sm1->sentBytes == replySz); cm1 = cm2; sm1 = sm2; bs.resize(1024 * 1024 * 10); // Try with large amount of data which should be sent in several chunks metrics->opByteS(bs); cm2 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); sm2 = getServerConnectionMetrics(serverMetrics, sm1->sentBytes + replySz); // 4 is for the seq variable size test(cm2->sentBytes - cm1->sentBytes == requestSz + static_cast<int>(bs.size()) + 4); test(cm2->receivedBytes - cm1->receivedBytes == replySz); test(sm2->receivedBytes - sm1->receivedBytes == requestSz + static_cast<int>(bs.size()) + 4); test(sm2->sentBytes - sm1->sentBytes == replySz); props["IceMX.Metrics.View.Map.Connection.GroupBy"] = "state"; updateProps(clientProps, serverProps, update, props, "Connection"); map<string, IceMX::MetricsPtr> map; map = toMap(serverMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["active"]->current == 1); ControllerPrx controller = ControllerPrx::checkedCast(communicator->stringToProxy("controller:default -p 12011")); controller->hold(); map = toMap(clientMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["active"]->current == 1); map = toMap(serverMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["holding"]->current == 1); metrics->ice_getConnection()->close(false); map = toMap(clientMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["closing"]->current == 1); map = toMap(serverMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["holding"]->current == 1); controller->resume(); map = toMap(serverMetrics->getMetricsView("View", timestamp)["Connection"]); test(map["holding"]->current == 0); props["IceMX.Metrics.View.Map.Connection.GroupBy"] = "none"; updateProps(clientProps, serverProps, update, props, "Connection"); metrics->ice_getConnection()->close(false); metrics->ice_timeout(500)->ice_ping(); controller->hold(); try { metrics->ice_timeout(500)->ice_ping(); test(false); } catch(const Ice::TimeoutException&) { } controller->resume(); cm1 = IceMX::ConnectionMetricsPtr::dynamicCast(clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); while(true) { sm1 = IceMX::ConnectionMetricsPtr::dynamicCast( serverMetrics->getMetricsView("View", timestamp)["Connection"][0]); if(sm1-> failures >= 2) { break; } IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10)); } test(cm1->failures == 2 && sm1->failures >= 1); checkFailure(clientMetrics, "Connection", cm1->id, "Ice::TimeoutException", 1); checkFailure(clientMetrics, "Connection", cm1->id, "Ice::ConnectTimeoutException", 1); checkFailure(serverMetrics, "Connection", sm1->id, "Ice::ConnectionLostException"); MetricsPrx m = metrics->ice_timeout(500)->ice_connectionId("Con1"); m->ice_ping(); testAttribute(clientMetrics, clientProps, update, "Connection", "parent", "Communicator"); //testAttribute(clientMetrics, clientProps, update, "Connection", "id", ""); testAttribute(clientMetrics, clientProps, update, "Connection", "endpoint", "tcp -h 127.0.0.1 -p 12010 -t 500"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointType", "1"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointIsDatagram", "false"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointIsSecure", "false"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointTimeout", "500"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointCompress", "false"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointHost", "127.0.0.1"); testAttribute(clientMetrics, clientProps, update, "Connection", "endpointPort", "12010"); testAttribute(clientMetrics, clientProps, update, "Connection", "incoming", "false"); testAttribute(clientMetrics, clientProps, update, "Connection", "adapterName", ""); testAttribute(clientMetrics, clientProps, update, "Connection", "connectionId", "Con1"); testAttribute(clientMetrics, clientProps, update, "Connection", "localHost", "127.0.0.1"); //testAttribute(clientMetrics, clientProps, update, "Connection", "localPort", ""); testAttribute(clientMetrics, clientProps, update, "Connection", "remoteHost", "127.0.0.1"); testAttribute(clientMetrics, clientProps, update, "Connection", "remotePort", "12010"); testAttribute(clientMetrics, clientProps, update, "Connection", "mcastHost", ""); testAttribute(clientMetrics, clientProps, update, "Connection", "mcastPort", ""); m->ice_getConnection()->close(false); waitForCurrent(clientMetrics, "View", "Connection", 0); waitForCurrent(serverMetrics, "View", "Connection", 0); cout << "ok" << endl; cout << "testing connection establishment metrics... " << flush; props["IceMX.Metrics.View.Map.ConnectionEstablishment.GroupBy"] = "id"; updateProps(clientProps, serverProps, update, props, "ConnectionEstablishment"); test(clientMetrics->getMetricsView("View", timestamp)["ConnectionEstablishment"].empty()); metrics->ice_ping(); test(clientMetrics->getMetricsView("View", timestamp)["ConnectionEstablishment"].size() == 1); IceMX::MetricsPtr m1 = clientMetrics->getMetricsView("View", timestamp)["ConnectionEstablishment"][0]; test(m1->current == 0 && m1->total == 1 && m1->id == "127.0.0.1:12010"); metrics->ice_getConnection()->close(false); controller->hold(); try { communicator->stringToProxy("test:tcp -p 12010 -h 127.0.0.1")->ice_timeout(10)->ice_ping(); test(false); } catch(const Ice::ConnectTimeoutException&) { } catch(const Ice::LocalException&) { test(false); } controller->resume(); test(clientMetrics->getMetricsView("View", timestamp)["ConnectionEstablishment"].size() == 1); m1 = clientMetrics->getMetricsView("View", timestamp)["ConnectionEstablishment"][0]; test(m1->id == "127.0.0.1:12010" && m1->total == 3 && m1->failures == 2); checkFailure(clientMetrics, "ConnectionEstablishment", m1->id, "Ice::ConnectTimeoutException", 2); Connect c(metrics); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "parent", "Communicator", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "id", "127.0.0.1:12010", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpoint", "tcp -h 127.0.0.1 -p 12010", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointType", "1", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointIsDatagram", "false", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointIsSecure", "false", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointTimeout", "-1", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointCompress", "false", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointHost", "127.0.0.1", c); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointPort", "12010", c); cout << "ok" << endl; // // Ice doesn't do any endpoint lookup with WinRT, the WinRT // runtime takes care of if. // #ifndef ICE_OS_WINRT cout << "testing endpoint lookup metrics... " << flush; props["IceMX.Metrics.View.Map.ConnectionEstablishment.GroupBy"] = "id"; updateProps(clientProps, serverProps, update, props, "EndpointLookup"); test(clientMetrics->getMetricsView("View", timestamp)["EndpointLookup"].empty()); Ice::ObjectPrx prx = communicator->stringToProxy("metrics:default -p 12010 -h localhost"); prx->ice_ping(); test(clientMetrics->getMetricsView("View", timestamp)["EndpointLookup"].size() == 1); m1 = clientMetrics->getMetricsView("View", timestamp)["EndpointLookup"][0]; test(m1->current <= 1 && m1->total == 1 && m1->id == "tcp -h localhost -p 12010"); prx->ice_getConnection()->close(false); bool dnsException = false; try { communicator->stringToProxy("test:tcp -t 500 -p 12010 -h unknownfoo.zeroc.com")->ice_ping(); test(false); } catch(const Ice::DNSException&) { dnsException = true; } catch(const Ice::LocalException&) { // Some DNS servers don't fail on unknown DNS names. } test(clientMetrics->getMetricsView("View", timestamp)["EndpointLookup"].size() == 2); m1 = clientMetrics->getMetricsView("View", timestamp)["EndpointLookup"][1]; test(m1->id == "tcp -h unknownfoo.zeroc.com -p 12010 -t 500" && m1->total == 2 && (!dnsException || m1->failures == 2)); if(dnsException) { checkFailure(clientMetrics, "EndpointLookup", m1->id, "Ice::DNSException", 2); } c = Connect(prx); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "parent", "Communicator", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "id", "tcp -h localhost -p 12010", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpoint", "tcp -h localhost -p 12010", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointType", "1", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointIsDatagram", "false", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointIsSecure", "false", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointTimeout", "-1", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointCompress", "false", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointHost", "localhost", c); testAttribute(clientMetrics, clientProps, update, "EndpointLookup", "endpointPort", "12010", c); cout << "ok" << endl; #endif cout << "testing dispatch metrics... " << flush; props["IceMX.Metrics.View.Map.Dispatch.GroupBy"] = "operation"; updateProps(clientProps, serverProps, update, props, "Dispatch"); test(serverMetrics->getMetricsView("View", timestamp)["Dispatch"].empty()); metrics->op(); try { metrics->opWithUserException(); test(false); } catch(const Test::UserEx&) { } try { metrics->opWithRequestFailedException(); test(false); } catch(const Ice::RequestFailedException&) { } try { metrics->opWithLocalException(); test(false); } catch(const Ice::LocalException&) { } try { metrics->opWithUnknownException(); test(false); } catch(const Ice::UnknownException&) { } try { metrics->fail(); test(false); } catch(const Ice::ConnectionLostException&) { } map = toMap(serverMetrics->getMetricsView("View", timestamp)["Dispatch"]); test(map.size() == 6); IceMX::DispatchMetricsPtr dm1 = IceMX::DispatchMetricsPtr::dynamicCast(map["op"]); test(dm1->current <= 1 && dm1->total == 1 && dm1->failures == 0 && dm1->userException == 0); test(dm1->size == 21 && dm1->replySize == 7); dm1 = IceMX::DispatchMetricsPtr::dynamicCast(map["opWithUserException"]); test(dm1->current <= 1 && dm1->total == 1 && dm1->failures == 0 && dm1->userException == 1); test(dm1->size == 38 && dm1->replySize == 23); dm1 = IceMX::DispatchMetricsPtr::dynamicCast(map["opWithLocalException"]); test(dm1->current <= 1 && dm1->total == 1 && dm1->failures == 1 && dm1->userException == 0); checkFailure(serverMetrics, "Dispatch", dm1->id, "Ice::SyscallException", 1); test(dm1->size == 39 && dm1->replySize > 7); // Reply contains the exception stack depending on the OS. dm1 = IceMX::DispatchMetricsPtr::dynamicCast(map["opWithRequestFailedException"]); test(dm1->current <= 1 && dm1->total == 1 && dm1->failures == 1 && dm1->userException == 0); checkFailure(serverMetrics, "Dispatch", dm1->id, "Ice::ObjectNotExistException", 1); test(dm1->size == 47 && dm1->replySize == 40); dm1 = IceMX::DispatchMetricsPtr::dynamicCast(map["opWithUnknownException"]); test(dm1->current <= 1 && dm1->total == 1 && dm1->failures == 1 && dm1->userException == 0); checkFailure(serverMetrics, "Dispatch", dm1->id, "unknown", 1); test(dm1->size == 41 && dm1->replySize == 23); InvokeOp op(metrics); testAttribute(serverMetrics, serverProps, update, "Dispatch", "parent", "TestAdapter", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "id", "metrics [op]", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpoint", "tcp -h 127.0.0.1 -p 12010", op); //testAttribute(serverMetrics, serverProps, update, "Dispatch", "connection", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointType", "1", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointIsDatagram", "false", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointIsSecure", "false", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointTimeout", "-1", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointCompress", "false", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointHost", "127.0.0.1", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "endpointPort", "12010", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "incoming", "true", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "adapterName", "TestAdapter", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "connectionId", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "localHost", "127.0.0.1", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "localPort", "12010", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "remoteHost", "127.0.0.1", op); //testAttribute(serverMetrics, serverProps, update, "Dispatch", "remotePort", "12010", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "mcastHost", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "mcastPort", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "operation", "op", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "identity", "metrics", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "facet", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "mode", "twoway", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "context.entry1", "test", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "context.entry2", "", op); testAttribute(serverMetrics, serverProps, update, "Dispatch", "context.entry3", "", op); cout << "ok" << endl; cout << "testing invocation metrics... " << flush; props["IceMX.Metrics.View.Map.Invocation.GroupBy"] = "operation"; props["IceMX.Metrics.View.Map.Invocation.Map.Remote.GroupBy"] = "localPort"; updateProps(clientProps, serverProps, update, props, "Invocation"); test(serverMetrics->getMetricsView("View", timestamp)["Invocation"].empty()); CallbackPtr cb = new Callback(); metrics->op(); metrics->end_op(metrics->begin_op()); metrics->begin_op(newCallback_Metrics_op(cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); // User exception try { metrics->opWithUserException(); test(false); } catch(const Test::UserEx&) { } try { metrics->end_opWithUserException(metrics->begin_opWithUserException()); test(false); } catch(const Test::UserEx&) { } metrics->begin_opWithUserException(newCallback_Metrics_opWithUserException( cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); // Request failed exception try { metrics->opWithRequestFailedException(); test(false); } catch(const Ice::RequestFailedException&) { } try { metrics->end_opWithRequestFailedException(metrics->begin_opWithRequestFailedException()); test(false); } catch(const Ice::RequestFailedException&) { } metrics->begin_opWithRequestFailedException(newCallback_Metrics_opWithRequestFailedException( cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); // Local exception try { metrics->opWithLocalException(); test(false); } catch(const Ice::LocalException&) { } try { metrics->end_opWithLocalException(metrics->begin_opWithLocalException()); test(false); } catch(const Ice::LocalException&) { } metrics->begin_opWithLocalException(newCallback_Metrics_opWithLocalException( cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); // Unknown exception try { metrics->opWithUnknownException(); test(false); } catch(const Ice::UnknownException&) { } try { metrics->end_opWithUnknownException(metrics->begin_opWithUnknownException()); test(false); } catch(const Ice::UnknownException&) { } metrics->begin_opWithUnknownException(newCallback_Metrics_opWithUnknownException( cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); // Fail try { metrics->fail(); test(false); } catch(const Ice::ConnectionLostException&) { } try { metrics->end_fail(metrics->begin_fail()); test(false); } catch(const Ice::ConnectionLostException&) { } metrics->begin_fail(newCallback_Metrics_fail(cb, &Callback::response, &Callback::exception)); cb->waitForResponse(); map = toMap(clientMetrics->getMetricsView("View", timestamp)["Invocation"]); test(map.size() == 6); IceMX::InvocationMetricsPtr im1; IceMX::RemoteMetricsPtr rim1; im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["op"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 0 && im1->retry == 0 && im1->remotes.size() == 1); rim1 = IceMX::RemoteMetricsPtr::dynamicCast(im1->remotes[0]); test(rim1->current == 0 && rim1->total == 3 && rim1->failures == 0); test(rim1->size == 63 && rim1->replySize == 21); im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["opWithUserException"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 0 && im1->retry == 0 && im1->remotes.size() == 1); rim1 = IceMX::RemoteMetricsPtr::dynamicCast(im1->remotes[0]); test(rim1->current == 0 && rim1->total == 3 && rim1->failures == 0); test(rim1->size == 114 && rim1->replySize == 69); test(im1->userException == 3); im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["opWithLocalException"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 3 && im1->retry == 0 && im1->remotes.size() == 1); rim1 = IceMX::RemoteMetricsPtr::dynamicCast(im1->remotes[0]); test(rim1->current == 0 && rim1->total == 3 && rim1->failures == 0); test(rim1->size == 117 && rim1->replySize > 7); checkFailure(clientMetrics, "Invocation", im1->id, "Ice::UnknownLocalException", 3); im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["opWithRequestFailedException"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 3 && im1->retry == 0 && im1->remotes.size() == 1); rim1 = IceMX::RemoteMetricsPtr::dynamicCast(im1->remotes[0]); test(rim1->current == 0 && rim1->total == 3 && rim1->failures == 0); test(rim1->size == 141 && rim1->replySize == 120); checkFailure(clientMetrics, "Invocation", im1->id, "Ice::ObjectNotExistException", 3); im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["opWithUnknownException"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 3 && im1->retry == 0 && im1->remotes.size() == 1); rim1 = IceMX::RemoteMetricsPtr::dynamicCast(im1->remotes[0]); test(rim1->current == 0 && rim1->total == 3 && rim1->failures == 0); test(rim1->size == 123 && rim1->replySize == 69); checkFailure(clientMetrics, "Invocation", im1->id, "Ice::UnknownException", 3); im1 = IceMX::InvocationMetricsPtr::dynamicCast(map["fail"]); test(im1->current <= 1 && im1->total == 3 && im1->failures == 3 && im1->retry == 3 && im1->remotes.size() == 6); test(im1->remotes[0]->current == 0 && im1->remotes[0]->total == 1 && im1->remotes[0]->failures == 1); test(im1->remotes[1]->current == 0 && im1->remotes[1]->total == 1 && im1->remotes[1]->failures == 1); test(im1->remotes[2]->current == 0 && im1->remotes[2]->total == 1 && im1->remotes[2]->failures == 1); test(im1->remotes[3]->current == 0 && im1->remotes[3]->total == 1 && im1->remotes[3]->failures == 1); test(im1->remotes[4]->current == 0 && im1->remotes[4]->total == 1 && im1->remotes[4]->failures == 1); test(im1->remotes[5]->current == 0 && im1->remotes[5]->total == 1 && im1->remotes[5]->failures == 1); checkFailure(clientMetrics, "Invocation", im1->id, "Ice::ConnectionLostException", 3); testAttribute(clientMetrics, clientProps, update, "Invocation", "parent", "Communicator", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "id", "metrics -t -e 1.1 [op]", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "operation", "op", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "identity", "metrics", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "facet", "", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "encoding", "1.1", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "mode", "twoway", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "proxy", "metrics -t -e 1.1:tcp -h 127.0.0.1 -p 12010", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "context.entry1", "test", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "context.entry2", "", op); testAttribute(clientMetrics, clientProps, update, "Invocation", "context.entry3", "", op); cout << "ok" << endl; cout << "testing metrics view enable/disable..." << flush; Ice::StringSeq disabledViews; props["IceMX.Metrics.View.GroupBy"] = "none"; props["IceMX.Metrics.View.Disabled"] = "0"; updateProps(clientProps, serverProps, update, props, "Thread"); test(!clientMetrics->getMetricsView("View", timestamp)["Thread"].empty()); test(clientMetrics->getMetricsViewNames(disabledViews).size() == 1 && disabledViews.empty()); props["IceMX.Metrics.View.Disabled"] = "1"; updateProps(clientProps, serverProps, update, props, "Thread"); test(clientMetrics->getMetricsView("View", timestamp)["Thread"].empty()); test(clientMetrics->getMetricsViewNames(disabledViews).empty() && disabledViews.size() == 1); clientMetrics->enableMetricsView("View"); test(!clientMetrics->getMetricsView("View", timestamp)["Thread"].empty()); test(clientMetrics->getMetricsViewNames(disabledViews).size() == 1 && disabledViews.empty()); clientMetrics->disableMetricsView("View"); test(clientMetrics->getMetricsView("View", timestamp)["Thread"].empty()); test(clientMetrics->getMetricsViewNames(disabledViews).empty() && disabledViews.size() == 1); try { clientMetrics->enableMetricsView("UnknownView"); } catch(const IceMX::UnknownMetricsView&) { } cout << "ok" << endl; cout << "testing instrumentation observer delegate... " << flush; test(obsv->threadObserver->getTotal() > 0); test(obsv->connectionObserver->getTotal() > 0); test(obsv->connectionEstablishmentObserver->getTotal() > 0); #ifndef ICE_OS_WINRT test(obsv->endpointLookupObserver->getTotal() > 0); #endif test(obsv->dispatchObserver->getTotal() > 0); test(obsv->invocationObserver->getTotal() > 0); test(obsv->invocationObserver->remoteObserver->getTotal() > 0); test(obsv->threadObserver->getCurrent() > 0); test(obsv->connectionObserver->getCurrent() > 0); test(obsv->connectionEstablishmentObserver->getCurrent() == 0); #ifndef ICE_OS_WINRT test(obsv->endpointLookupObserver->getCurrent() == 0); #endif test(obsv->dispatchObserver->getCurrent() == 0); test(obsv->invocationObserver->getCurrent() == 0); test(obsv->invocationObserver->remoteObserver->getCurrent() == 0); test(obsv->threadObserver->getFailedCount() == 0); test(obsv->connectionObserver->getFailedCount() > 0); test(obsv->connectionEstablishmentObserver->getFailedCount() > 0); #ifndef ICE_OS_WINRT test(obsv->endpointLookupObserver->getFailedCount() > 0); #endif //test(obsv->dispatchObserver->getFailedCount() > 0); test(obsv->invocationObserver->getFailedCount() > 0); test(obsv->invocationObserver->remoteObserver->getFailedCount() > 0); test(obsv->threadObserver->states > 0); test(obsv->connectionObserver->received > 0 && obsv->connectionObserver->sent > 0); //test(obsv->dispatchObserver->userExceptionCount > 0); test(obsv->invocationObserver->userExceptionCount > 0 && obsv->invocationObserver->retriedCount > 0); test(obsv->invocationObserver->remoteObserver->replySize > 0); cout << "ok" << endl; return metrics; }
void onewaysAMI(const Ice::CommunicatorPtr&, const Test::MyClassPrx& proxy) { Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(proxy->ice_oneway()); { CallbackPtr cb = new Callback; Ice::Callback_Object_ice_pingPtr callback = Ice::newCallback_Object_ice_ping(cb, &Callback::noException, &Callback::sent); p->begin_ice_ping(callback); cb->check(); } { try { p->begin_ice_isA(Test::MyClass::ice_staticId()); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_id(); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_ids(); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb, &Callback::noException, &Callback::sent); p->begin_opVoid(callback); cb->check(); } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opIdempotentPtr callback = Test::newCallback_MyClass_opIdempotent(cb, &Callback::noException, &Callback::sent); p->begin_opIdempotent(callback); cb->check(); } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opNonmutatingPtr callback = Test::newCallback_MyClass_opNonmutating(cb, &Callback::noException, &Callback::sent); p->begin_opNonmutating(callback); cb->check(); } { try { p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f)); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } #ifdef ICE_CPP11 { CallbackPtr cb = new Callback; p->begin_ice_ping(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { try { p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_id([=](const string&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_ids([=](const Ice::StringSeq&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { CallbackPtr cb = new Callback; p->begin_opVoid(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { CallbackPtr cb = new Callback; p->begin_opIdempotent(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { CallbackPtr cb = new Callback; p->begin_opNonmutating(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { try { p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), [=](const Ice::Byte&, const Ice::Byte&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } #endif }
TimeoutPrx allTests(const Ice::CommunicatorPtr& communicator) { string sref = "timeout:default -p 12010"; Ice::ObjectPrx obj = communicator->stringToProxy(sref); test(obj); TimeoutPrx timeout = TimeoutPrx::checkedCast(obj); test(timeout); cout << "testing connect timeout... " << flush; { // // Expect ConnectTimeoutException. // TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(250)); to->holdAdapter(750); to->ice_getConnection()->close(true); // Force a reconnect. try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(1000)); to->holdAdapter(500); to->ice_getConnection()->close(true); // Force a reconnect. try { to->op(); } catch(const Ice::ConnectTimeoutException&) { test(false); } } cout << "ok" << endl; cout << "testing read timeout... " << flush; { // // Expect TimeoutException. // TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(500)); try { to->sleep(750); test(false); } catch(const Ice::TimeoutException&) { // Expected. } } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(2000)); try { to->sleep(500); } catch(const Ice::TimeoutException&) { test(false); } } cout << "ok" << endl; cout << "testing write timeout... " << flush; { // // Expect TimeoutException. // TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(500)); to->holdAdapter(2000); try { ByteSeq seq(100000); to->sendData(seq); test(false); } catch(const Ice::TimeoutException&) { // Expected. } } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(1000)); to->holdAdapter(500); try { ByteSeq seq(100000); to->sendData(seq); } catch(const Ice::TimeoutException&) { test(false); } } cout << "ok" << endl; cout << "testing AMI read timeout... " << flush; { // // Expect TimeoutException. // TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(500)); CallbackPtr cb = new Callback(); to->begin_sleep(2000, newCallback_Timeout_sleep(cb, &Callback::responseEx, &Callback::exceptionEx)); cb->check(); } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(1000)); CallbackPtr cb = new Callback(); to->begin_sleep(500, newCallback_Timeout_sleep(cb, &Callback::response, &Callback::exception)); cb->check(); } cout << "ok" << endl; cout << "testing AMI write timeout... " << flush; { // // Expect TimeoutException. // TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(500)); to->holdAdapter(2000); ByteSeq seq(100000); CallbackPtr cb = new Callback(); to->begin_sendData(seq, newCallback_Timeout_sendData(cb, &Callback::responseEx, &Callback::exceptionEx)); cb->check(); } { // // Expect success. // timeout->op(); // Ensure adapter is active. TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(1000)); to->holdAdapter(500); ByteSeq seq(100000); CallbackPtr cb = new Callback(); to->begin_sendData(seq, newCallback_Timeout_sendData(cb, &Callback::response, &Callback::exception)); cb->check(); } cout << "ok" << endl; cout << "testing close timeout... " << flush; { TimeoutPrx to = TimeoutPrx::checkedCast(obj->ice_timeout(250)); Ice::ConnectionPtr connection = to->ice_getConnection(); timeout->holdAdapter(750); connection->close(false); try { connection->getInfo(); // getInfo() doesn't throw in the closing state. } catch(const Ice::LocalException&) { test(false); } IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); try { connection->getInfo(); test(false); } catch(const Ice::CloseConnectionException&) { // Expected. } timeout->op(); // Ensure adapter is active. } cout << "ok" << endl; cout << "testing timeout overrides... " << flush; { // // Test Ice.Override.Timeout. This property overrides all // endpoint timeouts. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.Timeout", "500"); Ice::CommunicatorPtr comm = Ice::initialize(initData); TimeoutPrx to = TimeoutPrx::checkedCast(comm->stringToProxy(sref)); try { to->sleep(750); test(false); } catch(const Ice::TimeoutException&) { // Expected. } // // Calling ice_timeout() should have no effect. // timeout->op(); // Ensure adapter is active. to = TimeoutPrx::checkedCast(to->ice_timeout(1000)); try { to->sleep(750); test(false); } catch(const Ice::TimeoutException&) { // Expected. } comm->destroy(); } { // // Test Ice.Override.ConnectTimeout. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.ConnectTimeout", "750"); Ice::CommunicatorPtr comm = Ice::initialize(initData); timeout->holdAdapter(1000); TimeoutPrx to = TimeoutPrx::uncheckedCast(comm->stringToProxy(sref)); try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } // // Calling ice_timeout() should have no effect on the connect timeout. // timeout->op(); // Ensure adapter is active. timeout->holdAdapter(1000); to = TimeoutPrx::uncheckedCast(to->ice_timeout(1250)); try { to->op(); test(false); } catch(const Ice::ConnectTimeoutException&) { // Expected. } // // Verify that timeout set via ice_timeout() is still used for requests. // to->op(); // Force connection. try { to->sleep(2000); test(false); } catch(const Ice::TimeoutException&) { // Expected. } comm->destroy(); } { // // Test Ice.Override.CloseTimeout. // Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Override.CloseTimeout", "200"); Ice::CommunicatorPtr comm = Ice::initialize(initData); Ice::ConnectionPtr connection = comm->stringToProxy(sref)->ice_getConnection(); timeout->holdAdapter(750); IceUtil::Time now = IceUtil::Time::now(); comm->destroy(); test(IceUtil::Time::now() - now < IceUtil::Time::milliSeconds(500)); } cout << "ok" << endl; return timeout; }
ThrowerPrx allTests(const Ice::CommunicatorPtr& communicator) { cout << "testing ice_print()/what()... " << flush; { A a; string aMsg = "Test::A"; Ice::UnknownLocalException ule("thisFile", 99); string uleMsg = "thisFile:99: Ice::UnknownLocalException:\nunknown local exception"; // // Test ice_print(). // { stringstream str; a.ice_print(str); test(str.str() == aMsg); } { stringstream str; ule.ice_print(str); test(str.str() == uleMsg); } // // Test operator<<(). // { stringstream str; str << a; test(str.str() == aMsg); } { stringstream str; str << ule; test(str.str() == uleMsg); } // // Test what(). (Called twice because of lazy initialization in what().) // test(aMsg == a.what()); test(aMsg == a.what()); test(uleMsg == ule.what()); test(uleMsg == ule.what()); { E ex("E"); ostringstream os; ex.ice_print(os); test(os.str() == "Test::E"); test(ex.data == "E"); } // // Test custom ice_print // { F ex("F"); ostringstream os; ex.ice_print(os); test(os.str() == "Test::F data:'F'"); test(ex.data == "F"); } { G ex(__FILE__, __LINE__, "G"); ostringstream os; ex.ice_print(os); test(endsWith(os.str(), "Test::G")); test(ex.data == "G"); } { H ex(__FILE__, __LINE__, "H"); ostringstream os; ex.ice_print(os); test(endsWith(os.str(), "Test::H data:'H'")); test(ex.data == "H"); } } cout << "ok" << endl; cout << "testing object adapter registration exceptions... " << flush; { Ice::ObjectAdapterPtr first; try { first = communicator->createObjectAdapter("TestAdapter0"); test(false); } catch(const Ice::InitializationException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected } string host = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.IPv6", 0) == 0 ? "127.0.0.1" : "\"0:0:0:0:0:0:0:1\""; communicator->getProperties()->setProperty("TestAdapter0.Endpoints", "default -h " + host); first = communicator->createObjectAdapter("TestAdapter0"); try { Ice::ObjectAdapterPtr second = communicator->createObjectAdapter("TestAdapter0"); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected } try { Ice::ObjectAdapterPtr second = communicator->createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } // Expected. } first->deactivate(); } cout << "ok" << endl; cout << "testing servant registration exceptions... " << flush; { string host = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.IPv6", 0) == 0 ? "127.0.0.1" : "\"0:0:0:0:0:0:0:1\""; communicator->getProperties()->setProperty("TestAdapter1.Endpoints", "default -h " + host); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter1"); Ice::ObjectPtr obj = new EmptyI; adapter->add(obj, communicator->stringToIdentity("x")); try { adapter->add(obj, communicator->stringToIdentity("x")); test(false); } catch(const Ice::AlreadyRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } try { adapter->add(obj, communicator->stringToIdentity("")); } catch(const Ice::IllegalIdentityException& ex) { test(ex.id.name == ""); if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } try { adapter->add(0, communicator->stringToIdentity("x")); } catch(const Ice::IllegalServantException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } adapter->remove(communicator->stringToIdentity("x")); try { adapter->remove(communicator->stringToIdentity("x")); test(false); } catch(const Ice::NotRegisteredException& ex) { if(printException) { Ice::Print printer(communicator->getLogger()); printer << ex; } } adapter->deactivate(); } cout << "ok" << endl; cout << "testing servant locator registrations exceptions... " << flush; { string host = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.IPv6", 0) == 0 ? "127.0.0.1" : "\"0:0:0:0:0:0:0:1\""; communicator->getProperties()->setProperty("TestAdapter2.Endpoints", "default -h " + host); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter2"); Ice::ServantLocatorPtr loc = new ServantLocatorI; adapter->addServantLocator(loc, "x"); try { adapter->addServantLocator(loc, "x"); test(false); } catch(const Ice::AlreadyRegisteredException&) { } adapter->deactivate(); } cout << "ok" << endl; cout << "testing object factory registration exception... " << flush; { Ice::ObjectFactoryPtr of = new ObjectFactoryI; communicator->addObjectFactory(of, "x"); try { communicator->addObjectFactory(of, "x"); test(false); } catch(const Ice::AlreadyRegisteredException&) { } } cout << "ok" << endl; cout << "testing stringToProxy... " << flush; string ref = "thrower:default -p 12010"; Ice::ObjectPrx base = communicator->stringToProxy(ref); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; ThrowerPrx thrower = ThrowerPrx::checkedCast(base); test(thrower); test(thrower == base); cout << "ok" << endl; cout << "catching exact types... " << flush; try { thrower->throwAasA(1); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::Exception& ex) { cout << ex << endl; test(false); } catch(...) { test(false); } try { thrower->throwAorDasAorD(1); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(...) { test(false); } try { thrower->throwAorDasAorD(-1); test(false); } catch(const D& ex) { test(ex.dMem == -1); } catch(...) { test(false); } try { thrower->throwBasB(1, 2); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwCasC(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } try { thrower->throwModA(1, 2); test(false); } catch(const Mod::A& ex) { test(ex.aMem == 1); test(ex.a2Mem == 2); } catch(const Ice::OperationNotExistException&) { // // This operation is not supported in Java. // } catch(...) { test(false); } cout << "ok" << endl; cout << "catching base types... " << flush; try { thrower->throwBasB(1, 2); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(...) { test(false); } try { thrower->throwCasC(1, 2, 3); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwModA(1, 2); test(false); } catch(const A& ex) { test(ex.aMem == 1); } catch(const Ice::OperationNotExistException&) { // // This operation is not supported in Java. // } catch(...) { test(false); } cout << "ok" << endl; cout << "catching derived types... " << flush; try { thrower->throwBasA(1, 2); test(false); } catch(const B& ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch(...) { test(false); } try { thrower->throwCasA(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } try { thrower->throwCasB(1, 2, 3); test(false); } catch(const C& ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch(...) { test(false); } cout << "ok" << endl; if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception... " << flush; try { thrower->throwUndeclaredA(1); test(false); } catch(const Ice::UnknownUserException&) { } catch(const Ice::Exception& ex) { cout << ex << endl; cout << ex.ice_stackTrace() << endl; test(false); } catch(...) { test(false); } try { thrower->throwUndeclaredB(1, 2); test(false); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } try { thrower->throwUndeclaredC(1, 2, 3); test(false); } catch(const Ice::UnknownUserException&) { } catch(...) { test(false); } cout << "ok" << endl; } if(thrower->ice_getConnection()) { cout << "testing memory limit marshal exception..." << flush; try { thrower->throwMemoryLimitException(Ice::ByteSeq()); test(false); } catch(const Ice::MemoryLimitException&) { } catch(...) { test(false); } try { thrower->throwMemoryLimitException(Ice::ByteSeq(20 * 1024)); // 20KB test(false); } catch(const Ice::ConnectionLostException&) { } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(communicator->stringToProxy("thrower:default -p 12011")); try { thrower2->throwMemoryLimitException(Ice::ByteSeq(2 * 1024 * 1024)); // 2MB (no limits) } catch(const Ice::MemoryLimitException&) { } ThrowerPrx thrower3 = ThrowerPrx::uncheckedCast(communicator->stringToProxy("thrower:default -p 12012")); try { thrower3->throwMemoryLimitException(Ice::ByteSeq(1024)); // 1KB limit test(false); } catch(const Ice::ConnectionLostException&) { } cout << "ok" << endl; } cout << "catching object not exist exception... " << flush; Ice::Identity id = communicator->stringToIdentity("does not exist"); try { ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower->ice_identity(id)); thrower2->throwAasA(1); // thrower2->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException& ex) { test(ex.id == id); } catch(...) { test(false); } cout << "ok" << endl; cout << "catching facet not exist exception... " << flush; try { ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower, "no such facet"); try { thrower2->ice_ping(); test(false); } catch(const Ice::FacetNotExistException& ex) { test(ex.facet == "no such facet"); } } catch(...) { test(false); } cout << "ok" << endl; cout << "catching operation not exist exception... " << flush; try { WrongOperationPrx thrower2 = WrongOperationPrx::uncheckedCast(thrower); thrower2->noSuchOperation(); test(false); } catch(const Ice::OperationNotExistException& ex) { test(ex.operation == "noSuchOperation"); } catch(...) { test(false); } cout << "ok" << endl; cout << "catching unknown local exception... " << flush; try { thrower->throwLocalException(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(...) { test(false); } try { thrower->throwLocalExceptionIdempotent(); test(false); } catch(const Ice::UnknownLocalException&) { } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "catching unknown non-Ice exception... " << flush; try { thrower->throwNonIceException(); test(false); } catch(const Ice::UnknownException&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "testing asynchronous exceptions... " << flush; try { thrower->throwAfterResponse(); } catch(...) { test(false); } try { thrower->throwAfterException(); } catch(const A&) { } catch(...) { test(false); } cout << "ok" << endl; cout << "catching exact types with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasA); thrower->begin_throwAasA(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwAorDasAorDPtr callback = newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); thrower->begin_throwAorDasAorD(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwAorDasAorDPtr callback = newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); thrower->begin_throwAorDasAorD(-1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwBasBPtr callback = newCallback_Thrower_throwBasB(cb, &Callback::response, &Callback::exception_BasB); thrower->begin_throwBasB(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasCPtr callback = newCallback_Thrower_throwCasC(cb, &Callback::response, &Callback::exception_CasC); thrower->begin_throwCasC(1, 2, 3, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwModAPtr callback = newCallback_Thrower_throwModA(cb, &Callback::response, &Callback::exception_ModA); thrower->begin_throwModA(1, 2, callback); cb->check(); } cout << "ok" << endl; cout << "catching derived types with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_Thrower_throwBasAPtr callback = newCallback_Thrower_throwBasA(cb, &Callback::response, &Callback::exception_BasA); thrower->begin_throwBasA(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasAPtr callback = newCallback_Thrower_throwCasA(cb, &Callback::response, &Callback::exception_CasA); thrower->begin_throwCasA(1, 2, 3, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwCasBPtr callback = newCallback_Thrower_throwCasB(cb, &Callback::response, &Callback::exception_CasB); thrower->begin_throwCasB(1, 2, 3, callback); cb->check(); } cout << "ok" << endl; if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredAPtr callback = newCallback_Thrower_throwUndeclaredA(cb, &Callback::response, &Callback::exception_UndeclaredA); thrower->begin_throwUndeclaredA(1, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredBPtr callback = newCallback_Thrower_throwUndeclaredB(cb, &Callback::response, &Callback::exception_UndeclaredB); thrower->begin_throwUndeclaredB(1, 2, callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwUndeclaredCPtr callback = newCallback_Thrower_throwUndeclaredC(cb, &Callback::response, &Callback::exception_UndeclaredC); thrower->begin_throwUndeclaredC(1, 2, 3, callback); cb->check(); } cout << "ok" << endl; } cout << "catching object not exist exception with new AMI mapping... " << flush; { id = communicator->stringToIdentity("does not exist"); ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower->ice_identity(id)); CallbackPtr cb = new Callback(communicator); Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAObjectNotExist); thrower2->begin_throwAasA(1, callback); cb->check(); } cout << "ok" << endl; cout << "catching facet not exist exception with new AMI mapping... " << flush; { ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower, "no such facet"); CallbackPtr cb = new Callback; Callback_Thrower_throwAasAPtr callback = newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAFacetNotExist); thrower2->begin_throwAasA(1, callback); cb->check(); } cout << "ok" << endl; cout << "catching operation not exist exception with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_WrongOperation_noSuchOperationPtr callback = newCallback_WrongOperation_noSuchOperation(cb, &Callback::response, &Callback::exception_noSuchOperation); WrongOperationPrx thrower4 = WrongOperationPrx::uncheckedCast(thrower); thrower4->begin_noSuchOperation(callback); cb->check(); } cout << "ok" << endl; cout << "catching unknown local exception with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_Thrower_throwLocalExceptionPtr callback = newCallback_Thrower_throwLocalException(cb, &Callback::response, &Callback::exception_LocalException); thrower->begin_throwLocalException(callback); cb->check(); } { CallbackPtr cb = new Callback; Callback_Thrower_throwLocalExceptionIdempotentPtr callback = newCallback_Thrower_throwLocalExceptionIdempotent(cb, &Callback::response, &Callback::exception_LocalException); thrower->begin_throwLocalExceptionIdempotent(callback); cb->check(); } cout << "ok" << endl; cout << "catching unknown non-Ice exception with new AMI mapping... " << flush; { CallbackPtr cb = new Callback; Callback_Thrower_throwNonIceExceptionPtr callback = newCallback_Thrower_throwNonIceException(cb, &Callback::response, &Callback::exception_NonIceException); thrower->begin_throwNonIceException(callback); cb->check(); } cout << "ok" << endl; return thrower; }
Test::MyClassPrx allTests(const Ice::CommunicatorPtr& communicator) { string ref = "test:default -p 12010"; Ice::ObjectPrx base = communicator->stringToProxy(ref); test(base); Test::MyClassPrx cl = Test::MyClassPrx::checkedCast(base); test(cl); Test::MyClassPrx oneway = cl->ice_oneway(); void (Callback::*nullEx)(const Ice::Exception&) = 0; void (Callback::*nullExWC)(const Ice::Exception&, const CookiePtr&) = 0; cout << "testing ice_invoke... " << flush; { Ice::ByteSeq inParams, outParams; if(!oneway->ice_invoke("opOneway", Ice::Normal, inParams, outParams)) { test(false); } Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); out->write(testString); out->finished(inParams); // ice_invoke if(cl->ice_invoke("opString", Ice::Normal, inParams, outParams)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); } // ice_invoke with array mapping pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size()); if(cl->ice_invoke("opString", Ice::Normal, inPair, outParams)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); } } { Ice::ByteSeq inParams, outParams; if(cl->ice_invoke("opException", Ice::Normal, inParams, outParams)) { test(false); } else { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); try { in->throwException(); } catch(const Test::MyException&) { } catch(...) { test(false); } } } cout << "ok" << endl; cout << "testing asynchronous ice_invoke... " << flush; { CookiePtr cookie = new Cookie(); Ice::ByteSeq inParams, outParams; Ice::AsyncResultPtr result = oneway->begin_ice_invoke("opOneway", Ice::Normal, inParams); if(!oneway->end_ice_invoke(outParams, result)) { test(false); } Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); out->write(testString); out->finished(inParams); // begin_ice_invoke with no callback result = cl->begin_ice_invoke("opString", Ice::Normal, inParams); if(cl->end_ice_invoke(outParams, result)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); }; // begin_ice_invoke with no callback and array mapping pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size()); result = cl->begin_ice_invoke("opString", Ice::Normal, inPair); if(cl->end_ice_invoke(outParams, result)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); }; // begin_ice_invoke with Callback CallbackPtr cb = new Callback(communicator, false); cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString)); cb->check(); // begin_ice_invoke with Callback and Cookie cb = new Callback(communicator, true); cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString), cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke cb = new Callback(communicator, false); Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx); cl->begin_ice_invoke("opString", Ice::Normal, inParams, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC); cl->begin_ice_invoke("opString", Ice::Normal, inParams, d, cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke and array mapping cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx); cl->begin_ice_invoke("opString", Ice::Normal, inPair, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke and array mapping with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC); cl->begin_ice_invoke("opString", Ice::Normal, inPair, d, cookie); cb->check(); } { CookiePtr cookie = new Cookie(); Ice::ByteSeq inParams, outParams; // begin_ice_invoke with no callback Ice::AsyncResultPtr result = cl->begin_ice_invoke("opException", Ice::Normal, inParams); if(cl->end_ice_invoke(outParams, result)) { test(false); } else { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); try { in->throwException(); } catch(const Test::MyException&) { } catch(...) { test(false); } } // begin_ice_invoke with Callback CallbackPtr cb = new Callback(communicator, false); cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException)); cb->check(); // begin_ice_invoke with Callback and Cookie cb = new Callback(communicator, true); cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException), cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke cb = new Callback(communicator, false); Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionNC, nullEx); cl->begin_ice_invoke("opException", Ice::Normal, inParams, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionWC, nullExWC); cl->begin_ice_invoke("opException", Ice::Normal, inParams, d, cookie); cb->check(); } cout << "ok" << endl; return cl; }