コード例 #1
0
 static minie_backend_client()
 {
     string[] parray = new string[] {"--Ice.Plugin.IceSSL=IceSSL.dll:IceSSL.PluginFactory",
         "--IceSSL.DefaultDir=.",
         "--IceSSL.CAs=root.pem",
         "--IceSSL.CertFile=client.p12",
         "--IceSSL.VerifyPeer=2",
         "--Ice.ThreadPool.Server.SizeMax=8",
         "--Ice.ThreadPool.Client.SizeMax=16",
         "--Ice.MessageSizeMax=10485760",
         "--Ice.Override.ConnectTimeout=5000",
         "--Ice.Override.Timeout=5000"};
     //Ice.InitializationData inid = new Ice.InitializationData();
     //inid.properties = Ice.Util.createProperties();
     //inid.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.dll:IceSSL.PluginFactory");
     //inid.properties.setProperty("IceSSL.DefaultDir", ".");
     //inid.properties.setProperty("IceSSL.CAs", "root.pem");
     //inid.properties.setProperty("IceSSL.CertFile", "client.p12");
     //inid.properties.setProperty("IceSSL.VerifyPeer", "2");
     //inid.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "8");
     //inid.properties.setProperty("Ice.ThreadPool.Client.SizeMax", "16");
     //inid.properties.setProperty("Ice.MessageSizeMax", "10485760");
     //inid.properties.setProperty("Ice.Override.ConnectTimeout", "5000");
     //inid.properties.setProperty("Ice.Override.Timeout", "5000");
     s_ic = Ice.Util.initialize(ref parray);
     s_adapter = s_ic.createObjectAdapter("");
     s_adapter.activate();
 }
コード例 #2
0
 static minie_backend_client()
 {
     string[] parray = new string[] { "--Ice.Plugin.IceSSL=IceSSL.dll:IceSSL.PluginFactory",
                                      "--IceSSL.DefaultDir=.",
                                      "--IceSSL.CAs=root.pem",
                                      "--IceSSL.CertFile=client.p12",
                                      "--IceSSL.VerifyPeer=2",
                                      "--Ice.ThreadPool.Server.SizeMax=8",
                                      "--Ice.ThreadPool.Client.SizeMax=16",
                                      "--Ice.MessageSizeMax=10485760",
                                      "--Ice.Override.ConnectTimeout=5000",
                                      "--Ice.Override.Timeout=5000" };
     //Ice.InitializationData inid = new Ice.InitializationData();
     //inid.properties = Ice.Util.createProperties();
     //inid.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.dll:IceSSL.PluginFactory");
     //inid.properties.setProperty("IceSSL.DefaultDir", ".");
     //inid.properties.setProperty("IceSSL.CAs", "root.pem");
     //inid.properties.setProperty("IceSSL.CertFile", "client.p12");
     //inid.properties.setProperty("IceSSL.VerifyPeer", "2");
     //inid.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "8");
     //inid.properties.setProperty("Ice.ThreadPool.Client.SizeMax", "16");
     //inid.properties.setProperty("Ice.MessageSizeMax", "10485760");
     //inid.properties.setProperty("Ice.Override.ConnectTimeout", "5000");
     //inid.properties.setProperty("Ice.Override.Timeout", "5000");
     s_ic      = Ice.Util.initialize(ref parray);
     s_adapter = s_ic.createObjectAdapter("");
     s_adapter.activate();
 }
コード例 #3
0
        public void Init(IceOptions options, IClusterClient orleansClient, IObserverClient observerClient)
        {
            try
            {
                var initData = new Ice.InitializationData();
                //设置日志输出
                if (options.Logger == null)
                {
                    options.Logger = new FootStone.Core.NLogice(NLog.LogManager.GetLogger("Ice"));
                }
                initData.logger     = options.Logger;
                initData.properties = Ice.Util.createProperties();
                initData.properties.load(options.ConfigFile);

                communicator = Ice.Util.initialize(initData);
                var adapter    = communicator.createObjectAdapter("SessionFactoryAdapter");
                var properties = communicator.getProperties();
                var id         = Ice.Util.stringToIdentity(properties.getProperty("Identity"));
                var serverName = properties.getProperty("Ice.ProgramName");
                adapter.add(new SessionFactoryI(serverName, initData.logger), id);
                //添加facet
                foreach (var facet in options.FacetTypes)
                {
                    if (facet.type is IServantBase)
                    {
                        options.Logger.error($"Facet(${facet.type.Name}) must inherit IServantBase!!!");
                        continue;
                    }
                    object[] args        = new object[] { orleansClient, observerClient };
                    var      servant     = (IServantBase)Activator.CreateInstance(facet.type, args);
                    var      intercpetor = new FSInterceptor((Ice.Object)servant, options.Logger);
                    adapter.addFacet(intercpetor, id, facet.name);
                }
                adapter.activate();
                options.Logger.print("Ice inited!");
            }
            catch (Ice.Exception ex)
            {
                options.Logger.error("Ice init failed:" + ex.ToString());
            }
        }
