示例#1
0
 public override Ice.InitializationData initData()
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties();
     initData.properties.setProperty("Ice.Default.Locator", "locator:default -p 12010");
     return initData;
 }
示例#2
0
文件: Client.cs 项目: externl/ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#3
0
 /// <summary>
 /// Creates a Glacier2 session.
 /// </summary>
 /// <param name="callback">The callback for notifications about session
 /// establishment.</param>
 /// <param name="initData">The Ice.InitializationData for initializing
 /// the communicator.</param>
 /// <param name="finderStr">The stringified Ice.RouterFinder proxy.</param>
 /// <param name="useCallbacks">True if the session should create an object adapter for receiving callbacks.</param>
 internal SessionHelper(SessionCallback callback, Ice.InitializationData initData, string finderStr, bool useCallbacks)
 {
     _callback     = callback;
     _initData     = initData;
     _finderStr    = finderStr;
     _useCallbacks = useCallbacks;
 }
示例#4
0
 public override Ice.InitializationData initData()
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties();
     initData.properties.setProperty("Ice.FactoryAssemblies", "optional,version=1.0.0.0");
     return initData;
 }
示例#5
0
        private static Ice.Communicator createSendLogCommunicator(Ice.Communicator communicator, Ice.Logger logger)
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.logger     = logger;
            initData.properties = Ice.Util.createProperties();

            Ice.Properties mainProps = communicator.Properties;

            copyProperties("Ice.Default.Locator", mainProps, initData.properties);
            copyProperties("Ice.Plugin.IceSSL", mainProps, initData.properties);
            copyProperties("IceSSL.", mainProps, initData.properties);

            string[] extraProps = mainProps.getPropertyAsList("Ice.Admin.Logger.Properties");

            if (extraProps.Length > 0)
            {
                for (int i = 0; i < extraProps.Length; ++i)
                {
                    string p = extraProps[i];
                    if (!p.StartsWith("--"))
                    {
                        extraProps[i] = "--" + p;
                    }
                }
                initData.properties.parseCommandLineOptions("", extraProps);
            }
            return(Ice.Util.initialize(initData));
        }
示例#6
0
文件: Server.cs 项目: externl/ice
 public static int Main(string[] args)
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties(ref args);
     App app = new App();
     return app.main(args, initData);
 }
示例#7
0
文件: Client.cs 项目: externl/ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;
        Debug.Listeners.Add(new ConsoleTraceListener());

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.Default.Host", "127.0.0.1");
            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#8
0
文件: AllTests.cs 项目: joshmoore/ice
 public override Ice.InitializationData initData()
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties();
     initData.properties.setProperty("Ice.Warn.Connections", "0");
     return initData;
 }
示例#9
0
文件: AllTests.cs 项目: joshmoore/ice
 createClientProps(Ice.Properties defaultProperties, string defaultDir, string defaultHost)
 {
     Ice.InitializationData result = new Ice.InitializationData();
     result.properties = Ice.Util.createProperties();
     //
     // TODO:
     //
     // When an application loads IceSSL.dll directly, as this one does, we
     // must ensure that it uses the same DLL as the one loaded dynamically
     // by Ice.
     //
     // When Mono supports .NET 2.0, we'll need to fix this.
     //
     result.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:IceSSL.PluginFactory");
     if(defaultProperties.getProperty("Ice.IPv6").Length > 0)
     {
         result.properties.setProperty("Ice.IPv6", defaultProperties.getProperty("Ice.IPv6"));
     }
     result.properties.setProperty("Ice.RetryIntervals", "-1");
     if(defaultHost.Length > 0)
     {
         result.properties.setProperty("Ice.Default.Host", defaultHost);
     }
     if(defaultDir.Length > 0)
     {
         result.properties.setProperty("IceSSL.DefaultDir", defaultDir);
     }
     //result.properties.setProperty("IceSSL.Trace.Security", "1");
     return result;
 }
示例#10
0
 public override Ice.InitializationData initData()
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties();
     initData.properties.setProperty("Ice.FactoryAssemblies", "servantLocator,version=1.0.0.0");
     return(initData);
 }
示例#11
0
文件: Collocated.cs 项目: motuii/ice
    public override void run(string[] args)
    {
        CommunicatorObserverI observer = new CommunicatorObserverI();

        Ice.InitializationData initData = new Ice.InitializationData();
        initData.observer   = observer;
        initData.properties = createTestProperties(ref args);
        initData.properties.setProperty("Ice.Admin.Endpoints", "tcp");
        initData.properties.setProperty("Ice.Admin.InstanceName", "client");
        initData.properties.setProperty("Ice.Admin.DelayCreation", "1");
        initData.properties.setProperty("Ice.Warn.Connections", "0");
        initData.properties.setProperty("Ice.Warn.Dispatch", "0");
        initData.properties.setProperty("Ice.Default.Host", "127.0.0.1");

        using (var communicator = initialize(initData))
        {
            communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter");
            adapter.Add(new MetricsI(), "metrics");
            //adapter.activate(); // Don't activate OA to ensure collocation is used.

            communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1));
            Ice.ObjectAdapter controllerAdapter = communicator.createObjectAdapter("ControllerAdapter");
            controllerAdapter.Add(new ControllerI(adapter), "controller");
            //controllerAdapter.activate(); // Don't activate OA to ensure collocation is used.

            Test.MetricsPrx metrics = AllTests.allTests(this, observer);
            metrics.shutdown();
        }
    }
示例#12
0
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData data = new Ice.InitializationData();
            communicator = Ice.Util.initialize(ref args, data);
            status = AllTests.run(communicator);
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#13
0
 public override Ice.InitializationData initData()
 {
     Ice.InitializationData initData = new Ice.InitializationData();
     initData.properties = Ice.Util.createProperties();
     initData.properties.setProperty("Ice.Default.Host", "127.0.0.1");
     return initData;
 }
示例#14
0
    public static int Main(string[] args)
    {
        int status = 0;
        try
        {
            Console.Out.Write("testing load properties from UTF-8 path... ");
            Console.Out.Flush();
            Ice.InitializationData id = new Ice.InitializationData();
            id.properties = Ice.Util.createProperties();
            id.properties.load("./config/中国_client.config");
            test(id.properties.getProperty("Ice.Trace.Network").Equals("1"));
            test(id.properties.getProperty("Ice.Trace.Protocol").Equals("1"));
            test(id.properties.getProperty("Config.Path").Equals("./config/中国_client.config"));
            test(id.properties.getProperty("Ice.ProgramName").Equals("PropertiesClient"));
            Console.Out.WriteLine("ok");
            Console.Out.Write("testing load properties from UTF-8 path using Ice::Application... ");
            Console.Out.Flush();
            PropertiesClient c = new PropertiesClient();
            c.main(args, "./config/中国_client.config");
            Console.Out.WriteLine("ok");
        }
        catch(System.Exception ex)
        {
            System.Console.Error.WriteLine(ex);
            status = 1;
        }

        return status;
    }
示例#15
0
文件: Client.cs 项目: bholl/zeroc-ice
    public static int Main(string[] args)
    {
        #if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
        #endif

        //
        // We must disable connection warnings, because we attempt to
        // ping the router before session establishment, as well as
        // after session destruction. Both will cause a
        // ConnectionLostException.
        //
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties(ref args);

        initData.properties.setProperty("Ice.Warn.Connections", "0");

        #if COMPACT
        //
        // When using Ice for .NET Compact Framework, we need to specify
        // the assembly so that Ice can locate classes and exceptions.
        //
        initData.properties.setProperty("Ice.FactoryAssemblies", "client");
        #endif

        App app = new App();
        return app.main(args, initData);
    }
示例#16
0
文件: Server.cs 项目: joshmoore/ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.ThreadPool.Server.ThreadPriority", "AboveNormal");
            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#17
0
文件: Client.cs 项目: pedia/zeroc-ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            //
            // For this test, we want to disable retries.
            //
            initData.properties.setProperty("Ice.RetryIntervals", "-1");

            //
            // This test kills connections, so we don't want warnings.
            //
            initData.properties.setProperty("Ice.Warn.Connections", "0");

            initData.properties.setProperty("Ice.MessageSizeMax", "50000");

            // This test relies on filling the TCP send/recv buffer, so
            // we rely on a fixed value for these buffers.
            initData.properties.setProperty("Ice.TCP.SndSize", "50000");

            //
            // Setup the test transport plug-in.
            //
            string defaultProtocol = initData.properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");
            initData.properties.setProperty("Ice.Default.Protocol", "test-" + defaultProtocol);

            communicator = Ice.Util.initialize(ref args, initData);
            PluginI plugin = new PluginI(communicator);
            plugin.initialize();
            communicator.getPluginManager().addPlugin("Test", plugin);

            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#18
0
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator ic = null;
        try
        {
            Ice.InitializationData data = new Ice.InitializationData();
#if COMPACT
            //
            // When using Ice for .NET Compact Framework, we need to specify
            // the assembly so that Ice can locate classes and exceptions.
            //
            data.properties = Ice.Util.createProperties();
            data.properties.setProperty("Ice.FactoryAssemblies", "client,version=1.0.0.0");
#endif

            //
            // Create a communicator
            //
            ic = Ice.Util.initialize(ref args, data);

            //
            // Create a proxy for the root directory
            //
            Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000");

            //
            // Down-cast the proxy to a Directory proxy
            //
            DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj);
            if(rootDir == null)
            {
                throw new ApplicationException("Invalid proxy");
            }

            //
            // Recursively list the contents of the root directory
            //
            Console.WriteLine("Contents of root directory:");
            listRecursive(rootDir, 0);
        }
        catch(Exception e)
        {
            Console.Error.WriteLine(e);
            status = 1;
        }
        if(ic != null)
        {
            try
            {
                ic.destroy();
            }
            catch(Exception e)
            {
                Console.Error.WriteLine(e);
                status = 1;
            }
        }
        return status;
    }
        public TempCommunicator(string configFileClasspath)
        {
            log("Constructor called");
            try
            {
                InitializationData initData = new InitializationData();
                initData.properties = Util.createProperties();
                initData.properties.load(configFileClasspath);
                communicator = Util.initialize(initData);
                log("Properties Loaded!");
            }
            catch (Exception e)
            {
                log(e.ToString());
                throw e;
            }
            string proxy1 = "'::TeRK::TeRKUser':tcp -h 127.0.0.1 -p 10101";
            log("Calling stringToProxy on " + proxy1);
            communicator.stringToProxy(proxy1);
            log("Complete!");

            string proxy2 = "'::TeRK::TeRKUser':tcp -h 192.168.0.16 -p 10101";
            log("Calling stringToProxy on " + proxy2);
            communicator.stringToProxy(proxy2);
            log("Complete!");

            log("Constructor terminated");
            writeLog("C:\\tempCommLog.txt");
        }
示例#20
0
文件: Collocated.cs 项目: externl/ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties();
            initData.properties.setProperty("Ice.Warn.Dispatch", "0");
            initData.properties.setProperty("Ice.MessageSizeMax", "10"); // 10KB max
            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#21
0
        public CommunicatorObserverI(Ice.InitializationData initData)
        {
            _metrics     = new MetricsAdminI(initData.properties, initData.logger);
            _delegate    = initData.observer;
            _connections = new ObserverFactoryWithDelegate <ConnectionMetrics, ConnectionObserverI,
                                                            Ice.Instrumentation.ConnectionObserver>(_metrics, "Connection");
            _dispatch = new ObserverFactoryWithDelegate <DispatchMetrics, DispatchObserverI,
                                                         Ice.Instrumentation.DispatchObserver>(_metrics, "Dispatch");
            _invocations = new ObserverFactoryWithDelegate <InvocationMetrics, InvocationObserverI,
                                                            Ice.Instrumentation.InvocationObserver>(_metrics, "Invocation");
            _threads = new ObserverFactoryWithDelegate <ThreadMetrics, ThreadObserverI,
                                                        Ice.Instrumentation.ThreadObserver>(_metrics, "Thread");
            _connects = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                         Ice.Instrumentation.Observer>(_metrics, "ConnectionEstablishment");
            _endpointLookups = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                                Ice.Instrumentation.Observer>(_metrics, "EndpointLookup");

            try
            {
                Type cl = typeof(InvocationMetrics);
                _invocations.registerSubMap <RemoteMetrics>("Remote", cl.GetField("remotes"));
                _invocations.registerSubMap <CollocatedMetrics>("Collocated", cl.GetField("collocated"));
            }
            catch (System.Exception)
            {
                Debug.Assert(false);
            }
        }
示例#22
0
文件: Client.cs 项目: bholl/zeroc-ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        #if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
        #endif

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            //
            // For this test, we want to disable retries.
            //
            initData.properties.setProperty("Ice.RetryIntervals", "-1");

            //
            // This test kills connections, so we don't want warnings.
            //
            initData.properties.setProperty("Ice.Warn.Connections", "0");

            //
            // Setup the test transport plug-in.
            //
            string defaultProtocol = initData.properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");
            initData.properties.setProperty("Ice.Default.Protocol", "test-" + defaultProtocol);

            communicator = Ice.Util.initialize(ref args, initData);
            PluginI plugin = new PluginI(communicator);
            plugin.initialize();
            communicator.getPluginManager().addPlugin("Test", plugin);

            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#23
0
文件: Client.cs 项目: externl/ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            //
            // We need to send messages large enough to cause the transport
            // buffers to fill up.
            //
            initData.properties.setProperty("Ice.MessageSizeMax", "20000");

            //
            // For this test, we want to disable retries.
            //
            initData.properties.setProperty("Ice.RetryIntervals", "-1");

            //
            // This test kills connections, so we don't want warnings.
            //
            initData.properties.setProperty("Ice.Warn.Connections", "0");

            //
            // Limit the send buffer size, this test relies on the socket
            // send() blocking after sending a given amount of data.
            //
            initData.properties.setProperty("Ice.TCP.SndSize", "50000");

            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#24
0
    public override Ice.InitializationData initData()
    {
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties();
        WriteLine("setting Ice.FactoryAssemblies");
        initData.properties.setProperty("Ice.FactoryAssemblies", "exceptions,version=1.0.0.0");
        initData.properties.setProperty("Ice.MessageSizeMax", "10");
	initData.properties.setProperty("Ice.Warn.Connections", "0");
        return initData;
    }
示例#25
0
 internal ServerManagerI(ServerLocatorRegistry registry,
     Ice.InitializationData initData)
 {
     _registry = registry;
     _communicators = new ArrayList();
     _initData = initData;
     _initData.properties.setProperty("TestAdapter.AdapterId", "TestAdapter");
     _initData.properties.setProperty("TestAdapter.ReplicaGroupId", "ReplicatedAdapter");
     _initData.properties.setProperty("TestAdapter2.AdapterId", "TestAdapter2");
 }
示例#26
0
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

#if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
#endif

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.Package.Test", "test.Ice.metrics");
            initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010");
            initData.properties.setProperty("Ice.Admin.Endpoints", "tcp");
            initData.properties.setProperty("Ice.Admin.InstanceName", "client");
            initData.properties.setProperty("Ice.Admin.DelayCreation", "1");
            initData.properties.setProperty("Ice.Warn.Connections", "0");
            initData.properties.setProperty("Ice.Warn.Dispatch", "0");
            initData.properties.setProperty("Ice.MessageSizeMax", "50000");
            initData.properties.setProperty("Ice.Default.Host", "127.0.0.1");
#if COMPACT
            //
            // When using Ice for .NET Compact Framework, we need to specify
            // the assembly so that Ice can locate classes and exceptions.
            //
            initData.properties.setProperty("Ice.FactoryAssemblies", "collocated");
#endif
            initData.observer = _observer;
            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#27
0
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator ic = null;
        try
        {
            Ice.InitializationData data = new Ice.InitializationData();

            //
            // Create a communicator
            //
            ic = Ice.Util.initialize(ref args, data);

            //
            // Create a proxy for the root directory
            //
            Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000");

            //
            // Down-cast the proxy to a Directory proxy
            //
            DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj);
            if(rootDir == null)
            {
                throw new ApplicationException("Invalid proxy");
            }

            //
            // Recursively list the contents of the root directory
            //
            Console.WriteLine("Contents of root directory:");
            listRecursive(rootDir, 0);
        }
        catch(Exception e)
        {
            Console.Error.WriteLine(e);
            status = 1;
        }
        if(ic != null)
        {
            try
            {
                ic.destroy();
            }
            catch(Exception e)
            {
                Console.Error.WriteLine(e);
                status = 1;
            }
        }
        return status;
    }
示例#28
0
        static void Main(string[] args)
        {
            Server server = new Server();

            InitializationData initializationData = new InitializationData {properties = Util.createProperties()};
            initializationData.properties.setProperty("Ice.ThreadPool.Client.Size", "1");
            initializationData.properties.setProperty("Ice.ThreadPool.Client.SizeMax", "10");
            initializationData.properties.setProperty("Ice.ThreadPool.Server.Size", "1");
            initializationData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "10");
            initializationData.properties.setProperty("Ice.ACM.Client", "0");

            Environment.Exit(server.main(args, initializationData));
        }
示例#29
0
文件: Client.cs 项目: bholl/zeroc-ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        #if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
        #endif

        try
        {
            //
            // In this test, we need at least two threads in the
            // client side thread pool for nested AMI.
            //
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.ThreadPool.Client.Size", "2");
            initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0");

            //
            // We must set MessageSizeMax to an explicit values,
            // because we run tests to check whether
            // Ice.MemoryLimitException is raised as expected.
            //
            initData.properties.setProperty("Ice.MessageSizeMax", "100");

            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#30
0
文件: Client.cs 项目: pedia/zeroc-ice
    static public int Main(String[] args)
    {
        App app = new App();
        Ice.InitializationData data = new Ice.InitializationData();
#if COMPACT
        //
        // When using Ice for .NET Compact Framework, we need to specify
        // the assembly so that Ice can locate classes and exceptions.
        //
        data.properties = Ice.Util.createProperties();
        data.properties.setProperty("Ice.FactoryAssemblies", "client,version=1.0.0.0");
#endif
        return app.main(args, data);
    }
示例#31
0
    public override Ice.InitializationData initData()
    {
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties();
        initData.observer = Instrumentation.getObserver();

        initData.properties.setProperty("Ice.RetryIntervals", "0 1 10 1");

        //
        // This test kills connections, so we don't want warnings.
        //
        initData.properties.setProperty("Ice.Warn.Connections", "0");
        return initData;
    }
示例#32
0
文件: AllTests.cs 项目: joshmoore/ice
    public override Ice.InitializationData initData()
    {
        //
        // In this test, we need at least two threads in the
        // client side thread pool for nested AMI.
        //
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties();
        initData.properties.setProperty("Ice.ThreadPool.Client.Size", "2");
        initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0");

	initData.properties.setProperty("Ice.BatchAutoFlushSize", "100");
        return initData;
    }
示例#33
0
文件: Util.cs 项目: xingx001/ice
        /// <summary>
        /// Creates a communicator.
        /// </summary>
        /// <param name="args">A command-line argument vector. Any Ice-related options
        /// in this vector are used to initialize the communicator.
        /// This method modifies the argument vector by removing any Ice-related options.</param>
        /// <param name="initData">Additional intialization data. Property settings in args
        /// override property settings in initData.</param>
        /// <returns>The initialized communicator.</returns>
        public static Communicator initialize(ref string[] args, InitializationData?initData)
        {
            if (initData == null)
            {
                initData = new InitializationData();
            }
            else
            {
                initData = (InitializationData)initData.Clone();
            }

            initData.properties = createProperties(ref args, initData.properties);

            return(new Communicator(initData, ref args));
        }
示例#34
0
文件: Client.cs 项目: externl/ice
    public static int Main(string[] args)
    {
        //
        // We must disable connection warnings, because we attempt to
        // ping the router before session establishment, as well as
        // after session destruction. Both will cause a
        // ConnectionLostException.
        //
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties(ref args);

        initData.properties.setProperty("Ice.Warn.Connections", "0");
        App app = new App();
        return app.main(args, initData);
    }
示例#35
0
文件: Client.cs 项目: bholl/zeroc-ice
    public static int Main(string[] args)
    {
        int status = 0;
        Ice.Communicator communicator = null;

        #if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
        #endif

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            //
            // For this test, we want to disable retries.
            //
            initData.properties.setProperty("Ice.RetryIntervals", "-1");

            //
            // This test kills connections, so we don't want warnings.
            //
            initData.properties.setProperty("Ice.Warn.Connections", "0");

            communicator = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch(System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if(communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return status;
    }
示例#36
0
文件: Client.cs 项目: bholl/zeroc-ice
        public App()
        {
            me = this;

            _initData = new Ice.InitializationData();
            _initData.properties = Ice.Util.createProperties();
            _initData.properties.setProperty("Ice.Default.Router", "Glacier2/router:default -p 12347");
            #if COMPACT
            _initData.dispatcher = delegate(Ice.VoidAction action, Ice.Connection connection)
            #else
            _initData.dispatcher = delegate(System.Action action, Ice.Connection connection)
            #endif
                {
                    action();
                };
        }
示例#37
0
文件: Util.cs 项目: zhoushiyi/ice
        /// <summary>
        /// Creates a communicator.
        /// </summary>
        /// <param name="initData">Additional intialization data.</param>
        /// <returns>The initialized communicator.</returns>
        public static Communicator initialize(InitializationData initData)
        {
            if (initData == null)
            {
                initData = new InitializationData();
            }
            else
            {
                initData = (InitializationData)initData.Clone();
            }

            CommunicatorI result = new CommunicatorI(initData);

            string[] args = new string[0];
            result.finishSetup(ref args);
            return(result);
        }
示例#38
0
文件: Util.cs 项目: zhoushiyi/ice
        /// <summary>
        /// Creates a communicator.
        /// </summary>
        /// <param name="args">A command-line argument vector. Any Ice-related options
        /// in this vector are used to intialize the communicator.
        /// This method modifies the argument vector by removing any Ice-related options.</param>
        /// <param name="initData">Additional intialization data. Property settings in args
        /// override property settings in initData.</param>
        /// <returns>The initialized communicator.</returns>
        public static Communicator initialize(ref string[] args, InitializationData initData)
        {
            if (initData == null)
            {
                initData = new InitializationData();
            }
            else
            {
                initData = (InitializationData)initData.Clone();
            }

            initData.properties = createProperties(ref args, initData.properties);

            CommunicatorI result = new CommunicatorI(initData);

            result.finishSetup(ref args);
            return(result);
        }
示例#39
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);

            initData.properties.setProperty("Ice.Warn.Connections", "0");
            initData.properties.setProperty("Ice.UDP.RcvSize", "16384");

            communicator = Ice.Util.initialize(ref args, initData);
            status       = run(args, communicator);
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return(status);
    }
示例#40
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

#if !COMPACT
        Debug.Listeners.Add(new ConsoleTraceListener());
#endif

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            communicator        = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch (System.Exception ex)
        {
            System.Console.Error.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                System.Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return(status);
    }
示例#41
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.Warn.AMICallback", "0");
            initData.dispatcher = new Dispatcher().dispatch;
            communicator        = Ice.Util.initialize(ref args, initData);
            status = run(args, communicator);
        }
        catch (System.Exception ex)
        {
            System.Console.Error.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                System.Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        Dispatcher.terminate();

        return(status);
    }
