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