示例#1
0
    allTestsWithDeploy(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        Console.Out.Write("testing stringToProxy... ");
        Console.Out.Flush();
        IObjectPrx @base = IObjectPrx.Parse("test @ TestAdapter", communicator);

        test(@base != null);
        IObjectPrx @base2 = IObjectPrx.Parse("test", communicator);

        test(@base2 != null);
        Console.Out.WriteLine("ok");

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

        test(obj.Equals(@base));
        TestIntfPrx obj2 = TestIntfPrx.CheckedCast(@base2);

        test(obj2.Equals(@base2));
        Console.Out.WriteLine("ok");

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

        Console.Out.Write("testing encoding versioning... ");
        Console.Out.Flush();
        IObjectPrx base10  = IObjectPrx.Parse("test10 @ TestAdapter10", communicator);
        IObjectPrx base102 = IObjectPrx.Parse("test10", communicator);

        try
        {
            base10.IcePing();
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        try
        {
            base102.IcePing();
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        base10  = base10.Clone(encodingVersion: Util.Encoding_1_0);
        base102 = base102.Clone(encodingVersion: Util.Encoding_1_0);
        base10.IcePing();
        base102.IcePing();
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing reference with unknown identity... ");
        Console.Out.Flush();
        try
        {
            IObjectPrx.Parse("unknown/unknown", communicator).IcePing();
            test(false);
        }
        catch (NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object"));
            test(ex.id.Equals("unknown/unknown"));
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing reference with unknown adapter... ");
        Console.Out.Flush();
        try
        {
            IObjectPrx.Parse("test @ TestAdapterUnknown", communicator).IcePing();
            test(false);
        }
        catch (NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object adapter"));
            test(ex.id.Equals("TestAdapterUnknown"));
        }
        Console.Out.WriteLine("ok");

        IceGrid.RegistryPrx registry = IceGrid.RegistryPrx.Parse(
            communicator.getDefaultLocator().Identity.category + "/Registry", communicator);
        IceGrid.AdminSessionPrx session = registry.createAdminSession("foo", "bar");
        session.GetConnection().setACM(registry.getACMTimeout(), null, ACMHeartbeat.HeartbeatAlways);

        IceGrid.AdminPrx admin = session.getAdmin();
        admin.enableServer("server", false);
        admin.stopServer("server");

        Console.Out.Write("testing whether server is still reachable... ");
        Console.Out.Flush();
        try
        {
            obj = TestIntfPrx.CheckedCast(@base);
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        try
        {
            obj2 = TestIntfPrx.CheckedCast(@base2);
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }

        try
        {
            admin.enableServer("server", true);
        }
        catch (IceGrid.ServerNotExistException)
        {
            test(false);
        }
        catch (IceGrid.NodeUnreachableException)
        {
            test(false);
        }

        try
        {
            obj = TestIntfPrx.CheckedCast(@base);
        }
        catch (Ice.NoEndpointException)
        {
            test(false);
        }
        try
        {
            obj2 = TestIntfPrx.CheckedCast(@base2);
        }
        catch (Ice.NoEndpointException)
        {
            test(false);
        }
        Console.Out.WriteLine("ok");

        try
        {
            admin.stopServer("server");
        }
        catch (IceGrid.ServerNotExistException)
        {
            test(false);
        }
        catch (IceGrid.ServerStopException)
        {
            test(false);
        }
        catch (IceGrid.NodeUnreachableException)
        {
            test(false);
        }

        session.destroy();
    }
示例#2
0
文件: AllTests.cs 项目: xingx001/ice
    public static void allTests(Test.TestHelper helper, List <int> ports)
    {
        Ice.Communicator communicator = helper.communicator();
        var output = helper.getWriter();

        output.Write("testing stringToProxy... ");
        output.Flush();
        string refString = "test";

        for (int i = 0; i < ports.Count; i++)
        {
            refString += ":" + helper.getTestEndpoint(ports[i]);
        }
        Ice.IObjectPrx basePrx = Ice.IObjectPrx.Parse(refString, communicator);
        test(basePrx != null);
        output.WriteLine("ok");

        output.Write("testing checked cast... ");
        output.Flush();
        TestIntfPrx obj = TestIntfPrx.CheckedCast(basePrx);

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

        int  oldPid = 0;
        bool ami    = false;

        for (int i = 1, j = 0; i <= ports.Count; ++i, ++j)
        {
            if (j > 3)
            {
                j   = 0;
                ami = !ami;
            }

            if (!ami)
            {
                output.Write("testing server #" + i + "... ");
                output.Flush();
                int pid = obj.pid();
                test(pid != oldPid);
                output.WriteLine("ok");
                oldPid = pid;
            }
            else
            {
                output.Write("testing server #" + i + " with AMI... ");
                output.Flush();
                var pid = obj.pidAsync().Result;
                test(pid != oldPid);
                output.WriteLine("ok");
                oldPid = pid;
            }

            if (j == 0)
            {
                if (!ami)
                {
                    output.Write("shutting down server #" + i + "... ");
                    output.Flush();
                    obj.shutdown();
                    output.WriteLine("ok");
                }
                else
                {
                    output.Write("shutting down server #" + i + " with AMI... ");
                    obj.shutdownAsync().Wait();
                    output.WriteLine("ok");
                }
            }
            else if (j == 1 || i + 1 > ports.Count)
            {
                if (!ami)
                {
                    output.Write("aborting server #" + i + "... ");
                    output.Flush();
                    try
                    {
                        obj.abort();
                        test(false);
                    }
                    catch (Ice.ConnectionLostException)
                    {
                        output.WriteLine("ok");
                    }
                    catch (Ice.ConnectFailedException)
                    {
                        output.WriteLine("ok");
                    }
                    catch (Ice.SocketException)
                    {
                        output.WriteLine("ok");
                    }
                }
                else
                {
                    output.Write("aborting server #" + i + " with AMI... ");
                    output.Flush();
                    try
                    {
                        obj.abortAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        exceptAbortI(ex.InnerException as Ice.Exception, output);
                    }
                    output.WriteLine("ok");
                }
            }
            else if (j == 2 || j == 3)
            {
                if (!ami)
                {
                    output.Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent call... ");
                    output.Flush();
                    try
                    {
                        obj.idempotentAbort();
                        test(false);
                    }
                    catch (Ice.ConnectionLostException)
                    {
                        output.WriteLine("ok");
                    }
                    catch (Ice.ConnectFailedException)
                    {
                        output.WriteLine("ok");
                    }
                    catch (Ice.SocketException)
                    {
                        output.WriteLine("ok");
                    }
                }
                else
                {
                    output.Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent AMI call... ");
                    output.Flush();
                    try
                    {
                        obj.idempotentAbortAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        exceptAbortI(ex.InnerException as Ice.Exception, output);
                    }
                    output.WriteLine("ok");
                }
                ++i;
            }
            else
            {
                Debug.Assert(false);
            }
        }

        output.Write("testing whether all servers are gone... ");
        output.Flush();
        try
        {
            obj.IcePing();
            test(false);
        }
        catch (Ice.LocalException)
        {
            output.WriteLine("ok");
        }
    }
示例#3
0
    public static void allTests(Test.TestHelper helper)
    {
        Ice.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.LocatorPrx locator = IceGrid.LocatorPrx.UncheckedCast(@base);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing checked cast... ");
        Console.Out.Flush();
        TestIntfPrx obj = TestIntfPrx.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... ");
        Ice.Identity finderId = new Ice.Identity();
        finderId.category = "Ice";
        finderId.name     = "LocatorFinder";
        Ice.LocatorFinderPrx finder = Ice.LocatorFinderPrx.CheckedCast(communicator.getDefaultLocator().Clone(finderId));
        test(finder.getLocator() != null);
        Console.Out.WriteLine("ok");

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

            IceGrid.AdminSessionPrx 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.
            //
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.Properties.Clone();
            initData.properties.setProperty("Ice.Default.Locator", "");
            initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery",
                                            "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory");
            initData.properties.setProperty("IceLocatorDiscovery.Port", helper.getTestPort(99).ToString());
            initData.properties.setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter");
            initData.properties.setProperty("AdapterForDiscoveryTest.Endpoints", "default");

            Ice.Communicator com = Ice.Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            IObjectPrx.Parse("test", com).IcePing();

            test(com.getDefaultLocator().getRegistry() != null);
            test(IceGrid.LocatorPrx.UncheckedCast(com.getDefaultLocator()).getLocalRegistry() != null);
            test(IceGrid.LocatorPrx.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.
            //
            initData.properties.setProperty("IceLocatorDiscovery.InstanceName", "unknown");
            initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1");
            initData.properties.setProperty("IceLocatorDiscovery.Timeout", "100");
            com = Ice.Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            }
            catch (Ice.NoEndpointException)
            {
            }
            try
            {
                IObjectPrx.Parse("test", com).IcePing();
            }
            catch (Ice.NoEndpointException)
            {
            }
            test(com.getDefaultLocator().getRegistry() == null);
            test(IceGrid.LocatorPrx.CheckedCast(com.getDefaultLocator()) == null);
            try
            {
                IceGrid.LocatorPrx.UncheckedCast(com.getDefaultLocator()).getLocalRegistry();
            }
            catch (Ice.OperationNotExistException)
            {
            }

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

            com.destroy();

            string multicast;
            if (communicator.Properties.getProperty("Ice.IPv6").Equals("1"))
            {
                multicast = "\"ff15::1\"";
            }
            else
            {
                multicast = "239.255.0.1";
            }

            //
            // Test invalid lookup endpoints
            //
            initData.properties = communicator.Properties.Clone();
            initData.properties.setProperty("Ice.Default.Locator", "");
            initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery",
                                            "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory");
            initData.properties.setProperty("IceLocatorDiscovery.Lookup",
                                            $"udp -h {multicast} --interface unknown");
            com = Ice.Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
            com.destroy();

            initData.properties = communicator.Properties.Clone();
            initData.properties.setProperty("Ice.Default.Locator", "");
            initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "0");
            initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery",
                                            "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory");
            initData.properties.setProperty("IceLocatorDiscovery.Lookup",
                                            "udp -h " + multicast + " --interface unknown");
            com = Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
            com.destroy();

            initData.properties = communicator.Properties.Clone();
            initData.properties.setProperty("Ice.Default.Locator", "");
            initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1");
            initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery",
                                            "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory");
            {
                string intf = initData.properties.getProperty("IceLocatorDiscovery.Interface");
                if (!intf.Equals(""))
                {
                    intf = " --interface \"" + intf + "\"";
                }
                string port = helper.getTestPort(99).ToString();
                initData.properties.setProperty("IceLocatorDiscovery.Lookup",
                                                "udp -h " + multicast + " --interface unknown:" +
                                                "udp -h " + multicast + " -p " + port + intf);
            }
            com = Ice.Util.initialize(initData);
            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");
    }