コード例 #4
0
ファイル: AllTests.cs プロジェクト: zj771484545/ice
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp");
                Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter");
                PingReplyI        replyI  = new PingReplyI();

                Test.PingReplyPrx reply =
                    (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                adapter.activate();

                Console.Out.Write("testing udp... ");
                Console.Out.Flush();
                Ice.ObjectPrx    @base = communicator.stringToProxy("test:" + helper.getTestEndpoint(0, "udp")).ice_datagram();
                Test.TestIntfPrx obj   = Test.TestIntfPrxHelper.uncheckedCast(@base);

                int  nRetry = 5;
                bool ret    = false;

                while (nRetry-- > 0)
                {
                    replyI.reset();
                    obj.ping(reply);
                    obj.ping(reply);
                    obj.ping(reply);
                    ret = replyI.waitReply(3, 2000);
                    if (ret)
                    {
                        break; // Success
                    }

                    // If the 3 datagrams were not received within the 2 seconds, we try again to
                    // receive 3 new datagrams using a new object. We give up after 5 retries.
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                test(ret == true);

                if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0)
                {
                    //
                    // Only run this test if compression is disabled, the test expect fixed message size
                    // to be sent over the wire.
                    //
                    byte[] seq = null;
                    try
                    {
                        seq = new byte[1024];
                        while (true)
                        {
                            seq = new byte[seq.Length * 2 + 10];
                            replyI.reset();
                            obj.sendByteSeq(seq, reply);
                            replyI.waitReply(1, 10000);
                        }
                    }
                    catch (Ice.DatagramLimitException)
                    {
                        //
                        // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                        // will be throw when try to send a packet bigger than that.
                        //
                        test(seq.Length > 16384);
                    }
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000");
                    seq = new byte[50000];
                    try
                    {
                        replyI.reset();
                        obj.sendByteSeq(seq, reply);

                        bool b = replyI.waitReply(1, 500);
                        //
                        // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                        // should not be delivered.
                        //
                        test(!b);
                    }
                    catch (Ice.DatagramLimitException)
                    {
                    }
                    catch (Ice.LocalException ex)
                    {
                        Console.Out.WriteLine(ex);
                        test(false);
                    }
                }

                Console.Out.WriteLine("ok");

                Console.Out.Write("testing udp multicast... ");
                Console.Out.Flush();
                StringBuilder endpoint = new StringBuilder();

                //
                // Use loopback to prevent other machines to answer.
                //
                if (communicator.getProperties().getProperty("Ice.IPv6") == "1")
                {
                    endpoint.Append("udp -h \"ff15::1:1\"");
                    if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS)
                    {
                        endpoint.Append(" --interface \"::1\"");
                    }
                }
                else
                {
                    endpoint.Append("udp -h 239.255.1.1");
                    if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS)
                    {
                        endpoint.Append(" --interface 127.0.0.1");
                    }
                }
                endpoint.Append(" -p ");
                endpoint.Append(helper.getTestPort(10));
                @base = communicator.stringToProxy("test -d:" + endpoint.ToString());
                var objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base);

                nRetry = 5;
                while (nRetry-- > 0)
                {
                    replyI.reset();
                    try
                    {
                        objMcast.ping(reply);
                    }
                    catch (Ice.SocketException)
                    {
                        if (communicator.getProperties().getProperty("Ice.IPv6") == "1")
                        {
                            // Multicast IPv6 not supported on the platform. This occurs for example on macOS big_suir
                            Console.Out.Write("(not supported) ");
                            ret = true;
                            break;
                        }
                        throw;
                    }
                    ret = replyI.waitReply(5, 5000);
                    if (ret)
                    {
                        break;
                    }
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                if (!ret)
                {
                    Console.Out.WriteLine("failed(is a firewall enabled?)");
                }
                else
                {
                    Console.Out.WriteLine("ok");
                }

                Console.Out.Write("testing udp bi-dir connection... ");
                Console.Out.Flush();
                obj.ice_getConnection().setAdapter(adapter);
                nRetry = 5;
                while (nRetry-- > 0)
                {
                    replyI.reset();
                    obj.pingBiDir(reply.ice_getIdentity());
                    obj.pingBiDir(reply.ice_getIdentity());
                    obj.pingBiDir(reply.ice_getIdentity());
                    ret = replyI.waitReply(3, 2000);
                    if (ret)
                    {
                        break; // Success
                    }
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                test(ret);
                Console.Out.WriteLine("ok");

                //
                // Sending the replies back on the multicast UDP connection doesn't work for most
                // platform(it works for macOS Leopard but not Snow Leopard, doesn't work on SLES,
                // Windows...). For Windows, see UdpTransceiver constructor for the details. So
                // we don't run this test.
                //
                //         Console.Out.Write("testing udp bi-dir connection... ");
                //         nRetry = 5;
                //         while(nRetry-- > 0)
                //         {
                //             replyI.reset();
                //             objMcast.pingBiDir(reply.ice_getIdentity());
                //             ret = replyI.waitReply(5, 2000);
                //             if(ret)
                //             {
                //                 break; // Success
                //             }
                //             replyI = new PingReplyI();
                //             reply =(PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                //         }

                //         if(!ret)
                //         {
                //             Console.Out.WriteLine("failed(is a firewall enabled?)");
                //         }
                //         else
                //         {
                //             Console.Out.WriteLine("ok");
                //         }
            }
コード例 #5
0
            public override void startServer(Ice.Current current)
            {
                foreach (Ice.Communicator c in _communicators)
                {
                    c.waitForShutdown();
                    c.destroy();
                }
                _communicators.Clear();

                //
                // Simulate a server: create a new communicator and object
                // adapter. The object adapter is started on a system allocated
                // port. The configuration used here contains the Ice.Locator
                // configuration variable. The new object adapter will register
                // its endpoints with the locator and create references containing
                // the adapter id instead of the endpoints.
                //
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = _helper.communicator().getProperties().ice_clone_();
                initData.properties.setProperty("TestAdapter.AdapterId", "TestAdapter");
                initData.properties.setProperty("TestAdapter.ReplicaGroupId", "ReplicatedAdapter");
                initData.properties.setProperty("TestAdapter2.AdapterId", "TestAdapter2");

                Ice.Communicator serverCommunicator = _helper.initialize(initData);
                _communicators.Add(serverCommunicator);

                //
                // Use fixed port to ensure that OA re-activation doesn't re-use previous port from
                // another OA(e.g.: TestAdapter2 is re-activated using port of TestAdapter).
                //
                int nRetry = 10;

                while (--nRetry > 0)
                {
                    Ice.ObjectAdapter adapter  = null;
                    Ice.ObjectAdapter adapter2 = null;
                    try
                    {
                        serverCommunicator.getProperties().setProperty("TestAdapter.Endpoints",
                                                                       _helper.getTestEndpoint(_nextPort++));
                        serverCommunicator.getProperties().setProperty("TestAdapter2.Endpoints",
                                                                       _helper.getTestEndpoint(_nextPort++));

                        adapter  = serverCommunicator.createObjectAdapter("TestAdapter");
                        adapter2 = serverCommunicator.createObjectAdapter("TestAdapter2");

                        Ice.ObjectPrx locator = serverCommunicator.stringToProxy("locator:" + _helper.getTestEndpoint(0));
                        adapter.setLocator(Ice.LocatorPrxHelper.uncheckedCast(locator));
                        adapter2.setLocator(Ice.LocatorPrxHelper.uncheckedCast(locator));

                        Ice.Object @object = new TestI(adapter, adapter2, _registry);
                        _registry.addObject(adapter.add(@object, Ice.Util.stringToIdentity("test")));
                        _registry.addObject(adapter.add(@object, Ice.Util.stringToIdentity("test2")));
                        adapter.add(@object, Ice.Util.stringToIdentity("test3"));

                        adapter.activate();
                        adapter2.activate();
                        break;
                    }
                    catch (Ice.SocketException ex)
                    {
                        if (nRetry == 0)
                        {
                            throw ex;
                        }

                        // Retry, if OA creation fails with EADDRINUSE(this can occur when running with JS web
                        // browser clients if the driver uses ports in the same range as this test, ICE-8148)
                        if (adapter != null)
                        {
                            adapter.destroy();
                        }
                        if (adapter2 != null)
                        {
                            adapter2.destroy();
                        }
                    }
                }
            }
コード例 #6
0
ファイル: AllTests.cs プロジェクト: zk2013/ice
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing communicator operations... ");
                output.Flush();
                {
                    //
                    // Test: Exercise addAdminFacet, findAdminFacet, removeAdminFacet with a typical configuration.
                    //
                    Ice.InitializationData init = new Ice.InitializationData();
                    init.properties = Ice.Util.createProperties();
                    init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    init.properties.setProperty("Ice.Admin.InstanceName", "Test");
                    Ice.Communicator com = Ice.Util.initialize(init);
                    testFacets(com, true);
                    com.destroy();
                }
                {
                    //
                    // Test: Verify that the operations work correctly in the presence of facet filters.
                    //
                    Ice.InitializationData init = new Ice.InitializationData();
                    init.properties = Ice.Util.createProperties();
                    init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    init.properties.setProperty("Ice.Admin.InstanceName", "Test");
                    init.properties.setProperty("Ice.Admin.Facets", "Properties");
                    Ice.Communicator com = Ice.Util.initialize(init);
                    testFacets(com, false);
                    com.destroy();
                }
                {
                    //
                    // Test: Verify that the operations work correctly with the Admin object disabled.
                    //
                    Ice.Communicator com = Ice.Util.initialize();
                    testFacets(com, false);
                    com.destroy();
                }
                {
                    //
                    // Test: Verify that the operations work correctly with Ice.Admin.Enabled=1
                    //
                    Ice.InitializationData init = new Ice.InitializationData();
                    init.properties = Ice.Util.createProperties();
                    init.properties.setProperty("Ice.Admin.Enabled", "1");
                    Ice.Communicator com = Ice.Util.initialize(init);
                    test(com.getAdmin() == null);
                    Ice.Identity id = Ice.Util.stringToIdentity("test-admin");
                    try
                    {
                        com.createAdmin(null, id);
                        test(false);
                    }
                    catch (Ice.InitializationException)
                    {
                    }

                    Ice.ObjectAdapter adapter = com.createObjectAdapter("");
                    test(com.createAdmin(adapter, id) != null);
                    test(com.getAdmin() != null);

                    testFacets(com, true);
                    com.destroy();
                }
                {
                    //
                    // Test: Verify that the operations work correctly when creation of the Admin object is delayed.
                    //
                    Ice.InitializationData init = new Ice.InitializationData();
                    init.properties = Ice.Util.createProperties();
                    init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    init.properties.setProperty("Ice.Admin.InstanceName", "Test");
                    init.properties.setProperty("Ice.Admin.DelayCreation", "1");
                    Ice.Communicator com = Ice.Util.initialize(init);
                    testFacets(com, true);
                    com.getAdmin();
                    testFacets(com, true);
                    com.destroy();
                }
                output.WriteLine("ok");

                string @ref = "factory:" + helper.getTestEndpoint(0) + " -t 10000";

                Test.RemoteCommunicatorFactoryPrx factory =
                    Test.RemoteCommunicatorFactoryPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

                output.Write("testing process facet... ");
                output.Flush();
                {
                    //
                    // Test: Verify that Process::shutdown() operation shuts down the communicator.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    var            com  = factory.createCommunicator(props);
                    Ice.ObjectPrx  obj  = com.getAdmin();
                    Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
                    proc.shutdown();
                    com.waitForShutdown();
                    com.destroy();
                }
                output.WriteLine("ok");

                output.Write("testing properties facet... ");
                output.Flush();
                {
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Prop1", "1");
                    props.Add("Prop2", "2");
                    props.Add("Prop3", "3");
                    var                    com = factory.createCommunicator(props);
                    Ice.ObjectPrx          obj = com.getAdmin();
                    Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");

                    //
                    // Test: PropertiesAdmin::getProperty()
                    //
                    test(pa.getProperty("Prop2").Equals("2"));
                    test(pa.getProperty("Bogus").Equals(""));

                    //
                    // Test: PropertiesAdmin::getProperties()
                    //
                    Dictionary <string, string> pd = pa.getPropertiesForPrefix("");
                    test(pd.Count == 5);
                    test(pd["Ice.Admin.Endpoints"].Equals("tcp -h 127.0.0.1"));
                    test(pd["Ice.Admin.InstanceName"].Equals("Test"));
                    test(pd["Prop1"].Equals("1"));
                    test(pd["Prop2"].Equals("2"));
                    test(pd["Prop3"].Equals("3"));

                    Dictionary <string, string> changes;

                    //
                    // Test: PropertiesAdmin::setProperties()
                    //
                    Dictionary <string, string> setProps = new Dictionary <string, string>();
                    setProps.Add("Prop1", "10"); // Changed
                    setProps.Add("Prop2", "20"); // Changed
                    setProps.Add("Prop3", "");   // Removed
                    setProps.Add("Prop4", "4");  // Added
                    setProps.Add("Prop5", "5");  // Added
                    pa.setProperties(setProps);
                    test(pa.getProperty("Prop1").Equals("10"));
                    test(pa.getProperty("Prop2").Equals("20"));
                    test(pa.getProperty("Prop3").Equals(""));
                    test(pa.getProperty("Prop4").Equals("4"));
                    test(pa.getProperty("Prop5").Equals("5"));
                    changes = com.getChanges();
                    test(changes.Count == 5);
                    test(changes["Prop1"].Equals("10"));
                    test(changes["Prop2"].Equals("20"));
                    test(changes["Prop3"].Equals(""));
                    test(changes["Prop4"].Equals("4"));
                    test(changes["Prop5"].Equals("5"));
                    pa.setProperties(setProps);
                    changes = com.getChanges();
                    test(changes.Count == 0);

                    com.destroy();
                }
                output.WriteLine("ok");

                output.Write("testing logger facet... ");
                output.Flush();
                {
                    Dictionary <String, String> props = new Dictionary <String, String>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("NullLogger", "1");
                    var com = factory.createCommunicator(props);

                    com.trace("testCat", "trace");
                    com.warning("warning");
                    com.error("error");
                    com.print("print");

                    Ice.ObjectPrx      obj    = com.getAdmin();
                    Ice.LoggerAdminPrx logger = Ice.LoggerAdminPrxHelper.checkedCast(obj, "Logger");
                    test(logger != null);

                    string prefix = null;

                    //
                    // Get all
                    //
                    Ice.LogMessage[] logMessages = logger.getLog(null, null, -1, out prefix);

                    test(logMessages.Length == 4);
                    test(prefix.Equals("NullLogger"));
                    test(logMessages[0].traceCategory.Equals("testCat") && logMessages[0].message.Equals("trace"));
                    test(logMessages[1].message.Equals("warning"));
                    test(logMessages[2].message.Equals("error"));
                    test(logMessages[3].message.Equals("print"));

                    //
                    // Get only errors and warnings
                    //
                    com.error("error2");
                    com.print("print2");
                    com.trace("testCat", "trace2");
                    com.warning("warning2");

                    Ice.LogMessageType[] messageTypes =
                    {
                        Ice.LogMessageType.ErrorMessage,
                        Ice.LogMessageType.WarningMessage
                    };

                    logMessages = logger.getLog(messageTypes, null, -1, out prefix);

                    test(logMessages.Length == 4);
                    test(prefix.Equals("NullLogger"));

                    foreach (var msg in logMessages)
                    {
                        test(msg.type == Ice.LogMessageType.ErrorMessage ||
                             msg.type == Ice.LogMessageType.WarningMessage);
                    }

                    //
                    // Get only errors and traces with Cat = "testCat"
                    //
                    com.trace("testCat2", "A");
                    com.trace("testCat", "trace3");
                    com.trace("testCat2", "B");

                    messageTypes = new Ice.LogMessageType[] {
                        Ice.LogMessageType.ErrorMessage,
                        Ice.LogMessageType.TraceMessage
                    };
                    string[] categories = { "testCat" };
                    logMessages = logger.getLog(messageTypes, categories, -1, out prefix);
                    test(logMessages.Length == 5);
                    test(prefix.Equals("NullLogger"));

                    foreach (var msg in logMessages)
                    {
                        test(msg.type == Ice.LogMessageType.ErrorMessage ||
                             (msg.type == Ice.LogMessageType.TraceMessage && msg.traceCategory.Equals("testCat")));
                    }

                    //
                    // Same, but limited to last 2 messages(trace3 + error3)
                    //
                    com.error("error3");

                    logMessages = logger.getLog(messageTypes, categories, 2, out prefix);
                    test(logMessages.Length == 2);
                    test(prefix.Equals("NullLogger"));

                    test(logMessages[0].message.Equals("trace3"));
                    test(logMessages[1].message.Equals("error3"));

                    //
                    // Now, test RemoteLogger
                    //
                    Ice.ObjectAdapter adapter =
                        communicator.createObjectAdapterWithEndpoints("RemoteLoggerAdapter", "tcp -h localhost");

                    RemoteLoggerI remoteLogger = new RemoteLoggerI();

                    Ice.RemoteLoggerPrx myProxy =
                        Ice.RemoteLoggerPrxHelper.uncheckedCast(adapter.addWithUUID(remoteLogger));

                    adapter.activate();

                    //
                    // No filtering
                    //
                    logMessages = logger.getLog(null, null, -1, out prefix);

                    logger.attachRemoteLogger(myProxy, null, null, -1);
                    remoteLogger.wait(1);

                    foreach (var m in logMessages)
                    {
                        remoteLogger.checkNextInit(prefix, m.type, m.message, m.traceCategory);
                    }

                    com.trace("testCat", "rtrace");
                    com.warning("rwarning");
                    com.error("rerror");
                    com.print("rprint");

                    remoteLogger.wait(4);

                    remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace", "testCat");
                    remoteLogger.checkNextLog(Ice.LogMessageType.WarningMessage, "rwarning", "");
                    remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror", "");
                    remoteLogger.checkNextLog(Ice.LogMessageType.PrintMessage, "rprint", "");

                    test(logger.detachRemoteLogger(myProxy));
                    test(!logger.detachRemoteLogger(myProxy));

                    //
                    // Use Error + Trace with "traceCat" filter with 4 limit
                    //
                    logMessages = logger.getLog(messageTypes, categories, 4, out prefix);
                    test(logMessages.Length == 4);

                    logger.attachRemoteLogger(myProxy, messageTypes, categories, 4);
                    remoteLogger.wait(1);

                    foreach (var m in logMessages)
                    {
                        remoteLogger.checkNextInit(prefix, m.type, m.message, m.traceCategory);
                    }

                    com.warning("rwarning2");
                    com.trace("testCat", "rtrace2");
                    com.warning("rwarning3");
                    com.error("rerror2");
                    com.print("rprint2");

                    remoteLogger.wait(2);

                    remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace2", "testCat");
                    remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror2", "");

                    //
                    // Attempt reconnection with slightly different proxy
                    //
                    try
                    {
                        logger.attachRemoteLogger(Ice.RemoteLoggerPrxHelper.uncheckedCast(myProxy.ice_oneway()),
                                                  messageTypes, categories, 4);
                        test(false);
                    }
                    catch (Ice.RemoteLoggerAlreadyAttachedException)
                    {
                        // expected
                    }

                    com.destroy();
                }
                output.WriteLine("ok");

                output.Write("testing custom facet... ");
                output.Flush();
                {
                    //
                    // Test: Verify that the custom facet is present.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    var           com = factory.createCommunicator(props);
                    Ice.ObjectPrx obj = com.getAdmin();
                    var           tf  = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet");
                    tf.op();
                    com.destroy();
                }
                output.WriteLine("ok");

                output.Write("testing facet filtering... ");
                output.Flush();
                {
                    //
                    // Test: Set Ice.Admin.Facets to expose only the Properties facet,
                    // meaning no other facet is available.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Ice.Admin.Facets", "Properties");
                    var            com  = factory.createCommunicator(props);
                    Ice.ObjectPrx  obj  = com.getAdmin();
                    Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
                    test(proc == null);
                    var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet");
                    test(tf == null);
                    com.destroy();
                }
                {
                    //
                    // Test: Set Ice.Admin.Facets to expose only the Process facet,
                    // meaning no other facet is available.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Ice.Admin.Facets", "Process");
                    var                    com = factory.createCommunicator(props);
                    Ice.ObjectPrx          obj = com.getAdmin();
                    Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
                    test(pa == null);
                    var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet");
                    test(tf == null);
                    com.destroy();
                }
                {
                    //
                    // Test: Set Ice.Admin.Facets to expose only the TestFacet facet,
                    // meaning no other facet is available.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Ice.Admin.Facets", "TestFacet");
                    var                    com = factory.createCommunicator(props);
                    Ice.ObjectPrx          obj = com.getAdmin();
                    Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
                    test(pa == null);
                    Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
                    test(proc == null);
                    com.destroy();
                }
                {
                    //
                    // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the
                    // facet names.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Ice.Admin.Facets", "Properties TestFacet");
                    var                    com = factory.createCommunicator(props);
                    Ice.ObjectPrx          obj = com.getAdmin();
                    Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
                    test(pa.getProperty("Ice.Admin.InstanceName").Equals("Test"));
                    var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet");
                    tf.op();
                    Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
                    test(proc == null);
                    com.destroy();
                }
                {
                    //
                    // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the
                    // facet names.
                    //
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
                    props.Add("Ice.Admin.InstanceName", "Test");
                    props.Add("Ice.Admin.Facets", "TestFacet, Process");
                    var                    com = factory.createCommunicator(props);
                    Ice.ObjectPrx          obj = com.getAdmin();
                    Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
                    test(pa == null);
                    var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet");
                    tf.op();
                    Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
                    proc.shutdown();
                    com.waitForShutdown();
                    com.destroy();
                }
                output.WriteLine("ok");

                factory.shutdown();
            }
