⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alltests.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************//// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.//// This copy of Ice is licensed to you under the terms described in the// ICE_LICENSE file included in this distribution.//// **********************************************************************#include <Ice/Ice.h>#include <Ice/BuiltinSequences.h>#include <IceGrid/Query.h>#include <IceGrid/Admin.h>#include <IceGrid/Registry.h>#include <IceUtil/Thread.h>#include <TestCommon.h>#include <Test.h>#include <fstream>using namespace std;using namespace Test;using namespace IceGrid;namespace {voidwriteLongLine(ostream& os){    os << 'a';    for(int i = 0; i < 2400; i++)    {        os << 'b';    }    os << 'c';}boolisLongLineStart(const string& line){    test(line.size() < 1024);    return line.size() > 1 && line[0] == 'a' && line[1] == 'b';}boolisLongLineContent(const string& line){    test(line.size() < 1024);    return line.size() > 1 && line[0] == 'b' && line[line.size() - 1] == 'b';}bool isLongLineEnd(const string& line){    test(line.size() < 1024);    return line.size() > 1 && line[line.size() - 2] == 'b' && line[line.size() - 1] == 'c';}}struct ProxyIdentityEqual : public std::binary_function<Ice::ObjectPrx,string,bool>{public:    ProxyIdentityEqual(const Ice::CommunicatorPtr& communicator) :        _communicator(communicator)    {    }    bool     operator()(const Ice::ObjectPrx& p1, const string& id) const    {        return p1->ice_getIdentity() == _communicator->stringToIdentity(id);    }private:    Ice::CommunicatorPtr _communicator;};class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>{public:    SessionKeepAliveThread(const IceGrid::AdminSessionPrx& session, long timeout) :        _session(session),        _timeout(IceUtil::Time::seconds(timeout)),        _destroy(false)    {    }    virtual void    run()    {        Lock sync(*this);        while(!_destroy)        {            timedWait(_timeout);            if(_destroy)            {                break;            }            try            {                _session->keepAlive();            }            catch(const Ice::Exception&)            {                break;            }        }    }    void    destroy()    {        Lock sync(*this);        _destroy = true;        notify();    }private:    IceGrid::AdminSessionPrx _session;    const IceUtil::Time _timeout;    bool _destroy;};typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr;voidallTests(const Ice::CommunicatorPtr& comm){    RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(comm->stringToProxy("IceGrid/Registry"));    test(registry);    AdminSessionPrx session = registry->createAdminSession("foo", "bar");    SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout()/2);    keepAlive->start();    AdminPrx admin = session->getAdmin();    test(admin);    cout << "testing server registration... "  << flush;    Ice::StringSeq serverIds = admin->getAllServerIds();    test(find(serverIds.begin(), serverIds.end(), "Server1") != serverIds.end());    test(find(serverIds.begin(), serverIds.end(), "Server2") != serverIds.end());    test(find(serverIds.begin(), serverIds.end(), "IceBox1") != serverIds.end());    test(find(serverIds.begin(), serverIds.end(), "IceBox2") != serverIds.end());    test(find(serverIds.begin(), serverIds.end(), "SimpleServer") != serverIds.end());    test(find(serverIds.begin(), serverIds.end(), "SimpleIceBox") != serverIds.end());    cout << "ok" << endl;    cout << "testing adapter registration... " << flush;    Ice::StringSeq adapterIds = admin->getAllAdapterIds();    test(find(adapterIds.begin(), adapterIds.end(), "Server1.Server") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "Server2.Server") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "SimpleServer.Server") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "IceBox1.Service1.Service1") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "IceBox1Service2Adapter") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "IceBox2.Service1.Service1") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "IceBox2Service2Adapter") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "SimpleIceBox.SimpleService.SimpleService") != adapterIds.end());    test(find(adapterIds.begin(), adapterIds.end(), "ReplicatedAdapter") != adapterIds.end());    cout << "ok" << endl;    QueryPrx query = QueryPrx::checkedCast(comm->stringToProxy("IceGrid/Query"));    test(query);    cout << "testing object registration... " << flush;    Ice::ObjectProxySeq objs = query->findAllObjectsByType("::Test");    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"Server1")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"Server2")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"SimpleServer")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox1-Service1")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox1-Service2")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox2-Service1")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"IceBox2-Service2")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"SimpleIceBox-SimpleService")) != objs.end());    test(find_if(objs.begin(), objs.end(), bind2nd(ProxyIdentityEqual(comm),"ReplicatedObject")) != objs.end());    {        test(comm->identityToString(query->findObjectByType("::TestId1")->ice_getIdentity()) == "cat/name1");        test(comm->identityToString(query->findObjectByType("::TestId2")->ice_getIdentity()) == "cat1/name1");        test(comm->identityToString(query->findObjectByType("::TestId3")->ice_getIdentity()) == "cat1/name1-bis");        test(comm->identityToString(query->findObjectByType("::TestId4")->ice_getIdentity()) == "c2\\/c2/n2\\/n2");        test(comm->identityToString(query->findObjectByType("::TestId5")->ice_getIdentity()) == "n2\\/n2");    }    {        Ice::ObjectPrx obj = query->findObjectByType("::Test");        string id = comm->identityToString(obj->ice_getIdentity());        test(id == "Server1" || id == "Server2" || id == "SimpleServer" ||             id == "IceBox1-Service1" || id == "IceBox1-Service2" ||             id == "IceBox2-Service1" || id == "IceBox2-Service2" ||             id == "SimpleIceBox-SimpleService" || "ReplicatedObject");    }    {        Ice::ObjectPrx obj = query->findObjectByTypeOnLeastLoadedNode("::Test", LoadSample5);        string id = comm->identityToString(obj->ice_getIdentity());        test(id == "Server1" || id == "Server2" || id == "SimpleServer" ||             id == "IceBox1-Service1" || id == "IceBox1-Service2" ||             id == "IceBox2-Service1" || id == "IceBox2-Service2" ||             id == "SimpleIceBox-SimpleService" || "ReplicatedObject");    }    {        Ice::ObjectPrx obj = query->findObjectByType("::Foo");        test(!obj);        obj = query->findObjectByTypeOnLeastLoadedNode("::Foo", LoadSample15);        test(!obj);    }    cout << "ok" << endl;    //    // Ensure that all server and service objects are reachable.    //    // The identity for the test object in deployed server or services    // is the name of the service or server. The object adapter name    // is Adapter prefixed with the name of the service or    // server. Ensure we can reach each object.    //    cout << "pinging server objects... " << flush;    TestIntfPrx obj;    obj = TestIntfPrx::checkedCast(comm->stringToProxy("Server1@Server1.Server"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("Server2@Server2.Server"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("SimpleServer@SimpleServer.Server"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox1-Service1@IceBox1.Service1.Service1"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service1@IceBox2.Service1.Service1"));    obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter"));    obj = TestIntfPrx::checkedCast(        comm->stringToProxy("SimpleIceBox-SimpleService@SimpleIceBox.SimpleService.SimpleService"));    cout << "ok" << endl;    cout << "testing server configuration... " << flush;    obj = TestIntfPrx::checkedCast(comm->stringToProxy("Server1@Server1.Server"));    test(obj->getProperty("Type") == "Server");    test(obj->getProperty("Name") == "Server1");    test(obj->getProperty("NameName") == "Server1Server1");    test(obj->getProperty("NameEscaped") == "${name}");    test(obj->getProperty("NameEscapeEscaped") == "$Server1");    test(obj->getProperty("NameEscapedEscapeEscaped") == "$${name}");    test(obj->getProperty("ManyEscape") == "$$$${name}");        test(obj->getProperty("TestServer1Identity") == "Server1");    test(obj->getProperty("LogFilePath") == "test-Server1.log");    test(obj->getProperty("LogFilePath-Server1") == "test.log");    cout << "ok" << endl;    cout << "testing service configuration... " << flush;    obj = TestIntfPrx::checkedCast(comm->stringToProxy("IceBox1-Service1@IceBox1.Service1.Service1"));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -