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

📄 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 <IceUtil/Thread.h>#include <Ice/Ice.h>#include <IceGrid/Observer.h>#include <IceGrid/Admin.h>#include <IceGrid/Registry.h>#include <TestCommon.h>#include <Test.h>using namespace std;using namespace Test;using namespace IceGrid;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;void addProperty(const CommunicatorDescriptorPtr& communicator, const string& name, const string& value){    PropertyDescriptor prop;    prop.name = name;    prop.value = value;    communicator->propertySet.properties.push_back(prop);}stringgetProperty(const PropertyDescriptorSeq& properties, const string& name){    for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q)    {        if(q->name == name)        {            return q->value;        }    }    return "";}PropertyDescriptorcreateProperty(const string& name, const string& value){    PropertyDescriptor prop;    prop.name = name;    prop.value = value;    return prop;}boolhasProperty(const CommunicatorDescriptorPtr& desc, const string& name, const string& value){    for(PropertyDescriptorSeq::const_iterator p = desc->propertySet.properties.begin();         p != desc->propertySet.properties.end(); ++p)    {        if(p->name == name)        {            return p->value == value;        }    }    return false;}void allTests(const Ice::CommunicatorPtr& communicator){    RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(        communicator->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);    Ice::PropertiesPtr properties = communicator->getProperties();    {        ApplicationDescriptor testApp;        testApp.name = "TestApp";        admin->addApplication(testApp);        ApplicationUpdateDescriptor empty;        empty.name = "TestApp";        NodeUpdateDescriptor node;        node.name = "localnode";        empty.nodes.push_back(node);        ApplicationUpdateDescriptor update = empty;        cout << "testing server add... " << flush;        ServerDescriptorPtr server = new ServerDescriptor();        server->id = "Server";        server->exe = properties->getProperty("TestDir") + "/server";        server->pwd = ".";        AdapterDescriptor adapter;        adapter.name = "Server";        adapter.id = "ServerAdapter";        adapter.registerProcess = true;        addProperty(server, "Server.Endpoints", "default");        ObjectDescriptor object;        object.id = communicator->stringToIdentity("test");        object.type = "::Test::TestIntf";        adapter.objects.push_back(object);        server->adapters.push_back(adapter);        update.nodes[0].servers.push_back(server);        admin->updateApplication(update);        update.nodes[0].servers[0]->id = "Server2";        try        {            admin->updateApplication(update);            test(false);        }        catch(const DeploymentException&)        {            // Adapter already exists        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }                update.nodes[0].servers[0]->adapters[0].id = "ServerAdapter2";        try        {            admin->updateApplication(update);            test(false);        }        catch(const DeploymentException&)        {            // Object already exists        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update.nodes[0].servers[0]->adapters[0].objects[0].id = communicator->stringToIdentity("test2");        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        TemplateDescriptor templ;        templ.parameters.push_back("name");        templ.descriptor = new ServerDescriptor();        server = ServerDescriptorPtr::dynamicCast(templ.descriptor);        server->id = "${name}";        server->exe = "${test.dir}/server";        server->pwd = ".";        adapter = AdapterDescriptor();        adapter.name = "Server";        adapter.id = "${server}";        adapter.registerProcess = true;        addProperty(server, "Server.Endpoints", "default");        object = ObjectDescriptor();        object.id = communicator->stringToIdentity("${server}");        object.type = "::Test::TestIntf";        adapter.objects.push_back(object);        server->adapters.push_back(adapter);        update = empty;        update.serverTemplates["ServerTemplate"] = templ;        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update = empty;        ServerInstanceDescriptor instance;        instance._cpp_template = "ServerTemplate";        update.nodes[0].serverInstances.push_back(instance);        try        {            admin->updateApplication(update);            test(false);        }        catch(const DeploymentException&)        {            // Missing parameter        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update = empty;         update.variables["test.dir"] = properties->getProperty("TestDir");        update.variables["variable"] = "";        instance = ServerInstanceDescriptor();        instance._cpp_template = "ServerTemplate";        instance.parameterValues["name"] = "Server1";        update.nodes[0].serverInstances.push_back(instance);        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }                cout << "ok" << endl;        cout << "testing server remove... " << flush;        update = empty;        update.nodes[0].removeServers.push_back("Server2");        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        try        {            admin->getServerInfo("Server2");            test(false);        }        catch(const ServerNotExistException&)        {        }        try        {            admin->updateApplication(update);        }        catch(const DeploymentException& ex)        {            cerr << ex.reason << endl;            test(false);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update = empty;        update.removeServerTemplates.push_back("ServerTemplate");        try        {            admin->updateApplication(update);            test(false);        }        catch(const DeploymentException&)        {            // Server without template!        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update = empty;        update.nodes[0].removeServers.push_back("Server1");        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        try        {            admin->getServerInfo("Server1");            test(false);        }        catch(const ServerNotExistException&)        {        }                update = empty;        update.removeServerTemplates.push_back("ServerTemplate");        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        cout << "ok" << endl;        cout << "testing server update... " << flush;        ServerInfo info = admin->getServerInfo("Server");        test(info.descriptor);        addProperty(info.descriptor, "test", "test");        update = empty;        update.nodes[0].servers.push_back(info.descriptor);        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        info = admin->getServerInfo("Server");        test(info.descriptor);        test(getProperty(info.descriptor->propertySet.properties, "test") == "test");        update = empty;        update.serverTemplates["ServerTemplate"] = templ;        instance = ServerInstanceDescriptor();        instance._cpp_template = "ServerTemplate";        instance.parameterValues["name"] = "Server1";        update.nodes[0].serverInstances.push_back(instance);        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            test(false);        }        update = empty;        addProperty(server, "test", "test");        assert(templ.descriptor == server);        update.serverTemplates["ServerTemplate"] = templ;        try        {            admin->updateApplication(update);        }        catch(const Ice::Exception& ex)        {

⌨️ 快捷键说明

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