コード例 #7
0
            public static Test.ITestIntfPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing stringToProxy... ");
                output.Flush();
                string @ref = "test:" + helper.getTestEndpoint(0);

                Ice.IObjectPrx @base = IObjectPrx.Parse(@ref, communicator);
                test(@base != null);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                var obj = Test.ITestIntfPrx.CheckedCast(@base);

                test(obj != null);
                test(obj.Equals(@base));
                output.WriteLine("ok");

                {
                    output.Write("creating/destroying/recreating object adapter... ");
                    output.Flush();
                    ObjectAdapter adapter =
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                        test(false);
                    }
                    catch (ArgumentException)
                    {
                    }
                    adapter.Destroy();

                    //
                    // Use a different port than the first adapter to avoid an "address already in use" error.
                    //
                    adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    adapter.Destroy();
                    output.WriteLine("ok");
                }

                output.Write("creating/activating/deactivating object adapter in one operation... ");
                output.Flush();
                obj.transient();
                obj.transientAsync().Wait();
                output.WriteLine("ok");

                {
                    output.Write("testing connection closure... ");
                    output.Flush();
                    for (int i = 0; i < 10; ++i)
                    {
                        var comm = new Communicator(communicator.GetProperties());
                        IObjectPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator).IcePingAsync();
                        comm.destroy();
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter published endpoints... ");
                output.Flush();
                {
                    communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000");
                    var adapter = communicator.createObjectAdapter("PAdapter");
                    test(adapter.GetPublishedEndpoints().Length == 1);
                    var endpt = adapter.GetPublishedEndpoints()[0];
                    test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000"));
                    var prx = IObjectPrx.Parse("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000", communicator);
                    adapter.SetPublishedEndpoints(prx.Endpoints);
                    test(adapter.GetPublishedEndpoints().Length == 2);
                    test(Collections.Equals(adapter.CreateProxy(new Identity("dummy", "")).Endpoints, prx.Endpoints));
                    test(Collections.Equals(adapter.GetPublishedEndpoints(), prx.Endpoints));
                    adapter.RefreshPublishedEndpoints();
                    test(adapter.GetPublishedEndpoints().Length == 1);
                    test(adapter.GetPublishedEndpoints()[0].Equals(endpt));
                    communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000");
                    adapter.RefreshPublishedEndpoints();
                    test(adapter.GetPublishedEndpoints().Length == 1);
                    test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000"));
                    adapter.Destroy();
                    test(adapter.GetPublishedEndpoints().Length == 0);
                }
                output.WriteLine("ok");

                if (obj.GetConnection() != null)
                {
                    output.Write("testing object adapter with bi-dir connection... ");
                    output.Flush();
                    var adapter = communicator.createObjectAdapter("");
                    obj.GetConnection().setAdapter(adapter);
                    obj.GetConnection().setAdapter(null);
                    adapter.Deactivate();
                    try
                    {
                        obj.GetConnection().setAdapter(adapter);
                        test(false);
                    }
                    catch (ObjectAdapterDeactivatedException)
                    {
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter with router... ");
                output.Flush();
                {
                    var routerId = new Identity();
                    routerId.name = "router";
                    var router  = IRouterPrx.UncheckedCast(@base.Clone(routerId, connectionId: "rc"));
                    var adapter = communicator.createObjectAdapterWithRouter("", router);
                    test(adapter.GetPublishedEndpoints().Length == 1);
                    test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000"));
                    adapter.RefreshPublishedEndpoints();
                    test(adapter.GetPublishedEndpoints().Length == 1);
                    test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000"));
                    try
                    {
                        adapter.SetPublishedEndpoints(router.Endpoints);
                        test(false);
                    }
                    catch (ArgumentException)
                    {
                        // Expected.
                    }
                    adapter.Destroy();

                    try
                    {
                        routerId.name = "test";
                        router        = IRouterPrx.UncheckedCast(@base.Clone(routerId));
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (OperationNotExistException)
                    {
                        // Expected: the "test" object doesn't implement Ice::Router!
                    }

                    try
                    {
                        router = IRouterPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator);
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (ConnectFailedException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing object adapter creation with port in use... ");
                output.Flush();
                {
                    var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10));
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10));
                        test(false);
                    }
                    catch (LocalException)
                    {
                        // Expected can't re-use the same endpoint.
                    }
                    adapter1.Destroy();
                }
                output.WriteLine("ok");

                output.Write("deactivating object adapter in the server... ");
                output.Flush();
                obj.deactivate();
                output.WriteLine("ok");

                output.Write("testing whether server is gone... ");
                output.Flush();
                try
                {
                    obj.Clone(connectionTimeout: 100).IcePing(); // Use timeout to speed up testing on Windows
                    test(false);
                }
                catch (LocalException)
                {
                    output.WriteLine("ok");
                }

                return(obj);
            }