示例#42
0
文件: Collocated.cs 项目: sk163/ice-1
    public static int Main(String[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.ThreadPool.Client.Size", "2"); // For nested AMI.
            initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0");
            initData.properties.setProperty("Ice.Warn.Dispatch", "0");

            communicator = Ice.Util.initialize(ref args, initData);
            status       = run(args, communicator);
        }
        catch (System.Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return(status);
    }
示例#43
0
文件: Server.cs 项目: saxonelf/ice
    protected override Ice.InitializationData getInitData(ref string[] args)
    {
        Ice.InitializationData initData = base.getInitData(ref args);

        //
        // This test kills connections, so we don't want warnings.
        //
        initData.properties.setProperty("Ice.Warn.Connections", "0");

        initData.properties.setProperty("Ice.MessageSizeMax", "50000");

        // This test relies on filling the TCP send/recv buffer, so
        // we rely on a fixed value for these buffers.
        initData.properties.setProperty("Ice.TCP.RcvSize", "50000");

        //
        // Setup the test transport plug-in.
        //
        string defaultProtocol = initData.properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");

        initData.properties.setProperty("Ice.Default.Protocol", "test-" + defaultProtocol);
        return(initData);
    }
示例#44
0
文件: Client.cs 项目: zk2013/ice
 public override void run(string[] args)
 {
     try
     {
         Ice.InitializationData initData = new Ice.InitializationData();
         initData.properties = createTestProperties(ref args);
         initData.properties.setProperty("Ice.Warn.AMICallback", "0");
         //
         // Limit the send buffer size, this test relies on the socket
         // send() blocking after sending a given amount of data.
         //
         initData.properties.setProperty("Ice.TCP.SndSize", "50000");
         initData.dispatcher = new Dispatcher().dispatch;
         using (var communicator = initialize(initData))
         {
             AllTests.allTests(this);
         }
     }
     finally
     {
         Dispatcher.terminate();
     }
 }
示例#45
0
文件: Client.cs 项目: zhj149/ice
    public static int Main(string[] args)
    {
        int status = 0;

        try
        {
            Console.Out.Write("testing preloading assemblies... ");
            Console.Out.Flush();
            User.UserInfo          info = new User.UserInfo();
            Ice.InitializationData id   = new Ice.InitializationData();
            id.properties = Ice.Util.createProperties();
            id.properties.setProperty("Ice.PreloadAssemblies", "0");

            string assembly =
                String.Format("{0}/core.dll",
                              Path.GetFileName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)));
            Ice.Communicator ic = Ice.Util.initialize(id);
            test(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((e) =>
            {
                return(e.CodeBase.EndsWith(assembly, StringComparison.InvariantCultureIgnoreCase));
            }) == null);
            ic.destroy();
            id.properties.setProperty("Ice.PreloadAssemblies", "1");
            ic = Ice.Util.initialize(id);
            test(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((e) =>
            {
                return(e.CodeBase.EndsWith(assembly, StringComparison.InvariantCultureIgnoreCase));
            }) != null);
            Console.Out.WriteLine("ok");
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }
        return(status);
    }
示例#46
0
文件: Client.cs 项目: zhoushiyi/ice
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.Warn.Connections", "0");
            initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010:udp");
            initData.properties.setProperty("Ice.MessageSizeMax", "10"); // 10KB max
            communicator = Ice.Util.initialize(ref args, initData);
            status       = run(args, communicator);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                Console.WriteLine(ex);
                status = 1;
            }
        }

        return(status);
    }
示例#47
0
文件: Server.cs 项目: zhoushiyi/ice
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        Debug.Listeners.Add(new ConsoleTraceListener());

        try
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            initData.properties.setProperty("Ice.ServerIdleTime", "30");
            communicator = Ice.Util.initialize(ref args, initData);
            status       = run(args, communicator);
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        if (communicator != null)
        {
            try
            {
                communicator.destroy();
            }
            catch (Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                status = 1;
            }
        }

        return(status);
    }
示例#48
0
    override public RemoteCommunicatorPrx createCommunicator(Dictionary <string, string> props, Ice.Current current)
    {
        //
        // Prepare the property set using the given properties.
        //
        Ice.InitializationData init = new Ice.InitializationData();
        init.properties = Ice.Util.createProperties();
        foreach (KeyValuePair <string, string> e in props)
        {
            init.properties.setProperty(e.Key, e.Value);
        }

        //
        // Initialize a new communicator.
        //
        Ice.Communicator communicator = Ice.Util.initialize(init);

        //
        // Install a custom admin facet.
        //
        communicator.addAdminFacet(new TestFacetI(), "TestFacet");

        //
        // The RemoteCommunicator servant also implements PropertiesAdminUpdateCallback.
        // Set the callback on the admin facet.
        //
        RemoteCommunicatorI servant = new RemoteCommunicatorI(communicator);

        Ice.Object propFacet = communicator.findAdminFacet("Properties");

        Ice.NativePropertiesAdmin admin = (Ice.NativePropertiesAdmin)propFacet;
        Debug.Assert(admin != null);
        admin.addUpdateCallback(servant);

        Ice.ObjectPrx proxy = current.adapter.addWithUUID(servant);
        return(RemoteCommunicatorPrxHelper.uncheckedCast(proxy));
    }
示例#49
0
文件: Client.cs 项目: sk163/ice-1
    public static int Main(string[] args)
    {
        //
        // We must disable connection warnings, because we attempt to
        // ping the router before session establishment, as well as
        // after session destruction. Both will cause a
        // ConnectionLostException.
        //
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties(ref args);

        initData.properties.setProperty("Ice.Warn.Connections", "0");

#if COMPACT
        //
        // When using Ice for .NET Compact Framework, we need to specify
        // the assembly so that Ice can locate classes and exceptions.
        //
        initData.properties.setProperty("Ice.FactoryAssemblies", "client");
#endif

        App app = new App();
        return(app.main(args, initData));
    }
示例#50
0
    public override int run(string[] args)
    {
        //
        // Configure a second communicator for the invocation timeout
        // + retry test, we need to configure a large retry interval
        // to avoid time-sensitive failures.
        //
        Ice.InitializationData initData2 = new Ice.InitializationData();
        initData2.properties = communicator().getProperties().ice_clone_();
        initData2.properties.setProperty("Ice.RetryIntervals", "0 1 10000");
        initData2.observer = Instrumentation.getObserver();
        Ice.Communicator communicator2 = Ice.Util.initialize(initData2);

        try
        {
            Test.RetryPrx retry = AllTests.allTests(this, communicator2, "retry:" + getTestEndpoint(0));
            retry.shutdown();
            return(0);
        }
        finally
        {
            communicator2.destroy();
        }
    }
