Esempio n. 1
0
    public void run()
    {
        TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(_communicator.stringToProxy(
                                                                _adapter.getTestIntf().ToString()));

        try
        {
            proxy.ice_getConnection().setCloseCallback(_ =>
            {
                lock (this)
                {
                    _closed = true;
                    Monitor.Pulse(this);
                }
            });

            proxy.ice_getConnection().setHeartbeatCallback(_ =>
            {
                lock (this)
                {
                    ++_heartbeat;
                }
            });

            runTestCase(_adapter, proxy);
        }
        catch (Exception ex)
        {
            _msg = "unexpected exception:\n" + ex.ToString();
        }
    }
Esempio n. 2
0
    public void run()
    {
        TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(_communicator.stringToProxy(
                                                                _adapter.getTestIntf().ToString()));

        try
        {
            proxy.ice_getConnection().setCallback(this);
            runTestCase(_adapter, proxy);
        }
        catch (Exception ex)
        {
            _msg = "unexpected exception:\n" + ex.ToString();
        }
    }
Esempio n. 3
0
    private static TestIntfPrx createTestIntfPrx(List <RemoteObjectAdapterPrx> adapters)
    {
        List <Ice.Endpoint> endpoints          = new List <Ice.Endpoint>();
        TestIntfPrx         obj                = null;
        IEnumerator <RemoteObjectAdapterPrx> p = adapters.GetEnumerator();

        while (p.MoveNext())
        {
            obj = p.Current.getTestIntf();
            foreach (Ice.Endpoint e in obj.ice_getEndpoints())
            {
                endpoints.Add(e);
            }
        }
        return(TestIntfPrxHelper.uncheckedCast(obj.ice_endpoints(endpoints.ToArray())));
    }
Esempio n. 4
0
 opEx(Ice.AsyncResult result)
 {
     test(result.AsyncState == _cookie);
     try
     {
         TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result);
         test(false);
     }
     catch (Ice.NoEndpointException)
     {
         called();
     }
     catch (Ice.Exception)
     {
         test(false);
     }
 }
Esempio n. 5
0
    private static int run(string[] args, Ice.Communicator communicator)
    {
        AllTests.allTests(communicator);

        int num;

        try
        {
            num = args.Length == 1 ? System.Int32.Parse(args[0]) : 0;
        }
        catch (System.FormatException)
        {
            num = 0;
        }
        for (int i = 0; i < num; ++i)
        {
            TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("control:tcp -p " + (12010 + i))).shutdown();
        }
        return(0);
    }
Esempio n. 6
0
    public override int run(string[] args)
    {
        AllTests.allTests(this);

        int num;

        try
        {
            num = args.Length == 1 ? Int32.Parse(args[0]) : 0;
        }
        catch (FormatException)
        {
            num = 0;
        }
        for (int i = 0; i < num; ++i)
        {
            string endpoint = getTestEndpoint(i, "tcp");
            TestIntfPrxHelper.uncheckedCast(communicator().stringToProxy("control:" + endpoint)).shutdown();
        }
        return(0);
    }
Esempio n. 7
0
    public static void allTests(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        TestIntfPrx      service1     = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                                   helper.getTestEndpoint(0)));
        TestIntfPrx service2 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                          helper.getTestEndpoint(1)));
        TestIntfPrx service3 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                          helper.getTestEndpoint(2)));
        TestIntfPrx service4 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                          helper.getTestEndpoint(3)));

        if (service1.getProperty("IceBox.InheritProperties").Equals(""))
        {
            Console.Out.Write("testing service properties... ");
            Console.Out.Flush();

            test(service1.getProperty("Ice.ProgramName").Equals("IceBox-Service1"));
            test(service1.getProperty("Service").Equals("1"));
            test(service1.getProperty("Service1.Ovrd").Equals("2"));
            test(service1.getProperty("Service1.Unset").Equals(""));
            test(service1.getProperty("Arg").Equals("1"));

            string[] args1 = { "-a", "--Arg=2" };
            test(IceUtilInternal.Arrays.Equals(service1.getArgs(), args1));

            test(service2.getProperty("Ice.ProgramName").Equals("Test"));
            test(service2.getProperty("Service").Equals("2"));
            test(service2.getProperty("Service1.ArgProp").Equals(""));
            test(service2.getProperty("IceBox.InheritProperties").Equals("1"));

            string[] args2 = { "--Service1.ArgProp=1" };
            test(IceUtilInternal.Arrays.Equals(service2.getArgs(), args2));

            Console.Out.WriteLine("ok");

            Console.Out.Write("testing with shared communicator... ");
            Console.Out.Flush();

            test(service3.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator"));
            test(service3.getProperty("Service").Equals("4"));
            test(service3.getProperty("Prop").Equals(""));
            test(service3.getProperty("Service3.Prop").Equals("1"));
            test(service3.getProperty("Ice.Trace.Slicing").Equals("3"));

            test(service4.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator"));
            test(service4.getProperty("Service").Equals("4"));
            test(service4.getProperty("Prop").Equals(""));
            test(service4.getProperty("Service3.Prop").Equals("1"));
            test(service4.getProperty("Ice.Trace.Slicing").Equals("3"));

            string[] args4 = { "--Service3.Prop=2" };
            test(IceUtilInternal.Arrays.Equals(service4.getArgs(), args4));

            Console.Out.WriteLine("ok");
        }
        else
        {
            Console.Out.Write("testing property inheritance... ");
            Console.Out.Flush();

            test(service1.getProperty("Ice.ProgramName").Equals("IceBox2-Service1"));
            test(service1.getProperty("ServerProp").Equals("1"));
            test(service1.getProperty("OverrideMe").Equals("2"));
            test(service1.getProperty("UnsetMe").Equals(""));
            test(service1.getProperty("Service1.Prop").Equals("1"));
            test(service1.getProperty("Service1.ArgProp").Equals("2"));

            test(service2.getProperty("Ice.ProgramName").Equals("IceBox2-SharedCommunicator"));
            test(service2.getProperty("ServerProp").Equals("1"));
            test(service2.getProperty("OverrideMe").Equals("3"));
            test(service2.getProperty("UnsetMe").Equals(""));
            test(service2.getProperty("Service2.Prop").Equals("1"));

            Console.Out.WriteLine("ok");
        }
    }
Esempio n. 8
0
    public static TestIntfPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        string           sref         = "test:" + app.getTestEndpoint(0);

        Ice.ObjectPrx obj = communicator.stringToProxy(sref);
        test(obj != null);
        TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(obj);

        test(proxy != null);

        Console.Out.Write("testing enum values... ");
        Console.Out.Flush();

        test((int)ByteEnum.benum1 == 0);
        test((int)ByteEnum.benum2 == 1);
        test((int)ByteEnum.benum3 == ByteConst1.value);
        test((int)ByteEnum.benum4 == ByteConst1.value + 1);
        test((int)ByteEnum.benum5 == ShortConst1.value);
        test((int)ByteEnum.benum6 == ShortConst1.value + 1);
        test((int)ByteEnum.benum7 == IntConst1.value);
        test((int)ByteEnum.benum8 == IntConst1.value + 1);
        test((int)ByteEnum.benum9 == LongConst1.value);
        test((int)ByteEnum.benum10 == LongConst1.value + 1);
        test((int)ByteEnum.benum11 == ByteConst2.value);

        test((int)ShortEnum.senum1 == 3);
        test((int)ShortEnum.senum2 == 4);
        test((int)ShortEnum.senum3 == ByteConst1.value);
        test((int)ShortEnum.senum4 == ByteConst1.value + 1);
        test((int)ShortEnum.senum5 == ShortConst1.value);
        test((int)ShortEnum.senum6 == ShortConst1.value + 1);
        test((int)ShortEnum.senum7 == IntConst1.value);
        test((int)ShortEnum.senum8 == IntConst1.value + 1);
        test((int)ShortEnum.senum9 == LongConst1.value);
        test((int)ShortEnum.senum10 == LongConst1.value + 1);
        test((int)ShortEnum.senum11 == ShortConst2.value);

        test((int)IntEnum.ienum1 == 0);
        test((int)IntEnum.ienum2 == 1);
        test((int)IntEnum.ienum3 == ByteConst1.value);
        test((int)IntEnum.ienum4 == ByteConst1.value + 1);
        test((int)IntEnum.ienum5 == ShortConst1.value);
        test((int)IntEnum.ienum6 == ShortConst1.value + 1);
        test((int)IntEnum.ienum7 == IntConst1.value);
        test((int)IntEnum.ienum8 == IntConst1.value + 1);
        test((int)IntEnum.ienum9 == LongConst1.value);
        test((int)IntEnum.ienum10 == LongConst1.value + 1);
        test((int)IntEnum.ienum11 == IntConst2.value);
        test((int)IntEnum.ienum12 == LongConst2.value);

        test((int)SimpleEnum.red == 0);
        test((int)SimpleEnum.green == 1);
        test((int)SimpleEnum.blue == 2);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum streaming... ");
        Console.Out.Flush();

        Ice.OutputStream ostr;
        byte[]           bytes;

        bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0");

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)ByteEnum.benum11, (int)ByteEnum.benum11);
        bytes = ostr.finished();
        test(bytes.Length == 1); // ByteEnum should require one byte

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)ShortEnum.senum11, (int)ShortEnum.senum11);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 2 : 5));

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)IntEnum.ienum11, (int)IntEnum.ienum12);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 4 : 5));

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)SimpleEnum.blue, (int)SimpleEnum.blue);
        bytes = ostr.finished();
        test(bytes.Length == 1); // SimpleEnum should require one byte

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum operations... ");
        Console.Out.Flush();

        ByteEnum byteEnum;

        test(proxy.opByte(ByteEnum.benum1, out byteEnum) == ByteEnum.benum1);
        test(byteEnum == ByteEnum.benum1);
        test(proxy.opByte(ByteEnum.benum11, out byteEnum) == ByteEnum.benum11);
        test(byteEnum == ByteEnum.benum11);

        ShortEnum shortEnum;

        test(proxy.opShort(ShortEnum.senum1, out shortEnum) == ShortEnum.senum1);
        test(shortEnum == ShortEnum.senum1);
        test(proxy.opShort(ShortEnum.senum11, out shortEnum) == ShortEnum.senum11);
        test(shortEnum == ShortEnum.senum11);

        IntEnum intEnum;

        test(proxy.opInt(IntEnum.ienum1, out intEnum) == IntEnum.ienum1);
        test(intEnum == IntEnum.ienum1);
        test(proxy.opInt(IntEnum.ienum11, out intEnum) == IntEnum.ienum11);
        test(intEnum == IntEnum.ienum11);
        test(proxy.opInt(IntEnum.ienum12, out intEnum) == IntEnum.ienum12);
        test(intEnum == IntEnum.ienum12);

        SimpleEnum s;

        test(proxy.opSimple(SimpleEnum.green, out s) == SimpleEnum.green);
        test(s == SimpleEnum.green);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum sequences operations... ");
        Console.Out.Flush();

        {
            ByteEnum[] b1 = new ByteEnum[11]
            {
                ByteEnum.benum1, ByteEnum.benum2, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5,
                ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, ByteEnum.benum9, ByteEnum.benum10,
                ByteEnum.benum11
            };

            ByteEnum[] b2;
            ByteEnum[] b3 = proxy.opByteSeq(b1, out b2);

            for (int i = 0; i < b1.Length; ++i)
            {
                test(b1[i] == b2[i]);
                test(b1[i] == b3[i]);
            }
        }

        {
            ShortEnum[] s1 = new ShortEnum[11]
            {
                ShortEnum.senum1, ShortEnum.senum2, ShortEnum.senum3, ShortEnum.senum4, ShortEnum.senum5,
                ShortEnum.senum6, ShortEnum.senum7, ShortEnum.senum8, ShortEnum.senum9, ShortEnum.senum10,
                ShortEnum.senum11
            };

            ShortEnum[] s2;
            ShortEnum[] s3 = proxy.opShortSeq(s1, out s2);

            for (int i = 0; i < s1.Length; ++i)
            {
                test(s1[i] == s2[i]);
                test(s1[i] == s3[i]);
            }
        }

        {
            IntEnum[] i1 = new IntEnum[11]
            {
                IntEnum.ienum1, IntEnum.ienum2, IntEnum.ienum3, IntEnum.ienum4, IntEnum.ienum5,
                IntEnum.ienum6, IntEnum.ienum7, IntEnum.ienum8, IntEnum.ienum9, IntEnum.ienum10,
                IntEnum.ienum11
            };

            IntEnum[] i2;
            IntEnum[] i3 = proxy.opIntSeq(i1, out i2);

            for (int i = 0; i < i1.Length; ++i)
            {
                test(i1[i] == i2[i]);
                test(i1[i] == i3[i]);
            }
        }

        {
            SimpleEnum[] s1 = new SimpleEnum[3]
            {
                SimpleEnum.red, SimpleEnum.green, SimpleEnum.blue
            };

            SimpleEnum[] s2;
            SimpleEnum[] s3 = proxy.opSimpleSeq(s1, out s2);

            for (int i = 0; i < s1.Length; ++i)
            {
                test(s1[i] == s2[i]);
                test(s1[i] == s3[i]);
            }
        }

        Console.Out.WriteLine("ok");
        return(proxy);
    }
Esempio n. 9
0
 self(Ice.Current current)
 {
     return(TestIntfPrxHelper.uncheckedCast(current.adapter.createProxy(current.id)));
 }
Esempio n. 10
0
    allTests(TestCommon.Application app, int num)
    {
        Ice.Communicator     communicator    = app.communicator();
        List <ControllerPrx> proxies         = new List <ControllerPrx>();
        List <ControllerPrx> indirectProxies = new List <ControllerPrx>();

        for (int i = 0; i < num; ++i)
        {
            string id = "controller" + i;
            proxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id)));
            indirectProxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id + "@control" + i)));
        }

        Write("testing indirect proxies... ");
        Flush();
        {
            foreach (ControllerPrx prx in indirectProxies)
            {
                prx.ice_ping();
            }
        }
        WriteLine("ok");

        Write("testing well-known proxies... ");
        Flush();
        {
            foreach (ControllerPrx prx in proxies)
            {
                prx.ice_ping();
            }
        }
        WriteLine("ok");

        Write("testing object adapter registration... ");
        Flush();
        {
            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
                test(false);
            }
            catch (Ice.NoEndpointException)
            {
            }

            proxies[0].activateObjectAdapter("oa", "oa1", "");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
                test(false);
            }
            catch (Ice.NoEndpointException)
            {
            }
        }
        WriteLine("ok");

        Write("testing object adapter migration...");
        Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[0].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            proxies[0].removeObject("oa", "object");
            proxies[0].deactivateObjectAdapter("oa");

            proxies[1].activateObjectAdapter("oa", "oa1", "");
            proxies[1].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            proxies[1].removeObject("oa", "object");
            proxies[1].deactivateObjectAdapter("oa");
        }
        WriteLine("ok");

        Write("testing object migration...");
        Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[1].activateObjectAdapter("oa", "oa2", "");

            proxies[0].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            communicator.stringToProxy("object").ice_ping();
            proxies[0].removeObject("oa", "object");

            proxies[1].addObject("oa", "object");
            communicator.stringToProxy("object @ oa2").ice_ping();
            communicator.stringToProxy("object").ice_ping();
            proxies[1].removeObject("oa", "object");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }
            try
            {
                communicator.stringToProxy("object @ oa2").ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
        }
        WriteLine("ok");

        Write("testing replica groups...");
        Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[1].activateObjectAdapter("oa", "oa2", "rg");
            proxies[2].activateObjectAdapter("oa", "oa3", "rg");

            proxies[0].addObject("oa", "object");
            proxies[1].addObject("oa", "object");
            proxies[2].addObject("oa", "object");

            communicator.stringToProxy("object @ oa1").ice_ping();
            communicator.stringToProxy("object @ oa2").ice_ping();
            communicator.stringToProxy("object @ oa3").ice_ping();

            communicator.stringToProxy("object @ rg").ice_ping();

            List <string> adapterIds = new List <string>();
            adapterIds.Add("oa1");
            adapterIds.Add("oa2");
            adapterIds.Add("oa3");
            TestIntfPrx intf = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("object"));
            intf = (TestIntfPrx)intf.ice_connectionCached(false).ice_locatorCacheTimeout(0);
            while (adapterIds.Count > 0)
            {
                adapterIds.Remove(intf.getAdapterId());
            }

            while (true)
            {
                adapterIds.Add("oa1");
                adapterIds.Add("oa2");
                adapterIds.Add("oa3");
                intf = TestIntfPrxHelper.uncheckedCast(
                    communicator.stringToProxy("object @ rg").ice_connectionCached(false));
                int nRetry = 100;
                while (adapterIds.Count > 0 && --nRetry > 0)
                {
                    adapterIds.Remove(intf.getAdapterId());
                }
                if (nRetry > 0)
                {
                    break;
                }

                // The previous locator lookup probably didn't return all the replicas... try again.
                communicator.stringToProxy("object @ rg").ice_locatorCacheTimeout(0).ice_ping();
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
            test(TestIntfPrxHelper.uncheckedCast(
                     communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa3"));
            proxies[2].deactivateObjectAdapter("oa");

            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[0].addObject("oa", "object");
            test(TestIntfPrxHelper.uncheckedCast(
                     communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa1"));
            proxies[0].deactivateObjectAdapter("oa");
        }
        WriteLine("ok");

        Write("testing invalid lookup endpoints... ");
        Flush();
        {
            String multicast;
            if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1"))
            {
                multicast = "\"ff15::1\"";
            }
            else
            {
                multicast = "239.255.0.1";
            }

            {
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = communicator.getProperties().ice_clone_();
                initData.properties.setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown");
                Ice.Communicator comm = Ice.Util.initialize(initData);
                test(comm.getDefaultLocator() != null);
                try
                {
                    comm.stringToProxy("controller0@control0").ice_ping();
                    test(false);
                }
                catch (Ice.LocalException)
                {
                }
                comm.destroy();
            }
            {
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = communicator.getProperties().ice_clone_();
                string intf = initData.properties.getProperty("IceDiscovery.Interface");
                if (!intf.Equals(""))
                {
                    intf = " --interface \"" + intf + "\"";
                }
                string port = initData.properties.getProperty("IceDiscovery.Port");
                initData.properties.setProperty("IceDiscovery.Lookup",
                                                "udp -h " + multicast + " --interface unknown:" +
                                                "udp -h " + multicast + " -p " + port + intf);
                Ice.Communicator comm = Ice.Util.initialize(initData);
                test(comm.getDefaultLocator() != null);
                comm.stringToProxy("controller0@control0").ice_ping();
                comm.destroy();
            }
        }
        WriteLine("ok");

        Write("shutting down... ");
        Flush();
        foreach (ControllerPrx prx in proxies)
        {
            prx.shutdown();
        }
        WriteLine("ok");
    }
Esempio n. 11
0
    allTests(Ice.Communicator communicator, int num)
    {
        List <ControllerPrx> proxies         = new List <ControllerPrx>();
        List <ControllerPrx> indirectProxies = new List <ControllerPrx>();

        for (int i = 0; i < num; ++i)
        {
            string id = "controller" + i;
            proxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id)));
            indirectProxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id + "@control" + i)));
        }

        Console.Out.Write("testing indirect proxies... ");
        Console.Out.Flush();
        {
            foreach (ControllerPrx prx in indirectProxies)
            {
                prx.ice_ping();
            }
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing well-known proxies... ");
        Console.Out.Flush();
        {
            foreach (ControllerPrx prx in proxies)
            {
                prx.ice_ping();
            }
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing object adapter registration... ");
        Console.Out.Flush();
        {
            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
            }
            catch (Ice.NoEndpointException)
            {
            }

            proxies[0].activateObjectAdapter("oa", "oa1", "");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
            }
            catch (Ice.NoEndpointException)
            {
            }
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing object adapter migration...");
        Console.Out.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[0].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            proxies[0].removeObject("oa", "object");
            proxies[0].deactivateObjectAdapter("oa");

            proxies[1].activateObjectAdapter("oa", "oa1", "");
            proxies[1].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            proxies[1].removeObject("oa", "object");
            proxies[1].deactivateObjectAdapter("oa");
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing object migration...");
        Console.Out.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[1].activateObjectAdapter("oa", "oa2", "");

            proxies[0].addObject("oa", "object");
            communicator.stringToProxy("object @ oa1").ice_ping();
            communicator.stringToProxy("object").ice_ping();
            proxies[0].removeObject("oa", "object");

            proxies[1].addObject("oa", "object");
            communicator.stringToProxy("object @ oa2").ice_ping();
            communicator.stringToProxy("object").ice_ping();
            proxies[1].removeObject("oa", "object");

            try
            {
                communicator.stringToProxy("object @ oa1").ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }
            try
            {
                communicator.stringToProxy("object @ oa2").ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing replica groups...");
        Console.Out.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[1].activateObjectAdapter("oa", "oa2", "rg");
            proxies[2].activateObjectAdapter("oa", "oa3", "rg");

            proxies[0].addObject("oa", "object");
            proxies[1].addObject("oa", "object");
            proxies[2].addObject("oa", "object");

            communicator.stringToProxy("object @ oa1").ice_ping();
            communicator.stringToProxy("object @ oa2").ice_ping();
            communicator.stringToProxy("object @ oa3").ice_ping();

            communicator.stringToProxy("object @ rg").ice_ping();

            List <string> adapterIds = new List <string>();
            adapterIds.Add("oa1");
            adapterIds.Add("oa2");
            adapterIds.Add("oa3");
            TestIntfPrx intf = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("object"));
            intf = (TestIntfPrx)intf.ice_connectionCached(false).ice_locatorCacheTimeout(0);
            while (adapterIds.Count > 0)
            {
                adapterIds.Remove(intf.getAdapterId());
            }

            while (true)
            {
                adapterIds.Add("oa1");
                adapterIds.Add("oa2");
                adapterIds.Add("oa3");
                intf = TestIntfPrxHelper.uncheckedCast(
                    communicator.stringToProxy("object @ rg").ice_connectionCached(false));
                int nRetry = 100;
                while (adapterIds.Count > 0 && --nRetry > 0)
                {
                    adapterIds.Remove(intf.getAdapterId());
                }
                if (nRetry > 0)
                {
                    break;
                }

                // The previous locator lookup probably didn't return all the replicas... try again.
                communicator.stringToProxy("object @ rg").ice_locatorCacheTimeout(0).ice_ping();
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
            test(TestIntfPrxHelper.uncheckedCast(
                     communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa3"));
            proxies[2].deactivateObjectAdapter("oa");

            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[0].addObject("oa", "object");
            test(TestIntfPrxHelper.uncheckedCast(
                     communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa1"));
            proxies[0].deactivateObjectAdapter("oa");
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("shutting down... ");
        Console.Out.Flush();
        foreach (ControllerPrx prx in proxies)
        {
            prx.shutdown();
        }
        Console.Out.WriteLine("ok");
    }
Esempio n. 12
0
    public static void allTests(Test.TestHelper helper)
    {
        var output = helper.getWriter();

        Ice.Communicator communicator = helper.communicator();
        string           sref         = "test:" + helper.getTestEndpoint(0);

        Ice.ObjectPrx obj = communicator.stringToProxy(sref);
        test(obj != null);

        Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj);

        sref = "testController:" + helper.getTestEndpoint(1);
        obj  = communicator.stringToProxy(sref);
        test(obj != null);

        Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj);

        output.Write("testing dispatcher with continuations... ");
        output.Flush();
        {
            p.op();

            Callback      cb           = new Callback(output);
            Action <Task> continuation = (Task previous) =>
            {
                try
                {
                    previous.Wait();
                    cb.response();
                }
                catch (AggregateException ex)
                {
                    cb.exception((Ice.Exception)ex.InnerException);
                }
            };
            // We use sleepAsync instead of opAsync to ensure the response isn't received before
            // we setup the continuation
            var t = p.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously);
            t.Wait();
            cb.check();

            var i = (TestIntfPrx)p.ice_adapterId("dummy");

            //
            // sleepAsync doesn't help here as the test will fail with Ice.NoEndpointException and sleepAsync
            // will not be called.
            //
            //i.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously).Wait();
            //cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                // The continuation might be (rarely) executed on the current thread if the setup of the
                // continuation occurs after the invocation timeout.
                var         thread = Thread.CurrentThread;
                TestIntfPrx to     = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(20));
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        test(ex.InnerException is Ice.InvocationTimeoutException);
                        test(Dispatcher.isDispatcherThread() || thread == Thread.CurrentThread);
                    }
                }, TaskContinuationOptions.ExecuteSynchronously).Wait();
            }

            //
            // Repeat using the proxy scheduler in this case we don't need to call sleepAsync, continuations
            // are waranted to run with the dispatcher even if not executed synchronously.
            //

            t = p.opAsync().ContinueWith(continuation, p.ice_scheduler());
            t.Wait();
            cb.check();

            i.opAsync().ContinueWith(continuation, i.ice_scheduler()).Wait();
            cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                TestIntfPrx to = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10));
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        test(ex.InnerException is Ice.InvocationTimeoutException);
                        test(Dispatcher.isDispatcherThread());
                    }
                }, p.ice_scheduler()).Wait();
            }

            //
            // Hold adapter to ensure the invocations don't complete synchronously
            // Also disable collocation optimization on p
            //
            testController.holdAdapter();
            var           p2            = TestIntfPrxHelper.uncheckedCast(p.ice_collocationOptimized(false));
            Action <Task> continuation2 = (Task previous) =>
            {
                test(Dispatcher.isDispatcherThread());
                try
                {
                    previous.Wait();
                }
                catch (AggregateException ex)
                {
                    test(ex.InnerException is Ice.CommunicatorDestroyedException);
                }
            };

            byte[] seq = new byte[10 * 1024];
            (new Random()).NextBytes(seq);
            Progress sentSynchronously;
            do
            {
                sentSynchronously = new Progress();
                t = p2.opWithPayloadAsync(seq, progress: sentSynchronously).ContinueWith(
                    continuation2,
                    TaskContinuationOptions.ExecuteSynchronously);
            }while (sentSynchronously.getResult());
            testController.resumeAdapter();
            t.Wait();
        }
        output.WriteLine("ok");

        output.Write("testing dispatcher with async/await... ");
        output.Flush();
        {
            TaskCompletionSource <object> t = new TaskCompletionSource <object>();
            p.opAsync().ContinueWith(async previous => // Execute the code below from the Ice client thread pool
            {
                try
                {
                    await p.opAsync();
                    test(Dispatcher.isDispatcherThread());

                    try
                    {
                        TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
                        await i.opAsync();
                        test(false);
                    }
                    catch (Exception)
                    {
                        test(Dispatcher.isDispatcherThread());
                    }

                    TestIntfPrx to = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10));
                    try
                    {
                        await to.sleepAsync(500);
                        test(false);
                    }
                    catch (Ice.InvocationTimeoutException)
                    {
                        test(Dispatcher.isDispatcherThread());
                    }
                    t.SetResult(null);
                }
                catch (Exception ex)
                {
                    t.SetException(ex);
                }
            }, p.ice_scheduler());

            t.Task.Wait();
        }
        output.WriteLine("ok");

        p.shutdown();
    }
