Beispiel #1
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 locator discovery can discover the registries and make sure locator requests are forwarded.
                Dictionary <string, string>?properties = communicator.GetProperties();
                properties["Ice.Default.Locator"] = "LocatorDiscovery";
                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();

                    Ice.ILocatorPrx defaultLocator = com.DefaultLocator !;
                    TestHelper.Assert(defaultLocator.Protocol == Protocol.Ice2);
                    TestHelper.Assert(defaultLocator.Encoding == Encoding.V20);

                    // This works fine because the LocatorDiscovery Locator performs transcoding for Ice::Locator
                    // operations.
                    TestHelper.Assert(defaultLocator.GetRegistry() != null);

                    // CheckedCast on the _IceGrid_ Locator proxy fails because ice_isA is not forwarded (due to the
                    // encoding mismatch) but is instead implemented by the plain Locator of LocatorDiscovery.
                    TestHelper.Assert(defaultLocator.CheckedCast(ILocatorPrx.Factory) == null);

                    // Change the encoding to make it work:
                    defaultLocator = defaultLocator.Clone(encoding: Encoding.V11);
                    var iceGridLocator = defaultLocator.CheckedCast(ILocatorPrx.Factory);
                    TestHelper.Assert(iceGridLocator != null);
                    TestHelper.Assert(iceGridLocator.GetLocalRegistry() != null);
                    TestHelper.Assert(iceGridLocator.GetLocalQuery() != null);

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

                    try
                    {
                        IObjectPrx.Parse("test", com).IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (NoEndpointException)
                    {
                    }

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

                    try
                    {
                        defaultLocator.Clone(ILocatorPrx.Factory).GetLocalRegistry();
                        TestHelper.Assert(false);
                    }
                    catch (OperationNotExistException)
                    {
                    }

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

                string multicast;
                if (helper.Host.Contains(":"))
                {
                    multicast = "\"ff15::1\"";
                }
                else
                {
                    multicast = "239.255.0.1";
                }

                // Test invalid lookup endpoints
                {
                    properties = communicator.GetProperties();
                    properties["Ice.Default.Locator"]         = "locatordiscovery";
                    properties["Ice.LocatorDiscovery.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["Ice.Default.Locator"]             = "locatordiscovery";
                    properties["Ice.LocatorDiscovery.RetryCount"] = "0";
                    properties["Ice.LocatorDiscovery.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["Ice.Default.Locator"]             = "locatordiscovery";
                    properties["Ice.LocatorDiscovery.RetryCount"] = "1";
                    {
                        string intf = helper.Host.Contains(":") ? $"\"{helper.Host}\"" : helper.Host;
                        string port = $"{helper.BasePort + 99}";
                        properties["Ice.LocatorDiscovery.Lookup"] =
                            $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port} --interface {intf}";
                    }
                    using var com = new Communicator(properties);
                    TestHelper.Assert(com.DefaultLocator != null);
                    IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                }
            }
            Console.Out.WriteLine("ok");

            Console.Out.Write("shutting down server... ");
            Console.Out.Flush();
            obj.Shutdown();
            Console.Out.WriteLine("ok");
        }
Beispiel #2
0
    public static void allTests(TestHelper helper)
    {
        Communicator communicator = helper.communicator();

        Console.Out.Write("testing stringToProxy... ");
        Console.Out.Flush();
        string rf    = "test @ TestAdapter";
        var    @base = IObjectPrx.Parse(rf, communicator);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing IceGrid.Locator is present... ");
        IceGrid.ILocatorPrx locator = IceGrid.ILocatorPrx.UncheckedCast(@base);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing checked cast... ");
        Console.Out.Flush();
        ITestIntfPrx obj = ITestIntfPrx.CheckedCast(@base);

        test(obj.Equals(@base));
        Console.Out.WriteLine("ok");

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

        Console.Out.Write("testing locator finder... ");
        Identity          finderId = new Identity("LocatorFinder", "Ice");
        ILocatorFinderPrx finder   = ILocatorFinderPrx.CheckedCast(communicator.GetDefaultLocator().Clone(finderId));

        test(finder.GetLocator() != null);
        Console.Out.WriteLine("ok");

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

            IceGrid.IAdminSessionPrx session = registry.CreateAdminSession("foo", "bar");
            session.GetAdmin().AddObjectWithType(@base, "::Test");
            session.Destroy();

            //
            // Ensure the IceGrid discovery locator can discover the
            // registries and make sure locator requests are forwarded.
            //
            var properties = communicator.GetProperties();
            properties.Remove("Ice.Default.Locator");
            properties["Ice.Plugin.IceLocatorDiscovery"]    = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            properties["IceLocatorDiscovery.Port"]          = helper.getTestPort(99).ToString();
            properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter";
            properties["AdapterForDiscoveryTest.Endpoints"] = "default";

            Communicator com = new Communicator(properties);
            test(com.GetDefaultLocator() != null);
            IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            IObjectPrx.Parse("test", com).IcePing();

            test(com.GetDefaultLocator().GetRegistry() != null);
            test(IceGrid.ILocatorPrx.UncheckedCast(com.GetDefaultLocator()).GetLocalRegistry() != null);
            test(IceGrid.ILocatorPrx.UncheckedCast(com.GetDefaultLocator()).GetLocalQuery() != null);

            Ice.ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest");
            adapter.Activate();
            adapter.Deactivate();
            com.Destroy();

            //
            // 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"]      = "100";
            com = new Communicator(properties);
            test(com.GetDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            }
            catch (NoEndpointException)
            {
            }
            try
            {
                IObjectPrx.Parse("test", com).IcePing();
            }
            catch (NoEndpointException)
            {
            }
            test(com.GetDefaultLocator().GetRegistry() == null);
            test(IceGrid.ILocatorPrx.CheckedCast(com.GetDefaultLocator()) == null);
            try
            {
                IceGrid.ILocatorPrx.UncheckedCast(com.GetDefaultLocator()).GetLocalRegistry();
            }
            catch (Ice.OperationNotExistException)
            {
            }

            adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest");
            adapter.Activate();
            adapter.Deactivate();

            com.Destroy();

            string multicast;
            if (communicator.GetProperty("Ice.IPv6") == "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"] = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            properties["IceLocatorDiscovery.Lookup"]     = $"udp -h {multicast} --interface unknown";
            com = new Communicator(properties);
            test(com.GetDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
            com.Destroy();

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

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

        Console.Out.Write("shutting down server... ");
        Console.Out.Flush();
        obj.shutdown();
        Console.Out.WriteLine("ok");
    }
Beispiel #3
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");
        }