示例#51
0
文件: Server.cs 项目: motuii/ice
    public override void run(string[] args)
    {
        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = createTestProperties(ref args);
        initData.properties.setProperty("Ice.ServerIdleTime", "30");
        //
        // Limit the recv buffer size, this test relies on the socket
        // send() blocking after sending a given amount of data.
        //
        initData.properties.setProperty("Ice.TCP.RcvSize", "50000");
        try
        {
            initData.dispatcher = new Dispatcher().dispatch;

            using (var communicator = initialize(initData))
            {
                communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
                communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1));
                communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1");

                Ice.ObjectAdapter adapter  = communicator.createObjectAdapter("TestAdapter");
                Ice.ObjectAdapter adapter2 = communicator.createObjectAdapter("ControllerAdapter");

                adapter.Add(new TestI(), "test");
                adapter.Activate();
                adapter2.Add(new TestControllerI(adapter), "testController");
                adapter2.Activate();

                communicator.waitForShutdown();
            }
        }
        finally
        {
            Dispatcher.terminate();
        }
    }
示例#52
0
        /// <summary>
        /// Initialize data (do not use it, it is execute before Connect)
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public override int run(String[] args)
        {
            //
            // Terminate cleanly on receipt of a signal.
            //
            shutdownOnInterrupt();

            _data            = new Ice.InitializationData();
            _data.properties = Ice.Util.createProperties();
            _data.properties.setProperty("Ice.ImplicitContext", "Shared");
            _data.properties.setProperty("Ice.MessageSizeMax", "65535");
            //_data.properties.setProperty("Ice.Override.Timeout", "1000"); // https://doc.zeroc.com/pages/viewpage.action?pageId=2523191
            _data.logger = new ConsoleLoggerI("ice_");

#if COMPACT
            //
            // When using Ice for .NET Compact Framework, we need to specify
            // the assembly so that Ice can locate classes and exceptions.
            //
            _data.properties.setProperty("Ice.FactoryAssemblies", "client,version=1.0.0.0");
#endif

            return(0);
        }
示例#53
0
文件: Server.cs 项目: sk163/ice-1
    private static int run(string[] args, Ice.Communicator communicator,
                           Ice.InitializationData initData)
    {
        //
        // Register the server manager. The server manager creates a new
        // 'server' (a server isn't a different process, it's just a new
        // communicator and object adapter).
        //
        Ice.Properties properties = communicator.getProperties();
        properties.setProperty("Ice.ThreadPool.Server.Size", "2");
        properties.setProperty("ServerManagerAdapter.Endpoints", "default -p 12010:udp");

        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ServerManagerAdapter");

        //
        // We also register a sample server locator which implements the
        // locator interface, this locator is used by the clients and the
        // 'servers' created with the server manager interface.
        //
        ServerLocatorRegistry registry = new ServerLocatorRegistry();

        Ice.Object @object = new ServerManagerI(registry, initData);
        adapter.add(@object, communicator.stringToIdentity("ServerManager"));
        registry.addObject(adapter.createProxy(communicator.stringToIdentity("ServerManager")));
        Ice.LocatorRegistryPrx registryPrx = Ice.LocatorRegistryPrxHelper.uncheckedCast(
            adapter.add(registry, communicator.stringToIdentity("registry")));

        ServerLocator locator = new ServerLocator(registry, registryPrx);

        adapter.add(locator, communicator.stringToIdentity("locator"));

        adapter.activate();
        communicator.waitForShutdown();

        return(0);
    }
