Esempio n. 1
0
File: AdminI.cpp Progetto: zmyer/ice
StringSeq
AdminI::getAllRegistryNames(const Current&) const
{
    Ice::StringSeq replicas = _database->getReplicaCache().getAll("");
    replicas.push_back(_registry->getName());
    return replicas;
}
Esempio n. 2
0
Ice::StringSeq
ReplicaGroupFilterI::filter(const string& /* replicaGroupId */, 
                            const Ice::StringSeq& adapters, 
                            const Ice::ConnectionPtr&, 
                            const Ice::Context& ctx)
{
    Ice::Context::const_iterator p = ctx.find("currency");
    if(p == ctx.end())
    {
        return adapters;
    }

    string currency = p->second;

    //
    // Get the Currencies property value from the server descriptor
    // that owns the adapter and only keep adapters for servers that
    // are configured with the currency specified in the client
    // context.
    //
    Ice::StringSeq filteredAdapters;
    for(Ice::StringSeq::const_iterator p = adapters.begin(); p != adapters.end(); ++p)
    {
        if(_facade->getPropertyForAdapter(*p, "Currencies").find(currency) != string::npos)
        {
            filteredAdapters.push_back(*p);
        }
    }
    return filteredAdapters;
}
Esempio n. 3
0
bool AgentAdapter::init(const ::Ice::StringSeq& defaultAgents,const bool is_udp_protocol, const bool is_compress)
{  
    if (defaultAgents.empty())
    {
        XLOG_ERROR("AgentAdapter::init defaultAgent is empty!");
        return false;
    }

    srand(unsigned(time(NULL)));
    Ice::PropertiesPtr props=Ice::createProperties();
    props->setProperty("Ice.MessageSizeMax", ICE_MESSAGE_SIZE_MAX);
    props->setProperty("Ice.Override.Timeout", ICE_TIMEOUT_MILLISECONDS);
	Ice::InitializationData id;
    id.properties=props;
    _ic = ::Ice::initialize(id);

    srand((unsigned) time(NULL));
    current_agent_prx_number=0;

    std::vector<slice::AgentPrx> _prxs;
    for (::Ice::StringSeq::const_iterator it = defaultAgents.begin(); it != defaultAgents.end();
            ++it)
    {
        slice::AgentPrx prx = Util::getPrx<slice::AgentPrx>(_ic, *it, is_udp_protocol, 1000, is_compress);
	_prxs.push_back(prx);
    }
    agent_prxs.swap(_prxs);

    return true;
}
Esempio n. 4
0
int
main(int argc, char* argv[])
{
    ifstream in("./config/configPath");
    if(!in)
    {
        test(false);
    }
    
    if(!getline(in, configPath))
    {
        test(false);
    }
    try
    {
        cout << "testing load properties from UTF-8 path... " << flush;
        Ice::PropertiesPtr properties = Ice::createProperties();
        properties->load(configPath);
        test(properties->getProperty("Ice.Trace.Network") == "1");
        test(properties->getProperty("Ice.Trace.Protocol") == "1");       
        test(properties->getProperty("Config.Path") == configPath);
        test(properties->getProperty("Ice.ProgramName") == "PropertiesClient");
        cout << "ok" << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
        return EXIT_FAILURE;
    }
    
    cout << "testing load properties from UTF-8 path using Ice::Application... " << flush;
    Client c;
    c.main(argc, argv, configPath.c_str());
    cout << "ok" << endl;
    
    try
    {
        //
        // Try to load multiple config files.
        //
        cout << "testing using Ice.Config with multiple config files... " << flush;
        Ice::PropertiesPtr properties;
        Ice::StringSeq args;
        args.push_back("--Ice.Config=config/config.1, config/config.2, config/config.3");
        IceUtilInternal::ArgVector a(args);
        properties = Ice::createProperties(a.argc, a.argv);
        test(properties->getProperty("Config1") == "Config1");
        test(properties->getProperty("Config2") == "Config2");
        test(properties->getProperty("Config3") == "Config3");
        cout << "ok" << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
Esempio n. 5
0
bool PSIDynamicICESender::Connect()
{
	try
	{
		if(!FCommunicatorPtr)
		{
			Ice::StringSeq args;
			string Tmp=GetICECommunicatorConfig(FHostIP,FHostPort);
			args.push_back(Tmp);
			args.push_back("Ice.ACM.Client=0");
			args.push_back("Ice.MessageSizeMax=30000");
			//		FCommunicator = Ice::initialize(args);
			FCommunicatorPtr = Ice::initialize();
			cout<<FServiceName+":通讯器成功初始化!" <<std::endl;
		}
		Ice::ObjectPrx base=FCommunicatorPtr->stringToProxy(GetICEObjectConfig(FHostIP,FHostPort));
		FSendBufferPrx=InfoDTV::Multiplexer::Dynamic::Provider::DynamicBufferTransferPrx::checkedCast(base);
		if(!FSendBufferPrx)
		{
			if(FCommunicatorPtr)
			{
				FCommunicatorPtr->destroy();
				FCommunicatorPtr=NULL;
			}
			return false;
		}
	}
	catch (const Ice::Exception & e)
	{
		cout<<string(e.what())<<"dddd"<<std::endl;
		if(FCommunicatorPtr)
		{
			FCommunicatorPtr->destroy();
			FCommunicatorPtr=NULL;
		}
		return false;
	}
	catch (...)
	{

		cout<<FServiceName+":Connect:通讯器初始化失败!"<<std::endl;
		// Console.Error.WriteLine(ex);
		if(FCommunicatorPtr)
		{
			FCommunicatorPtr->destroy();
			FCommunicatorPtr=NULL;
		}
		return false;
	}


	return true;

}
Esempio n. 6
0
Ice::StringSeq
NodeSessionI::getServers(const Ice::Current&) const
{
    ServerEntrySeq servers =  _database->getNode(_info->name)->getServers();
    Ice::StringSeq names;
    for(ServerEntrySeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
    {
        names.push_back((*p)->getId());
    }
    return names;
}
Esempio n. 7
0
void
NodeI::checkConsistency(const NodeSessionPrx& session)
{
    //
    // Only do the consistency check on the startup. This ensures that servers can't
    // be removed by a bogus master when the master session is re-established.
    //
    if(_consistencyCheckDone)
    {
        return;
    }
    _consistencyCheckDone = true;

    //
    // We use a serial number to keep track of the concurrent changes
    // on the node. When a server is loaded/destroyed the serial is
    // incremented. This allows to ensure that the list of servers
    // returned by the registry is consistent with the servers
    // currently deployed on the node: if the serial didn't change
    // after getting the list of servers from the registry, we have
    // the accurate list of servers that should be deployed on the
    // node.
    //
    unsigned long serial = 0;
    Ice::StringSeq servers;
    vector<ServerCommandPtr> commands;
    while(true)
    {
        {
            Lock sync(*this);
            if(serial == _serial)
            {
                _serial = 1; // We can reset the serial number.
                commands = checkConsistencyNoSync(servers);
                break;
            }
            serial = _serial;
        }
        assert(session);
        try
        {
            servers = session->getServers();
        }
        catch(const Ice::LocalException&)
        {
            return; // The connection with the session was lost.
        }
        sort(servers.begin(), servers.end());
    }

    for_each(commands.begin(), commands.end(), IceUtil::voidMemFun(&ServerCommand::execute));
}
Esempio n. 8
0
Demo::BookPrx
LibraryI::createBook(const Demo::BookDescription& description, const Ice::Current& c)
{
    IceUtil::Mutex::Lock lock(*this);

    BookPrx book = IsbnToBook(c.adapter)(description.isbn);
    try
    {
        book->ice_ping();

        //
        // The book already exists.
        //
        throw BookExistsException();
    }
    catch(const Ice::ObjectNotExistException&)
    {
        //
        // Book doesn't exist, ignore the exception.
        //
    }

    BookPtr bookI = new BookI(this);
    bookI->description = description;

    //
    // Create a new Ice Object in the evictor, using the new identity
    // and the new Servant.
    //
    // This can throw EvictorDeactivatedException (which indicates an
    // internal error). The exception is currently ignored.
    //
    Ice::Identity ident = createBookIdentity(description.isbn);
    _evictor->add(bookI, ident);

    //
    // Add the isbn number to the authors map.
    //
    Ice::StringSeq isbnSeq;

    StringIsbnSeqDict::iterator p =  _authors.find(description.authors);
    if(p != _authors.end())
    {
        isbnSeq = p->second;
    }

    isbnSeq.push_back(description.isbn);
    _authors.put(StringIsbnSeqDict::value_type(description.authors, isbnSeq));

    return book;
}
Esempio n. 9
0
bool
IcePHP::createStringArray(zval* zv, const Ice::StringSeq& seq)
{
    array_init(zv);
    for(Ice::StringSeq::const_iterator p = seq.begin(); p != seq.end(); ++p)
    {
        if(add_next_index_stringl(zv, STRCAST(p->c_str()), static_cast<uint>(p->length())) == FAILURE)
        {
            return false;
        }
    }

    return true;
}
Esempio n. 10
0
int
main(int argc, char* argv[])

#endif
{
    Ice::StringSeq args = Ice::argsToStringSeq(argc, argv);
    assert(args.size() > 0);
    const string appName = args[0];

    Ice::InitializationData initData;
    FreezeScript::CompactIdResolverIPtr resolver = new FreezeScript::CompactIdResolverI;
    initData.compactIdResolver = resolver;

    Ice::CommunicatorPtr communicator;
    int status = EXIT_SUCCESS;
    try
    {
        communicator = Ice::initialize(args, initData);
        status = run(args, communicator, resolver);
    }
    catch(const FreezeScript::FailureException& ex)
    {
        string reason = ex.reason();
        cerr << appName << ": " << reason;
        if(reason[reason.size() - 1] != '\n')
        {
            cerr << endl;
        }
        return EXIT_FAILURE;
    }
    catch(const std::exception& ex)
    {
        cerr << appName << ": " << ex.what() << endl;
        status = EXIT_FAILURE;
    }
    catch(...)
    {
        cerr << appName << ": unknown error" << endl;
        return EXIT_FAILURE;
    }

    if(communicator)
    {
        communicator->destroy();
    }

    return status;
}
Esempio n. 11
0
bool
IcePy::listToStringSeq(PyObject* l, Ice::StringSeq& seq)
{
    assert(PyList_Check(l));

    Py_ssize_t sz = PyList_GET_SIZE(l);
    for(Py_ssize_t i = 0; i < sz; ++i)
    {
        PyObject* item = PyList_GET_ITEM(l, i);
        if(!item)
        {
            return false;
        }
        string str;
        if(checkString(item))
        {
            str = getString(item);
        }
        else if(item != Py_None)
        {
            PyErr_Format(PyExc_ValueError, STRCAST("list element must be a string"));
            return false;
        }
        seq.push_back(str);
    }

    return true;
}
Esempio n. 12
0
bool
IcePy::tupleToStringSeq(PyObject* t, Ice::StringSeq& seq)
{
    assert(PyTuple_Check(t));

    int sz = static_cast<int>(PyTuple_GET_SIZE(t));
    for(int i = 0; i < sz; ++i)
    {
        PyObject* item = PyTuple_GET_ITEM(t, i);
        if(!item)
        {
            return false;
        }
        string str;
        if(checkString(item))
        {
            str = getString(item);
        }
        else if(item != Py_None)
        {
            PyErr_Format(PyExc_ValueError, STRCAST("tuple element must be a string"));
            return false;
        }
        seq.push_back(str);
    }

    return true;
}
Esempio n. 13
0
bool
IcePHP::extractStringArray(zval* zv, Ice::StringSeq& seq)
{
    if(Z_TYPE_P(zv) != IS_ARRAY)
    {
        string s = zendTypeToString(Z_TYPE_P(zv));
        invalidArgument("expected an array of strings but received %s", s.c_str());
        return false;
    }

    HashTable* arr = Z_ARRVAL_P(zv);
    zval* val;
    ZEND_HASH_FOREACH_VAL(arr, val)
    {
        if(Z_TYPE_P(val) != IS_STRING)
        {
            invalidArgument("array element must be a string");
            return false;
        }

        string s(Z_STRVAL_P(val), Z_STRLEN_P(val));
        seq.push_back(s);
    }
    ZEND_HASH_FOREACH_END();

    return true;
}
Esempio n. 14
0
void ICEBufferReciver::InitCommunicator()
{
	try
	{
		Ice::StringSeq args;
		args.push_back(GetICECommunicatorConfig());
//		FCommunicator = Ice::initialize(args);
		FCommunicator = Ice::initialize();
		Log(FServiceName+":通讯器成功初始化!" );
	}
	catch (const Ice::Exception & e)
	{
		Log(string(e.what()));
	}

	catch (...)
	{

		Log(FServiceName+":通讯器初始化失败!");
		// Console.Error.WriteLine(ex);
	}
}
Esempio n. 15
0
Ice::StringSeq
MetricsAdminI::getMetricsViewNames(Ice::StringSeq& disabledViews, const Current&)
{
    Ice::StringSeq enabledViews;

    Lock sync(*this);
    for(map<string, MetricsViewIPtr>::const_iterator p = _views.begin(); p != _views.end(); ++p)
    {
        enabledViews.push_back(p->first);
    }

#if defined(__SUNPRO_CC) && defined(_RWSTD_NO_MEMBER_TEMPLATES)
    for(set<string>::const_iterator p = _disabledViews.begin(); p != _disabledViews.end(); ++p)
    {
        disabledViews.push_back(*p);
    }

#else
    disabledViews.insert(disabledViews.end(), _disabledViews.begin(), _disabledViews.end());
#endif    

    return enabledViews;
}
Esempio n. 16
0
bool
IcePy::stringSeqToList(const Ice::StringSeq& seq, PyObject* l)
{
    assert(PyList_Check(l));

    for(Ice::StringSeq::const_iterator p = seq.begin(); p != seq.end(); ++p)
    {
        PyObject* str = Py_BuildValue(STRCAST("s"), p->c_str());
        if(!str)
        {
            Py_DECREF(l);
            return false;
        }
        int status = PyList_Append(l, str);
        Py_DECREF(str); // Give ownership to the list.
        if(status < 0)
        {
            Py_DECREF(l);
            return false;
        }
    }

    return true;
}
Esempio n. 17
0
void
LibraryI::remove(const BookDescription& description)
{
    IceUtil::Mutex::Lock lock(*this);
    
    //
    // Note: no need to catch and retry on deadlock since all access to
    // _authors is serialized.
    //

    try
    {
        StringIsbnSeqDict::iterator p = _authors.find(description.authors);
        
        assert(p != _authors.end());

        //
        // Remove the isbn number from the sequence.
        //
        Ice::StringSeq isbnSeq  = p->second;
        isbnSeq.erase(remove_if(isbnSeq.begin(), isbnSeq.end(), bind2nd(equal_to<string>(), description.isbn)),
                         isbnSeq.end());
        
        if(isbnSeq.empty())
        {
            //
            // If there are no further associated isbn numbers then remove
            // the record.
            //
            _authors.erase(p);
        }
        else
        {
            //
            // Otherwise, write back the new record.
            //
            p.set(isbnSeq);
        }

        //
        // This can throw EvictorDeactivatedException (which indicates
        // an internal error). The exception is currently ignored.
        //
        _evictor->remove(createBookIdentity(description.isbn));
    }
    catch(const Freeze::DatabaseException& ex)
    {
        DatabaseException e;
        e.message = ex.message;
        throw e;
    }
}
Esempio n. 18
0
PyObject*
IcePy_loadSlice(PyObject* /*self*/, PyObject* args)
{
    char* cmd;
    PyObject* list = 0;
    if(!PyArg_ParseTuple(args, STRCAST("s|O!"), &cmd, &PyList_Type, &list))
    {
        return 0;
    }

    vector<string> argSeq;
    try
    {
        argSeq = IceUtilInternal::Options::split(cmd);
    }
    catch(const IceUtilInternal::BadOptException& ex)
    {
        PyErr_Format(PyExc_RuntimeError, "error in Slice options: %s", ex.reason.c_str());
        return 0;
    }
    catch(const IceUtilInternal::APIException& ex)
    {
        PyErr_Format(PyExc_RuntimeError, "error in Slice options: %s", ex.reason.c_str());
        return 0;
    }

    if(list)
    {
        if(!listToStringSeq(list, argSeq))
        {
            return 0;
        }
    }

    IceUtilInternal::Options opts;
    opts.addOpt("D", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
    opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
    opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
    opts.addOpt("d", "debug");
    opts.addOpt("", "ice");
    opts.addOpt("", "underscore");
    opts.addOpt("", "checksum");
    opts.addOpt("", "all");

    vector<string> files;
    try
    {
        argSeq.insert(argSeq.begin(), ""); // dummy argv[0]
        files = opts.parse(argSeq);
        if(files.empty())
        {
            PyErr_Format(PyExc_RuntimeError, "no Slice files specified in `%s'", cmd);
            return 0;
        }
    }
    catch(const IceUtilInternal::BadOptException& ex)
    {
        PyErr_Format(PyExc_RuntimeError, "error in Slice options: %s", ex.reason.c_str());
        return 0;
    }
    catch(const IceUtilInternal::APIException& ex)
    {
        PyErr_Format(PyExc_RuntimeError, "error in Slice options: %s", ex.reason.c_str());
        return 0;
    }

    vector<string> cppArgs;
    Ice::StringSeq includePaths;
    bool debug = false;
    bool ice = true; // This must be true so that we can create Ice::Identity when necessary.
    bool underscore = opts.isSet("underscore");
    bool all = false;
    bool checksum = false;
    if(opts.isSet("D"))
    {
        vector<string> optargs = opts.argVec("D");
        for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
        {
            cppArgs.push_back("-D" + *i);
        }
    }
    if(opts.isSet("U"))
    {
        vector<string> optargs = opts.argVec("U");
        for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
        {
            cppArgs.push_back("-U" + *i);
        }
    }
    if(opts.isSet("I"))
    {
        includePaths = opts.argVec("I");
        for(vector<string>::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i)
        {
            cppArgs.push_back("-I" + *i);
        }
    }
    debug = opts.isSet("d") || opts.isSet("debug");
    all = opts.isSet("all");
    checksum = opts.isSet("checksum");

    bool ignoreRedefs = false;
    bool keepComments = true;

    for(vector<string>::const_iterator p = files.begin(); p != files.end(); ++p)
    {
        string file = *p;
        Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("icecpp", file, cppArgs);
        FILE* cppHandle = icecpp->preprocess(keepComments, "-D__SLICE2PY__");

        if(cppHandle == 0)
        {
            PyErr_Format(PyExc_RuntimeError, "Slice preprocessing failed for `%s'", cmd);
            return 0;
        }

        UnitPtr u = Slice::Unit::createUnit(ignoreRedefs, all, ice, underscore);
        int parseStatus = u->parse(file, cppHandle, debug);

        if(!icecpp->close() || parseStatus == EXIT_FAILURE)
        {
            PyErr_Format(PyExc_RuntimeError, "Slice parsing failed for `%s'", cmd);
            u->destroy();
            return 0;
        }

        //
        // Generate the Python code into a string stream.
        //
        ostringstream codeStream;
        IceUtilInternal::Output out(codeStream);
        out.setUseTab(false);

        //
        // Emit a Python magic comment to set the file encoding.
        // It must be the first or second line.
        //
        out << "# -*- coding: utf-8 -*-\n";
        generate(u, all, checksum, includePaths, out);
        u->destroy();

        string code = codeStream.str();

        //
        // We need to invoke Ice.updateModules() so that all of the types we've just generated
        // are made "public".
        //
        code += "\nIce.updateModules()\n";

        PyObjectHandle src = Py_CompileString(const_cast<char*>(code.c_str()), const_cast<char*>(file.c_str()),
                                              Py_file_input);
        if(!src.get())
        {
            return 0;
        }

        PyObjectHandle globals = PyDict_New();
        if(!globals.get())
        {
            return 0;
        }
        PyDict_SetItemString(globals.get(), "__builtins__", PyEval_GetBuiltins());

#if PY_VERSION_HEX >= 0x03000000
        PyObjectHandle val = PyEval_EvalCode(src.get(), globals.get(), 0);
#else
        PyObjectHandle val = PyEval_EvalCode(reinterpret_cast<PyCodeObject*>(src.get()), globals.get(), 0);
#endif
        if(!val.get())
        {
            return 0;
        }
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 19
0
GPrxPtr
allTests(const Ice::CommunicatorPtr& communicator)
{
#ifdef ICE_OS_UWP
    bool uwp = true;
#else
    bool uwp = false;
#endif

    cout << "testing Ice.Admin.Facets property... " << flush;
    test(communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets").empty());
    communicator->getProperties()->setProperty("Ice.Admin.Facets", "foobar");
    Ice::StringSeq facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
    test(facetFilter.size() == 1 && facetFilter[0] == "foobar");
    communicator->getProperties()->setProperty("Ice.Admin.Facets", "foo\\'bar");
    facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
    test(facetFilter.size() == 1 && facetFilter[0] == "foo'bar");
    communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
    facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
    test(facetFilter.size() == 3 && facetFilter[0] == "foo bar" && facetFilter[1] == "toto" &&
         facetFilter[2] == "titi");
    communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
    facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
    test(facetFilter.size() == 2 && facetFilter[0] == "foo bar' toto" && facetFilter[1] == "titi");
    // communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
    // facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
    // test(facetFilter.size() == 0);
    communicator->getProperties()->setProperty("Ice.Admin.Facets", "");
    cout << "ok" << endl;

    cout << "testing facet registration exceptions... " << flush;
    string localOAEndpoint;
    {
        ostringstream ostr;
        if(communicator->getProperties()->getProperty("Ice.Default.Protocol") == "bt")
        {
            ostr << "default -a *";
        }
        else
        {
            ostr << "default -h *";
        }
        localOAEndpoint = ostr.str();
    }
    communicator->getProperties()->setProperty("FacetExceptionTestAdapter.Endpoints", localOAEndpoint);
    if(uwp || (communicator->getProperties()->getProperty("Ice.Default.Protocol") != "ssl" &&
                 communicator->getProperties()->getProperty("Ice.Default.Protocol") != "wss"))
    {
        Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("FacetExceptionTestAdapter");
        Ice::ObjectPtr obj = ICE_MAKE_SHARED(EmptyI);
        adapter->add(obj, Ice::stringToIdentity("d"));
        adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
        try
        {
            adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch(const Ice::AlreadyRegisteredException&)
        {
        }
        adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
        try
        {
            adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch(const Ice::NotRegisteredException&)
        {
        }
        cout << "ok" << endl;

        cout << "testing removeAllFacets... " << flush;
        Ice::ObjectPtr obj1 = ICE_MAKE_SHARED(EmptyI);
        Ice::ObjectPtr obj2 = ICE_MAKE_SHARED(EmptyI);
        adapter->addFacet(obj1, Ice::stringToIdentity("id1"), "f1");
        adapter->addFacet(obj2, Ice::stringToIdentity("id1"), "f2");
        Ice::ObjectPtr obj3 = ICE_MAKE_SHARED(EmptyI);
        adapter->addFacet(obj1, Ice::stringToIdentity("id2"), "f1");
        adapter->addFacet(obj2, Ice::stringToIdentity("id2"), "f2");
        adapter->addFacet(obj3, Ice::stringToIdentity("id2"), "");
        Ice::FacetMap fm = adapter->removeAllFacets(Ice::stringToIdentity("id1"));
        test(fm.size() == 2);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        try
        {
            adapter->removeAllFacets(Ice::stringToIdentity("id1"));
            test(false);
        }
        catch(const Ice::NotRegisteredException&)
        {
        }
        fm = adapter->removeAllFacets(Ice::stringToIdentity("id2"));
        test(fm.size() == 3);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        test(fm[""] == obj3);
        cout << "ok" << endl;

        adapter->deactivate();
    }

    cout << "testing stringToProxy... " << flush;
    string ref = "d:" + getTestEndpoint(communicator, 0);
    Ice::ObjectPrxPtr db = communicator->stringToProxy(ref);
    test(db);
    cout << "ok" << endl;

    cout << "testing unchecked cast... " << flush;
    Ice::ObjectPrxPtr prx = ICE_UNCHECKED_CAST(Ice::ObjectPrx, db);
    test(prx->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
    prx = Ice::uncheckedCast<Ice::ObjectPrx>(db, "facetABCD");
#else
    prx = Ice::ObjectPrx::uncheckedCast(db, "facetABCD");
#endif
    test(prx->ice_getFacet() == "facetABCD");
    Ice::ObjectPrxPtr prx2 = ICE_UNCHECKED_CAST(Ice::ObjectPrx, prx);
    test(prx2->ice_getFacet() == "facetABCD");

#ifdef ICE_CPP11_MAPPING
    shared_ptr<Ice::ObjectPrx> prx3 = Ice::uncheckedCast<Ice::ObjectPrx>(prx, "");
#else
    Ice::ObjectPrx prx3 = Ice::ObjectPrx::uncheckedCast(prx, "");
#endif
    test(prx3->ice_getFacet().empty());
    DPrxPtr d = ICE_UNCHECKED_CAST(Test::DPrx, db);
    test(d->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
    shared_ptr<DPrx> df = Ice::uncheckedCast<Test::DPrx>(db, "facetABCD");
#else
    DPrx df = Test::DPrx::uncheckedCast(db, "facetABCD");
#endif
    test(df->ice_getFacet() == "facetABCD");
    DPrxPtr df2 = ICE_UNCHECKED_CAST(Test::DPrx, df);
    test(df2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
    shared_ptr<DPrx> df3 = Ice::uncheckedCast<Test::DPrx>(df, "");
#else
    DPrx df3 = Test::DPrx::uncheckedCast(df, "");
#endif
    test(df3->ice_getFacet().empty());
    cout << "ok" << endl;

    cout << "testing checked cast... " << flush;
    prx = ICE_CHECKED_CAST(Ice::ObjectPrx, db);
    test(prx->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
    prx = Ice::checkedCast<Ice::ObjectPrx>(db, "facetABCD");
#else
    prx = Ice::ObjectPrx::checkedCast(db, "facetABCD");
#endif
    test(prx->ice_getFacet() == "facetABCD");
    prx2 = ICE_CHECKED_CAST(Ice::ObjectPrx, prx);
    test(prx2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
    prx3 = Ice::checkedCast<Ice::ObjectPrx>(prx, "");
#else
    prx3 = Ice::ObjectPrx::checkedCast(prx, "");
#endif
    test(prx3->ice_getFacet().empty());
    d = ICE_CHECKED_CAST(Test::DPrx, db);
    test(d->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
    df = Ice::checkedCast<Test::DPrx>(db, "facetABCD");
#else
    df = Test::DPrx::checkedCast(db, "facetABCD");
#endif
    test(df->ice_getFacet() == "facetABCD");
    df2 = ICE_CHECKED_CAST(Test::DPrx, df);
    test(df2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
    df3 = Ice::checkedCast<Test::DPrx>(df, "");
#else
    df3 = Test::DPrx::checkedCast(df, "");
#endif
    test(df3->ice_getFacet().empty());
    cout << "ok" << endl;

    cout << "testing non-facets A, B, C, and D... " << flush;
    d = ICE_CHECKED_CAST(DPrx, db);
    test(d);
#ifdef ICE_CPP11_MAPPING
    test(Ice::targetEqualTo(d, db));
#else
    test(d == db);
#endif
    test(d->callA() == "A");
    test(d->callB() == "B");
    test(d->callC() == "C");
    test(d->callD() == "D");
    cout << "ok" << endl;

    cout << "testing facets A, B, C, and D... " << flush;
#ifdef ICE_CPP11_MAPPING
    df = Ice::checkedCast<DPrx>(d, "facetABCD");
#else
    df = DPrx::checkedCast(d, "facetABCD");
#endif
    test(df);
    test(df->callA() == "A");
    test(df->callB() == "B");
    test(df->callC() == "C");
    test(df->callD() == "D");
    cout << "ok" << endl;

    cout << "testing facets E and F... " << flush;
#ifdef ICE_CPP11_MAPPING
    auto ff = Ice::checkedCast<FPrx>(d, "facetEF");
#else
    FPrx ff = FPrx::checkedCast(d, "facetEF");
#endif
    test(ff);
    test(ff->callE() == "E");
    test(ff->callF() == "F");
    cout << "ok" << endl;

    cout << "testing facet G... " << flush;
#ifdef ICE_CPP11_MAPPING
    auto gf = Ice::checkedCast<GPrx>(ff, "facetGH");
#else
    GPrx gf = GPrx::checkedCast(ff, "facetGH");
#endif
    test(gf);
    test(gf->callG() == "G");
    cout << "ok" << endl;

    cout << "testing whether casting preserves the facet... " << flush;
    HPrxPtr hf = ICE_CHECKED_CAST(HPrx, gf);
    test(hf);
    test(hf->callG() == "G");
    test(hf->callH() == "H");
    cout << "ok" << endl;

    return gf;
}
Esempio n. 20
0
vector<ServerCommandPtr>
NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers)
{
    vector<ServerCommandPtr> commands;

    //
    // Check if the servers directory doesn't contain more servers
    // than the registry really knows.
    //
    Ice::StringSeq contents;
    try
    {
        contents = readDirectory(_serversDir);
    }
    catch(const string& msg)
    {
        Ice::Error out(_traceLevels->logger);
        out << "couldn't read directory `" << _serversDir << "':\n" << msg;
        return commands;
    }

    vector<string> remove;
    set_difference(contents.begin(), contents.end(), servers.begin(), servers.end(), back_inserter(remove));

    //
    // Remove the extra servers if possible.
    //
    try
    {
        vector<string>::iterator p = remove.begin();
        while(p != remove.end())
        {
            ServerIPtr server = ServerIPtr::dynamicCast(_adapter->find(createServerIdentity(*p)));
            if(server)
            {
                //
                // If the server is loaded, we invoke on it to destroy it.
                //
                try
                {
                    ServerCommandPtr command = server->destroy(0, "", 0, "Master", false);
                    if(command)
                    {
                        commands.push_back(command);
                    }
                    p = remove.erase(p);
                    continue;
                }
                catch(const Ice::LocalException& ex)
                {
                    Ice::Error out(_traceLevels->logger);
                    out << "server `" << *p << "' destroy failed:\n" << ex;
                }
                catch(const string&)
                {
                    assert(false);
                }
            }

            try
            {
                if(canRemoveServerDirectory(*p))
                {
                    //
                    // If the server directory can be removed and we
                    // either remove it or back it up before to remove it.
                    //
                    removeRecursive(_serversDir + "/" + *p);
                    p = remove.erase(p);
                    continue;
                }
            }
            catch(const string& msg)
            {
                Ice::Warning out(_traceLevels->logger);
                out << "removing server directory `" << _serversDir << "/" << *p << "' failed:\n" << msg;
            }

            *p = _serversDir + "/" + *p;
            ++p;
        }
    }
    catch(const Ice::ObjectAdapterDeactivatedException&)
    {
        //
        // Just return the server commands, we'll finish the
        // consistency check next time the node is started.
        //
        return commands;
    }

    if(!remove.empty())
    {
        Ice::Warning out(_traceLevels->logger);
        out << "server directories containing data not created or written by IceGrid were not removed:\n";
        out << toString(remove);
    }
    return commands;
}
Esempio n. 21
0
bool
NodeI::canRemoveServerDirectory(const string& name)
{
    //
    // Check if there's files which we didn't create.
    //
    Ice::StringSeq c = readDirectory(_serversDir + "/" + name);
    set<string> contents(c.begin(), c.end());
    contents.erase("dbs");
    contents.erase("config");
    contents.erase("distrib");
    contents.erase("revision");
    contents.erase("data");
    Ice::StringSeq serviceDataDirs;
    for(set<string>::const_iterator p = contents.begin(); p != contents.end(); ++p)
    {
        if(p->find("data_") != 0)
        {
            return false;
        }
        serviceDataDirs.push_back(*p);
    }
    if(!contents.empty())
    {
        return false;
    }

    c = readDirectory(_serversDir + "/" + name + "/config");
    for(Ice::StringSeq::const_iterator p = c.begin() ; p != c.end(); ++p)
    {
        if(p->find("config") != 0)
        {
            return false;
        }
    }

    if(IceUtilInternal::directoryExists(_serversDir + "/" + name + "/dbs"))
    {
        c = readDirectory(_serversDir + "/" + name + "/dbs");
        for(Ice::StringSeq::const_iterator p = c.begin() ; p != c.end(); ++p)
        {
            try
            {
                Ice::StringSeq files = readDirectory(_serversDir + "/" + name + "/dbs/" + *p);
                files.erase(remove(files.begin(), files.end(), "DB_CONFIG"), files.end());
                files.erase(remove(files.begin(), files.end(), "__Freeze"), files.end());
                if(!files.empty())
                {
                    return false;
                }
            }
            catch(const string&)
            {
                return false;
            }
        }
    }

    if(IceUtilInternal::directoryExists(_serversDir + "/" + name + "/data"))
    {
        if(!readDirectory(_serversDir + "/" + name + "/data").empty())
        {
            return false;
        }
    }

    for(Ice::StringSeq::const_iterator p = serviceDataDirs.begin(); p != serviceDataDirs.end(); ++p)
    {
        try
        {
            if(!readDirectory(_serversDir + "/" + name + "/" + *p).empty())
            {
                return false;
            }
        }
        catch(const string&)
        {
            return false;
        }
    }
    return true;
}
Esempio n. 22
0
void
ServerEntry::released(const SessionIPtr& session)
{
    if(!_loaded.get() && !_load.get())
    {
        return;
    }

    ServerDescriptorPtr desc = _loaded.get() ? _loaded->descriptor : _load->descriptor;

    //
    // If the server has the session activation mode, we re-load the
    // server on the node as its deployment might have changed (it's
    // possible to use ${session.*} variable with server with the
    // session activation mode. Synchronizing the server will also
    // shutdown the server on the node.
    //
    if(desc->activation == "session")
    {
        _updated = true;
        if(!_load.get())
        {
            _load.reset(_loaded.release());
        }
        _load->sessionId = "";
        _session = 0;
    }

    TraceLevelsPtr traceLevels = _cache.getTraceLevels();

    Glacier2::IdentitySetPrx identitySet = session->getGlacier2IdentitySet();
    Glacier2::StringSetPrx adapterIdSet = session->getGlacier2AdapterIdSet();
    if(identitySet && adapterIdSet)
    {
        ServerHelperPtr helper = createHelper(desc);
        multiset<string> adapterIds;
        multiset<Ice::Identity> identities;
        helper->getIds(adapterIds, identities);
        try
        {
            //
            // SunCC won't accept the following:
            //
            // ctl->adapterIds()->remove(Ice::StringSeq(adapterIds.begin(), adapterIds.end()));
            // ctl->identities()->remove(Ice::IdentitySeq(identities.begin(), identities.end()));
            //
            Ice::StringSeq adapterIdSeq;
            for(multiset<string>::iterator p = adapterIds.begin(); p != adapterIds.end(); ++p)
            {
                adapterIdSeq.push_back(*p);
            }
            Ice::IdentitySeq identitySeq;
            for(multiset<Ice::Identity>::iterator q = identities.begin(); q != identities.end(); ++q)
            {
                identitySeq.push_back(*q);
            }
            adapterIdSet->remove(adapterIdSeq);
            identitySet->remove(identitySeq);
        }
        catch(const Ice::LocalException& ex)
        {
            if(traceLevels && traceLevels->server > 0)
            {
                Ice::Trace out(traceLevels->logger, traceLevels->serverCat);
                out << "couldn't remove Glacier2 filters for server `" << _id << "' allocated by `";
                out << session->getId() << ":\n" << ex;
            }
        }
    }

    if(traceLevels && traceLevels->server > 1)
    {
        Ice::Trace out(traceLevels->logger, traceLevels->serverCat);
        out << "server `" << _id << "' released by `" << session->getId() << "' (" << _count << ")";
    }
}
Esempio n. 23
0
static int
communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
{
    PyObject* argList = 0;
    PyObject* initData = 0;
    if(!PyArg_ParseTuple(args, STRCAST("|OO"), &argList, &initData))
    {
        return -1;
    }

    if(argList == Py_None)
    {
        argList = 0;
    }

    if(initData == Py_None)
    {
        initData = 0;
    }

    PyObject* initDataType = lookupType("Ice.InitializationData");

    if(argList && !initData)
    {
        if(PyObject_IsInstance(argList, initDataType))
        {
            initData = argList;
            argList = 0;
        }
        else if(!PyList_Check(argList))
        {
            PyErr_Format(PyExc_ValueError, STRCAST("initialize expects an argument list or Ice.InitializationData"));
            return -1;
        }
    }
    else if(argList && initData)
    {
        if(!PyList_Check(argList) || !PyObject_IsInstance(initData, initDataType))
        {
            PyErr_Format(PyExc_ValueError, STRCAST("initialize expects an argument list and Ice.InitializationData"));
            return -1;
        }
    }

    Ice::StringSeq seq;
    if(argList && !listToStringSeq(argList, seq))
    {
        return -1;
    }

    //
    // Use the with-args or the without-args version of initialize()?
    //
    bool hasArgs = argList != 0;

    Ice::InitializationData data;

    if(initData)
    {
        PyObjectHandle properties = PyObject_GetAttrString(initData, STRCAST("properties"));
        PyObjectHandle logger = PyObject_GetAttrString(initData, STRCAST("logger"));
        PyObjectHandle threadHook = PyObject_GetAttrString(initData, STRCAST("threadHook"));
        PyObjectHandle batchRequestInterceptor = PyObject_GetAttrString(initData, STRCAST("batchRequestInterceptor"));

        PyErr_Clear(); // PyObject_GetAttrString sets an error on failure.

        if(properties.get() && properties.get() != Py_None)
        {
            //
            // Get the properties implementation.
            //
            PyObjectHandle impl = PyObject_GetAttrString(properties.get(), STRCAST("_impl"));
            assert(impl.get());
            data.properties = getProperties(impl.get());
        }

        if(logger.get() && logger.get() != Py_None)
        {
            data.logger = new LoggerWrapper(logger.get());
        }

        if(threadHook.get() && threadHook.get() != Py_None)
        {
            data.threadHook = new ThreadHook(threadHook.get());
        }

        if(batchRequestInterceptor.get() && batchRequestInterceptor.get() != Py_None)
        {
            data.batchRequestInterceptor = new BatchRequestInterceptor(batchRequestInterceptor.get());
        }
    }

    //
    // We always supply our own implementation of ValueFactoryManager.
    //
    data.valueFactoryManager = new ValueFactoryManager;

    try
    {
        if(argList)
        {
            data.properties = Ice::createProperties(seq, data.properties);
        }
        else if(!data.properties)
        {
            data.properties = Ice::createProperties();
        }
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return -1;
    }

    //
    // Remaining command line options are passed to the communicator
    // as an argument vector in case they contain plug-in properties.
    //
    int argc = static_cast<int>(seq.size());
    char** argv = new char*[argc + 1];
    int i = 0;
    for(Ice::StringSeq::const_iterator s = seq.begin(); s != seq.end(); ++s, ++i)
    {
        argv[i] = strdup(s->c_str());
    }
    argv[argc] = 0;

    data.compactIdResolver = new IdResolver;

    Ice::CommunicatorPtr communicator;
    try
    {
        AllowThreads allowThreads;
        if(hasArgs)
        {
            communicator = Ice::initialize(argc, argv, data);
        }
        else
        {
            communicator = Ice::initialize(data);
        }
    }
    catch(const Ice::Exception& ex)
    {
        for(i = 0; i < argc; ++i)
        {
            free(argv[i]);
        }
        delete[] argv;

        setPythonException(ex);
        return -1;
    }

    //
    // Replace the contents of the given argument list with the filtered arguments.
    //
    if(argList)
    {
        PyList_SetSlice(argList, 0, PyList_Size(argList), 0); // Clear the list.

        for(i = 0; i < argc; ++i)
        {
            PyObjectHandle str = Py_BuildValue(STRCAST("s"), argv[i]);
            PyList_Append(argList, str.get());
        }
    }

    for(i = 0; i < argc; ++i)
    {
        free(argv[i]);
    }
    delete[] argv;

    self->communicator = new Ice::CommunicatorPtr(communicator);

    CommunicatorMap::iterator p = _communicatorMap.find(communicator);
    if(p != _communicatorMap.end())
    {
        _communicatorMap.erase(p);
    }
    _communicatorMap.insert(CommunicatorMap::value_type(communicator, reinterpret_cast<PyObject*>(self)));

    return 0;
}
Esempio n. 24
0
bool
FileCache::read(const string& file, Ice::Long offset, int size, Ice::Long& newOffset, Ice::StringSeq& lines)
{
    assert(size > 0);

    if(size > _messageSizeMax)
    {
        size = _messageSizeMax;
    }

    if(size <= 5)
    {
        throw FileNotAvailableException("maximum bytes per read request is too low");
    }

    IceUtilInternal::ifstream is(file); // file is a UTF-8 string
    if(is.fail())
    {
        throw FileNotAvailableException("failed to open file `" + file + "'");
    }

    //
    // Check if the requested offset is past the end of the file, if
    // that's the case return an empty sequence of lines and indicate
    // the EOF.
    //
    is.seekg(0, ios::end);
    if(offset >= is.tellg())
    {
        newOffset = is.tellg();
        lines = Ice::StringSeq();
        return true;
    }

    //
    // Read lines from the file until we read enough or reached EOF.
    // 
    newOffset = offset;
    lines = Ice::StringSeq();
    is.seekg(static_cast<streamoff>(offset), ios::beg);
    int totalSize = 0;
    string line;

    for(int i = 0; is.good(); ++i)
    {
        getline(is, line);

        int lineSize = static_cast<int>(line.size()) + 5; // 5 bytes for the encoding of the string size (worst case)
        if(lineSize + totalSize > size)
        {
            if(totalSize + 5 < size)
            {
                // There's some room left for a part of the string, return a partial string
                line = line.substr(0, size - totalSize - 5);
                lines.push_back(line);
                newOffset += line.size();
            }
            else
            {
                lines.push_back("");
            }
            return false; // We didn't reach the end of file, we've just reached the size limit!
        }

        totalSize += lineSize;
        lines.push_back(line);

        //
        // If there was a partial read update the offset using the current line size,
        // otherwise we have read a new complete line and we can use tellg to update
        // the offset.
        //
        if(!is.good())
        {
            newOffset += line.size();
        }
        else
        {
            newOffset = is.tellg();
        }
    }

    if(is.bad())
    {
        throw FileNotAvailableException("unrecoverable error occured while reading file `" + file + "'");
    }

    return is.eof();
}
Esempio n. 25
0
static int
communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
{
    //
    // The argument options are:
    //
    // Ice.initialize()
    // Ice.initialize(args)
    // Ice.initialize(initData)
    // Ice.initialize(configFile)
    // Ice.initialize(args, initData)
    // Ice.initialize(args, configFile)
    //

    PyObject* arg1 = 0;
    PyObject* arg2 = 0;
    if(!PyArg_ParseTuple(args, STRCAST("|OO"), &arg1, &arg2))
    {
        return -1;
    }

    PyObject* argList = 0;
    PyObject* initData = 0;
    PyObject* configFile = 0;

    if(arg1 == Py_None)
    {
        arg1 = 0;
    }

    if(arg2 == Py_None)
    {
        arg2 = 0;
    }

    PyObject* initDataType = lookupType("Ice.InitializationData");

    if(arg1)
    {
        if(PyList_Check(arg1))
        {
            argList = arg1;
        }
        else if(PyObject_IsInstance(arg1, initDataType))
        {
            initData = arg1;
        }
        else if(checkString(arg1))
        {
            configFile = arg1;
        }
        else
        {
            PyErr_Format(PyExc_ValueError,
                STRCAST("initialize expects an argument list, Ice.InitializationData or a configuration filename"));
            return -1;
        }
    }

    if(arg2)
    {
        if(PyList_Check(arg2))
        {
            if(argList)
            {
                PyErr_Format(PyExc_ValueError, STRCAST("unexpected list argument to initialize"));
                return -1;
            }
            argList = arg2;
        }
        else if(PyObject_IsInstance(arg2, initDataType))
        {
            if(initData)
            {
                PyErr_Format(PyExc_ValueError, STRCAST("unexpected Ice.InitializationData argument to initialize"));
                return -1;
            }
            initData = arg2;
        }
        else if(checkString(arg2))
        {
            if(configFile)
            {
                PyErr_Format(PyExc_ValueError, STRCAST("unexpected string argument to initialize"));
                return -1;
            }
            configFile = arg2;
        }
        else
        {
            PyErr_Format(PyExc_ValueError,
                STRCAST("initialize expects an argument list, Ice.InitializationData or a configuration filename"));
            return -1;
        }
    }

    if(initData && configFile)
    {
        PyErr_Format(PyExc_ValueError,
            STRCAST("initialize accepts either Ice.InitializationData or a configuration filename"));
        return -1;
    }

    Ice::StringSeq seq;
    if(argList && !listToStringSeq(argList, seq))
    {
        return -1;
    }

    Ice::InitializationData data;
    DispatcherPtr dispatcherWrapper;

    try
    {
        if(initData)
        {
            PyObjectHandle properties = getAttr(initData, "properties", false);
            PyObjectHandle logger = getAttr(initData, "logger", false);
            PyObjectHandle threadHook = getAttr(initData, "threadHook", false);
            PyObjectHandle threadStart = getAttr(initData, "threadStart", false);
            PyObjectHandle threadStop = getAttr(initData, "threadStop", false);
            PyObjectHandle batchRequestInterceptor = getAttr(initData, "batchRequestInterceptor", false);
            PyObjectHandle dispatcher = getAttr(initData, "dispatcher", false);

            if(properties.get())
            {
                //
                // Get the properties implementation.
                //
                PyObjectHandle impl = getAttr(properties.get(), "_impl", false);
                assert(impl.get());
                data.properties = getProperties(impl.get());
            }

            if(logger.get())
            {
                data.logger = new LoggerWrapper(logger.get());
            }

            if(threadHook.get() || threadStart.get() || threadStop.get())
            {
                data.threadHook = new ThreadHook(threadHook.get(), threadStart.get(), threadStop.get());
            }

            if(dispatcher.get())
            {
                dispatcherWrapper = new Dispatcher(dispatcher.get());
                data.dispatcher = dispatcherWrapper;
            }

            if(batchRequestInterceptor.get())
            {
                data.batchRequestInterceptor = new BatchRequestInterceptor(batchRequestInterceptor.get());
            }
        }

        //
        // We always supply our own implementation of ValueFactoryManager.
        //
        data.valueFactoryManager = new ValueFactoryManager;

        if(!data.properties)
        {
            data.properties = Ice::createProperties();
        }

        if(configFile)
        {
            data.properties->load(getString(configFile));
        }

        if(argList)
        {
            data.properties = Ice::createProperties(seq, data.properties);
        }
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return -1;
    }

    //
    // Remaining command line options are passed to the communicator
    // as an argument vector in case they contain plug-in properties.
    //
    int argc = static_cast<int>(seq.size());
    char** argv = new char*[argc + 1];
    int i = 0;
    for(Ice::StringSeq::const_iterator s = seq.begin(); s != seq.end(); ++s, ++i)
    {
        argv[i] = strdup(s->c_str());
    }
    argv[argc] = 0;

    data.compactIdResolver = new IdResolver;

    Ice::CommunicatorPtr communicator;
    try
    {
        AllowThreads allowThreads;
        if(argList)
        {
            communicator = Ice::initialize(argc, argv, data);
        }
        else
        {
            communicator = Ice::initialize(data);
        }
    }
    catch(const Ice::Exception& ex)
    {
        for(i = 0; i < argc; ++i)
        {
            free(argv[i]);
        }
        delete[] argv;

        setPythonException(ex);
        return -1;
    }

    //
    // Replace the contents of the given argument list with the filtered arguments.
    //
    if(argList)
    {
        PyList_SetSlice(argList, 0, PyList_Size(argList), 0); // Clear the list.

        for(i = 0; i < argc; ++i)
        {
            PyObjectHandle str = Py_BuildValue(STRCAST("s"), argv[i]);
            PyList_Append(argList, str.get());
        }
    }

    for(i = 0; i < argc; ++i)
    {
        free(argv[i]);
    }
    delete[] argv;

    self->communicator = new Ice::CommunicatorPtr(communicator);

    CommunicatorMap::iterator p = _communicatorMap.find(communicator);
    if(p != _communicatorMap.end())
    {
        _communicatorMap.erase(p);
    }
    _communicatorMap.insert(CommunicatorMap::value_type(communicator, reinterpret_cast<PyObject*>(self)));

    if(dispatcherWrapper)
    {
        self->dispatcher = new DispatcherPtr(dispatcherWrapper);
        dispatcherWrapper->setCommunicator(communicator);
    }

    return 0;
}
Esempio n. 26
0
int
Activator::activate(const string& name,
                    const string& exePath,
                    const string& pwdPath,
#ifndef _WIN32
                    uid_t uid,
                    gid_t gid,
#endif
                    const Ice::StringSeq& options,
                    const Ice::StringSeq& envs,
                    const ServerIPtr& server)
{
    IceUtil::Monitor< IceUtil::Mutex>::Lock sync(*this);

    if(_deactivating)
    {
        throw string("The node is being shutdown.");
    }

    string path = exePath;
    if(path.empty())
    {
        throw string("The server executable path is empty.");
    }

    string pwd = IcePatch2Internal::simplify(pwdPath);
#ifdef _WIN32
    if(!IceUtilInternal::isAbsolutePath(path))
    {
        if(path.find('/') == string::npos)
        {
            //
            // Get the absolute pathname of the executable.
            //
            wchar_t absbuf[_MAX_PATH];
            wchar_t* fPart;
            wstring ext = path.size() <= 4 || path[path.size() - 4] != '.' ? L".exe" : L"";

            //
            // IceGrid doesn't support to use string converters, so don't need to use
            // any string converter in wstringToString conversions.
            //
            if(SearchPathW(NULL, IceUtil::stringToWstring(path).c_str(), ext.c_str(), _MAX_PATH, absbuf, &fPart) == 0)
            {
                if(_traceLevels->activator > 0)
                {
                    Trace out(_traceLevels->logger, _traceLevels->activatorCat);
                    out << "couldn't find `" << path << "' executable.";
                }
                throw string("Couldn't find `" + path + "' executable.");
            }
            path = IceUtil::wstringToString(absbuf);
        }
        else if(!pwd.empty())
        {
            path = pwd + "/" + path;
        }
    }

    //
    // Get the absolute pathname of the working directory.
    //
    // IceGrid doesn't support to use string converters, so
    // don't need to use any string converter in stringToWstring
    // conversions.
    //
    if(!pwd.empty())
    {
        wchar_t absbuf[_MAX_PATH];
        if(_wfullpath(absbuf, IceUtil::stringToWstring(pwd).c_str(), _MAX_PATH) == NULL)
        {
            if(_traceLevels->activator > 0)
            {
                Trace out(_traceLevels->logger, _traceLevels->activatorCat);
                out << "cannot convert `" << pwd << "' into an absolute path";
            }
            throw string("The server working directory path `" + pwd + "' can't be converted into an absolute path.");
        }
        pwd = IceUtil::wstringToString(absbuf);
    }
#endif

    //
    // Setup arguments.
    //
    StringSeq args;
    args.push_back(path);
    args.insert(args.end(), options.begin(), options.end());

    if(_traceLevels->activator > 0)
    {
        Ice::Trace out(_traceLevels->logger, _traceLevels->activatorCat);
        out << "activating server `" << name << "'";
        if(_traceLevels->activator > 1)
        {
            out << "\n";
            out << "path = " << path << "\n";
            if(pwd.empty())
            {
                string cwd;
                if(IceUtilInternal::getcwd(cwd) == 0)
                {
                    out << "pwd = " << cwd << "\n";
                }
            }
            else
            {
                out << "pwd = " << pwd << "\n";
            }
#ifndef _WIN32
            out << "uid/gid = " << uid << "/" << gid << "\n";
#endif
            if(!envs.empty())
            {
                out << "envs = " << toString(envs, ", ") << "\n";
            }
            if(!args.empty())
            {
                out << "args = " << toString(args);
            }
        }
    }

    //
    // Activate and create.
    //
#ifdef _WIN32

    //
    // Compose command line.
    //
    string cmd;
    for(StringSeq::const_iterator p = args.begin(); p != args.end(); ++p)
    {
        if(p != args.begin())
        {
            cmd.push_back(' ');
        }
        //
        // Enclose arguments containing spaces in double quotes.
        //
        if((*p).find(' ') != string::npos)
        {
            cmd.push_back('"');
            cmd.append(*p);
            cmd.push_back('"');
        }
        else
        {
            cmd.append(*p);
        }
    }

    //
    // IceGrid doesn't support to use string converters, so don't need to use
    // any string converter in stringToWstring conversions.
    //
    wstring wpwd = IceUtil::stringToWstring(pwd);
    const wchar_t* dir = !wpwd.empty() ? wpwd.c_str() : NULL;

    //
    // Make a copy of the command line.
    //
    wchar_t* cmdbuf = _wcsdup(IceUtil::stringToWstring(cmd).c_str());

    //
    // Create the environment block for the child process. We start with the environment
    // of this process, and then merge environment variables from the server description.
    // Since Windows is case insensitive wrt environment variables we convert the keys to
    // uppercase to ensure matches are found.
    //
    const wchar_t* env = NULL;
    wstring envbuf;
    if(!envs.empty())
    {
        map<wstring, wstring, UnicodeStringLess> envMap;
        LPVOID parentEnv = GetEnvironmentStringsW();
        const wchar_t* var = reinterpret_cast<const wchar_t*>(parentEnv);
        if(*var == L'=')
        {
            //
            // The environment block may start with some information about the
            // current drive and working directory. This is indicated by a leading
            // '=' character, so we skip to the first '\0' byte.
            //
            while(*var != L'\0')
                var++;
            var++;
        }
        while(*var != L'\0')
        {
            wstring s(var);
            wstring::size_type pos = s.find(L'=');
            if(pos != wstring::npos)
            {
                envMap[s.substr(0, pos)] = s.substr(pos + 1);
            }
            var += s.size();
            var++; // Skip the '\0' byte
        }
        FreeEnvironmentStringsW(static_cast<wchar_t*>(parentEnv));
        for(StringSeq::const_iterator p = envs.begin(); p != envs.end(); ++p)
        {
            //
            // IceGrid doesn't support to use string converters, so don't need to use
            // any string converter in stringToWstring conversions.
            //
            wstring s = IceUtil::stringToWstring(*p);
            wstring::size_type pos = s.find(L'=');
            if(pos != wstring::npos)
            {
                envMap[s.substr(0, pos)] = s.substr(pos + 1);
            }
        }

        for(map<wstring, wstring, UnicodeStringLess>::const_iterator q = envMap.begin(); q != envMap.end(); ++q)
        {
            envbuf.append(q->first);
            envbuf.push_back(L'=');
            envbuf.append(q->second);
            envbuf.push_back(L'\0');
        }
        envbuf.push_back(L'\0');
        env = envbuf.c_str();
    }

    Process process;

    STARTUPINFOW si;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);

    PROCESS_INFORMATION pi;
    ZeroMemory(&pi, sizeof(pi));
    BOOL b = CreateProcessW(
        NULL,                     // Executable
        cmdbuf,                   // Command line
        NULL,                     // Process attributes
        NULL,                     // Thread attributes
        FALSE,                    // Do NOT inherit handles
        CREATE_NEW_PROCESS_GROUP | CREATE_UNICODE_ENVIRONMENT, // Process creation flags
        (LPVOID)env,              // Process environment
        dir,                      // Current directory
        &si,                      // Startup info
        &pi                       // Process info
    );

    free(cmdbuf);

    if(!b)
    {
        throw IceUtilInternal::lastErrorToString();
    }

    //
    // Caller is responsible for closing handles in PROCESS_INFORMATION. We don't need to
    // keep the thread handle, so we close it now. The process handle will be closed later.
    //
    CloseHandle(pi.hThread);
    process.activator = this;
    process.pid = pi.dwProcessId;
    process.hnd = pi.hProcess;
    process.server = server;
    map<string, Process>::iterator it = _processes.insert(make_pair(name, process)).first;

    Process* pp = &it->second;
    if(!RegisterWaitForSingleObject(&pp->waithnd, pp->hnd, activatorWaitCallback, pp, INFINITE,
                                    WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE))
    {
        throw IceUtilInternal::lastErrorToString();
    }

    //
    // Don't print the following trace, this might interfer with the
    // output of the started process if it fails with an error message.
    //
//     if(_traceLevels->activator > 0)
//     {
//         Ice::Trace out(_traceLevels->logger, _traceLevels->activatorCat);
//         out << "activated server `" << name << "' (pid = " << pi.dwProcessId << ")";
//     }

    return static_cast<Ice::Int>(process.pid);
#else
    int fds[2];
    if(pipe(fds) != 0)
    {
        SyscallException ex(__FILE__, __LINE__);
        ex.error = getSystemErrno();
        throw ex;
    }

    int errorFds[2];
    if(pipe(errorFds) != 0)
    {
        SyscallException ex(__FILE__, __LINE__);
        ex.error = getSystemErrno();
        throw ex;
    }


    //
    // Convert to standard argc/argv.
    //
    IceUtilInternal::ArgVector av(args);
    IceUtilInternal::ArgVector env(envs);

    //
    // Current directory
    //
    const char* pwdCStr = pwd.c_str();

    pid_t pid = fork();
    if(pid == -1)
    {
        SyscallException ex(__FILE__, __LINE__);
        ex.error = getSystemErrno();
        throw ex;
    }

    if(pid == 0) // Child process.
    {
        //
        // Until exec, we can only use async-signal safe functions
        //

        //
        // Unblock signals blocked by IceUtil::CtrlCHandler.
        //
        sigset_t sigs;
        sigemptyset(&sigs);
        sigaddset(&sigs, SIGHUP);
        sigaddset(&sigs, SIGINT);
        sigaddset(&sigs, SIGTERM);
        sigprocmask(SIG_UNBLOCK, &sigs, 0);

        //
        // Change the uid/gid under which the process will run.
        //
        if(setgid(gid) == -1)
        {
            ostringstream os;
            os << gid;
            reportChildError(getSystemErrno(), errorFds[1], "cannot set process group id", os.str().c_str(),
                             _traceLevels);
        }

        errno = 0;
        struct passwd* pw = getpwuid(uid);
        if(!pw)
        {
            if(errno)
            {
                reportChildError(getSystemErrno(), errorFds[1], "cannot read the password database", "",
                                 _traceLevels);
            }
            else
            {
                ostringstream os;
                os << uid;
                reportChildError(getSystemErrno(), errorFds[1], "unknown user uid"  , os.str().c_str(),
                                 _traceLevels);
            }
        }

        //
        // Don't initialize supplementary groups if we are not running as root.
        //
        if(getuid() == 0 && initgroups(pw->pw_name, gid) == -1)
        {
            ostringstream os;
            os << pw->pw_name;
            reportChildError(getSystemErrno(), errorFds[1], "cannot initialize process supplementary group access list for user",
                             os.str().c_str(), _traceLevels);
        }

        if(setuid(uid) == -1)
        {
            ostringstream os;
            os << uid;
            reportChildError(getSystemErrno(), errorFds[1], "cannot set process user id", os.str().c_str(),
                             _traceLevels);
        }

        //
        // Assign a new process group for this process.
        //
        setpgid(0, 0);

        //
        // Close all file descriptors, except for standard input,
        // standard output, standard error, and the write side
        // of the newly created pipe.
        //
        int maxFd = static_cast<int>(sysconf(_SC_OPEN_MAX));
        for(int fd = 3; fd < maxFd; ++fd)
        {
            if(fd != fds[1] && fd != errorFds[1])
            {
                close(fd);
            }
        }

        for(int i = 0; i < env.argc; i++)
        {
            //
            // Each env is leaked on purpose ... see man putenv().
            //
            if(putenv(strdup(env.argv[i])) != 0)
            {
                reportChildError(errno, errorFds[1], "cannot set environment variable",  env.argv[i],
                                 _traceLevels);
            }
        }

        //
        // Change working directory.
        //
        if(strlen(pwdCStr) != 0)
        {
            if(chdir(pwdCStr) == -1)
            {
                reportChildError(errno, errorFds[1], "cannot change working directory to",  pwdCStr,
                                 _traceLevels);
            }
        }

        //
        // Close on exec the error message file descriptor.
        //
        int flags = fcntl(errorFds[1], F_GETFD);
        flags |= 1; // FD_CLOEXEC
        if(fcntl(errorFds[1], F_SETFD, flags) == -1)
        {
            close(errorFds[1]);
            errorFds[1] = -1;
        }

        if(execvp(av.argv[0], av.argv) == -1)
        {
            if(errorFds[1] != -1)
            {
                reportChildError(errno, errorFds[1], "cannot execute",  av.argv[0], _traceLevels);
            }
            else
            {
                reportChildError(errno, fds[1], "cannot execute",  av.argv[0], _traceLevels);
            }
        }
    }
    else // Parent process.
    {
        close(fds[1]);
        close(errorFds[1]);

        //
        // Read a potential error message over the error message pipe.
        //
        char s[16];
        ssize_t rs;
        string message;
        while((rs = read(errorFds[0], &s, 16)) > 0)
        {
            message.append(s, rs);
        }

        //
        // If an error occured before the exec() we do some cleanup and throw.
        //
        if(!message.empty())
        {
            close(fds[0]);
            close(errorFds[0]);
            waitPid(pid);
            throw message;
        }

        //
        // Otherwise, the exec() was successfull and we don't need the error message
        // pipe anymore.
        //
        close(errorFds[0]);

        Process process;
        process.pid = pid;
        process.pipeFd = fds[0];
        process.server = server;
        _processes.insert(make_pair(name, process));

        int flags = fcntl(process.pipeFd, F_GETFL);
        flags |= O_NONBLOCK;
        fcntl(process.pipeFd, F_SETFL, flags);

        setInterrupt();

    //
    // Don't print the following trace, this might interfere with the
    // output of the started process if it fails with an error message.
    //
//      if(_traceLevels->activator > 0)
//      {
//          Ice::Trace out(_traceLevels->logger, _traceLevels->activatorCat);
//          out << "activated server `" << name << "' (pid = " << pid << ")";
//      }
    }

    return pid;
#endif
}
Esempio n. 27
0
int
main(int argc, char* argv[])
{
#ifdef ICE_STATIC_LIBS
    Ice::registerIceSSL();
#endif

    ifstream in("./config/configPath");
    if(!in)
    {
        test(false);
    }

    if(!getline(in, configPath))
    {
        test(false);
    }
    try
    {
        cout << "testing load properties from UTF-8 path... " << flush;
        Ice::PropertiesPtr properties = Ice::createProperties();
        properties->load(configPath);
        test(properties->getProperty("Ice.Trace.Network") == "1");
        test(properties->getProperty("Ice.Trace.Protocol") == "1");
        test(properties->getProperty("Config.Path") == configPath);
        test(properties->getProperty("Ice.ProgramName") == "PropertiesClient");
        cout << "ok" << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
        return EXIT_FAILURE;
    }

    cout << "testing load properties from UTF-8 path using Ice::Application... " << flush;
    Client c;
    c.main(argc, argv, configPath.c_str());
    cout << "ok" << endl;

    try
    {
        //
        // Try to load multiple config files.
        //
        cout << "testing using Ice.Config with multiple config files... " << flush;
        Ice::PropertiesPtr properties;
        Ice::StringSeq args;
        args.push_back("--Ice.Config=config/config.1, config/config.2, config/config.3");
        properties = Ice::createProperties(args);
        test(properties->getProperty("Config1") == "Config1");
        test(properties->getProperty("Config2") == "Config2");
        test(properties->getProperty("Config3") == "Config3");
        cout << "ok" << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
        return EXIT_FAILURE;
    }

    try
    {
        cout << "testing configuration file escapes... " << flush;
        Ice::PropertiesPtr properties;
        Ice::StringSeq args;
        args.push_back("--Ice.Config=config/escapes.cfg");
        properties = Ice::createProperties(args);

        string props[] = { "Foo\tBar", "3",
                           "Foo\\tBar", "4",
                           "Escape\\ Space", "2",
                           "Prop1", "1",
                           "Prop2", "2",
                           "Prop3", "3",
                           "My Prop1", "1",
                           "My Prop2", "2",
                           "My.Prop1", "a property",
                           "My.Prop2", "a     property",
                           "My.Prop3", "  a     property  ",
                           "My.Prop4", "  a     property  ",
                           "My.Prop5", "a \\ property",
                           "foo=bar", "1",
                           "foo#bar", "2",
                           "foo bar", "3",
                           "A", "1",
                           "B", "2 3 4",
                           "C", "5=#6",
                           "AServer", "\\\\server\\dir",
                           "BServer", "\\server\\dir",
                           ""
        } ;

        for(size_t i = 0; props[i] != ""; i += 2)
        {
            test(properties->getProperty(props[i]) == props[i + 1]);
        }

        cout << "ok" << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Esempio n. 28
0
void
twoways(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrxPtr& p)
{
    {
        p->ice_ping();
    }

    {
#ifdef ICE_CPP11_MAPPING
        test(Test::MyClassPrx::ice_staticId() == Test::MyClassDisp::ice_staticId());
#else
        test(Test::MyClassPrx::ice_staticId() == Test::MyClass::ice_staticId());
#endif
        test(Ice::ObjectPrx::ice_staticId() == Ice::Object::ice_staticId());
    }

    {
        test(p->ice_isA(Test::MyClass::ice_staticId()));
    }

    {
        test(p->ice_id() == Test::MyDerivedClass::ice_staticId());
    }

    {
        Ice::StringSeq ids = p->ice_ids();
        test(ids.size() == 3);
        test(ids[0] == "::Ice::Object");
        test(ids[1] == "::Test::MyClass");
        test(ids[2] == "::Test::MyDerivedClass");
    }

    {
        p->opVoid();
    }

    {
        Ice::Byte b;
        Ice::Byte r;

        r = p->opByte(Ice::Byte(0xff), Ice::Byte(0x0f), b);
        test(b == Ice::Byte(0xf0));
        test(r == Ice::Byte(0xff));
    }

    {
        bool b;
        bool r;

        r = p->opBool(true, false, b);
        test(b);
        test(!r);
    }

    {
        Ice::Short s;
        Ice::Int i;
        Ice::Long l;
        Ice::Long r;

        r = p->opShortIntLong(10, 11, 12, s, i, l);
        test(s == 10);
        test(i == 11);
        test(l == 12);
        test(r == 12);

        r = p->opShortIntLong(numeric_limits<Ice::Short>::min(), numeric_limits<Ice::Int>::min(),
                              numeric_limits<Ice::Long>::min(), s, i, l);
        test(s == numeric_limits<Ice::Short>::min());
        test(i == numeric_limits<Ice::Int>::min());
        test(l == numeric_limits<Ice::Long>::min());
        test(r == numeric_limits<Ice::Long>::min());

        r = p->opShortIntLong(numeric_limits<Ice::Short>::max(), numeric_limits<Ice::Int>::max(),
                              numeric_limits<Ice::Long>::max(), s, i, l);
        test(s == numeric_limits<Ice::Short>::max());
        test(i == numeric_limits<Ice::Int>::max());
        test(l == numeric_limits<Ice::Long>::max());
        test(r == numeric_limits<Ice::Long>::max());
    }

    {
        Ice::Float f;
        Ice::Double d;
        Ice::Double r;

        r = p->opFloatDouble(Ice::Float(3.14), Ice::Double(1.1E10), f, d);
        test(f == Ice::Float(3.14));
        test(d == Ice::Double(1.1E10));
        test(r == Ice::Double(1.1E10));

        r = p->opFloatDouble(numeric_limits<Ice::Float>::min(), numeric_limits<Ice::Double>::min(), f, d);
        test(f == numeric_limits<Ice::Float>::min());
        test(d == numeric_limits<Ice::Double>::min());
        test(r == numeric_limits<Ice::Double>::min());

        r = p->opFloatDouble(numeric_limits<Ice::Float>::max(), numeric_limits<Ice::Double>::max(), f, d);
        test(f == numeric_limits<Ice::Float>::max());
        test(d == numeric_limits<Ice::Double>::max());
        test(r == numeric_limits<Ice::Double>::max());
    }

    {
        string s;
        string r;

        r = p->opString("hello", "world", s);
        test(s == "world hello");
        test(r == "hello world");
    }

    {
        Test::MyEnum e;
        Test::MyEnum r;

        r = p->opMyEnum(ICE_ENUM(MyEnum, enum2), e);
        test(e == ICE_ENUM(MyEnum, enum2));
        test(r == ICE_ENUM(MyEnum, enum3));
    }

    {
        Test::MyClassPrxPtr c1;
        Test::MyClassPrxPtr c2;
        Test::MyClassPrxPtr r;

        r = p->opMyClass(p, c1, c2);
        test(Ice::proxyIdentityAndFacetEqual(c1, p));
        test(!Ice::proxyIdentityAndFacetEqual(c2, p));
        test(Ice::proxyIdentityAndFacetEqual(r, p));
        test(c1->ice_getIdentity() == communicator->stringToIdentity("test"));
        test(c2->ice_getIdentity() == communicator->stringToIdentity("noSuchIdentity"));
        test(r->ice_getIdentity() == communicator->stringToIdentity("test"));
        r->opVoid();
        c1->opVoid();
        try
        {
            c2->opVoid();
            test(false);
        }
        catch(const Ice::ObjectNotExistException&)
        {
        }

        r = p->opMyClass(0, c1, c2);
        test(c1 == 0);
        test(c2 != 0);
        test(Ice::proxyIdentityAndFacetEqual(r, p));
        r->opVoid();
    }


    {
        Test::Structure si1;
        si1.p = p;
        si1.e = ICE_ENUM(MyEnum, enum3);
        si1.s.s = "abc";
        Test::Structure si2;
        si2.p = 0;
        si2.e = ICE_ENUM(MyEnum, enum2);
        si2.s.s = "def";

        Test::Structure so;
        Test::Structure rso = p->opStruct(si1, si2, so);
        test(rso.p == 0);
        test(rso.e == ICE_ENUM(MyEnum, enum2));
        test(rso.s.s == "def");
#ifdef ICE_CPP11_MAPPING
        test(Ice::targetEquals(so.p, p));
#else
        test(so.p == p);
#endif
        test(so.e == ICE_ENUM(MyEnum, enum3));
        test(so.s.s == "a new string");
        so.p->opVoid();
    }

    {
        Test::ByteS bsi1;
        Test::ByteS bsi2;

        bsi1.push_back(Ice::Byte(0x01));
        bsi1.push_back(Ice::Byte(0x11));
        bsi1.push_back(Ice::Byte(0x12));
        bsi1.push_back(Ice::Byte(0x22));

        bsi2.push_back(Ice::Byte(0xf1));
        bsi2.push_back(Ice::Byte(0xf2));
        bsi2.push_back(Ice::Byte(0xf3));
        bsi2.push_back(Ice::Byte(0xf4));

        Test::ByteS bso;
        Test::ByteS rso;

        rso = p->opByteS(bsi1, bsi2, bso);
        test(bso.size() == 4);
        test(bso[0] == Ice::Byte(0x22));
        test(bso[1] == Ice::Byte(0x12));
        test(bso[2] == Ice::Byte(0x11));
        test(bso[3] == Ice::Byte(0x01));
        test(rso.size() == 8);
        test(rso[0] == Ice::Byte(0x01));
        test(rso[1] == Ice::Byte(0x11));
        test(rso[2] == Ice::Byte(0x12));
        test(rso[3] == Ice::Byte(0x22));
        test(rso[4] == Ice::Byte(0xf1));
        test(rso[5] == Ice::Byte(0xf2));
        test(rso[6] == Ice::Byte(0xf3));
        test(rso[7] == Ice::Byte(0xf4));
    }

    {
        Test::BoolS bsi1;
        Test::BoolS bsi2;

        bsi1.push_back(true);
        bsi1.push_back(true);
        bsi1.push_back(false);

        bsi2.push_back(false);

        Test::BoolS bso;
        Test::BoolS rso;

        rso = p->opBoolS(bsi1, bsi2, bso);
        test(bso.size() == 4);
        test(bso[0]);
        test(bso[1]);
        test(!bso[2]);
        test(!bso[3]);
        test(rso.size() == 3);
        test(!rso[0]);
        test(rso[1]);
        test(rso[2]);
    }

    {
        Test::ShortS ssi;
        Test::IntS isi;
        Test::LongS lsi;

        ssi.push_back(1);
        ssi.push_back(2);
        ssi.push_back(3);

        isi.push_back(5);
        isi.push_back(6);
        isi.push_back(7);
        isi.push_back(8);

        lsi.push_back(10);
        lsi.push_back(30);
        lsi.push_back(20);

        Test::ShortS sso;
        Test::IntS iso;
        Test::LongS lso;
        Test::LongS rso;

        rso = p->opShortIntLongS(ssi, isi, lsi, sso, iso, lso);
        test(sso.size() == 3);
        test(sso[0] == 1);
        test(sso[1] == 2);
        test(sso[2] == 3);
        test(iso.size() == 4);
        test(iso[0] == 8);
        test(iso[1] == 7);
        test(iso[2] == 6);
        test(iso[3] == 5);
        test(lso.size() == 6);
        test(lso[0] == 10);
        test(lso[1] == 30);
        test(lso[2] == 20);
        test(lso[3] == 10);
        test(lso[4] == 30);
        test(lso[5] == 20);
        test(rso.size() == 3);
        test(rso[0] == 10);
        test(rso[1] == 30);
        test(rso[2] == 20);
    }

    {
        Test::FloatS fsi;
        Test::DoubleS dsi;

        fsi.push_back(Ice::Float(3.14));
        fsi.push_back(Ice::Float(1.11));

        dsi.push_back(Ice::Double(1.1E10));
        dsi.push_back(Ice::Double(1.2E10));
        dsi.push_back(Ice::Double(1.3E10));

        Test::FloatS fso;
        Test::DoubleS dso;
        Test::DoubleS rso;

        rso = p->opFloatDoubleS(fsi, dsi, fso, dso);
        test(fso.size() == 2);
        test(fso[0] == ::Ice::Float(3.14));
        test(fso[1] == ::Ice::Float(1.11));
        test(dso.size() == 3);
        test(dso[0] == ::Ice::Double(1.3E10));
        test(dso[1] == ::Ice::Double(1.2E10));
        test(dso[2] == ::Ice::Double(1.1E10));
        test(rso.size() == 5);
        test(rso[0] == ::Ice::Double(1.1E10));
        test(rso[1] == ::Ice::Double(1.2E10));
        test(rso[2] == ::Ice::Double(1.3E10));
        test(::Ice::Float(rso[3]) == ::Ice::Float(3.14));
        test(::Ice::Float(rso[4]) == ::Ice::Float(1.11));
    }

    {
        Test::StringS ssi1;
        Test::StringS ssi2;

        ssi1.push_back("abc");
        ssi1.push_back("de");
        ssi1.push_back("fghi");

        ssi2.push_back("xyz");

        Test::StringS sso;
        Test::StringS rso;

        rso = p->opStringS(ssi1, ssi2, sso);
        test(sso.size() == 4);
        test(sso[0] == "abc");
        test(sso[1] == "de");
        test(sso[2] == "fghi");
        test(sso[3] == "xyz");
        test(rso.size() == 3);
        test(rso[0] == "fghi");
        test(rso[1] == "de");
        test(rso[2] == "abc");
    }

    {
        Test::ByteSS bsi1;
        bsi1.resize(2);
        Test::ByteSS bsi2;
        bsi2.resize(2);

        bsi1[0].push_back(Ice::Byte(0x01));
        bsi1[0].push_back(Ice::Byte(0x11));
        bsi1[0].push_back(Ice::Byte(0x12));
        bsi1[1].push_back(Ice::Byte(0xff));

        bsi2[0].push_back(Ice::Byte(0x0e));
        bsi2[1].push_back(Ice::Byte(0xf2));
        bsi2[1].push_back(Ice::Byte(0xf1));

        Test::ByteSS bso;
        Test::ByteSS rso;

        rso = p->opByteSS(bsi1, bsi2, bso);
        test(bso.size() == 2);
        test(bso[0].size() == 1);
        test(bso[0][0] == Ice::Byte(0xff));
        test(bso[1].size() == 3);
        test(bso[1][0] == Ice::Byte(0x01));
        test(bso[1][1] == Ice::Byte(0x11));
        test(bso[1][2] == Ice::Byte(0x12));
        test(rso.size() == 4);
        test(rso[0].size() == 3);
        test(rso[0][0] == Ice::Byte(0x01));
        test(rso[0][1] == Ice::Byte(0x11));
        test(rso[0][2] == Ice::Byte(0x12));
        test(rso[1].size() == 1);
        test(rso[1][0] == Ice::Byte(0xff));
        test(rso[2].size() == 1);
        test(rso[2][0] == Ice::Byte(0x0e));
        test(rso[3].size() == 2);
        test(rso[3][0] == Ice::Byte(0xf2));
        test(rso[3][1] == Ice::Byte(0xf1));
    }

    {
        Test::BoolSS bsi1;
        bsi1.resize(3);
        Test::BoolSS bsi2;
        bsi2.resize(1);

        bsi1[0].push_back(true);
        bsi1[1].push_back(false);
        bsi1[2].push_back(true);
        bsi1[2].push_back(true);

        bsi2[0].push_back(false);
        bsi2[0].push_back(false);
        bsi2[0].push_back(true);

        Test::BoolSS bso;
        Test::BoolSS rso;

        rso = p->opBoolSS(bsi1, bsi2, bso);
        test(bso.size() == 4);
        test(bso[0].size() == 1);
        test(bso[0][0]);
        test(bso[1].size() == 1);
        test(!bso[1][0]);
        test(bso[2].size() == 2);
        test(bso[2][0]);
        test(bso[2][1]);
        test(bso[3].size() == 3);
        test(!bso[3][0]);
        test(!bso[3][1]);
        test(bso[3][2]);
        test(rso.size() == 3);
        test(rso[0].size() == 2);
        test(rso[0][0]);
        test(rso[0][1]);
        test(rso[1].size() == 1);
        test(!rso[1][0]);
        test(rso[2].size() == 1);
        test(rso[2][0]);
    }

    {
        Test::ShortSS ssi;
        ssi.resize(3);
        Test::IntSS isi;
        isi.resize(2);
        Test::LongSS lsi;
        lsi.resize(1);
        ssi[0].push_back(1);
        ssi[0].push_back(2);
        ssi[0].push_back(5);
        ssi[1].push_back(13);
        isi[0].push_back(24);
        isi[0].push_back(98);
        isi[1].push_back(42);
        lsi[0].push_back(496);
        lsi[0].push_back(1729);

        Test::LongSS rso;
        Test::ShortSS sso;
        Test::IntSS iso;
        Test::LongSS lso;

        rso = p->opShortIntLongSS(ssi, isi, lsi, sso, iso, lso);
        test(rso.size() == 1);
        test(rso[0].size() == 2);
        test(rso[0][0] == 496);
        test(rso[0][1] == 1729);
        test(sso.size() == 3);
        test(sso[0].size() == 3);
        test(sso[0][0] == 1);
        test(sso[0][1] == 2);
        test(sso[0][2] == 5);
        test(sso[1].size() == 1);
        test(sso[1][0] == 13);
        test(sso[2].size() == 0);
        test(iso.size() == 2);
        test(iso[0].size() == 1);
        test(iso[0][0] == 42);
        test(iso[1].size() == 2);
        test(iso[1][0] == 24);
        test(iso[1][1] == 98);
        test(lso.size() == 2);
        test(lso[0].size() == 2);
        test(lso[0][0] == 496);
        test(lso[0][1] == 1729);
        test(lso[1].size() == 2);
        test(lso[1][0] == 496);
        test(lso[1][1] == 1729);
    }

    {
        Test::FloatSS fsi;
        fsi.resize(3);
        Test::DoubleSS dsi;
        dsi.resize(1);

        fsi[0].push_back(Ice::Float(3.14));
        fsi[1].push_back(Ice::Float(1.11));

        dsi[0].push_back(Ice::Double(1.1E10));
        dsi[0].push_back(Ice::Double(1.2E10));
        dsi[0].push_back(Ice::Double(1.3E10));

        Test::FloatSS fso;
        Test::DoubleSS dso;
        Test::DoubleSS rso;

        rso = p->opFloatDoubleSS(fsi, dsi, fso, dso);
        test(fso.size() == 3);
        test(fso[0].size() == 1);
        test(fso[0][0] == ::Ice::Float(3.14));
        test(fso[1].size() == 1);
        test(fso[1][0] == ::Ice::Float(1.11));
        test(fso[2].size() == 0);
        test(dso.size() == 1);
        test(dso[0].size() == 3);
        test(dso[0][0] == ::Ice::Double(1.1E10));
        test(dso[0][1] == ::Ice::Double(1.2E10));
        test(dso[0][2] == ::Ice::Double(1.3E10));
        test(rso.size() == 2);
        test(rso[0].size() == 3);
        test(rso[0][0] == ::Ice::Double(1.1E10));
        test(rso[0][1] == ::Ice::Double(1.2E10));
        test(rso[0][2] == ::Ice::Double(1.3E10));
        test(rso[1].size() == 3);
        test(rso[1][0] == ::Ice::Double(1.1E10));
        test(rso[1][1] == ::Ice::Double(1.2E10));
        test(rso[1][2] == ::Ice::Double(1.3E10));
    }

    {
        Test::StringSS ssi1;
        ssi1.resize(2);
        Test::StringSS ssi2;
        ssi2.resize(3);

        ssi1[0].push_back("abc");
        ssi1[1].push_back("de");
        ssi1[1].push_back("fghi");

        ssi2[2].push_back("xyz");

        Test::StringSS sso;
        Test::StringSS rso;

        rso = p->opStringSS(ssi1, ssi2, sso);
        test(sso.size() == 5);
        test(sso[0].size() == 1);
        test(sso[0][0] == "abc");
        test(sso[1].size() == 2);
        test(sso[1][0] == "de");
        test(sso[1][1] == "fghi");
        test(sso[2].size() == 0);
        test(sso[3].size() == 0);
        test(sso[4].size() == 1);
        test(sso[4][0] == "xyz");
        test(rso.size() == 3);
        test(rso[0].size() == 1);
        test(rso[0][0] == "xyz");
        test(rso[1].size() == 0);
        test(rso[2].size() == 0);
    }

    {
        Test::StringSSS sssi1;
        sssi1.resize(2);
        sssi1[0].resize(2);
        sssi1[0][0].push_back("abc");
        sssi1[0][0].push_back("de");
        sssi1[0][1].push_back("xyz");
        sssi1[1].resize(1);
        sssi1[1][0].push_back("hello");

        Test::StringSSS sssi2;
        sssi2.resize(3);
        sssi2[0].resize(2);
        sssi2[0][0].push_back("");
        sssi2[0][0].push_back("");
        sssi2[0][1].push_back("abcd");
        sssi2[1].resize(1);
        sssi2[1][0].push_back("");

        Test::StringSSS ssso;
        Test::StringSSS rsso;

        rsso = p->opStringSSS(sssi1, sssi2, ssso);
        test(ssso.size() == 5);
        test(ssso[0].size() == 2);
        test(ssso[0][0].size() == 2);
        test(ssso[0][1].size() == 1);
        test(ssso[1].size() == 1);
        test(ssso[1][0].size() == 1);
        test(ssso[2].size() == 2);
        test(ssso[2][0].size() == 2);
        test(ssso[2][1].size() == 1);
        test(ssso[3].size() == 1);
        test(ssso[3][0].size() == 1);
        test(ssso[4].size() == 0);
        test(ssso[0][0][0] == "abc");
        test(ssso[0][0][1] == "de");
        test(ssso[0][1][0] == "xyz");
        test(ssso[1][0][0] == "hello");
        test(ssso[2][0][0] == "");
        test(ssso[2][0][1] == "");
        test(ssso[2][1][0] == "abcd");
        test(ssso[3][0][0] == "");

        test(rsso.size() == 3);
        test(rsso[0].size() == 0);
        test(rsso[1].size() == 1);
        test(rsso[1][0].size() == 1);
        test(rsso[2].size() == 2);
        test(rsso[2][0].size() == 2);
        test(rsso[2][1].size() == 1);
        test(rsso[1][0][0] == "");
        test(rsso[2][0][0] == "");
        test(rsso[2][0][1] == "");
        test(rsso[2][1][0] == "abcd");
    }

    {
        Test::ByteBoolD di1;
        di1[10] = true;
        di1[100] = false;
        Test::ByteBoolD di2;
        di2[10] = true;
        di2[11] = false;
        di2[101] = true;

        Test::ByteBoolD _do;
        Test::ByteBoolD ro = p->opByteBoolD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro[10] == true);
        test(ro[11] == false);
        test(ro[100] == false);
        test(ro[101] == true);
    }

    {
        Test::ShortIntD di1;
        di1[110] = -1;
        di1[1100] = 123123;
        Test::ShortIntD di2;
        di2[110] = -1;
        di2[111] = -100;
        di2[1101] = 0;

        Test::ShortIntD _do;
        Test::ShortIntD ro = p->opShortIntD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro[110] == -1);
        test(ro[111] == -100);
        test(ro[1100] == 123123);
        test(ro[1101] == 0);
    }

    {
        Test::LongFloatD di1;
        di1[999999110] = Ice::Float(-1.1);
        di1[999999111] = Ice::Float(123123.2);
        Test::LongFloatD di2;
        di2[999999110] = Ice::Float(-1.1);
        di2[999999120] = Ice::Float(-100.4);
        di2[999999130] = Ice::Float(0.5);

        Test::LongFloatD _do;
        Test::LongFloatD ro = p->opLongFloatD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro[999999110] == Ice::Float(-1.1));
        test(ro[999999120] == Ice::Float(-100.4));
        test(ro[999999111] == Ice::Float(123123.2));
        test(ro[999999130] == Ice::Float(0.5));
    }

    {
        Test::StringStringD di1;
        di1["foo"] = "abc -1.1";
        di1["bar"] = "abc 123123.2";
        Test::StringStringD di2;
        di2["foo"] = "abc -1.1";
        di2["FOO"] = "abc -100.4";
        di2["BAR"] = "abc 0.5";

        Test::StringStringD _do;
        Test::StringStringD ro = p->opStringStringD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro["foo"] == "abc -1.1");
        test(ro["FOO"] == "abc -100.4");
        test(ro["bar"] == "abc 123123.2");
        test(ro["BAR"] == "abc 0.5");
    }

    {
        Test::StringMyEnumD di1;
        di1["abc"] = ICE_ENUM(MyEnum, enum1);
        di1[""] = ICE_ENUM(MyEnum, enum2);
        Test::StringMyEnumD di2;
        di2["abc"] = ICE_ENUM(MyEnum, enum1);
        di2["qwerty"] = ICE_ENUM(MyEnum, enum3);
        di2["Hello!!"] = ICE_ENUM(MyEnum, enum2);

        Test::StringMyEnumD _do;
        Test::StringMyEnumD ro = p->opStringMyEnumD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro["abc"] == ICE_ENUM(MyEnum, enum1));
        test(ro["qwerty"] == ICE_ENUM(MyEnum, enum3));
        test(ro[""] == ICE_ENUM(MyEnum, enum2));
        test(ro["Hello!!"] == ICE_ENUM(MyEnum, enum2));
    }

    {
        Test::MyEnumStringD di1;
        di1[ICE_ENUM(MyEnum, enum1)] = "abc";
        Test::MyEnumStringD di2;
        di2[ICE_ENUM(MyEnum, enum2)] = "Hello!!";
        di2[ICE_ENUM(MyEnum, enum3)] = "qwerty";

        Test::MyEnumStringD _do;
        Test::MyEnumStringD ro = p->opMyEnumStringD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 3);
        test(ro[ICE_ENUM(MyEnum, enum1)] == "abc");
        test(ro[ICE_ENUM(MyEnum, enum2)] == "Hello!!");
        test(ro[ICE_ENUM(MyEnum, enum3)] == "qwerty");
    }

    {
        Test::MyStruct s11 = { 1, 1 };
        Test::MyStruct s12 = { 1, 2 };
        Test::MyStructMyEnumD di1;
        di1[s11] = ICE_ENUM(MyEnum, enum1);
        di1[s12] = ICE_ENUM(MyEnum, enum2);

        Test::MyStruct s22 = { 2, 2 };
        Test::MyStruct s23 = { 2, 3 };
        Test::MyStructMyEnumD di2;
        di2[s11] = ICE_ENUM(MyEnum, enum1);
        di2[s22] = ICE_ENUM(MyEnum, enum3);
        di2[s23] = ICE_ENUM(MyEnum, enum2);

        Test::MyStructMyEnumD _do;
        Test::MyStructMyEnumD ro = p->opMyStructMyEnumD(di1, di2, _do);

        test(_do == di1);
        test(ro.size() == 4);
        test(ro[s11] == ICE_ENUM(MyEnum, enum1));
        test(ro[s12] == ICE_ENUM(MyEnum, enum2));
        test(ro[s22] == ICE_ENUM(MyEnum, enum3));
        test(ro[s23] == ICE_ENUM(MyEnum, enum2));
    }

    {
        Test::ByteBoolDS dsi1;
        dsi1.resize(2);
        Test::ByteBoolDS dsi2;
        dsi2.resize(1);

        Test::ByteBoolD di1;
        di1[10] = true;
        di1[100] = false;
        Test::ByteBoolD di2;
        di2[10] = true;
        di2[11] = false;
        di2[101] = true;
        Test::ByteBoolD di3;
        di3[100] = false;
        di3[101] = false;

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try {
            Test::ByteBoolDS _do;
            Test::ByteBoolDS ro = p->opByteBoolDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0][10] == true);
            test(ro[0][11] == false);
            test(ro[0][101] == true);
            test(ro[1].size() == 2);
            test(ro[1][10] == true);
            test(ro[1][100] == false);

            test(_do.size() == 3);
            test(_do[0].size() == 2);
            test(_do[0][100] == false);
            test(_do[0][101] == false);
            test(_do[1].size() == 2);
            test(_do[1][10] == true);
            test(_do[1][100] == false);
            test(_do[2].size() == 3);
            test(_do[2][10] == true);
            test(_do[2][11] == false);
            test(_do[2][101] == true);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::ShortIntDS dsi1;
        dsi1.resize(2);
        Test::ShortIntDS dsi2;
        dsi2.resize(1);

        Test::ShortIntD di1;
        di1[110] = -1;
        di1[1100] = 123123;
        Test::ShortIntD di2;
        di2[110] = -1;
        di2[111] = -100;
        di2[1101] = 0;
        Test::ShortIntD di3;
        di3[100] = -1001;

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::ShortIntDS _do;
            Test::ShortIntDS ro = p->opShortIntDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0][110] == -1);
            test(ro[0][111] == -100);
            test(ro[0][1101] == 0);
            test(ro[1].size() == 2);
            test(ro[1][110] == -1);
            test(ro[1][1100] == 123123);

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0][100] == -1001);
            test(_do[1].size() == 2);
            test(_do[1][110] == -1);
            test(_do[1][1100] == 123123);
            test(_do[2].size() == 3);
            test(_do[2][110] == -1);
            test(_do[2][111] == -100);
            test(_do[2][1101] == 0);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::LongFloatDS dsi1;
        dsi1.resize(2);
        Test::LongFloatDS dsi2;
        dsi2.resize(1);

        Test::LongFloatD di1;
        di1[999999110] = Ice::Float(-1.1);
        di1[999999111] = Ice::Float(123123.2);
        Test::LongFloatD di2;
        di2[999999110] = Ice::Float(-1.1);
        di2[999999120] = Ice::Float(-100.4);
        di2[999999130] = Ice::Float(0.5);
        Test::LongFloatD di3;
        di3[999999140] = Ice::Float(3.14);

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::LongFloatDS _do;
            Test::LongFloatDS ro = p->opLongFloatDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0][999999110] == Ice::Float(-1.1));
            test(ro[0][999999120] == Ice::Float(-100.4));
            test(ro[0][999999130] == Ice::Float(0.5));
            test(ro[1].size() == 2);
            test(ro[1][999999110] == Ice::Float(-1.1));
            test(ro[1][999999111] == Ice::Float(123123.2));

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0][999999140] == Ice::Float(3.14));
            test(_do[1].size() == 2);
            test(_do[1][999999110] == Ice::Float(-1.1));
            test(_do[1][999999111] == Ice::Float(123123.2));
            test(_do[2].size() == 3);
            test(_do[2][999999110] == Ice::Float(-1.1));
            test(_do[2][999999120] == Ice::Float(-100.4));
            test(_do[2][999999130] == Ice::Float(0.5));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::StringStringDS dsi1;
        dsi1.resize(2);
        Test::StringStringDS dsi2;
        dsi2.resize(1);

        Test::StringStringD di1;
        di1["foo"] = "abc -1.1";
        di1["bar"] = "abc 123123.2";
        Test::StringStringD di2;
        di2["foo"] = "abc -1.1";
        di2["FOO"] = "abc -100.4";
        di2["BAR"] = "abc 0.5";
        Test::StringStringD di3;
        di3["f00"] = "ABC -3.14";

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::StringStringDS _do;
            Test::StringStringDS ro = p->opStringStringDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0]["foo"] == "abc -1.1");
            test(ro[0]["FOO"] == "abc -100.4");
            test(ro[0]["BAR"] == "abc 0.5");
            test(ro[1].size() == 2);
            test(ro[1]["foo"] == "abc -1.1");
            test(ro[1]["bar"] == "abc 123123.2");

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0]["f00"] == "ABC -3.14");
            test(_do[1].size() == 2);
            test(_do[1]["foo"] == "abc -1.1");
            test(_do[1]["bar"] == "abc 123123.2");
            test(_do[2].size() == 3);
            test(_do[2]["foo"] == "abc -1.1");
            test(_do[2]["FOO"] == "abc -100.4");
            test(_do[2]["BAR"] == "abc 0.5");
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::StringMyEnumDS dsi1;
        dsi1.resize(2);
        Test::StringMyEnumDS dsi2;
        dsi2.resize(1);

        Test::StringMyEnumD di1;
        di1["abc"] = ICE_ENUM(MyEnum, enum1);
        di1[""] = ICE_ENUM(MyEnum, enum2);
        Test::StringMyEnumD di2;
        di2["abc"] = ICE_ENUM(MyEnum, enum1);
        di2["qwerty"] = ICE_ENUM(MyEnum, enum3);
        di2["Hello!!"] = ICE_ENUM(MyEnum, enum2);
        Test::StringMyEnumD di3;
        di3["Goodbye"] = ICE_ENUM(MyEnum, enum1);

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::StringMyEnumDS _do;
            Test::StringMyEnumDS ro = p->opStringMyEnumDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0]["abc"] == ICE_ENUM(MyEnum, enum1));
            test(ro[0]["qwerty"] == ICE_ENUM(MyEnum, enum3));
            test(ro[0]["Hello!!"] == ICE_ENUM(MyEnum, enum2));
            test(ro[1].size() == 2);
            test(ro[1]["abc"] == ICE_ENUM(MyEnum, enum1));
            test(ro[1][""] == ICE_ENUM(MyEnum, enum2));

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0]["Goodbye"] == ICE_ENUM(MyEnum, enum1));
            test(_do[1].size() == 2);
            test(_do[1]["abc"] == ICE_ENUM(MyEnum, enum1));
            test(_do[1][""] == ICE_ENUM(MyEnum, enum2));
            test(_do[2].size() == 3);
            test(_do[2]["abc"] == ICE_ENUM(MyEnum, enum1));
            test(_do[2]["qwerty"] == ICE_ENUM(MyEnum, enum3));
            test(_do[2]["Hello!!"] == ICE_ENUM(MyEnum, enum2));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::MyEnumStringDS dsi1;
        dsi1.resize(2);
        Test::MyEnumStringDS dsi2;
        dsi2.resize(1);

        Test::MyEnumStringD di1;
        di1[ICE_ENUM(MyEnum, enum1)] = "abc";
        Test::MyEnumStringD di2;
        di2[ICE_ENUM(MyEnum, enum2)] = "Hello!!";
        di2[ICE_ENUM(MyEnum, enum3)] = "qwerty";
        Test::MyEnumStringD di3;
        di3[ICE_ENUM(MyEnum, enum1)] = "Goodbye";

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::MyEnumStringDS _do;
            Test::MyEnumStringDS ro = p->opMyEnumStringDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 2);
            test(ro[0][ICE_ENUM(MyEnum, enum2)] == "Hello!!");
            test(ro[0][ICE_ENUM(MyEnum, enum3)] == "qwerty");
            test(ro[1].size() == 1);
            test(ro[1][ICE_ENUM(MyEnum, enum1)] == "abc");

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0][ICE_ENUM(MyEnum, enum1)] == "Goodbye");
            test(_do[1].size() == 1);
            test(_do[1][ICE_ENUM(MyEnum, enum1)] == "abc");
            test(_do[2].size() == 2);
            test(_do[2][ICE_ENUM(MyEnum, enum2)] == "Hello!!");
            test(_do[2][ICE_ENUM(MyEnum, enum3)] == "qwerty");
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::MyStructMyEnumDS dsi1;
        dsi1.resize(2);
        Test::MyStructMyEnumDS dsi2;
        dsi2.resize(1);

        Test::MyStruct s11 = { 1, 1 };
        Test::MyStruct s12 = { 1, 2 };
        Test::MyStructMyEnumD di1;
        di1[s11] = ICE_ENUM(MyEnum, enum1);
        di1[s12] = ICE_ENUM(MyEnum, enum2);

        Test::MyStruct s22 = { 2, 2 };
        Test::MyStruct s23 = { 2, 3 };
        Test::MyStructMyEnumD di2;
        di2[s11] = ICE_ENUM(MyEnum, enum1);
        di2[s22] = ICE_ENUM(MyEnum, enum3);
        di2[s23] = ICE_ENUM(MyEnum, enum2);

        Test::MyStructMyEnumD di3;
        di3[s23] = ICE_ENUM(MyEnum, enum3);

        dsi1[0] = di1;
        dsi1[1] = di2;
        dsi2[0] = di3;

        try
        {
            Test::MyStructMyEnumDS _do;
            Test::MyStructMyEnumDS ro = p->opMyStructMyEnumDS(dsi1, dsi2, _do);

            test(ro.size() == 2);
            test(ro[0].size() == 3);
            test(ro[0][s11] == ICE_ENUM(MyEnum, enum1));
            test(ro[0][s22] == ICE_ENUM(MyEnum, enum3));
            test(ro[0][s23] == ICE_ENUM(MyEnum, enum2));
            test(ro[1].size() == 2);
            test(ro[1][s11] == ICE_ENUM(MyEnum, enum1));
            test(ro[1][s12] == ICE_ENUM(MyEnum, enum2));

            test(_do.size() == 3);
            test(_do[0].size() == 1);
            test(_do[0][s23] == ICE_ENUM(MyEnum, enum3));
            test(_do[1].size() == 2);
            test(_do[1][s11] == ICE_ENUM(MyEnum, enum1));
            test(_do[1][s12] == ICE_ENUM(MyEnum, enum2));
            test(_do[2].size() == 3);
            test(_do[2][s11] == ICE_ENUM(MyEnum, enum1));
            test(_do[2][s22] == ICE_ENUM(MyEnum, enum3));
            test(_do[2][s23] == ICE_ENUM(MyEnum, enum2));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::ByteByteSD sdi1;
        Test::ByteByteSD sdi2;

        Test::ByteS si1;
        Test::ByteS si2;
        Test::ByteS si3;

        si1.push_back(Ice::Byte(0x01));
        si1.push_back(Ice::Byte(0x11));
        si2.push_back(Ice::Byte(0x12));
        si3.push_back(Ice::Byte(0xf2));
        si3.push_back(Ice::Byte(0xf3));

        sdi1[Ice::Byte(0x01)] = si1;
        sdi1[Ice::Byte(0x22)] = si2;
        sdi2[Ice::Byte(0xf1)] = si3;

        try
        {
            Test::ByteByteSD _do;
            Test::ByteByteSD ro = p->opByteByteSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro[Ice::Byte(0x01)].size() == 2);
            test(ro[Ice::Byte(0x01)][0] == Ice::Byte(0x01));
            test(ro[Ice::Byte(0x01)][1] == Ice::Byte(0x11));
            test(ro[Ice::Byte(0x22)].size() == 1);
            test(ro[Ice::Byte(0x22)][0] == Ice::Byte(0x12));
            test(ro[Ice::Byte(0xf1)].size() == 2);
            test(ro[Ice::Byte(0xf1)][0] == Ice::Byte(0xf2));
            test(ro[Ice::Byte(0xf1)][1] == Ice::Byte(0xf3));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::BoolBoolSD sdi1;
        Test::BoolBoolSD sdi2;

        Test::BoolS si1;
        Test::BoolS si2;

        si1.push_back(true);
        si1.push_back(false);
        si2.push_back(false);
        si2.push_back(true);
        si2.push_back(true);

        sdi1[false] = si1;
        sdi1[true] = si2;
        sdi2[false] = si1;

        try
        {
            Test::BoolBoolSD _do;
            Test::BoolBoolSD ro = p->opBoolBoolSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 2);
            test(ro[false].size() == 2);
            test(ro[false][0] == true);
            test(ro[false][1] == false);
            test(ro[true].size() == 3);
            test(ro[true][0] == false);
            test(ro[true][1] == true);
            test(ro[true][2] == true);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::ShortShortSD sdi1;
        Test::ShortShortSD sdi2;

        Test::ShortS si1;
        Test::ShortS si2;
        Test::ShortS si3;

        si1.push_back(1);
        si1.push_back(2);
        si1.push_back(3);
        si2.push_back(4);
        si2.push_back(5);
        si3.push_back(6);
        si3.push_back(7);

        sdi1[1] = si1;
        sdi1[2] = si2;
        sdi2[4] = si3;

        try
        {
            Test::ShortShortSD _do;
            Test::ShortShortSD ro = p->opShortShortSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro[1].size() == 3);
            test(ro[1][0] == 1);
            test(ro[1][1] == 2);
            test(ro[1][2] == 3);
            test(ro[2].size() == 2);
            test(ro[2][0] == 4);
            test(ro[2][1] == 5);
            test(ro[4].size() == 2);
            test(ro[4][0] == 6);
            test(ro[4][1] == 7);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::IntIntSD sdi1;
        Test::IntIntSD sdi2;

        Test::IntS si1;
        Test::IntS si2;
        Test::IntS si3;

        si1.push_back(100);
        si1.push_back(200);
        si1.push_back(300);
        si2.push_back(400);
        si2.push_back(500);
        si3.push_back(600);
        si3.push_back(700);

        sdi1[100] = si1;
        sdi1[200] = si2;
        sdi2[400] = si3;

        try
        {
            Test::IntIntSD _do;
            Test::IntIntSD ro = p->opIntIntSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro[100].size() == 3);
            test(ro[100][0] == 100);
            test(ro[100][1] == 200);
            test(ro[100][2] == 300);
            test(ro[200].size() == 2);
            test(ro[200][0] == 400);
            test(ro[200][1] == 500);
            test(ro[400].size() == 2);
            test(ro[400][0] == 600);
            test(ro[400][1] == 700);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::LongLongSD sdi1;
        Test::LongLongSD sdi2;

        Test::LongS si1;
        Test::LongS si2;
        Test::LongS si3;

        si1.push_back(999999110);
        si1.push_back(999999111);
        si1.push_back(999999110);
        si2.push_back(999999120);
        si2.push_back(999999130);
        si3.push_back(999999110);
        si3.push_back(999999120);

        sdi1[999999990] = si1;
        sdi1[999999991] = si2;
        sdi2[999999992] = si3;

        try
        {
            Test::LongLongSD _do;
            Test::LongLongSD ro = p->opLongLongSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro[999999990].size() == 3);
            test(ro[999999990][0] == 999999110);
            test(ro[999999990][1] == 999999111);
            test(ro[999999990][2] == 999999110);
            test(ro[999999991].size() == 2);
            test(ro[999999991][0] == 999999120);
            test(ro[999999991][1] == 999999130);
            test(ro[999999992].size() == 2);
            test(ro[999999992][0] == 999999110);
            test(ro[999999992][1] == 999999120);
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::StringFloatSD sdi1;
        Test::StringFloatSD sdi2;

        Test::FloatS si1;
        Test::FloatS si2;
        Test::FloatS si3;

        si1.push_back(Ice::Float(-1.1));
        si1.push_back(Ice::Float(123123.2));
        si1.push_back(Ice::Float(100.0));
        si2.push_back(Ice::Float(42.24));
        si2.push_back(Ice::Float(-1.61));
        si3.push_back(Ice::Float(-3.14));
        si3.push_back(Ice::Float(3.14));

        sdi1["abc"] = si1;
        sdi1["ABC"] = si2;
        sdi2["aBc"] = si3;

        try
        {
            Test::StringFloatSD _do;
            Test::StringFloatSD ro = p->opStringFloatSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro["abc"].size() == 3);
            test(ro["abc"][0] == Ice::Float(-1.1));
            test(ro["abc"][1] == Ice::Float(123123.2));
            test(ro["abc"][2] == Ice::Float(100.0));
            test(ro["ABC"].size() == 2);
            test(ro["ABC"][0] == Ice::Float(42.24));
            test(ro["ABC"][1] == Ice::Float(-1.61));
            test(ro["aBc"].size() == 2);
            test(ro["aBc"][0] == Ice::Float(-3.14));
            test(ro["aBc"][1] == Ice::Float(3.14));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::StringDoubleSD sdi1;
        Test::StringDoubleSD sdi2;

        Test::DoubleS si1;
        Test::DoubleS si2;
        Test::DoubleS si3;

        si1.push_back(Ice::Double(1.1E10));
        si1.push_back(Ice::Double(1.2E10));
        si1.push_back(Ice::Double(1.3E10));
        si2.push_back(Ice::Double(1.4E10));
        si2.push_back(Ice::Double(1.5E10));
        si3.push_back(Ice::Double(1.6E10));
        si3.push_back(Ice::Double(1.7E10));

        sdi1["Hello!!"] = si1;
        sdi1["Goodbye"] = si2;
        sdi2[""] = si3;

        try
        {
            Test::StringDoubleSD _do;
            Test::StringDoubleSD ro = p->opStringDoubleSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro["Hello!!"].size() == 3);
            test(ro["Hello!!"][0] == Ice::Double(1.1E10));
            test(ro["Hello!!"][1] == Ice::Double(1.2E10));
            test(ro["Hello!!"][2] == Ice::Double(1.3E10));
            test(ro["Goodbye"].size() == 2);
            test(ro["Goodbye"][0] == Ice::Double(1.4E10));
            test(ro["Goodbye"][1] == Ice::Double(1.5E10));
            test(ro[""].size() == 2);
            test(ro[""][0] == Ice::Double(1.6E10));
            test(ro[""][1] == Ice::Double(1.7E10));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::StringStringSD sdi1;
        Test::StringStringSD sdi2;

        Test::StringS si1;
        Test::StringS si2;
        Test::StringS si3;

        si1.push_back("abc");
        si1.push_back("de");
        si1.push_back("fghi");

        si2.push_back("xyz");
        si2.push_back("or");

        si3.push_back("and");
        si3.push_back("xor");

        sdi1["abc"] = si1;
        sdi1["def"] = si2;
        sdi2["ghi"] = si3;

        try
        {
            Test::StringStringSD _do;
            Test::StringStringSD ro = p->opStringStringSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro["abc"].size() == 3);
            test(ro["abc"][0] == "abc");
            test(ro["abc"][1] == "de");
            test(ro["abc"][2] == "fghi");
            test(ro["def"].size() == 2);
            test(ro["def"][0] == "xyz");
            test(ro["def"][1] == "or");
            test(ro["ghi"].size() == 2);
            test(ro["ghi"][0] == "and");
            test(ro["ghi"][1] == "xor");
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        Test::MyEnumMyEnumSD sdi1;
        Test::MyEnumMyEnumSD sdi2;

        Test::MyEnumS si1;
        Test::MyEnumS si2;
        Test::MyEnumS si3;

        si1.push_back(ICE_ENUM(MyEnum, enum1));
        si1.push_back(ICE_ENUM(MyEnum, enum1));
        si1.push_back(ICE_ENUM(MyEnum, enum2));
        si2.push_back(ICE_ENUM(MyEnum, enum1));
        si2.push_back(ICE_ENUM(MyEnum, enum2));
        si3.push_back(ICE_ENUM(MyEnum, enum3));
        si3.push_back(ICE_ENUM(MyEnum, enum3));

        sdi1[ICE_ENUM(MyEnum, enum3)] = si1;
        sdi1[ICE_ENUM(MyEnum, enum2)] = si2;
        sdi2[ICE_ENUM(MyEnum, enum1)] = si3;

        try
        {
            Test::MyEnumMyEnumSD _do;
            Test::MyEnumMyEnumSD ro = p->opMyEnumMyEnumSD(sdi1, sdi2, _do);

            test(_do == sdi2);
            test(ro.size() == 3);
            test(ro[ICE_ENUM(MyEnum, enum3)].size() == 3);
            test(ro[ICE_ENUM(MyEnum, enum3)][0] == ICE_ENUM(MyEnum, enum1));
            test(ro[ICE_ENUM(MyEnum, enum3)][1] == ICE_ENUM(MyEnum, enum1));
            test(ro[ICE_ENUM(MyEnum, enum3)][2] == ICE_ENUM(MyEnum, enum2));
            test(ro[ICE_ENUM(MyEnum, enum2)].size() == 2);
            test(ro[ICE_ENUM(MyEnum, enum2)][0] == ICE_ENUM(MyEnum, enum1));
            test(ro[ICE_ENUM(MyEnum, enum2)][1] == ICE_ENUM(MyEnum, enum2));
            test(ro[ICE_ENUM(MyEnum, enum1)].size() == 2);
            test(ro[ICE_ENUM(MyEnum, enum1)][0] == ICE_ENUM(MyEnum, enum3));
            test(ro[ICE_ENUM(MyEnum, enum1)][1] == ICE_ENUM(MyEnum, enum3));
        }
        catch(const Ice::OperationNotExistException&)
        {
        }
    }

    {
        const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 };

        for(unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l)
        {
            Test::IntS s;
            for(int i = 0; i < lengths[l]; ++i)
            {
                s.push_back(i);
            }
            Test::IntS r = p->opIntS(s);
            test(r.size() == static_cast<size_t>(lengths[l]));
            for(int j = 0; j < static_cast<int>(r.size()); ++j)
            {
                test(r[j] == -j);
            }
        }
    }

    {
        Ice::Context ctx;
        ctx["one"] = "ONE";
        ctx["two"] = "TWO";
        ctx["three"] = "THREE";
        {
            Test::StringStringD r = p->opContext();
            test(p->ice_getContext().empty());
            test(r != ctx);
        }
        {
            Test::StringStringD r = p->opContext(ctx);
            test(p->ice_getContext().empty());
            test(r == ctx);
        }
        {
            Test::MyClassPrxPtr p2 = ICE_CHECKED_CAST(Test::MyClassPrx, p->ice_context(ctx));
            test(p2->ice_getContext() == ctx);
            Test::StringStringD r = p2->opContext();
            test(r == ctx);
            r = p2->opContext(ctx);
            test(r == ctx);
        }

#ifndef ICE_OS_WINRT
        if(p->ice_getConnection() && communicator->getProperties()->getProperty("Ice.Default.Protocol") != "bt")
        {
            //
            // Test implicit context propagation
            //

            string impls[] = {"Shared", "PerThread"};
            for(int i = 0; i < 2; i++)
            {
                Ice::InitializationData initData;
                initData.properties = communicator->getProperties()->clone();
                initData.properties->setProperty("Ice.ImplicitContext", impls[i]);

                Ice::CommunicatorPtr ic = Ice::initialize(initData);

                Ice::Context ctx;
                ctx["one"] = "ONE";
                ctx["two"] = "TWO";
                ctx["three"] = "THREE";

                Test::MyClassPrxPtr p = ICE_UNCHECKED_CAST(Test::MyClassPrx,
                                                           ic->stringToProxy("test:" + getTestEndpoint(ic, 0)));

                ic->getImplicitContext()->setContext(ctx);
                test(ic->getImplicitContext()->getContext() == ctx);
                test(p->opContext() == ctx);

                test(ic->getImplicitContext()->containsKey("zero") == false);
                string r = ic->getImplicitContext()->put("zero", "ZERO");
                test(r == "");
                test(ic->getImplicitContext()->containsKey("zero") == true);
                test(ic->getImplicitContext()->get("zero") == "ZERO");

                ctx = ic->getImplicitContext()->getContext();
                test(p->opContext() == ctx);
                Ice::Context prxContext;
                prxContext["one"] = "UN";
                prxContext["four"] = "QUATRE";

                Ice::Context combined = prxContext;
                combined.insert(ctx.begin(), ctx.end());
                test(combined["one"] == "UN");

                p = ICE_UNCHECKED_CAST(Test::MyClassPrx, p->ice_context(prxContext));

                ic->getImplicitContext()->setContext(Ice::Context());
                test(p->opContext() == prxContext);

                ic->getImplicitContext()->setContext(ctx);
                test(p->opContext() == combined);

                test(ic->getImplicitContext()->remove("one") == "ONE");

                if(impls[i] == "PerThread")
                {
                    IceUtil::ThreadPtr thread = new PerThreadContextInvokeThread(p->ice_context(Ice::Context()));
                    thread->start();
                    thread->getThreadControl().join();
                }

                ic->getImplicitContext()->setContext(Ice::Context()); // Clear the context to avoid leak report.
                ic->destroy();
            }
        }
#endif
        }

    {
        Ice::Double d = 1278312346.0 / 13.0;
        Test::DoubleS ds(5, d);
        p->opDoubleMarshaling(d, ds);
    }

    p->opIdempotent();

    p->opNonmutating();

    test(p->opByte1(0xFF) == 0xFF);
    test(p->opShort1(0x7FFF) == 0x7FFF);
    test(p->opInt1(0x7FFFFFFF) == 0x7FFFFFFF);
    test(p->opLong1(0x7FFFFFFFFFFFFFFFLL) == 0x7FFFFFFFFFFFFFFFLL);
    test(p->opFloat1(1.0) == 1.0);
    test(p->opDouble1(1.0) == 1.0);
    test(p->opString1("opString1") == "opString1");

    Test::MyDerivedClassPrxPtr d = ICE_UNCHECKED_CAST(Test::MyDerivedClassPrx, p);

    Test::MyStruct1 s;
    s.tesT = "Test::MyStruct1::s";
    s.myClass = 0;
    s.myStruct1 = "Test::MyStruct1::myStruct1";
    s = d->opMyStruct1(s);
    test(s.tesT == "Test::MyStruct1::s");
    test(s.myClass == 0);
    test(s.myStruct1 == "Test::MyStruct1::myStruct1");

    Test::MyClass1Ptr c = ICE_MAKE_SHARED(Test::MyClass1);
    c->tesT = "Test::MyClass1::testT";
    c->myClass = 0;
    c->myClass1 = "Test::MyClass1::myClass1";
    c = d->opMyClass1(c);
    test(c->tesT == "Test::MyClass1::testT");
    test(c->myClass == 0);
    test(c->myClass1 == "Test::MyClass1::myClass1");

    Test::StringS seq;
    p->opStringS1(seq);

    Test::ByteBoolD dict;
    p->opByteBoolD1(dict);


}
Esempio n. 29
0
void
allTests(const Ice::CommunicatorPtr& communicator)
{
    string ref = "DemoIceBox/admin:default -p 9996 -t 10000";
    Ice::ObjectPrx admin = communicator->stringToProxy(ref);

    TestFacetPrx facet;

    cout << "testing custom facet... " << flush;
    {
        //
        // Test: Verify that the custom facet is present.
        //
        facet = Test::TestFacetPrx::checkedCast(admin, "TestFacet");
        facet->ice_ping();
    }
    cout << "ok" << endl;

    cout << "testing properties facet... " << flush;
    {
        Ice::PropertiesAdminPrx pa =
            Ice::PropertiesAdminPrx::checkedCast(admin, "IceBox.Service.TestService.Properties");

        //
        // Test: PropertiesAdmin::getProperty()
        //
        test(pa->getProperty("Prop1") == "1");
        test(pa->getProperty("Bogus") == "");

        //
        // Test: PropertiesAdmin::getProperties()
        //
        Ice::PropertyDict pd = pa->getPropertiesForPrefix("");
        test(pd.size() == 5);
        test(pd["Prop1"] == "1");
        test(pd["Prop2"] == "2");
        test(pd["Prop3"] == "3");
        test(pd["Ice.Config"] == "config.service");
        test(pd["Ice.ProgramName"] == "IceBox-TestService");

        Ice::PropertyDict changes;

        //
        // Test: PropertiesAdmin::setProperties()
        //
        Ice::PropertyDict setProps;
        setProps["Prop1"] = "10"; // Changed
        setProps["Prop2"] = "20"; // Changed
        setProps["Prop3"] = ""; // Removed
        setProps["Prop4"] = "4"; // Added
        setProps["Prop5"] = "5"; // Added
        pa->setProperties(setProps);
        test(pa->getProperty("Prop1") == "10");
        test(pa->getProperty("Prop2") == "20");
        test(pa->getProperty("Prop3") == "");
        test(pa->getProperty("Prop4") == "4");
        test(pa->getProperty("Prop5") == "5");
        changes = facet->getChanges();
        test(changes.size() == 5);
        test(changes["Prop1"] == "10");
        test(changes["Prop2"] == "20");
        test(changes["Prop3"] == "");
        test(changes["Prop4"] == "4");
        test(changes["Prop5"] == "5");
        pa->setProperties(setProps);
        changes = facet->getChanges();
        test(changes.empty());
    }
    cout << "ok" << endl;

    cout << "testing metrics admin facet... " << flush;
    {
        IceMX::MetricsAdminPrx ma = IceMX::MetricsAdminPrx::checkedCast(admin, "IceBox.Service.TestService.Metrics");

        Ice::PropertiesAdminPrx pa =
            Ice::PropertiesAdminPrx::checkedCast(admin, "IceBox.Service.TestService.Properties");

        Ice::StringSeq views;
        Ice::StringSeq disabledViews;
        views = ma->getMetricsViewNames(disabledViews);
        test(views.empty());

        Ice::PropertyDict setProps;
        setProps["IceMX.Metrics.Debug.GroupBy"] = "id";
        setProps["IceMX.Metrics.All.GroupBy"] = "none";
        setProps["IceMX.Metrics.Parent.GroupBy"] = "parent";
        pa->setProperties(setProps);
        pa->setProperties(Ice::PropertyDict());

        views = ma->getMetricsViewNames(disabledViews);
        test(views.size() == 3);
        
        // Make sure that the IceBox communicator metrics admin is a separate instance.
        test(IceMX::MetricsAdminPrx::checkedCast(admin, "Metrics")->getMetricsViewNames(disabledViews).empty());
    }
    cout << "ok" << endl;
}
Esempio n. 30
0
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;
}