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

📄 client.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }        //    // Evict and verify values.    //    evictor->setSize(0);    evictor->setSize(size);    for(i = 0; i < size; i++)    {        test(servants[i]->getValue() == i + 100);        Test::FacetPrx facet1 = Test::FacetPrx::checkedCast(servants[i], "facet1");        test(facet1);        test(facet1->getValue() == 10 * i + 100);        Test::FacetPrx facet2 = Test::FacetPrx::checkedCast(facet1, "facet2");        test(facet2);        test(facet2->getValue() == 100 * i + 100);    }    //     // Test saving while busy    //    Test::AMI_Servant_setValueAsyncPtr setCB = new AMI_Servant_setValueAsyncI;    for(i = 0; i < size; i++)    {        //        // Start a mutating operation so that the object is not idle.        //        servants[i]->setValueAsync_async(setCB, i + 300);                test(servants[i]->getValue() == i + 100);        //        // This operation modifies the object state but is not saved        // because the setValueAsync operation is still pending.        //        servants[i]->setValue(i + 200);        test(servants[i]->getValue() == i + 200);        //        // Force the response to setValueAsync        //        servants[i]->releaseAsync();        test(servants[i]->getValue() == i + 300);    }    //    // Add duplicate facet and catch corresponding exception    //     for(i = 0; i < size; i++)    {        try        {            servants[i]->addFacet("facet1", "foobar");            test(false);        }        catch(const Test::AlreadyRegisteredException&)        {        }    }        //    // Remove a facet that does not exist    //     try    {        servants[0]->removeFacet("facet3");        test(false);    }    catch(const Test::NotRegisteredException&)    {    }       //    // Remove all facets    //    for(i = 0; i < size; i++)    {        servants[i]->removeFacet("facet1");        servants[i]->removeFacet("facet2");    }    //    // Check they are all gone    //    for(i = 0; i < size; i++)    {        Test::FacetPrx facet1 = Test::FacetPrx::checkedCast(servants[i], "facet1");        test(facet1 == 0);        Test::FacetPrx facet2 = Test::FacetPrx::checkedCast(servants[i], "facet2");        test(facet2 == 0);    }    evictor->setSize(0);    evictor->setSize(size);    for(i = 0; i < size; i++)    {        test(servants[i]->getValue() == i + 300);        Test::FacetPrx facet1 = Test::FacetPrx::checkedCast(servants[i], "facet1");        test(facet1 == 0);    }    //    // Destroy servants and verify ObjectNotExistException.    //    for(i = 0; i < size; i++)    {        servants[i]->destroy();        try        {            servants[i]->getValue();            test(false);        }        catch(const Ice::ObjectNotExistException&)        {            // Expected        }        try        {            servants[i]->ice_ping();            test(false);        }        catch(const Ice::ObjectNotExistException&)        {            // Expected        }    }              //    // Recreate servants, set transient value    //      servants.clear();    for(i = 0; i < size; i++)    {        ostringstream ostr;        ostr << i;        string id = ostr.str();        servants.push_back(evictor->createServant(id, i));        servants[i]->setTransientValue(i);    }        //    // Evict all    //    evictor->saveNow();    evictor->setSize(0);    evictor->setSize(size);        //    // Check the transient value    //    for(i = 0; i < size; i++)    {        test(servants[i]->getTransientValue() == -1);    }        //    // Now with keep    //    for(i = 0; i < size; i++)    {        servants[i]->keepInCache();        servants[i]->keepInCache();        servants[i]->setTransientValue(i);    }    evictor->saveNow();    evictor->setSize(0);    evictor->setSize(size);           //    // Check the transient value    //    for(i = 0; i < size; i++)    {        test(servants[i]->getTransientValue() == i);    }    //    // Again, after one release    //    for(i = 0; i < size; i++)    {        servants[i]->release();    }    evictor->saveNow();    evictor->setSize(0);    evictor->setSize(size);    for(i = 0; i < size; i++)    {        test(servants[i]->getTransientValue() == i);    }    //    // Again, after a second release    //    for(i = 0; i < size; i++)    {        servants[i]->release();    }    evictor->saveNow();    evictor->setSize(0);    evictor->setSize(size);    for(i = 0; i < size; i++)    {        test(servants[i]->getTransientValue() == -1);    }    //    // Release one more time    //    for(i = 0; i < size; i++)    {        try        {            servants[i]->release();            test(false);        }        catch(const Test::NotRegisteredException&)        {            // Expected        }    }    // Deactivate and recreate evictor, to ensure that servants    // are restored properly after database close and reopen.    //    evictor->deactivate();        evictor = factory->createEvictor("Test");    evictor->setSize(size);    for(i = 0; i < size; i++)    {
        ostringstream ostr;
        ostr << i;
        string id = ostr.str();
        servants[i] = evictor->getServant(id);        test(servants[i]->getValue() == i);    }    //    // Test concurrent lookups with a smaller evictor    // size and one missing servant    //    evictor->setSize(size / 2);    servants[0]->destroy();    {        const int threadCount = size * 2;                ThreadPtr threads[threadCount];        for(i = 0; i < threadCount; i++)        {            threads[i] = new ReadThread(servants);            threads[i]->start();        }                for(i = 0; i < threadCount; i++)        {            threads[i]->getThreadControl().join();        }    }        //    // Clean up.    //    evictor->destroyAllServants("");    evictor->destroyAllServants("facet1");    evictor->destroyAllServants("facet2");    //    // CreateDestroy threads    //    {        const int threadCount = size;;                ThreadPtr threads[threadCount];        for(i = 0; i < threadCount; i++)        {            threads[i] = new CreateDestroyThread(evictor, i, size);            threads[i]->start();        }                for(i = 0; i < threadCount; i++)        {            threads[i]->getThreadControl().join();        }        //        // Verify all destroyed        //         for(i = 0; i < size; i++)           {            try            {                servants[i]->getValue();                test(false);            }            catch(const Ice::ObjectNotExistException&)            {                // Expected            }        }    }    //    // Recreate servants.    //      servants.clear();    for(i = 0; i < size; i++)    {        ostringstream ostr;        ostr << i;        string id = ostr.str();        servants.push_back(evictor->createServant(id, i));    }    //    // Deactivate in the middle of remote AMD operations    // (really testing Ice here)    //    {        const int threadCount = size;                ReadForeverThreadPtr threads[threadCount];        for(i = 0; i < threadCount; i++)        {            threads[i] = new ReadForeverThread(servants);            threads[i]->start();        }        ThreadControl::sleep(Time::milliSeconds(500));        for(i = 0; i < threadCount; i++)        {            threads[i]->setState(ReadForeverThread::StateDeactivating);        }        evictor->deactivate();        for(i = 0; i < threadCount; i++)        {            threads[i]->setState(ReadForeverThread::StateDeactivated);        }        for(i = 0; i < threadCount; i++)        {            threads[i]->getThreadControl().join();        }    }    //    // Resurrect    //    evictor = factory->createEvictor("Test");    evictor->destroyAllServants("");    //    // Deactivate in the middle of adds    //    {        const int threadCount = size;                AddForeverThreadPtr threads[threadCount];        for(i = 0; i < threadCount; i++)        {            threads[i] = new AddForeverThread(evictor, i);            threads[i]->start();        }        ThreadControl::sleep(Time::milliSeconds(500));        for(i = 0; i < threadCount; i++)        {            threads[i]->setState(AddForeverThread::StateDeactivating);        }        evictor->deactivate();        for(i = 0; i < threadCount; i++)        {            threads[i]->setState(AddForeverThread::StateDeactivated);        }                for(i = 0; i < threadCount; i++)        {            threads[i]->getThreadControl().join();        }    }            //    // Clean up.    //    evictor = factory->createEvictor("Test");    evictor->destroyAllServants("");    evictor->deactivate();    cout << "ok" << endl;    factory->shutdown();        return EXIT_SUCCESS;}intmain(int argc, char* argv[]){    int status;    Ice::CommunicatorPtr communicator;    try    {        communicator = Ice::initialize(argc, argv);        status = run(argc, argv, communicator);    }    catch(const Ice::Exception& ex)    {        cerr << ex << endl;        status = EXIT_FAILURE;    }    if(communicator)    {        try        {            communicator->destroy();        }        catch(const Ice::Exception& ex)        {            cerr << ex << endl;            status = EXIT_FAILURE;        }    }    return status;}

⌨️ 快捷键说明

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