Esempio n. 13
0
    public static TestIntfPrx allTests(Ice.Communicator communicator)
#endif
    {
        string sref = "test:default -p 12010";

        Ice.ObjectPrx obj = communicator.stringToProxy(sref);
        test(obj != null);
        TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(obj);

        test(proxy != null);

        Console.Out.Write("testing enum values... ");
        Console.Out.Flush();

        test((int)ByteEnum.benum1 == 0);
        test((int)ByteEnum.benum2 == 1);
        test((int)ByteEnum.benum3 == ByteConst1.value);
        test((int)ByteEnum.benum4 == ByteConst1.value + 1);
        test((int)ByteEnum.benum5 == ShortConst1.value);
        test((int)ByteEnum.benum6 == ShortConst1.value + 1);
        test((int)ByteEnum.benum7 == IntConst1.value);
        test((int)ByteEnum.benum8 == IntConst1.value + 1);
        test((int)ByteEnum.benum9 == LongConst1.value);
        test((int)ByteEnum.benum10 == LongConst1.value + 1);
        test((int)ByteEnum.benum11 == ByteConst2.value);

        test((int)ShortEnum.senum1 == 3);
        test((int)ShortEnum.senum2 == 4);
        test((int)ShortEnum.senum3 == ByteConst1.value);
        test((int)ShortEnum.senum4 == ByteConst1.value + 1);
        test((int)ShortEnum.senum5 == ShortConst1.value);
        test((int)ShortEnum.senum6 == ShortConst1.value + 1);
        test((int)ShortEnum.senum7 == IntConst1.value);
        test((int)ShortEnum.senum8 == IntConst1.value + 1);
        test((int)ShortEnum.senum9 == LongConst1.value);
        test((int)ShortEnum.senum10 == LongConst1.value + 1);
        test((int)ShortEnum.senum11 == ShortConst2.value);

        test((int)IntEnum.ienum1 == 0);
        test((int)IntEnum.ienum2 == 1);
        test((int)IntEnum.ienum3 == ByteConst1.value);
        test((int)IntEnum.ienum4 == ByteConst1.value + 1);
        test((int)IntEnum.ienum5 == ShortConst1.value);
        test((int)IntEnum.ienum6 == ShortConst1.value + 1);
        test((int)IntEnum.ienum7 == IntConst1.value);
        test((int)IntEnum.ienum8 == IntConst1.value + 1);
        test((int)IntEnum.ienum9 == LongConst1.value);
        test((int)IntEnum.ienum10 == LongConst1.value + 1);
        test((int)IntEnum.ienum11 == IntConst2.value);
        test((int)IntEnum.ienum12 == LongConst2.value);

        test((int)SimpleEnum.red == 0);
        test((int)SimpleEnum.green == 1);
        test((int)SimpleEnum.blue == 2);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum streaming... ");
        Console.Out.Flush();

        Ice.OutputStream ostr;
        byte[]           bytes;

        bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0");

        ostr = Ice.Util.createOutputStream(communicator);
        ByteEnumHelper.write(ostr, ByteEnum.benum11);
        bytes = ostr.finished();
        test(bytes.Length == 1); // ByteEnum should require one byte

        ostr = Ice.Util.createOutputStream(communicator);
        ShortEnumHelper.write(ostr, ShortEnum.senum11);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 2 : 5));

        ostr = Ice.Util.createOutputStream(communicator);
        IntEnumHelper.write(ostr, IntEnum.ienum11);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 4 : 5));

        ostr = Ice.Util.createOutputStream(communicator);
        SimpleEnumHelper.write(ostr, SimpleEnum.blue);
        bytes = ostr.finished();
        test(bytes.Length == 1); // SimpleEnum should require one byte

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum operations... ");
        Console.Out.Flush();

        ByteEnum byteEnum;

        test(proxy.opByte(ByteEnum.benum1, out byteEnum) == ByteEnum.benum1);
        test(byteEnum == ByteEnum.benum1);
        test(proxy.opByte(ByteEnum.benum11, out byteEnum) == ByteEnum.benum11);
        test(byteEnum == ByteEnum.benum11);

        ShortEnum shortEnum;

        test(proxy.opShort(ShortEnum.senum1, out shortEnum) == ShortEnum.senum1);
        test(shortEnum == ShortEnum.senum1);
        test(proxy.opShort(ShortEnum.senum11, out shortEnum) == ShortEnum.senum11);
        test(shortEnum == ShortEnum.senum11);

        IntEnum intEnum;

        test(proxy.opInt(IntEnum.ienum1, out intEnum) == IntEnum.ienum1);
        test(intEnum == IntEnum.ienum1);
        test(proxy.opInt(IntEnum.ienum11, out intEnum) == IntEnum.ienum11);
        test(intEnum == IntEnum.ienum11);
        test(proxy.opInt(IntEnum.ienum12, out intEnum) == IntEnum.ienum12);
        test(intEnum == IntEnum.ienum12);

        SimpleEnum s;

        test(proxy.opSimple(SimpleEnum.green, out s) == SimpleEnum.green);
        test(s == SimpleEnum.green);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum exceptions... ");
        Console.Out.Flush();

        try
        {
            ostr = Ice.Util.createOutputStream(communicator);
            ostr.writeByte((byte)128); // Invalid enumerator
            Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished());
            ByteEnumHelper.read(istr);
            test(false);
        }
        catch (Ice.MarshalException)
        {
        }

        try
        {
            ostr = Ice.Util.createOutputStream(communicator);
            ostr.writeShort((short)-1); // Negative enumerators are not supported
            Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished());
            ShortEnumHelper.read(istr);
            test(false);
        }
        catch (Ice.MarshalException)
        {
        }

        try
        {
            ostr = Ice.Util.createOutputStream(communicator);
            ostr.writeShort((short)0); // Invalid enumerator
            Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished());
            ShortEnumHelper.read(istr);
            test(false);
        }
        catch (Ice.MarshalException)
        {
        }

        try
        {
            ostr = Ice.Util.createOutputStream(communicator);
            ostr.writeShort((short)32767); // Invalid enumerator
            Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished());
            ShortEnumHelper.read(istr);
            test(false);
        }
        catch (Ice.MarshalException)
        {
        }

        try
        {
            ostr = Ice.Util.createOutputStream(communicator);
            ostr.writeInt(-1); // Negative enumerators are not supported
            Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished());
            IntEnumHelper.read(istr);
            test(false);
        }
        catch (Ice.MarshalException)
        {
        }

        Console.Out.WriteLine("ok");
#if SILVERLIGHT
        proxy.shutdown();
#else
        return(proxy);
#endif
    }
Esempio n. 14
0
 opWithResult(Ice.AsyncResult result)
 {
     test(result.AsyncState == _cookie);
     test(TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithResult(result) == 15);
     called();
 }