コード例 #8
0
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                string           @ref         = "communicator:" + helper.getTestEndpoint(0);

                Test.RemoteCommunicatorPrx com = Test.RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

                var rand   = new Random(unchecked ((int)DateTime.Now.Ticks));
                var output = helper.getWriter();

                output.Write("testing binding with single endpoint... ");
                output.Flush();
                {
                    Test.RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default");

                    var test1 = adapter.getTestIntf();
                    var test2 = adapter.getTestIntf();
                    test(test1.ice_getConnection() == test2.ice_getConnection());

                    test1.ice_ping();
                    test2.ice_ping();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1);
                    test(test3.ice_getConnection() == test1.ice_getConnection());
                    test(test3.ice_getConnection() == test2.ice_getConnection());

                    try
                    {
                        test3.ice_ping();
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter11", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter12", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("Adapter11");
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.ice_ping();
                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(test1.getAdapterName());
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_ping();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = t.getAdapterName();
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[0]);
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(test1.getAdapterName());
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple random endpoints... ");
                output.Flush();
                {
                    var adapters = new Test.RemoteObjectAdapterPrx[5];
                    adapters[0] = com.createObjectAdapter("AdapterRandom11", "default");
                    adapters[1] = com.createObjectAdapter("AdapterRandom12", "default");
                    adapters[2] = com.createObjectAdapter("AdapterRandom13", "default");
                    adapters[3] = com.createObjectAdapter("AdapterRandom14", "default");
                    adapters[4] = com.createObjectAdapter("AdapterRandom15", "default");

                    int count        = 20;
                    int adapterCount = adapters.Length;
                    while (--count > 0)
                    {
                        Test.TestIntfPrx[] proxies;
                        if (count == 1)
                        {
                            com.deactivateObjectAdapter(adapters[4]);
                            --adapterCount;
                        }
                        proxies = new Test.TestIntfPrx[10];

                        int i;
                        for (i = 0; i < proxies.Length; ++i)
                        {
                            var adpts = new Test.RemoteObjectAdapterPrx[rand.Next(adapters.Length)];
                            if (adpts.Length == 0)
                            {
                                adpts = new Test.RemoteObjectAdapterPrx[1];
                            }
                            for (int j = 0; j < adpts.Length; ++j)
                            {
                                adpts[j] = adapters[rand.Next(adapters.Length)];
                            }
                            proxies[i] = createTestIntfPrx(new List <Test.RemoteObjectAdapterPrx>(adpts));
                        }

                        for (i = 0; i < proxies.Length; i++)
                        {
                            proxies[i].begin_getAdapterName();
                        }
                        for (i = 0; i < proxies.Length; i++)
                        {
                            try
                            {
                                proxies[i].ice_ping();
                            }
                            catch (Ice.LocalException)
                            {
                            }
                        }

                        List <Ice.Connection> connections = new List <Ice.Connection>();
                        for (i = 0; i < proxies.Length; i++)
                        {
                            if (proxies[i].ice_getCachedConnection() != null)
                            {
                                if (!connections.Contains(proxies[i].ice_getCachedConnection()))
                                {
                                    connections.Add(proxies[i].ice_getCachedConnection());
                                }
                            }
                        }
                        test(connections.Count <= adapterCount);

                        foreach (var a in adapters)
                        {
                            try
                            {
                                a.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                            }
                            catch (Ice.LocalException)
                            {
                                // Expected if adapter is down.
                            }
                        }
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI11", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI12", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("AdapterAMI11");
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.ice_ping();
                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_ping();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = getAdapterNameWithAMI(t);
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter(adapters[0]);
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter(adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing random endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter21", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter22", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter23", "default"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);

                    var names = new List <string>();
                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Random));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);

                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter31", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter32", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter33", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with single endpoint... ");
                output.Flush();
                {
                    var adapter = com.createObjectAdapter("Adapter41", "default");

                    var test1 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false));
                    var test2 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false));
                    test(!test1.ice_isConnectionCached());
                    test(!test2.ice_isConnectionCached());
                    test(test1.ice_getConnection() != null && test2.ice_getConnection() != null);
                    test(test1.ice_getConnection() == test2.ice_getConnection());

                    test1.ice_ping();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1);
                    try
                    {
                        test(test3.ice_getConnection() == test1.ice_getConnection());
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter51", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter52", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter53", "default"));

                    var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());

                    List <string> names = new List <string>();
                    names.Add("Adapter51");
                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(obj.getAdapterName().Equals("Adapter52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI51", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI52", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI53", "default"));

                    var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());

                    var names = new List <string>();
                    names.Add("AdapterAMI51");
                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter61", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter62", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI61", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI62", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter71", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter72", "udp"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter71"));

                    var testUDP = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_datagram());
                    test(obj.ice_getConnection() != testUDP.ice_getConnection());
                    try
                    {
                        testUDP.getAdapterName();
                    }
                    catch (Ice.TwowayOnlyException)
                    {
                    }
                }
                output.WriteLine("ok");
                if (communicator.getProperties().getProperty("Ice.Plugin.IceSSL").Length > 0)
                {
                    output.Write("testing unsecure vs. secure endpoints... ");
                    output.Flush();
                    {
                        var adapters = new List <Test.RemoteObjectAdapterPrx>();
                        adapters.Add(com.createObjectAdapter("Adapter81", "ssl"));
                        adapters.Add(com.createObjectAdapter("Adapter82", "tcp"));

                        var obj = createTestIntfPrx(adapters);
                        int i;
                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter82"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        var testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true));
                        test(testSecure.ice_isSecure());
                        testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(false));
                        test(!testSecure.ice_isSecure());
                        testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true));
                        test(testSecure.ice_isSecure());
                        test(obj.ice_getConnection() != testSecure.ice_getConnection());

                        com.deactivateObjectAdapter(adapters[1]);

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter81"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        com.createObjectAdapter("Adapter83", (obj.ice_getEndpoints()[1]).ToString()); // Reactive tcp OA.

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter83"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        com.deactivateObjectAdapter(adapters[0]);
                        try
                        {
                            testSecure.ice_ping();
                            test(false);
                        }
                        catch (Ice.ConnectFailedException)
                        {
                        }
                        catch (Ice.ConnectTimeoutException)
                        {
                        }

                        deactivate(com, adapters);
                    }
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing ipv4 & ipv6 connections... ");
                    output.Flush();

                    Ice.Properties ipv4 = Ice.Util.createProperties();
                    ipv4.setProperty("Ice.IPv4", "1");
                    ipv4.setProperty("Ice.IPv6", "0");
                    ipv4.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties ipv6 = Ice.Util.createProperties();
                    ipv6.setProperty("Ice.IPv4", "0");
                    ipv6.setProperty("Ice.IPv6", "1");
                    ipv6.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties bothPreferIPv4 = Ice.Util.createProperties();
                    bothPreferIPv4.setProperty("Ice.IPv4", "1");
                    bothPreferIPv4.setProperty("Ice.IPv6", "1");
                    bothPreferIPv4.setProperty("Ice.PreferIPv6Address", "0");
                    bothPreferIPv4.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties bothPreferIPv6 = Ice.Util.createProperties();
                    bothPreferIPv6.setProperty("Ice.IPv4", "1");
                    bothPreferIPv6.setProperty("Ice.IPv6", "1");
                    bothPreferIPv6.setProperty("Ice.PreferIPv6Address", "1");
                    bothPreferIPv6.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    List <Ice.Properties> clientProps = new List <Ice.Properties>();
                    clientProps.Add(ipv4);
                    clientProps.Add(ipv6);
                    clientProps.Add(bothPreferIPv4);
                    clientProps.Add(bothPreferIPv6);

                    string endpoint = "tcp -p " + helper.getTestPort(2).ToString();

                    Ice.Properties anyipv4 = ipv4.ice_clone_();
                    anyipv4.setProperty("Adapter.Endpoints", endpoint);
                    anyipv4.setProperty("Adapter.PublishedEndpoints", endpoint + " -h 127.0.0.1");

                    Ice.Properties anyipv6 = ipv6.ice_clone_();
                    anyipv6.setProperty("Adapter.Endpoints", endpoint);
                    anyipv6.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \".1\"");

                    Ice.Properties anyboth = Ice.Util.createProperties();
                    anyboth.setProperty("Ice.IPv4", "1");
                    anyboth.setProperty("Ice.IPv6", "1");
                    anyboth.setProperty("Adapter.Endpoints", endpoint);
                    anyboth.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \"::1\":" + endpoint + " -h 127.0.0.1");

                    Ice.Properties localipv4 = ipv4.ice_clone_();
                    localipv4.setProperty("Adapter.Endpoints", "tcp -h 127.0.0.1");

                    Ice.Properties localipv6 = ipv6.ice_clone_();
                    localipv6.setProperty("Adapter.Endpoints", "tcp -h \"::1\"");

                    List <Ice.Properties> serverProps = new List <Ice.Properties>(clientProps);
                    serverProps.Add(anyipv4);
                    serverProps.Add(anyipv6);
                    serverProps.Add(anyboth);
                    serverProps.Add(localipv4);
                    serverProps.Add(localipv6);

                    bool ipv6NotSupported = false;
                    foreach (Ice.Properties p in serverProps)
                    {
                        Ice.InitializationData serverInitData = new Ice.InitializationData();
                        serverInitData.properties = p;
                        Ice.Communicator  serverCommunicator = Ice.Util.initialize(serverInitData);
                        Ice.ObjectAdapter oa;
                        try
                        {
                            oa = serverCommunicator.createObjectAdapter("Adapter");
                            oa.activate();
                        }
                        catch (Ice.DNSException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }
                        catch (Ice.SocketException)
                        {
                            if (p == ipv6)
                            {
                                ipv6NotSupported = true;
                            }
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        Ice.ObjectPrx prx = oa.createProxy(Ice.Util.stringToIdentity("dummy"));
                        try
                        {
                            prx.ice_collocationOptimized(false).ice_ping();
                        }
                        catch (Ice.LocalException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        string strPrx = prx.ToString();
                        foreach (Ice.Properties q in clientProps)
                        {
                            Ice.InitializationData clientInitData = new Ice.InitializationData();
                            clientInitData.properties = q;
                            Ice.Communicator clientCommunicator = Ice.Util.initialize(clientInitData);
                            prx = clientCommunicator.stringToProxy(strPrx);
                            try
                            {
                                prx.ice_ping();
                                test(false);
                            }
                            catch (Ice.ObjectNotExistException)
                            {
                                // Expected, no object registered.
                            }
                            catch (Ice.DNSException)
                            {
                                // Expected if no IPv4 or IPv6 address is
                                // associated to localhost or if trying to connect
                                // to an any endpoint with the wrong IP version,
                                // e.g.: resolving an IPv4 address when only IPv6
                                // is enabled fails with a DNS exception.
                            }
                            catch (Ice.SocketException)
                            {
                                test((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) ||
                                     (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) ||
                                     (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) ||
                                     (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) ||
                                     (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) ||
                                     (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) ||
                                     (p == bothPreferIPv6 && q == ipv6));
                            }
                            clientCommunicator.destroy();
                        }
                        serverCommunicator.destroy();
                    }

                    output.WriteLine("ok");
                }
                com.shutdown();
            }
