Ejemplo n.º 1
0
        internal LocatorInfo(ILocatorPrx locator, LocatorTable table, bool background)
        {
            Locator     = locator;
            _table      = table;
            _background = background;

            // The locator registry can't be located and we use ordered endpoint selection in case the locator
            // returned a proxy with some endpoints which are preferred to be tried first.
            _locatorRegistry = new Lazy <ILocatorRegistryPrx?>(
                () => locator.GetRegistry()?.Clone(clearLocator: true,
                                                   endpointSelection: EndpointSelectionType.Ordered));
        }
Ejemplo n.º 2
0
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            Console.Out.Write("testing stringToProxy... ");
            Console.Out.Flush();
            string rf  = "test @ TestAdapter";
            var    obj = ITestIntfPrx.Parse(rf, communicator);

            Console.Out.WriteLine("ok");

            Console.Out.Write("pinging server... ");
            Console.Out.Flush();
            obj.IcePing();
            Console.Out.WriteLine("ok");

            Console.Out.Write("testing locator finder... ");
            var finderId             = new Identity("LocatorFinder", "Ice");
            ILocatorFinderPrx finder = communicator.DefaultLocator !.Clone(ILocatorFinderPrx.Factory, identity: finderId);

            TestHelper.Assert(finder != null && finder.GetLocator() != null);
            Console.Out.WriteLine("ok");

            Console.Out.Write("testing discovery... ");
            Console.Out.Flush();
            {
                // Add test well-known object
                var registry = IRegistryPrx.Parse(
                    communicator.DefaultLocator !.Identity.Category + "/Registry", communicator);

                IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar");
                TestHelper.Assert(session != null);
                session.GetAdmin() !.AddObjectWithType(obj, "::Test");
                session.Destroy();

                // Ensure the IceGrid discovery locator can discover the registries and make sure locator requests are
                // forwarded.
                Dictionary <string, string>?properties = communicator.GetProperties();
                properties.Remove("Ice.Default.Locator");
                properties["Ice.Plugin.IceLocatorDiscovery"]    = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory";
                properties["IceLocatorDiscovery.Port"]          = $"{helper.BasePort + 99}";
                properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter";
                properties["AdapterForDiscoveryTest.Endpoints"] = $"{helper.Transport} -h 127.0.0.1";

                {
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                    IObjectPrx.Parse("test", com).IcePing();

                    // TODO: currently, com.DefaultLocator is a regular ice2/2.0 proxy and we don't want to forward
                    // 2.0-encoded requests to IceGrid until IceGrid supports such requests.

                    ILocatorPrx defaultLocator = com.DefaultLocator !.Clone(ILocatorPrx.Factory,
                                                                            encoding: Encoding.V11);

                    TestHelper.Assert(defaultLocator.GetRegistry() != null);
                    TestHelper.Assert(defaultLocator.GetLocalRegistry() != null);
                    TestHelper.Assert(defaultLocator.GetLocalQuery() != null);

                    ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest");
                    adapter.Activate();
                }
                // Now, ensure that the IceGrid discovery locator correctly handles failure to find a locator.
                {
                    properties["IceLocatorDiscovery.InstanceName"] = "unknown";
                    properties["IceLocatorDiscovery.RetryCount"]   = "1";
                    properties["IceLocatorDiscovery.Timeout"]      = "100ms";
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    try
                    {
                        IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                    }
                    catch (NoEndpointException)
                    {
                    }
                    try
                    {
                        IObjectPrx.Parse("test", com).IcePing();
                    }
                    catch (NoEndpointException)
                    {
                    }

                    Ice.ILocatorPrx defaultLocator = com.DefaultLocator !.Clone(encoding: Encoding.V11);

                    TestHelper.Assert(defaultLocator.GetRegistry() == null);
                    TestHelper.Assert(defaultLocator.CheckedCast(ILocatorPrx.Factory) == null);
                    try
                    {
                        com.DefaultLocator !.Clone(ILocatorPrx.Factory).GetLocalRegistry();
                    }
                    catch (OperationNotExistException)
                    {
                    }

                    using ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest");
                    adapter.Activate();
                }

                string multicast;
                if (communicator.GetProperty("Ice.PreferIPv6Address") == "1")
                {
                    multicast = "\"ff15::1\"";
                }
                else
                {
                    multicast = "239.255.0.1";
                }

                // Test invalid lookup endpoints
                {
                    properties = communicator.GetProperties();
                    properties.Remove("Ice.Default.Locator");
                    properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory";
                    properties["IceLocatorDiscovery.Lookup"]     = $"udp -h {multicast} --interface unknown";
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    try
                    {
                        IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (NoEndpointException)
                    {
                    }
                }

                {
                    properties = communicator.GetProperties();
                    properties.Remove("Ice.Default.Locator");
                    properties["IceLocatorDiscovery.RetryCount"] = "0";
                    properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory";
                    properties["IceLocatorDiscovery.Lookup"]     = $"udp -h {multicast} --interface unknown";
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    try
                    {
                        IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (NoEndpointException)
                    {
                    }
                }

                {
                    properties = communicator.GetProperties();
                    properties.Remove("Ice.Default.Locator");
                    properties["IceLocatorDiscovery.RetryCount"] = "1";
                    properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory";
                    {
                        string intf = communicator.GetProperty("IceLocatorDiscovery.Interface") ?? "";
                        if (intf.Length > 0)
                        {
                            intf = $" --interface \"{intf}\"";
                        }
                        string port = $"{helper.BasePort + 99}";
                        properties["IceLocatorDiscovery.Lookup"] =
                            $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}";
                    }
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    try
                    {
                        IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                    }
                    catch (NoEndpointException)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            Console.Out.WriteLine("ok");

            Console.Out.Write("shutting down server... ");
            Console.Out.Flush();
            obj.Shutdown();
            Console.Out.WriteLine("ok");
        }