示例#54
0
文件: AllTests.cs 项目: zmyer/ice
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        ServerManagerPrx manager      = ServerManagerPrxHelper.checkedCast(
            communicator.stringToProxy("ServerManager :" + app.getTestEndpoint(0)));

        test(manager != null);
        TestLocatorPrx locator = TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator());

        test(locator != null);
        TestLocatorRegistryPrx registry = TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry());

        test(registry != null);

        Write("testing stringToProxy... ");
        Flush();
        Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base3 = communicator.stringToProxy("test");
        Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager");
        Ice.ObjectPrx base5 = communicator.stringToProxy("test2");
        Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter");
        WriteLine("ok");

        Write("testing ice_locator and ice_getLocator... ");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0);
        Ice.LocatorPrx anotherLocator =
            Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator"));
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getLocator() == null);
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(locator);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0);

        //
        // We also test ice_router/ice_getRouter (perhaps we should add a
        // test/Ice/router test?)
        //
        test(@base.ice_getRouter() == null);
        Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter"));
        @base = @base.ice_router(anotherRouter);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0);
        Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter"));
        communicator.setDefaultRouter(router);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0);
        communicator.setDefaultRouter(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getRouter() == null);
        WriteLine("ok");

        Write("starting server... ");
        Flush();
        manager.startServer();
        WriteLine("ok");

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

        test(obj != null);
        TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(base2);

        test(obj2 != null);
        TestIntfPrx obj3 = TestIntfPrxHelper.checkedCast(base3);

        test(obj3 != null);
        ServerManagerPrx obj4 = ServerManagerPrxHelper.checkedCast(base4);

        test(obj4 != null);
        TestIntfPrx obj5 = TestIntfPrxHelper.checkedCast(base5);

        test(obj5 != null);
        TestIntfPrx obj6 = TestIntfPrxHelper.checkedCast(base6);

        test(obj6 != null);
        WriteLine("ok");

        Write("testing id@AdapterId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing id@ReplicaGroupId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj6.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing identity indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj5 = TestIntfPrxHelper.checkedCast(base5);
            obj5.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing proxy with unknown identity... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("unknown/unknown");
            @base.ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object"));
            test(ex.id.Equals("unknown/unknown"));
        }
        WriteLine("ok");

        Write("testing proxy with unknown adapter... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("test @ TestAdapterUnknown");
            @base.ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object adapter"));
            test(ex.id.Equals("TestAdapterUnknown"));
        }
        WriteLine("ok");

        Write("testing locator cache timeout... ");
        Flush();

        int count = locator.getRequestCount();

        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200);                                                  // 1200ms
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(++count == locator.getRequestCount());

        communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        count += 2;
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200);                                      // 1200ms
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        count += 2;
        test(count == locator.getRequestCount());

        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_ping();
        test(count == locator.getRequestCount());

        test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99);

        WriteLine("ok");

        Write("testing proxy from server... ");
        Flush();
        obj = TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter"));
        HelloPrx hello = obj.getHello();

        test(hello.ice_getAdapterId().Equals("TestAdapter"));
        hello.sayHello();
        hello = obj.getReplicatedHello();
        test(hello.ice_getAdapterId().Equals("ReplicatedAdapter"));
        hello.sayHello();
        WriteLine("ok");

        Write("testing locator request queuing... ");
        Flush();
        hello = (HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false);
        count = locator.getRequestCount();
        hello.ice_ping();
        test(++count == locator.getRequestCount());
        List <Ice.AsyncResult <Test.Callback_Hello_sayHello> > results =
            new List <Ice.AsyncResult <Test.Callback_Hello_sayHello> >();

        for (int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                                                                    whenCompleted(
                () =>
            {
            },
                (Ice.Exception ex) =>
            {
                test(false);
            });
            results.Add(result);
        }
        foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999);
        if (locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        count = locator.getRequestCount();
        hello = (HelloPrx)hello.ice_adapterId("unknown");
        for (int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                                                                    whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                test(ex is Ice.NotRegisteredException);
            });
            results.Add(result);
        }
        foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        // XXX:
        // Take into account the retries.
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999);
        if (locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        WriteLine("ok");

        Write("testing adapter locator cache... ");
        Flush();
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestAdapter3"));
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp"));
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing well-known object locator cache... ");
        Flush();
        registry.addObject(communicator.stringToProxy("test3@TestUnknown"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestUnknown"));
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update
        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        registry.addObject(communicator.stringToProxy("test4"));
        try
        {
            communicator.stringToProxy("test4").ice_ping();
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        WriteLine("ok");

        Write("testing locator cache background updates... ");
        Flush();
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().ice_clone_();
            initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1");
            Ice.Communicator ic = Ice.Util.initialize(initData);

            registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter"));
            registry.addObject(communicator.stringToProxy("test3@TestAdapter"));

            count = locator.getRequestCount();
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping();             // No locator cache.
            count += 3;
            test(count == locator.getRequestCount());
            registry.setAdapterDirectProxy("TestAdapter5", null);
            registry.addObject(communicator.stringToProxy("test3:tcp"));
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping();             // 10s timeout.
            test(count == locator.getRequestCount());
            System.Threading.Thread.Sleep(1200);

            // The following request should trigger the background
            // updates but still use the cached endpoints and
            // therefore succeed.
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping();             // 1s timeout.

            try
            {
                while (true)
                {
                    ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch (Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            try
            {
                while (true)
                {
                    ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch (Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            ic.destroy();
        }
        WriteLine("ok");

        Write("testing proxy from server after shutdown... ");
        Flush();
        hello = obj.getReplicatedHello();
        obj.shutdown();
        manager.startServer();
        hello.sayHello();
        WriteLine("ok");

        Write("testing object migration... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        obj.migrateHello();
        hello.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        WriteLine("ok");

        Write("testing locator encoding resolution... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        count = locator.getRequestCount();
        communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping();
        test(++count == locator.getRequestCount());
        WriteLine("ok");

        Write("shutdown server... ");
        Flush();
        obj.shutdown();
        WriteLine("ok");

        Write("testing whether server is gone... ");
        Flush();
        try
        {
            obj2.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            obj3.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            obj5.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        WriteLine("ok");

        Write("testing indirect proxies to collocated objects... ");
        Flush();

        //
        // Set up test for calling a collocated object through an
        // indirect, adapterless reference.
        //
        Ice.Properties properties = communicator.getProperties();
        properties.setProperty("Ice.PrintAdapterReady", "0");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -h *");
        adapter.setLocator(locator);

        Ice.Identity id = new Ice.Identity();
        id.name = Guid.NewGuid().ToString();
        registry.addObject(adapter.add(new HelloI(), id));
        adapter.activate();

        HelloPrx helloPrx = HelloPrxHelper.checkedCast(
            communicator.stringToProxy("\"" + communicator.identityToString(id) + "\""));

        test(helloPrx.ice_getConnection() == null);

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

        Write("shutdown server manager... ");
        Flush();
        manager.shutdown();
        WriteLine("ok");
    }
示例#55
0
文件: AllTests.cs 项目: sk163/ice-1
    public static void allTests(Ice.Communicator communicator)
#endif
    {
        Write("testing communicator operations... ");
        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 = com.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();
        }
        WriteLine("ok");

        string @ref = "factory:default -p 12010 -t 10000";
        RemoteCommunicatorFactoryPrx factory =
            RemoteCommunicatorFactoryPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

        Write("testing process facet... ");
        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");
            RemoteCommunicatorPrx com  = factory.createCommunicator(props);
            Ice.ObjectPrx         obj  = com.getAdmin();
            Ice.ProcessPrx        proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            proc.shutdown();
            com.waitForShutdown();
            com.destroy();
        }
        WriteLine("ok");

        Write("testing properties facet... ");
        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");
            RemoteCommunicatorPrx  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();
        }
        WriteLine("ok");

        Write("testing logger facet... ");
        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");
            RemoteCommunicatorPrx 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);
            remoteLogger.checkNextInit(prefix, logMessages);

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

            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", "");

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

            remoteLogger.wait(4);

            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);
            remoteLogger.checkNextInit(prefix, logMessages);

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

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

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

            remoteLogger.wait(2);

            //
            // 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();
        }
        WriteLine("ok");


        Write("testing custom facet... ");
        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");
            RemoteCommunicatorPrx com = factory.createCommunicator(props);
            Ice.ObjectPrx         obj = com.getAdmin();
            TestFacetPrx          tf  = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            tf.op();
            com.destroy();
        }
        WriteLine("ok");

        Write("testing facet filtering... ");
        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");
            RemoteCommunicatorPrx com  = factory.createCommunicator(props);
            Ice.ObjectPrx         obj  = com.getAdmin();
            Ice.ProcessPrx        proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            test(proc == null);
            TestFacetPrx tf = 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");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa == null);
            TestFacetPrx tf = 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");
            RemoteCommunicatorPrx  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");
            RemoteCommunicatorPrx  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"));
            TestFacetPrx tf = 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");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa == null);
            TestFacetPrx tf = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            tf.op();
            Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            proc.shutdown();
            com.waitForShutdown();
            com.destroy();
        }
        WriteLine("ok");

        factory.shutdown();
    }
示例#56
0
文件: Client.cs 项目: magicdogs/ice
 protected override Ice.InitializationData getInitData(ref string[] args)
 {
     Ice.InitializationData initData = base.getInitData(ref args);
     initData.properties.setProperty("Ice.Default.Locator", "locator:" + getTestEndpoint(initData.properties, 0));
     return(initData);
 }
示例#57
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Console.Error.Write("testing proxy & endpoint hash algorithm collisions... ");
            Console.Error.Flush();
            Dictionary <int, Ice.ObjectPrx> seenProxy    = new Dictionary <int, Ice.ObjectPrx>();
            Dictionary <int, Ice.Endpoint>  seenEndpoint = new Dictionary <int, Ice.Endpoint>();
            int proxyCollisions    = 0;
            int endpointCollisions = 0;
            int i             = 0;
            int maxCollisions = 10;
            int maxIterations = 10000;

            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            //initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:IceSSL.PluginFactory");
            communicator = Ice.Util.initialize(ref args, initData);
            {
                Random rand = new Random();
                for (i = 0; proxyCollisions < maxCollisions &&
                     endpointCollisions < maxCollisions &&
                     i < maxIterations; ++i)
                {
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    sw.Write(i);
                    sw.Write(":tcp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -t 10");
                    sw.Write(rand.Next(1000000));
                    sw.Write(":udp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -h ");
                    sw.Write(rand.Next(100));

                    Ice.ObjectPrx       obj       = communicator.stringToProxy(sw.ToString());
                    List <Ice.Endpoint> endpoints = new List <Ice.Endpoint>(obj.ice_getEndpoints());

                    if (seenProxy.ContainsKey(obj.GetHashCode()))
                    {
                        if (obj.Equals(seenProxy[obj.GetHashCode()]))
                        {
                            continue;
                        }
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[obj.GetHashCode()] = obj;
                    }

                    foreach (Ice.Endpoint endpoint in endpoints)
                    {
                        if (seenEndpoint.ContainsKey(endpoint.GetHashCode()))
                        {
                            if (endpoint.Equals(seenEndpoint[endpoint.GetHashCode()]))
                            {
                                continue;
                            }
                            ++endpointCollisions;
                        }
                        else
                        {
                            seenEndpoint[endpoint.GetHashCode()] = endpoint;
                        }
                        //
                        // Check the same endpoint produce always the same hash
                        //
                        test(endpoint.GetHashCode() == endpoint.GetHashCode());
                    }
                    //
                    // Check the same proxy produce always the same hash
                    //
                    test(obj.GetHashCode() == obj.GetHashCode());
                }
                test(proxyCollisions < maxCollisions);
                test(endpointCollisions < maxCollisions);
                {
                    Ice.ProxyIdentityKey comparer = new Ice.ProxyIdentityKey();
                    proxyCollisions = 0;
                    seenProxy       = new Dictionary <int, Ice.ObjectPrx>();
                    for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                    {
                        System.IO.StringWriter sw = new System.IO.StringWriter();
                        sw.Write(i);
                        sw.Write(":tcp -p ");
                        sw.Write(rand.Next(65536));
                        sw.Write(" -t 10");
                        sw.Write(rand.Next(1000000));
                        sw.Write(":udp -p ");
                        sw.Write(rand.Next(65536));
                        sw.Write(" -h ");
                        sw.Write(rand.Next(100));

                        Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());

                        if (seenProxy.ContainsKey(comparer.GetHashCode(obj)))
                        {
                            ++proxyCollisions;
                        }
                        else
                        {
                            seenProxy[comparer.GetHashCode(obj)] = obj;
                        }
                        //
                        // Check the same proxy produce always the same hash
                        //
                        test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
                    }
                    test(proxyCollisions < maxCollisions);
                }
            }

            {
                Random rand = new Random();
                Ice.ProxyIdentityFacetKey comparer = new Ice.ProxyIdentityFacetKey();
                proxyCollisions = 0;
                seenProxy       = new Dictionary <int, Ice.ObjectPrx>();
                for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                {
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    sw.Write(i);
                    sw.Write(" -f demo:tcp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -t 10");
                    sw.Write(rand.Next(1000000));
                    sw.Write(":udp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -h ");
                    sw.Write(rand.Next(100));

                    Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());

                    if (seenProxy.ContainsKey(comparer.GetHashCode(obj)))
                    {
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[comparer.GetHashCode(obj)] = obj;
                    }
                    //
                    // Check the same proxy produce always the same hash
                    //
                    test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
                }
                test(proxyCollisions < maxCollisions);
            }

            Ice.ProxyIdentityFacetKey iComparer  = new Ice.ProxyIdentityFacetKey();
            Ice.ProxyIdentityFacetKey ifComparer = new Ice.ProxyIdentityFacetKey();

            Ice.ObjectPrx prx1 = communicator.stringToProxy("Glacier2/router:tcp -p 10010");
            //Ice.ObjectPrx prx2 = communicator.stringToProxy("Glacier2/router:ssl -p 10011");
            Ice.ObjectPrx prx3 = communicator.stringToProxy("Glacier2/router:udp -p 10012");
            Ice.ObjectPrx prx4 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010");
            //Ice.ObjectPrx prx5 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011");
            Ice.ObjectPrx prx6 = communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012");
            Ice.ObjectPrx prx7 = communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000");
            //Ice.ObjectPrx prx8 = communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000");
            Ice.ObjectPrx prx9 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000");
            //Ice.ObjectPrx prx10 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000");

            Dictionary <string, int> proxyMap = new Dictionary <string, int>();
            proxyMap["prx1"] = prx1.GetHashCode();
            //proxyMap["prx2"] = prx2.GetHashCode();
            proxyMap["prx3"] = prx3.GetHashCode();
            proxyMap["prx4"] = prx4.GetHashCode();
            //proxyMap["prx5"] = prx5.GetHashCode();
            proxyMap["prx6"] = prx6.GetHashCode();
            proxyMap["prx7"] = prx7.GetHashCode();
            //proxyMap["prx8"] = prx8.GetHashCode();
            proxyMap["prx9"] = prx9.GetHashCode();
            //proxyMap["prx10"] = prx10.GetHashCode();

            test(communicator.stringToProxy("Glacier2/router:tcp -p 10010").GetHashCode() == proxyMap["prx1"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011").GetHashCode() == proxyMap["prx2"]);
            test(communicator.stringToProxy("Glacier2/router:udp -p 10012").GetHashCode() == proxyMap["prx3"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010").GetHashCode() == proxyMap["prx4"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011").GetHashCode() == proxyMap["prx5"]);
            test(communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012").GetHashCode() == proxyMap["prx6"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000").GetHashCode() == proxyMap["prx7"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000").GetHashCode() == proxyMap["prx8"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000").GetHashCode() == proxyMap["prx9"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000").GetHashCode() == proxyMap["prx10"]);

            test(iComparer.GetHashCode(prx1) == iComparer.GetHashCode(prx1));
            test(ifComparer.GetHashCode(prx1) == ifComparer.GetHashCode(prx1));

            test(iComparer.GetHashCode(prx3) == iComparer.GetHashCode(prx3));
            test(ifComparer.GetHashCode(prx3) == ifComparer.GetHashCode(prx3));

            test(iComparer.GetHashCode(prx4) == iComparer.GetHashCode(prx4));
            test(ifComparer.GetHashCode(prx4) == ifComparer.GetHashCode(prx4));

            test(iComparer.GetHashCode(prx6) == iComparer.GetHashCode(prx6));
            test(ifComparer.GetHashCode(prx6) == ifComparer.GetHashCode(prx6));

            test(iComparer.GetHashCode(prx7) == iComparer.GetHashCode(prx7));
            test(ifComparer.GetHashCode(prx7) == ifComparer.GetHashCode(prx7));

            test(iComparer.GetHashCode(prx9) == iComparer.GetHashCode(prx9));
            test(ifComparer.GetHashCode(prx9) == ifComparer.GetHashCode(prx9));

            Console.Error.WriteLine("ok");

            Console.Error.Write("testing exceptions hash algorithm collisions... ");

            {
                Dictionary <int, Test.OtherException> seenException = new Dictionary <int, Test.OtherException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    Test.OtherException ex = new Test.OtherException(rand.Next(100), rand.Next(100), 0, false);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }

            //
            // Same as above but with numbers in high ranges
            //
            {
                Dictionary <int, Test.OtherException> seenException = new Dictionary <int, Test.OtherException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    Test.OtherException ex = new Test.OtherException(rand.Next(100) * 2 ^ 30, rand.Next(100) * 2 ^ 30, rand.Next(100) * 2 ^ 30, false);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }

            {
                Dictionary <int, Test.BaseException> seenException = new Dictionary <int, Test.BaseException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    int v = rand.Next(1000);
                    Test.BaseException ex = new Test.InvalidPointException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());

                    ex = new Test.InvalidLengthException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");

            Console.Error.Write("testing struct hash algorithm collisions... ");
            {
                Dictionary <int, Test.PointF> seenPointF = new Dictionary <int, Test.PointF>();
                Random rand             = new Random();
                int    structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.PointF pf = new Test.PointF((float)rand.NextDouble(), (float)rand.NextDouble(),
                                                     (float)rand.NextDouble());
                    if (seenPointF.ContainsKey(pf.GetHashCode()))
                    {
                        if (pf.Equals(seenPointF[pf.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointF[pf.GetHashCode()] = pf;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(pf.GetHashCode() == pf.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.PointD> seenPointD = new Dictionary <int, Test.PointD>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.PointD pd = new Test.PointD(rand.NextDouble(), rand.NextDouble(),
                                                     rand.NextDouble());
                    if (seenPointD.ContainsKey(pd.GetHashCode()))
                    {
                        if (pd.Equals(seenPointD[pd.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointD[pd.GetHashCode()] = pd;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(pd.GetHashCode() == pd.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.Polyline> seenPolyline = new Dictionary <int, Test.Polyline>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Polyline     polyline = new Test.Polyline();
                    List <Test.Point> vertices = new List <Test.Point>();
                    for (int j = 0; j < 100; ++j)
                    {
                        vertices.Add(new Test.Point(rand.Next(100), rand.Next(100)));
                    }
                    polyline.vertices = vertices.ToArray();

                    if (seenPolyline.ContainsKey(polyline.GetHashCode()))
                    {
                        if (polyline.Equals(seenPolyline[polyline.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPolyline[polyline.GetHashCode()] = polyline;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(polyline.GetHashCode() == polyline.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.ColorPalette> seenColorPalette = new Dictionary <int, Test.ColorPalette>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.ColorPalette colorPalette = new Test.ColorPalette();
                    colorPalette.colors = new Dictionary <int, Test.Color>();
                    for (int j = 0; j < 100; ++j)
                    {
                        colorPalette.colors[j] = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
                    }

                    if (seenColorPalette.ContainsKey(colorPalette.GetHashCode()))
                    {
                        if (colorPalette.Equals(seenColorPalette[colorPalette.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColorPalette[colorPalette.GetHashCode()] = colorPalette;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(colorPalette.GetHashCode() == colorPalette.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.Color> seenColor = new Dictionary <int, Test.Color>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Color c = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
                    if (seenColor.ContainsKey(c.GetHashCode()))
                    {
                        if (c.Equals(seenColor[c.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColor[c.GetHashCode()] = c;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(c.GetHashCode() == c.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                structCollisions = 0;
                Dictionary <int, Test.Draw> seenDraw = new Dictionary <int, Test.Draw>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Draw draw = new Test.Draw(
                        new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)),
                        new Test.Pen(rand.Next(10),
                                     new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))),
                        false);

                    if (seenDraw.ContainsKey(draw.GetHashCode()))
                    {
                        if (draw.Equals(seenDraw[draw.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenDraw[draw.GetHashCode()] = draw;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(draw.GetHashCode() == draw.GetHashCode());
                }
                test(structCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");

            if (communicator != null)
            {
                communicator.destroy();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
            status = 1;
        }

        return(status);
    }
示例#58
0
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator      communicator = app.communicator();
        string                @ref         = "communicator:" + app.getTestEndpoint(0);
        RemoteCommunicatorPrx com          = RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

        System.Random rand = new System.Random(unchecked ((int)System.DateTime.Now.Ticks));

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

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

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

            com.deactivateObjectAdapter(adapter);

            TestIntfPrx test3 = 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)
            {
            }
        }
        WriteLine("ok");

        Write("testing binding with multiple endpoints... ");
        Flush();
        {
            List <RemoteObjectAdapterPrx> adapters = new List <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)
            {
                List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters);

                TestIntfPrx test1 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx test2 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx 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 (RemoteObjectAdapterPrx adpt in adapters)
                {
                    adpt.getTestIntf().ice_ping();
                }

                TestIntfPrx 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 (RemoteObjectAdapterPrx 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((RemoteObjectAdapterPrx)adapters[0]);
            names.Add("Adapter12");
            names.Add("Adapter13");
            while (names.Count > 0)
            {
                List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters);

                TestIntfPrx test1 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx test2 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx 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((RemoteObjectAdapterPrx)adapters[2]);
            TestIntfPrx obj = createTestIntfPrx(adapters);
            test(obj.getAdapterName().Equals("Adapter12"));

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

        Write("testing binding with multiple random endpoints... ");
        Flush();
        {
            RemoteObjectAdapterPrx[] adapters = new 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)
            {
                TestIntfPrx[] proxies;
                if (count == 1)
                {
                    com.deactivateObjectAdapter(adapters[4]);
                    --adapterCount;
                }
                proxies = new TestIntfPrx[10];

                int i;
                for (i = 0; i < proxies.Length; ++i)
                {
                    RemoteObjectAdapterPrx[] adpts = new RemoteObjectAdapterPrx[rand.Next(adapters.Length)];
                    if (adpts.Length == 0)
                    {
                        adpts = new RemoteObjectAdapterPrx[1];
                    }
                    for (int j = 0; j < adpts.Length; ++j)
                    {
                        adpts[j] = adapters[rand.Next(adapters.Length)];
                    }
                    proxies[i] = createTestIntfPrx(new List <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 (RemoteObjectAdapterPrx a in adapters)
                {
                    try
                    {
                        a.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }
                    catch (Ice.LocalException)
                    {
                        // Expected if adapter is down.
                    }
                }
            }
        }
        WriteLine("ok");

        Write("testing binding with multiple endpoints and AMI... ");
        Flush();
        {
            List <RemoteObjectAdapterPrx> adapters = new List <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)
            {
                List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters);

                TestIntfPrx test1 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx test2 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx 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 (RemoteObjectAdapterPrx adpt in adapters)
                {
                    adpt.getTestIntf().ice_ping();
                }

                TestIntfPrx 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 (RemoteObjectAdapterPrx 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((RemoteObjectAdapterPrx)adapters[0]);
            names.Add("AdapterAMI12");
            names.Add("AdapterAMI13");
            while (names.Count > 0)
            {
                List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters);

                TestIntfPrx test1 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx test2 = createTestIntfPrx(adpts);
                shuffle(ref adpts);
                TestIntfPrx 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((RemoteObjectAdapterPrx)adapters[2]);
            TestIntfPrx obj = createTestIntfPrx(adapters);
            test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

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

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

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

            List <string> 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 = 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);
        }
        WriteLine("ok");

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

            TestIntfPrx obj = createTestIntfPrx(adapters);
            obj = 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((RemoteObjectAdapterPrx)adapters[0]);
            for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]);
            for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)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);
        }
        WriteLine("ok");

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

            TestIntfPrx test1 = TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false));
            TestIntfPrx test2 = 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);

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

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

            TestIntfPrx obj = 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((RemoteObjectAdapterPrx)adapters[0]);

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

            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]);


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

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

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

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

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

            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]);

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

            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]);


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

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

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

            TestIntfPrx obj = createTestIntfPrx(adapters);
            obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
            test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
            obj = 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((RemoteObjectAdapterPrx)adapters[0]);
            for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]);
            for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)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);
        }
        WriteLine("ok");

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

            TestIntfPrx obj = createTestIntfPrx(adapters);
            obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
            test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
            obj = 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((RemoteObjectAdapterPrx)adapters[0]);
            for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]);
            for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++)
            {
                ;
            }
            test(i == nRetry);
            com.deactivateObjectAdapter((RemoteObjectAdapterPrx)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);
        }
        WriteLine("ok");

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

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

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

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

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

                com.deactivateObjectAdapter((RemoteObjectAdapterPrx)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((RemoteObjectAdapterPrx)adapters[0]);
                try
                {
                    testSecure.ice_ping();
                    test(false);
                }
                catch (Ice.ConnectFailedException)
                {
                }
                catch (Ice.ConnectTimeoutException)
                {
                }

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

        {
            Write("testing ipv4 & ipv6 connections... ");
            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 " + app.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();
            }

            WriteLine("ok");
        }
        com.shutdown();
    }
示例#59
0
文件: Server.cs 项目: zxh1986123/ice
 protected override Ice.InitializationData getInitData(ref string[] args)
 {
     Ice.InitializationData initData = base.getInitData(ref args);
     initData.properties.setProperty("Ice.ServerIdleTime", "30");
     return(initData);
 }
示例#60
0
文件: Server.cs 项目: magicdogs/ice
 protected override Ice.InitializationData getInitData(ref string[] args)
 {
     Ice.InitializationData initData = base.getInitData(ref args);
     initData.properties.setProperty("Ice.Warn.Dispatch", "0");
     return(initData);
 }