コード例 #9
0
ファイル: AllTests.cs プロジェクト: motuii/ice
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing proxy endpoint information... ");
                output.Flush();
                {
                    var p1 = IObjectPrx.Parse(
                        "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" +
                        "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" +
                        "opaque -e 1.8 -t 100 -v ABCD", communicator);

                    Ice.Endpoint[] endps = p1.Endpoints;

                    Ice.EndpointInfo    info        = endps[0].getInfo();
                    Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(info);
                    test(tcpEndpoint.host.Equals("tcphost"));
                    test(tcpEndpoint.port == 10000);
                    test(tcpEndpoint.sourceAddress.Equals("10.10.10.10"));
                    test(tcpEndpoint.timeout == 1200);
                    test(tcpEndpoint.compress);
                    test(!tcpEndpoint.datagram());

                    test(tcpEndpoint.type() == Ice.TCPEndpointType.value && !tcpEndpoint.secure() ||
                         tcpEndpoint.type() == Ice.SSLEndpointType.value && tcpEndpoint.secure() ||
                         tcpEndpoint.type() == Ice.WSEndpointType.value && !tcpEndpoint.secure() ||
                         tcpEndpoint.type() == Ice.WSSEndpointType.value && tcpEndpoint.secure());
                    test(tcpEndpoint.type() == Ice.TCPEndpointType.value && info is Ice.TCPEndpointInfo ||
                         tcpEndpoint.type() == Ice.SSLEndpointType.value && info is IceSSL.EndpointInfo ||
                         tcpEndpoint.type() == Ice.WSEndpointType.value && info is Ice.WSEndpointInfo ||
                         tcpEndpoint.type() == Ice.WSSEndpointType.value && info is Ice.WSEndpointInfo);

                    Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo();
                    test(udpEndpoint.host.Equals("udphost"));
                    test(udpEndpoint.port == 10001);
                    test(udpEndpoint.mcastInterface.Equals("eth0"));
                    test(udpEndpoint.mcastTtl == 5);
                    test(udpEndpoint.sourceAddress.Equals("10.10.10.10"));
                    test(udpEndpoint.timeout == -1);
                    test(!udpEndpoint.compress);
                    test(!udpEndpoint.secure());
                    test(udpEndpoint.datagram());
                    test(udpEndpoint.type() == 3);

                    Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo();
                    test(opaqueEndpoint.rawBytes.Length > 0);
                    test(opaqueEndpoint.rawEncoding.Equals(new Ice.EncodingVersion(1, 8)));
                }
                output.WriteLine("ok");

                Ice.ObjectAdapter adapter;
                output.Write("test object adapter endpoint information... ");
                output.Flush();
                {
                    string host = communicator.getProperties().getPropertyAsInt("Ice.IPv6") != 0 ? "::1" : "127.0.0.1";
                    communicator.getProperties().setProperty("TestAdapter.Endpoints", "tcp -h \"" + host +
                                                             "\" -t 15000:udp -h \"" + host + "\"");
                    adapter = communicator.createObjectAdapter("TestAdapter");

                    Ice.Endpoint[] endpoints = adapter.GetEndpoints();
                    test(endpoints.Length == 2);
                    Ice.Endpoint[] publishedEndpoints = adapter.GetPublishedEndpoints();
                    test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints));

                    Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(endpoints[0].getInfo());
                    test(tcpEndpoint.type() == Ice.TCPEndpointType.value ||
                         tcpEndpoint.type() == Ice.SSLEndpointType.value ||
                         tcpEndpoint.type() == Ice.WSEndpointType.value ||
                         tcpEndpoint.type() == Ice.WSSEndpointType.value);

                    test(tcpEndpoint.host.Equals(host));
                    test(tcpEndpoint.port > 0);
                    test(tcpEndpoint.timeout == 15000);

                    Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo();
                    test(udpEndpoint.host.Equals(host));
                    test(udpEndpoint.datagram());
                    test(udpEndpoint.port > 0);

                    endpoints = new Ice.Endpoint[] { endpoints[0] };
                    test(endpoints.Length == 1);
                    adapter.SetPublishedEndpoints(endpoints);
                    publishedEndpoints = adapter.GetPublishedEndpoints();
                    test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints));

                    adapter.Destroy();

                    int port = helper.getTestPort(1);
                    communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -h * -p " + port);
                    communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", helper.getTestEndpoint(1));
                    adapter = communicator.createObjectAdapter("TestAdapter");

                    endpoints = adapter.GetEndpoints();
                    test(endpoints.Length >= 1);
                    publishedEndpoints = adapter.GetPublishedEndpoints();
                    test(publishedEndpoints.Length == 1);

                    foreach (Ice.Endpoint endpoint in endpoints)
                    {
                        tcpEndpoint = getTCPEndpointInfo(endpoint.getInfo());
                        test(tcpEndpoint.port == port);
                    }

                    tcpEndpoint = getTCPEndpointInfo(publishedEndpoints[0].getInfo());
                    test(tcpEndpoint.host.Equals("127.0.0.1"));
                    test(tcpEndpoint.port == port);

                    adapter.Destroy();
                }
                output.WriteLine("ok");

                int endpointPort = helper.getTestPort(0);

                var @base = IObjectPrx.Parse("test:" +
                                             helper.getTestEndpoint(0) + ":" +
                                             helper.getTestEndpoint(0, "udp"), communicator);
                var testIntf = Test.TestIntfPrx.CheckedCast(@base);

                string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host");

                output.Write("test connection endpoint information... ");
                output.Flush();
                {
                    Ice.EndpointInfo    info    = @base.GetConnection().getEndpoint().getInfo();
                    Ice.TCPEndpointInfo tcpinfo = getTCPEndpointInfo(info);
                    test(tcpinfo.port == endpointPort);
                    test(!tcpinfo.compress);
                    test(tcpinfo.host.Equals(defaultHost));

                    Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext();
                    test(ctx["host"].Equals(tcpinfo.host));
                    test(ctx["compress"].Equals("false"));
                    int port = int.Parse(ctx["port"]);
                    test(port > 0);

                    info = @base.Clone(invocationMode: InvocationMode.Datagram).GetConnection().getEndpoint().getInfo();
                    Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info;
                    test(udp.port == endpointPort);
                    test(udp.host.Equals(defaultHost));
                }
                output.WriteLine("ok");

                output.Write("testing connection information... ");
                output.Flush();
                {
                    Ice.Connection connection = @base.GetConnection();
                    connection.setBufferSize(1024, 2048);

                    Ice.ConnectionInfo    info   = connection.getInfo();
                    Ice.TCPConnectionInfo ipInfo = getTCPConnectionInfo(info);
                    test(!info.incoming);
                    test(info.adapterName.Length == 0);
                    test(ipInfo.remotePort == endpointPort);
                    test(ipInfo.localPort > 0);
                    if (defaultHost.Equals("127.0.0.1"))
                    {
                        test(ipInfo.localAddress.Equals(defaultHost));
                        test(ipInfo.remoteAddress.Equals(defaultHost));
                    }
                    test(ipInfo.rcvSize >= 1024);
                    test(ipInfo.sndSize >= 2048);

                    Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext();
                    test(ctx["incoming"].Equals("true"));
                    test(ctx["adapterName"].Equals("TestAdapter"));
                    test(ctx["remoteAddress"].Equals(ipInfo.localAddress));
                    test(ctx["localAddress"].Equals(ipInfo.remoteAddress));
                    test(ctx["remotePort"].Equals(ipInfo.localPort.ToString()));
                    test(ctx["localPort"].Equals(ipInfo.remotePort.ToString()));

                    if (@base.GetConnection().type().Equals("ws") || @base.GetConnection().type().Equals("wss"))
                    {
                        Dictionary <string, string> headers = ((Ice.WSConnectionInfo)info).headers;
                        test(headers["Upgrade"].Equals("websocket"));
                        test(headers["Connection"].Equals("Upgrade"));
                        test(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                        test(headers["Sec-WebSocket-Accept"] != null);

                        test(ctx["ws.Upgrade"].Equals("websocket"));
                        test(ctx["ws.Connection"].Equals("Upgrade"));
                        test(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                        test(ctx["ws.Sec-WebSocket-Version"].Equals("13"));
                        test(ctx["ws.Sec-WebSocket-Key"] != null);
                    }

                    connection = @base.Clone(invocationMode: InvocationMode.Datagram).GetConnection();
                    connection.setBufferSize(2048, 1024);

                    Ice.UDPConnectionInfo udpInfo = (Ice.UDPConnectionInfo)connection.getInfo();
                    test(!udpInfo.incoming);
                    test(udpInfo.adapterName.Length == 0);
                    test(udpInfo.localPort > 0);
                    test(udpInfo.remotePort == endpointPort);

                    if (defaultHost.Equals("127.0.0.1"))
                    {
                        test(udpInfo.remoteAddress.Equals(defaultHost));
                        test(udpInfo.localAddress.Equals(defaultHost));
                    }
                    test(udpInfo.rcvSize >= 2048);
                    test(udpInfo.sndSize >= 1024);
                }
                output.WriteLine("ok");

                testIntf.shutdown();

                communicator.shutdown();
                communicator.waitForShutdown();
            }
コード例 #10
0
ファイル: icehms.cs プロジェクト: martin-ly/icehms
        public IceManager(string adapterName, string host, int port, bool catchSignals = true)
        {
            IceGridHost = host;
            IceGridPort = port;
            Name        = adapterName;

            logger = log4net.LogManager.GetLogger(this.GetType().Name + "::" + Name);

            _ServantIds = new List <Ice.Identity>(); //keep track of servants for emergency cleanup
            string myIP = findLocalIPAddress();

            logger.Info("My IPAddress is: " + myIP);

            //initialize Ice
            Ice.Properties prop = Ice.Util.createProperties();
            prop.setProperty("hms.AdapterId", adapterName);
            prop.setProperty("hms.Endpoints", "tcp -h " + myIP + ":udp -h " + myIP);
            prop.setProperty("Ice.Default.Locator", "IceGrid/Locator:tcp -p " + IceGridPort + " -h " + IceGridHost);
            prop.setProperty("Ice.ThreadPool.Server.Size", "5");
            prop.setProperty("Ice.ThreadPool.Server.SizeMax", "100000");
            prop.setProperty("Ice.ThreadPool.Client.Size", "5");
            prop.setProperty("Ice.ThreadPool.Client.SizeMax", "100000");

            Ice.InitializationData iceidata = new Ice.InitializationData();
            iceidata.properties = prop;
            Communicator        = Ice.Util.initialize(iceidata); // could add sys.argv
            try
            {
                _Adapter = Communicator.createObjectAdapter("hms");
                _Adapter.activate();
            }
            catch (Exception ex)
            {
                logger.Fatal("Network error, check configuration: " + ex.Message);
                logger.Fatal("Endpoint(should be local machine): " + prop.getProperty("hms.Endpoints"));
                logger.Fatal("Locator (should be IceGrid Server): " + prop.getProperty("Ice.Default.Locator"));
                throw (ex); // we are dead anyway
            }
            //Now are we ready to communicate with others
            //getting usefull proxies

            try
            {
                // proxy to icegrid to register our vc devices
                Query = IceGrid.QueryPrxHelper.checkedCast(Communicator.stringToProxy("IceGrid/Query"));
                if (Query == null)
                {
                    logger.Error("invalid ICeGrid proxy");
                }
                // proxy to icestorm to publish events
                EventMgr = IceStorm.TopicManagerPrxHelper.checkedCast(Communicator.stringToProxy("EventServer/TopicManager"));
                if (EventMgr == null)
                {
                    logger.Error("invalid IceStorm proxy");
                }
                //these 2 objects are only needed to get the IceGrid admin object in order to register
                _Registry = IceGrid.RegistryPrxHelper.uncheckedCast(Communicator.stringToProxy("IceGrid/Registry"));
                updateIceGridAdmin();
            }
            catch (Ice.NotRegisteredException e)
            {
                logger.Fatal("If we fail here it is probably because the Icebox objects are not registered: " + e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal("IceGrid Server not found!!!!!: " + e.Message);
                throw (e);//without yellow page system, there is no need to start
            }
            if (catchSignals)
            {
                setupSignals();
            }
        }
コード例 #11
0
ファイル: AllTests.cs プロジェクト: zk2013/ice
            public static Test.ThrowerPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                {
                    output.Write("testing object adapter registration exceptions... ");
                    Ice.ObjectAdapter first;
                    try
                    {
                        first = communicator.createObjectAdapter("TestAdapter0");
                    }
                    catch (Ice.InitializationException)
                    {
                        // Expected
                    }

                    communicator.getProperties().setProperty("TestAdapter0.Endpoints", "tcp -h *");
                    first = communicator.createObjectAdapter("TestAdapter0");
                    try
                    {
                        communicator.createObjectAdapter("TestAdapter0");
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                        // Expected.
                    }

                    try
                    {
                        Ice.ObjectAdapter second =
                            communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                        test(false);

                        //
                        // Quell mono error that variable second isn't used.
                        //
                        second.deactivate();
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                        // Expected
                    }
                    first.deactivate();
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing servant registration exceptions... ");
                    communicator.getProperties().setProperty("TestAdapter1.Endpoints", "tcp -h *");
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
                    Ice.Object        obj     = new EmptyI();
                    adapter.add(obj, Ice.Util.stringToIdentity("x"));
                    try
                    {
                        adapter.add(obj, Ice.Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                    }

                    try
                    {
                        adapter.add(obj, Ice.Util.stringToIdentity(""));
                        test(false);
                    }
                    catch (Ice.IllegalIdentityException e)
                    {
                        test(e.id.name.Equals(""));
                    }

                    try
                    {
                        adapter.add(null, Ice.Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (Ice.IllegalServantException)
                    {
                    }

                    adapter.remove(Ice.Util.stringToIdentity("x"));
                    try
                    {
                        adapter.remove(Ice.Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (Ice.NotRegisteredException)
                    {
                    }
                    adapter.deactivate();
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing servant locator registration exceptions... ");
                    communicator.getProperties().setProperty("TestAdapter2.Endpoints", "tcp -h *");
                    Ice.ObjectAdapter  adapter = communicator.createObjectAdapter("TestAdapter2");
                    Ice.ServantLocator loc     = new ServantLocatorI();
                    adapter.addServantLocator(loc, "x");
                    try
                    {
                        adapter.addServantLocator(loc, "x");
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                    }

                    adapter.deactivate();
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing object factory registration exception... ");
                    communicator.getValueFactoryManager().add(_ => { return(null); }, "::x");
                    try
                    {
                        communicator.getValueFactoryManager().add(_ => { return(null); }, "::x");
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing stringToProxy... ");
                output.Flush();
                String @ref = "thrower:" + helper.getTestEndpoint(0);

                Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
                test(@base != null);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                var thrower = Test.ThrowerPrxHelper.checkedCast(@base);

                test(thrower != null);
                test(thrower.Equals(@base));
                output.WriteLine("ok");

                output.Write("catching exact types... ");
                output.Flush();

                try
                {
                    thrower.throwAasA(1);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    test(false);
                }

                try
                {
                    thrower.throwAorDasAorD(1);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwAorDasAorD(-1);
                    test(false);
                }
                catch (Test.D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwBasB(1, 2);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasC(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching base types... ");
                output.Flush();

                try
                {
                    thrower.throwBasB(1, 2);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasC(1, 2, 3);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching derived types... ");
                output.Flush();

                try
                {
                    thrower.throwBasA(1, 2);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasA(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasB(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception... ");
                    output.Flush();

                    try
                    {
                        thrower.throwUndeclaredA(1);
                        test(false);
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwUndeclaredB(1, 2);
                        test(false);
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwUndeclaredC(1, 2, 3);
                        test(false);
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    output.WriteLine("ok");
                }

                if (thrower.ice_getConnection() != null)
                {
                    output.Write("testing memory limit marshal exception...");
                    output.Flush();
                    try
                    {
                        thrower.throwMemoryLimitException(null);
                        test(false);
                    }
                    catch (Ice.MemoryLimitException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                        test(false);
                    }
                    catch (Ice.ConnectionLostException)
                    {
                    }
                    catch (Ice.UnknownLocalException)
                    {
                        // Expected with JS bidir server
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(
                            communicator.stringToProxy("thrower:" + helper.getTestEndpoint(1)));
                        try
                        {
                            thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                        }
                        catch (Ice.MemoryLimitException)
                        {
                        }
                        var thrower3 = Test.ThrowerPrxHelper.uncheckedCast(
                            communicator.stringToProxy("thrower:" + helper.getTestEndpoint(2)));
                        try
                        {
                            thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                            test(false);
                        }
                        catch (Ice.ConnectionLostException)
                        {
                        }
                    }
                    catch (Ice.ConnectionRefusedException)
                    {
                        // Expected with JS bidir server
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception... ");
                output.Flush();

                {
                    Ice.Identity id = Ice.Util.stringToIdentity("does not exist");
                    try
                    {
                        var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                        thrower2.ice_ping();
                        test(false);
                    }
                    catch (Ice.ObjectNotExistException ex)
                    {
                        test(ex.id.Equals(id));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception... ");
                output.Flush();

                try
                {
                    var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    try
                    {
                        thrower2.ice_ping();
                        test(false);
                    }
                    catch (Ice.FacetNotExistException ex)
                    {
                        test(ex.facet.Equals("no such facet"));
                    }
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception... ");
                output.Flush();

                try
                {
                    var thrower2 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                    thrower2.noSuchOperation();
                    test(false);
                }
                catch (Ice.OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception... ");
                output.Flush();

                try
                {
                    thrower.throwLocalException();
                    test(false);
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                try
                {
                    thrower.throwLocalExceptionIdempotent();
                    test(false);
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception... ");
                output.Flush();

                try
                {
                    thrower.throwNonIceException();
                    test(false);
                }
                catch (Ice.UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("testing asynchronous exceptions... ");
                output.Flush();

                try
                {
                    thrower.throwAfterResponse();
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwAfterException();
                    test(false);
                }
                catch (Test.A)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching exact types with AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwAasA(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        test(exc is Test.A);
                        var ex = exc as Test.A;
                        test(ex.aMem == 1);
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwAorDasAorD(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.A ex)
                        {
                            test(ex.aMem == 1);
                        }
                        catch (Test.D ex)
                        {
                            test(ex.dMem == -1);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwAorDasAorD(-1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.A ex)
                        {
                            test(ex.aMem == 1);
                        }
                        catch (Test.D ex)
                        {
                            test(ex.dMem == -1);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwBasB(1, 2).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.B ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwCasC(1, 2, 3).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching derived types with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwBasA(1, 2).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.B ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwCasA(1, 2, 3).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwCasB(1, 2, 3).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception with new AMI mapping... ");
                    output.Flush();

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredA(1).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Ice.Identity id       = Ice.Util.stringToIdentity("does not exist");
                    var          thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                    Callback     cb       = new Callback();
                    thrower2.begin_throwAasA(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.ObjectNotExistException ex)
                        {
                            test(ex.id.Equals(id));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    var      thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    Callback cb       = new Callback();
                    thrower2.begin_throwAasA(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.FacetNotExistException ex)
                        {
                            test(ex.facet.Equals("no such facet"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb       = new Callback();
                    var      thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                    thrower4.begin_noSuchOperation().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.OperationNotExistException ex)
                        {
                            test(ex.operation.Equals("noSuchOperation"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwLocalException().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownLocalException)
                        {
                        }
                        catch (Ice.OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownLocalException)
                        {
                        }
                        catch (Ice.OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwNonIceException().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception with new AMI mapping... ");
                    output.Flush();

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredA(1).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    {
                        Callback cb = new Callback();
                        thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                            () =>
                        {
                            test(false);
                        },
                            (Ice.Exception exc) =>
                        {
                            try
                            {
                                throw exc;
                            }
                            catch (Ice.UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                            cb.called();
                        });
                        cb.check();
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Ice.Identity id       = Ice.Util.stringToIdentity("does not exist");
                    var          thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                    Callback     cb       = new Callback();
                    thrower2.begin_throwAasA(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.ObjectNotExistException ex)
                        {
                            test(ex.id.Equals(id));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    var      thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    Callback cb       = new Callback();
                    thrower2.begin_throwAasA(1).whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.FacetNotExistException ex)
                        {
                            test(ex.facet.Equals("no such facet"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb       = new Callback();
                    var      thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                    thrower4.begin_noSuchOperation().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.OperationNotExistException ex)
                        {
                            test(ex.operation.Equals("noSuchOperation"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwLocalException().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownLocalException)
                        {
                        }
                        catch (Ice.OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                {
                    Callback cb = new Callback();
                    thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownLocalException)
                        {
                        }
                        catch (Ice.OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception with new AMI mapping... ");
                output.Flush();

                {
                    Callback cb = new Callback();
                    thrower.begin_throwNonIceException().whenCompleted(
                        () =>
                    {
                        test(false);
                    },
                        (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch (Ice.UnknownException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                    cb.check();
                }

                output.WriteLine("ok");
                return(thrower);
            }
コード例 #12
0
ファイル: AllTests.cs プロジェクト: chuanqingli/ice
            public static Test.TestIntfPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing stringToProxy... ");
                output.Flush();
                string @ref = "test:" + helper.getTestEndpoint(0);

                Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
                test(@base != null);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                var obj = Test.TestIntfPrxHelper.checkedCast(@base);

                test(obj != null);
                test(obj.Equals(@base));
                output.WriteLine("ok");

                {
                    output.Write("creating/destroying/recreating object adapter... ");
                    output.Flush();
                    Ice.ObjectAdapter adapter =
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                    }
                    adapter.destroy();

                    //
                    // Use a different port than the first adapter to avoid an "address already in use" error.
                    //
                    adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    adapter.destroy();
                    output.WriteLine("ok");
                }

                output.Write("creating/activating/deactivating object adapter in one operation... ");
                output.Flush();
                obj.transient();
                obj.end_transient(obj.begin_transient());
                output.WriteLine("ok");

                {
                    output.Write("testing connection closure... ");
                    output.Flush();
                    for (int i = 0; i < 10; ++i)
                    {
                        Ice.InitializationData initData = new Ice.InitializationData();
                        initData.properties = communicator.getProperties().ice_clone_();
                        Ice.Communicator comm = Ice.Util.initialize(initData);
                        comm.stringToProxy("test:" + helper.getTestEndpoint(0)).begin_ice_ping();
                        comm.destroy();
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter published endpoints... ");
                output.Flush();
                {
                    communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000");
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter");
                    test(adapter.getPublishedEndpoints().Length == 1);
                    Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0];
                    test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000"));
                    Ice.ObjectPrx prx =
                        communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000");
                    adapter.setPublishedEndpoints(prx.ice_getEndpoints());
                    test(adapter.getPublishedEndpoints().Length == 2);
                    Ice.Identity id = new Ice.Identity();
                    id.name = "dummy";
                    test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints()));
                    test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints()));
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].Equals(endpt));
                    communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000");
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000"));
                    adapter.destroy();
                    test(adapter.getPublishedEndpoints().Length == 0);
                }
                output.WriteLine("ok");

                if (obj.ice_getConnection() != null)
                {
                    output.Write("testing object adapter with bi-dir connection... ");
                    output.Flush();
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
                    obj.ice_getConnection().setAdapter(adapter);
                    obj.ice_getConnection().setAdapter(null);
                    adapter.deactivate();
                    try
                    {
                        obj.ice_getConnection().setAdapter(adapter);
                        test(false);
                    }
                    catch (Ice.ObjectAdapterDeactivatedException)
                    {
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter with router... ");
                output.Flush();
                {
                    Ice.Identity routerId = new Ice.Identity();
                    routerId.name = "router";
                    Ice.RouterPrx router =
                        Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc"));
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router);
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000"));
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000"));
                    try
                    {
                        adapter.setPublishedEndpoints(router.ice_getEndpoints());
                        test(false);
                    }
                    catch (ArgumentException)
                    {
                        // Expected.
                    }
                    adapter.destroy();

                    try
                    {
                        routerId.name = "test";
                        router        = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId));
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                        // Expected: the "test" object doesn't implement Ice::Router!
                    }

                    try
                    {
                        router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                              helper.getTestEndpoint(1)));
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing object adapter creation with port in use... ");
                output.Flush();
                {
                    var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10));
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10));
                        test(false);
                    }
                    catch (Ice.LocalException)
                    {
                        // Expected can't re-use the same endpoint.
                    }
                    adapter1.destroy();
                }
                output.WriteLine("ok");

                output.Write("deactivating object adapter in the server... ");
                output.Flush();
                obj.deactivate();
                output.WriteLine("ok");

                output.Write("testing whether server is gone... ");
                output.Flush();
                try
                {
                    obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows
                    test(false);
                }
                catch (Ice.LocalException)
                {
                    output.WriteLine("ok");
                }

                return(obj);
            }
コード例 #13
0
ファイル: AllTests.cs プロジェクト: skyccn/ice
            public static Test.GPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing Ice.Admin.Facets property... ");
                test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").Length == 0);
                communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar");
                String[] facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
                test(facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
                communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar");
                facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
                test(facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
                communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
                facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
                test(facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto") &&
                     facetFilter[2].Equals("titi"));
                communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
                facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
                test(facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi"));
                // communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
                // facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
                // test(facetFilter.Length == 0);
                communicator.getProperties().setProperty("Ice.Admin.Facets", "");
                output.WriteLine("ok");

                output.Write("testing facet registration exceptions... ");
                communicator.getProperties().setProperty("FacetExceptionTestAdapter.Endpoints", "tcp -h *");
                Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");
                Ice.Object        obj     = new EmptyI();
                adapter.add(obj, Ice.Util.stringToIdentity("d"));
                adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD");
                try
                {
                    adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD");
                    test(false);
                }
                catch (Ice.AlreadyRegisteredException)
                {
                }
                adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD");
                try
                {
                    adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD");
                    test(false);
                }
                catch (Ice.NotRegisteredException)
                {
                }
                output.WriteLine("ok");

                output.Write("testing removeAllFacets... ");
                Ice.Object obj1 = new EmptyI();
                Ice.Object obj2 = new EmptyI();
                adapter.addFacet(obj1, Ice.Util.stringToIdentity("id1"), "f1");
                adapter.addFacet(obj2, Ice.Util.stringToIdentity("id1"), "f2");
                Ice.Object obj3 = new EmptyI();
                adapter.addFacet(obj1, Ice.Util.stringToIdentity("id2"), "f1");
                adapter.addFacet(obj2, Ice.Util.stringToIdentity("id2"), "f2");
                adapter.addFacet(obj3, Ice.Util.stringToIdentity("id2"), "");
                Dictionary <string, Ice.Object> fm
                    = adapter.removeAllFacets(Ice.Util.stringToIdentity("id1"));

                test(fm.Count == 2);
                test(fm["f1"] == obj1);
                test(fm["f2"] == obj2);
                try
                {
                    adapter.removeAllFacets(Ice.Util.stringToIdentity("id1"));
                    test(false);
                }
                catch (Ice.NotRegisteredException)
                {
                }
                fm = adapter.removeAllFacets(Ice.Util.stringToIdentity("id2"));
                test(fm.Count == 3);
                test(fm["f1"] == obj1);
                test(fm["f2"] == obj2);
                test(fm[""] == obj3);
                output.WriteLine("ok");

                adapter.deactivate();

                output.Write("testing stringToProxy... ");
                output.Flush();
                string @ref = "d:" + helper.getTestEndpoint(0);

                Ice.ObjectPrx db = communicator.stringToProxy(@ref);
                test(db != null);
                output.WriteLine("ok");

                output.Write("testing unchecked cast... ");
                output.Flush();
                Ice.ObjectPrx prx = Ice.ObjectPrxHelper.uncheckedCast(db);
                test(prx.ice_getFacet().Length == 0);
                prx = Ice.ObjectPrxHelper.uncheckedCast(db, "facetABCD");
                test(prx.ice_getFacet() == "facetABCD");
                Ice.ObjectPrx prx2 = Ice.ObjectPrxHelper.uncheckedCast(prx);
                test(prx2.ice_getFacet() == "facetABCD");
                Ice.ObjectPrx prx3 = Ice.ObjectPrxHelper.uncheckedCast(prx, "");
                test(prx3.ice_getFacet().Length == 0);
                var d = Test.DPrxHelper.uncheckedCast(db);

                test(d.ice_getFacet().Length == 0);
                var df = Test.DPrxHelper.uncheckedCast(db, "facetABCD");

                test(df.ice_getFacet() == "facetABCD");
                var df2 = Test.DPrxHelper.uncheckedCast(df);

                test(df2.ice_getFacet() == "facetABCD");
                var df3 = Test.DPrxHelper.uncheckedCast(df, "");

                test(df3.ice_getFacet().Length == 0);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                prx = Ice.ObjectPrxHelper.checkedCast(db);
                test(prx.ice_getFacet().Length == 0);
                prx = Ice.ObjectPrxHelper.checkedCast(db, "facetABCD");
                test(prx.ice_getFacet() == "facetABCD");
                prx2 = Ice.ObjectPrxHelper.checkedCast(prx);
                test(prx2.ice_getFacet() == "facetABCD");
                prx3 = Ice.ObjectPrxHelper.checkedCast(prx, "");
                test(prx3.ice_getFacet().Length == 0);
                d = Test.DPrxHelper.checkedCast(db);
                test(d.ice_getFacet().Length == 0);
                df = Test.DPrxHelper.checkedCast(db, "facetABCD");
                test(df.ice_getFacet() == "facetABCD");
                df2 = Test.DPrxHelper.checkedCast(df);
                test(df2.ice_getFacet() == "facetABCD");
                df3 = Test.DPrxHelper.checkedCast(df, "");
                test(df3.ice_getFacet().Length == 0);
                output.WriteLine("ok");

                output.Write("testing non-facets A, B, C, and D... ");
                output.Flush();
                d = Test.DPrxHelper.checkedCast(db);
                test(d != null);
                test(d.Equals(db));
                test(d.callA().Equals("A"));
                test(d.callB().Equals("B"));
                test(d.callC().Equals("C"));
                test(d.callD().Equals("D"));
                output.WriteLine("ok");

                output.Write("testing facets A, B, C, and D... ");
                output.Flush();
                df = Test.DPrxHelper.checkedCast(d, "facetABCD");
                test(df != null);
                test(df.callA().Equals("A"));
                test(df.callB().Equals("B"));
                test(df.callC().Equals("C"));
                test(df.callD().Equals("D"));
                output.WriteLine("ok");

                output.Write("testing facets E and F... ");
                output.Flush();
                var ff = Test.FPrxHelper.checkedCast(d, "facetEF");

                test(ff != null);
                test(ff.callE().Equals("E"));
                test(ff.callF().Equals("F"));
                output.WriteLine("ok");

                output.Write("testing facet G... ");
                output.Flush();
                var gf = Test.GPrxHelper.checkedCast(ff, "facetGH");

                test(gf != null);
                test(gf.callG().Equals("G"));
                output.WriteLine("ok");

                output.Write("testing whether casting preserves the facet... ");
                output.Flush();
                var hf = Test.HPrxHelper.checkedCast(gf);

                test(hf != null);
                test(hf.callG().Equals("G"));
                test(hf.callH().Equals("H"));
                output.WriteLine("ok");
                return(gf);
            }
コード例 #14
0
        public IceManager(string adapterName, string host, int port, bool catchSignals = true)
        {
            IceGridHost = host;
            IceGridPort = port;
            Name = adapterName;

            logger = log4net.LogManager.GetLogger(this.GetType().Name + "::" + Name);

            _ServantIds = new List<Ice.Identity>(); //keep track of servants for emergency cleanup
            string myIP = findLocalIPAddress();
            logger.Info("My IPAddress is: " + myIP);

            //initialize Ice
            Ice.Properties prop = Ice.Util.createProperties();
            prop.setProperty("hms.AdapterId", adapterName);
            prop.setProperty("hms.Endpoints", "tcp -h " + myIP + ":udp -h " + myIP);
            prop.setProperty("Ice.Default.Locator", "IceGrid/Locator:tcp -p " + IceGridPort + " -h " + IceGridHost);
            prop.setProperty("Ice.ThreadPool.Server.Size", "5");
            prop.setProperty("Ice.ThreadPool.Server.SizeMax", "100000");
            prop.setProperty("Ice.ThreadPool.Client.Size", "5");
            prop.setProperty("Ice.ThreadPool.Client.SizeMax", "100000");

            Ice.InitializationData iceidata = new Ice.InitializationData();
            iceidata.properties = prop;
            Communicator = Ice.Util.initialize(iceidata); // could add sys.argv
            try
            {
                _Adapter = Communicator.createObjectAdapter("hms");
                _Adapter.activate();
            }
            catch (Exception ex)
            {
                logger.Fatal("Network error, check configuration: " + ex.Message);
                logger.Fatal("Endpoint(should be local machine): " + prop.getProperty("hms.Endpoints"));
                logger.Fatal("Locator (should be IceGrid Server): " + prop.getProperty("Ice.Default.Locator"));
                throw (ex); // we are dead anyway
            }
            //Now are we ready to communicate with others
            //getting usefull proxies

            try
            {
                // proxy to icegrid to register our vc devices
                Query = IceGrid.QueryPrxHelper.checkedCast(Communicator.stringToProxy("IceGrid/Query"));
                if (Query == null)
                {
                    logger.Error("invalid ICeGrid proxy");
                }
                // proxy to icestorm to publish events
                EventMgr = IceStorm.TopicManagerPrxHelper.checkedCast(Communicator.stringToProxy("EventServer/TopicManager"));
                if (EventMgr == null)
                {
                    logger.Error("invalid IceStorm proxy");
                }
                //these 2 objects are only needed to get the IceGrid admin object in order to register
                _Registry = IceGrid.RegistryPrxHelper.uncheckedCast(Communicator.stringToProxy("IceGrid/Registry"));
                updateIceGridAdmin();

            }
            catch (Ice.NotRegisteredException e)
            {
                logger.Fatal("If we fail here it is probably because the Icebox objects are not registered: " + e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal("IceGrid Server not found!!!!!: " + e.Message);
                throw (e);//without yellow page system, there is no need to start
            }
            if (catchSignals)
            {
                setupSignals();
            }
        }