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

📄 alltests.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    //    // Test node session establishment.    //    // - start master, start slave1, start node, start slave2    // - shutdown slave1, start slave1 -> node should re-connect    // - shutdown master    // - shutdown slave2, start slave2 -> node should re-connect    // - shutdown slave1    // - start master -> node connects to master    // - start slave1 -> node connects to slave1    //    cout << "testing node session establishment... " << flush;    {        admin->startServer("Node1");                waitForNodeState(masterAdmin, "Node1", true);        waitForNodeState(slave1Admin, "Node1", true);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        waitForNodeState(slave2Admin, "Node1", true); // Node should connect.        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);        admin->startServer("Slave1");        slave1Admin = createAdminSession(slave1Locator, "Slave1");        try        {            test(slave1Admin->pingNode("Node1")); // Node should be re-connected.        }        catch(const NodeNotExistException&)        {            test(false);        }        masterAdmin->shutdown();        waitForServerState(admin, "Master", false);        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        try        {            test(slave2Admin->pingNode("Node1")); // Node should be re-connected even if the master is down.        }        catch(const NodeNotExistException&)        {            test(false);        }        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);        admin->startServer("Master");        masterAdmin = createAdminSession(masterLocator, "");        try        {            test(masterAdmin->pingNode("Node1")); // Node should be re-connected.        }        catch(const NodeNotExistException&)        {            test(false);        }        admin->startServer("Slave1");        slave1Admin = createAdminSession(slave1Locator, "Slave1");        try        {            test(slave1Admin->pingNode("Node1")); // Node should be re-connected.        }        catch(const NodeNotExistException&)        {            test(false);        }        try        {            test(masterAdmin->pingNode("Node1"));        }        catch(const NodeNotExistException&)        {            test(false);        }        try        {            test(slave2Admin->pingNode("Node1"));        }        catch(const NodeNotExistException&)        {            test(false);        }        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        try        {            test(slave2Admin->pingNode("Node1"));        }        catch(const NodeNotExistException&)        {            test(false);        }    }    cout << "ok" << endl;    //    // Testing updates with out-of-date replicas.    //    cout << "testing out-of-date replicas... " << flush;    {        ApplicationDescriptor app;        app.name = "TestApp";        app.description = "added application";        ServerDescriptorPtr server = new ServerDescriptor();        server->id = "Server";        server->exe = comm->getProperties()->getProperty("TestDir") + "/server";        server->pwd = ".";        server->activation = "on-demand";        AdapterDescriptor adapter;        adapter.name = "TestAdapter";        adapter.id = "TestAdapter.Server";        adapter.registerProcess = true;        PropertyDescriptor property;        property.name = "TestAdapter.Endpoints";        property.value = "default";        server->propertySet.properties.push_back(property);        property.name = "Identity";        property.value = "test";        server->propertySet.properties.push_back(property);        ObjectDescriptor object;        object.id = comm->stringToIdentity("test");        object.type = "::Test::TestIntf";        adapter.objects.push_back(object);        server->adapters.push_back(adapter);        app.nodes["Node1"].servers.push_back(server);        masterAdmin->addApplication(app);        comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        masterAdmin->stopServer("Server");        //        // Shutdown Slave2 and update application.        //        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        ApplicationUpdateDescriptor update;        update.name = "TestApp";        NodeUpdateDescriptor node;        node.name = "Node1";        node.servers.push_back(server);        update.nodes.push_back(node);        property.name = "Dummy";        property.value = "val";        server->propertySet.properties.push_back(property);        masterAdmin->updateApplication(update);        comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        masterAdmin->shutdown();        waitForServerState(admin, "Master", false);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        try        {            slave2Admin->startServer("Server");            test(false);        }        catch(const DeploymentException&)        {        }        try        {            comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();            test(false);        }        catch(const Ice::NoEndpointException&)        {        }        admin->startServer("Master");        masterAdmin = createAdminSession(masterLocator, "");        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        //        // Shutdown Node1 and update the application, then, shutdown        // the master.        //        slave1Admin->shutdownNode("Node1");        waitForServerState(admin, "Node1", false);        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        property.name = "Dummy2";        property.value = "val";        server->propertySet.properties.push_back(property);        masterAdmin->updateApplication(update);        masterAdmin->shutdown();        waitForServerState(admin, "Master", false);        //        // Restart Node1 and Slave2, Slave2 still has the old version        // of the server so it should be able to load it. Slave1 has         // a more recent version, so it can't load it.        //        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        admin->startServer("Node1");                waitForNodeState(slave2Admin, "Node1", true);        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        admin->startServer("Slave1");        slave1Admin = createAdminSession(slave1Locator, "Slave1");        try        {            comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();            }        catch(const Ice::NoEndpointException&)        {        }        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        slave2Admin->stopServer("Server");        //        // Start the master. This will re-load the server on the node        // and update the out-of-date replicas.        //        admin->startServer("Master");        masterAdmin = createAdminSession(masterLocator, "");        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);        admin->startServer("Slave1");        slave1Admin = createAdminSession(slave1Locator, "Slave1");        slave2Admin->shutdownNode("Node1");        waitForServerState(admin, "Node1", false);        admin->startServer("Node1");        slave2Admin->shutdown();        waitForServerState(admin, "Slave2", false);        admin->startServer("Slave2");        slave2Admin = createAdminSession(slave2Locator, "Slave2");        waitForNodeState(masterAdmin, "Node1", true);        waitForNodeState(slave1Admin, "Node1", true);        waitForNodeState(slave2Admin, "Node1", true);        comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        slave2Admin->stopServer("Server");        masterAdmin->removeApplication("TestApp");    }        cout << "ok" << endl;    cout << "testing master upgrade... " << flush;    {        ApplicationDescriptor app;        app.name = "TestApp";        app.description = "added application";        ServerDescriptorPtr server = new ServerDescriptor();        server->id = "Server";        server->exe = comm->getProperties()->getProperty("TestDir") + "/server";        server->pwd = ".";        server->activation = "on-demand";        AdapterDescriptor adapter;        adapter.name = "TestAdapter";        adapter.id = "TestAdapter.Server";        adapter.registerProcess = true;        PropertyDescriptor property;        property.name = "TestAdapter.Endpoints";        property.value = "default";        server->propertySet.properties.push_back(property);        property.name = "Identity";        property.value = "test";        server->propertySet.properties.push_back(property);        ObjectDescriptor object;        object.id = comm->stringToIdentity("test");        object.type = "::Test::TestIntf";        adapter.objects.push_back(object);        server->adapters.push_back(adapter);        app.nodes["Node1"].servers.push_back(server);        masterAdmin->addApplication(app);        comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        masterAdmin->stopServer("Server");        //        // Shutdown the Master, update Slave1 to be the Master.        //        masterAdmin->shutdown();        waitForServerState(admin, "Master", false);        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);                params["id"] = "Slave1";        params["port"] = "12051";        params["replicaName"] = "Master";        instantiateServer(admin, "IceGridRegistry", params);        admin->startServer("Slave1");        slave1Locator =             Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("TestIceGrid/Locator-Master:default -p 12051"));        slave1Admin = createAdminSession(slave1Locator, "");        ApplicationUpdateDescriptor update;        update.name = "TestApp";        NodeUpdateDescriptor node;        node.name = "Node1";        node.servers.push_back(server);        update.nodes.push_back(node);        property.name = "Dummy";        property.value = "val";        server->propertySet.properties.push_back(property);        slave1Admin->updateApplication(update);        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        slave1Admin->shutdown();        waitForServerState(admin, "Slave1", false);        params["id"] = "Slave1";        params["replicaName"] = "Slave1";        params["port"] = "12051";        instantiateServer(admin, "IceGridRegistry", params);        admin->startServer("Master");        masterAdmin = createAdminSession(masterLocator, "");        admin->startServer("Slave1");        slave1Locator =             Ice::LocatorPrx::uncheckedCast(comm->stringToProxy("TestIceGrid/Locator-Slave1:default -p 12051"));        slave1Admin = createAdminSession(slave1Locator, "Slave1");        comm->stringToProxy("test")->ice_locator(masterLocator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave1Locator)->ice_locatorCacheTimeout(0)->ice_ping();        comm->stringToProxy("test")->ice_locator(slave2Locator)->ice_locatorCacheTimeout(0)->ice_ping();        masterAdmin->stopServer("Server");                masterAdmin->removeApplication("TestApp");    }    cout << "ok" << endl;        slave1Admin->shutdownNode("Node1");    removeServer(admin, "Node1");    removeServer(admin, "Slave2");    slave1Admin->shutdown();    removeServer(admin, "Slave1");    masterAdmin->shutdown();    removeServer(admin, "Master");}

⌨️ 快捷键说明

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