예제 #1
1
파일: AllTests.cs 프로젝트: bholl/zeroc-ice
    public static void allTests(Ice.Communicator communicator)
    {
        communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp -p 12030");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter");
        PingReplyI replyI = new PingReplyI();
        Test.PingReplyPrx reply =
            (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        adapter.activate();

        Console.Out.Write("testing udp... ");
        Console.Out.Flush();
        Ice.ObjectPrx @base = communicator.stringToProxy("test:udp -p 12010").ice_datagram();
        Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(@base);

        int nRetry = 5;
        bool ret = false;
        while(nRetry-- > 0)
        {
            replyI.reset();
            obj.ping(reply);
            obj.ping(reply);
            obj.ping(reply);
            ret = replyI.waitReply(3, 2000);
            if(ret)
            {
                break; // Success
            }

            // If the 3 datagrams were not received within the 2 seconds, we try again to
            // receive 3 new datagrams using a new object. We give up after 5 retries.
            replyI = new PingReplyI();
            reply =(Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret == true);

        if(communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0)
        {
            //
            // Only run this test if compression is disabled, the test expect fixed message size
            // to be sent over the wire.
            //
            byte[] seq = null;
            try
            {
                seq = new byte[1024];
                while(true)
                {
                    seq = new byte[seq.Length * 2 + 10];
                    replyI.reset();
                    obj.sendByteSeq(seq, reply);
                    replyI.waitReply(1, 10000);
                }
            }
            catch(Ice.DatagramLimitException)
            {
                test(seq.Length > 16384);
            }
            obj.ice_getConnection().close(false);
            communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000");
            seq = new byte[50000];
            try
            {
                replyI.reset();
                obj.sendByteSeq(seq, reply);
                test(!replyI.waitReply(1, 500));
            }
            catch(Ice.LocalException ex)
            {
                Console.Out.WriteLine(ex);
                test(false);
            }
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing udp multicast... ");
        Console.Out.Flush();
        String host;
        if(communicator.getProperties().getProperty("Ice.IPv6") == "1")
        {
            host = "\"ff01::1:1\"";
        }
        else
        {
            host = "239.255.1.1";
        }
        @base = communicator.stringToProxy("test:udp -h " + host + " -p 12020").ice_datagram();
        TestIntfPrx objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base);

        nRetry = 5;
        while(nRetry-- > 0)
        {
            replyI.reset();
            objMcast.ping(reply);
            ret = replyI.waitReply(5, 5000);
            if(ret)
            {
                break;
            }
            replyI = new PingReplyI();
            reply =(Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        if(!ret)
        {
            Console.Out.WriteLine("failed (is a firewall enabled?)");
        }
        else
        {
            Console.Out.WriteLine("ok");
        }

        Console.Out.Write("testing udp bi-dir connection... ");
        Console.Out.Flush();
        obj.ice_getConnection().setAdapter(adapter);
        objMcast.ice_getConnection().setAdapter(adapter);
        nRetry = 5;
        while(nRetry-- > 0)
        {
            replyI.reset();
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            ret = replyI.waitReply(3, 2000);
            if(ret)
            {
                break; // Success
            }
            replyI = new PingReplyI();
            reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret);
        Console.Out.WriteLine("ok");

        //
        // Sending the replies back on the multicast UDP connection doesn't work for most
        // platform (it works for OS X Leopard but not Snow Leopard, doesn't work on SLES,
        // Windows...). For Windows, see UdpTransceiver constructor for the details. So
        // we don't run this test.
        //
        //         Console.Out.Write("testing udp bi-dir connection... ");
        //         nRetry = 5;
        //         while(nRetry-- > 0)
        //         {
        //             replyI.reset();
        //             objMcast.pingBiDir(reply.ice_getIdentity());
        //             ret = replyI.waitReply(5, 2000);
        //             if(ret)
        //             {
        //                 break; // Success
        //             }
        //             replyI = new PingReplyI();
        //             reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        //         }

        //         if(!ret)
        //         {
        //             Console.Out.WriteLine("failed (is a firewall enabled?)");
        //         }
        //         else
        //         {
        //             Console.Out.WriteLine("ok");
        //         }
    }
예제 #2
0
    public static void allTests(Ice.Communicator communicator)
    {
        communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp -p 12030");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter");
        PingReplyI        replyI  = new PingReplyI();

        Test.PingReplyPrx reply =
            (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        adapter.activate();

        Console.Out.Write("testing udp... ");
        Console.Out.Flush();
        Ice.ObjectPrx    @base = communicator.stringToProxy("test:udp -p 12010").ice_datagram();
        Test.TestIntfPrx obj   = Test.TestIntfPrxHelper.uncheckedCast(@base);

        int  nRetry = 5;
        bool ret    = false;

        while (nRetry-- > 0)
        {
            replyI.reset();
            obj.ping(reply);
            obj.ping(reply);
            obj.ping(reply);
            ret = replyI.waitReply(3, 2000);
            if (ret)
            {
                break; // Success
            }

            // If the 3 datagrams were not received within the 2 seconds, we try again to
            // receive 3 new datagrams using a new object. We give up after 5 retries.
            replyI = new PingReplyI();
            reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret == true);

        if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0)
        {
            //
            // Only run this test if compression is disabled, the test expect fixed message size
            // to be sent over the wire.
            //
            byte[] seq = null;
            try
            {
                seq = new byte[1024];
                while (true)
                {
                    seq = new byte[seq.Length * 2 + 10];
                    replyI.reset();
                    obj.sendByteSeq(seq, reply);
                    replyI.waitReply(1, 10000);
                }
            }
            catch (Ice.DatagramLimitException)
            {
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                // will be throw when try to send a packet bigger than that. However, Mono 2.10 bug in setting Socket
                // options could cause the RcvSize/SndSize to contain an arbitrary value so the test might fail
                // with smaller message sizes.
                //
                test(seq.Length > 16384 || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            obj.ice_getConnection().close(false);
            communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000");
            seq = new byte[50000];
            try
            {
                replyI.reset();
                obj.sendByteSeq(seq, reply);

                bool b = replyI.waitReply(1, 500);
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                // should not be delivered. However, Mono 2.10 bug in setting Socket options could
                // cause the RcvSize/SndSize to contain an arbitrary value so the packet might
                // be delivered successfully.
                //
                test(!b || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            catch (Ice.DatagramLimitException)
            {
                //
                // Mono 2.10 bug in setting Socket options could cause the RcvSize/SndSize to contain
                // an arbitrary value so the message send might fail if the effetive SndSize is minor
                // than expected.
                //
                test(IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            catch (Ice.LocalException ex)
            {
                Console.Out.WriteLine(ex);
                test(false);
            }
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing udp multicast... ");
        Console.Out.Flush();
        string endpoint;

        if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1"))
        {
            if (IceInternal.AssemblyUtil.osx_)
            {
                endpoint = "udp -h \"ff15::1:1\" -p 12020 --interface \"::1\"";
            }
            else
            {
                endpoint = "udp -h \"ff15::1:1\" -p 12020";
            }
        }
        else
        {
            endpoint = "udp -h 239.255.1.1 -p 12020";
        }
        @base = communicator.stringToProxy("test -d:" + endpoint);
        TestIntfPrx objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base);

        nRetry = 5;
        while (nRetry-- > 0)
        {
            replyI.reset();
            objMcast.ping(reply);
            ret = replyI.waitReply(5, 5000);
            if (ret)
            {
                break;
            }
            replyI = new PingReplyI();
            reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        if (!ret)
        {
            Console.Out.WriteLine("failed (is a firewall enabled?)");
        }
        else
        {
            Console.Out.WriteLine("ok");
        }

        Console.Out.Write("testing udp bi-dir connection... ");
        Console.Out.Flush();
        obj.ice_getConnection().setAdapter(adapter);
        objMcast.ice_getConnection().setAdapter(adapter);
        nRetry = 5;
        while (nRetry-- > 0)
        {
            replyI.reset();
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            ret = replyI.waitReply(3, 2000);
            if (ret)
            {
                break; // Success
            }
            replyI = new PingReplyI();
            reply  = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret);
        Console.Out.WriteLine("ok");

        //
        // Sending the replies back on the multicast UDP connection doesn't work for most
        // platform (it works for OS X Leopard but not Snow Leopard, doesn't work on SLES,
        // Windows...). For Windows, see UdpTransceiver constructor for the details. So
        // we don't run this test.
        //
//         Console.Out.Write("testing udp bi-dir connection... ");
//         nRetry = 5;
//         while(nRetry-- > 0)
//         {
//             replyI.reset();
//             objMcast.pingBiDir(reply.ice_getIdentity());
//             ret = replyI.waitReply(5, 2000);
//             if(ret)
//             {
//                 break; // Success
//             }
//             replyI = new PingReplyI();
//             reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
//         }

//         if(!ret)
//         {
//             Console.Out.WriteLine("failed (is a firewall enabled?)");
//         }
//         else
//         {
//             Console.Out.WriteLine("ok");
//         }
    }
예제 #3
0
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            communicator.SetProperty("ReplyAdapter.Endpoints", "udp");
            ObjectAdapter adapter = communicator.CreateObjectAdapter("ReplyAdapter");
            var           replyI  = new PingReplyI();
            IPingReplyPrx reply   = adapter.AddWithUUID(replyI, IPingReplyPrx.Factory)
                                    .Clone(invocationMode: InvocationMode.Datagram);

            adapter.Activate();

            Console.Out.Write("testing udp... ");
            Console.Out.Flush();
            ITestIntfPrx obj = ITestIntfPrx.Parse(
                helper.GetTestProxy("test", 0, "udp"),
                communicator).Clone(invocationMode: InvocationMode.Datagram);

            try
            {
                int val = obj.GetValue();
                TestHelper.Assert(false);
            }
            catch (InvalidOperationException)
            {
                // expected
            }

            int  nRetry = 5;
            bool ret    = false;

            while (nRetry-- > 0)
            {
                replyI.Reset();
                obj.Ping(reply);
                obj.Ping(reply);
                obj.Ping(reply);
                ret = replyI.WaitReply(3, TimeSpan.FromSeconds(2));
                if (ret)
                {
                    break; // Success
                }

                // If the 3 datagrams were not received within the 2 seconds, we try again to
                // receive 3 new datagrams using a new object. We give up after 5 retries.
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            TestHelper.Assert(ret == true);

            byte[] seq = new byte[1024];
            try
            {
                while (true)
                {
                    seq = new byte[(seq.Length * 2) + 10];
                    replyI.Reset();
                    obj.SendByteSeq(seq, reply);
                    replyI.WaitReply(1, TimeSpan.FromSeconds(10));
                }
            }
            catch (DatagramLimitException)
            {
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                // will be throw when try to send a packet bigger than that.
                //
                TestHelper.Assert(seq.Length > 16384);
            }
            obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
            communicator.SetProperty("Ice.UDP.SndSize", "64K");
            seq = new byte[50000];
            try
            {
                replyI.Reset();
                obj.SendByteSeq(seq, reply);

                bool b = replyI.WaitReply(1, TimeSpan.FromMilliseconds(500));
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                // should not be delivered.
                //
                TestHelper.Assert(!b);
            }
            catch (DatagramLimitException)
            {
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex);
                TestHelper.Assert(false);
            }

            Console.Out.WriteLine("ok");

            Console.Out.Write("testing udp multicast... ");
            Console.Out.Flush();

            var sb = new StringBuilder("test -d:udp -h ");

            // Use loopback to prevent other machines to answer.
            if (communicator.GetPropertyAsBool("Ice.IPv6") ?? false)
            {
                sb.Append("\"ff15::1:1\"");
            }
            else
            {
                sb.Append("239.255.1.1");
            }
            sb.Append(" -p ");
            sb.Append(helper.GetTestPort(10));
            if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS)
            {
                if (communicator.GetPropertyAsBool("Ice.IPv6") ?? false)
                {
                    sb.Append(" --interface \"::1\"");
                }
                else
                {
                    sb.Append(" --interface 127.0.0.1");
                }
            }
            var objMcast = ITestIntfPrx.Parse(sb.ToString(), communicator);

            nRetry = 5;
            while (nRetry-- > 0)
            {
                replyI.Reset();
                objMcast.Ping(reply);
                ret = replyI.WaitReply(5, TimeSpan.FromSeconds(5));
                if (ret)
                {
                    break;
                }
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            if (!ret)
            {
                Console.Out.WriteLine("failed(is a firewall enabled?)");
            }
            else
            {
                Console.Out.WriteLine("ok");
            }

            Console.Out.Write("testing udp bi-dir connection... ");
            Console.Out.Flush();
            obj.GetConnection() !.Adapter      = adapter;
            objMcast.GetConnection() !.Adapter = adapter;
            nRetry = 5;
            while (nRetry-- > 0)
            {
                replyI.Reset();
                obj.PingBiDir(reply.Identity);
                obj.PingBiDir(reply.Identity);
                obj.PingBiDir(reply.Identity);
                ret = replyI.WaitReply(3, TimeSpan.FromSeconds(2));
                if (ret)
                {
                    break; // Success
                }
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            TestHelper.Assert(ret);
            Console.Out.WriteLine("ok");
        }
예제 #4
0
파일: AllTests.cs 프로젝트: zj771484545/ice
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp");
                Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter");
                PingReplyI        replyI  = new PingReplyI();

                Test.PingReplyPrx reply =
                    (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                adapter.activate();

                Console.Out.Write("testing udp... ");
                Console.Out.Flush();
                Ice.ObjectPrx    @base = communicator.stringToProxy("test:" + helper.getTestEndpoint(0, "udp")).ice_datagram();
                Test.TestIntfPrx obj   = Test.TestIntfPrxHelper.uncheckedCast(@base);

                int  nRetry = 5;
                bool ret    = false;

                while (nRetry-- > 0)
                {
                    replyI.reset();
                    obj.ping(reply);
                    obj.ping(reply);
                    obj.ping(reply);
                    ret = replyI.waitReply(3, 2000);
                    if (ret)
                    {
                        break; // Success
                    }

                    // If the 3 datagrams were not received within the 2 seconds, we try again to
                    // receive 3 new datagrams using a new object. We give up after 5 retries.
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                test(ret == true);

                if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0)
                {
                    //
                    // Only run this test if compression is disabled, the test expect fixed message size
                    // to be sent over the wire.
                    //
                    byte[] seq = null;
                    try
                    {
                        seq = new byte[1024];
                        while (true)
                        {
                            seq = new byte[seq.Length * 2 + 10];
                            replyI.reset();
                            obj.sendByteSeq(seq, reply);
                            replyI.waitReply(1, 10000);
                        }
                    }
                    catch (Ice.DatagramLimitException)
                    {
                        //
                        // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                        // will be throw when try to send a packet bigger than that.
                        //
                        test(seq.Length > 16384);
                    }
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000");
                    seq = new byte[50000];
                    try
                    {
                        replyI.reset();
                        obj.sendByteSeq(seq, reply);

                        bool b = replyI.waitReply(1, 500);
                        //
                        // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                        // should not be delivered.
                        //
                        test(!b);
                    }
                    catch (Ice.DatagramLimitException)
                    {
                    }
                    catch (Ice.LocalException ex)
                    {
                        Console.Out.WriteLine(ex);
                        test(false);
                    }
                }

                Console.Out.WriteLine("ok");

                Console.Out.Write("testing udp multicast... ");
                Console.Out.Flush();
                StringBuilder endpoint = new StringBuilder();

                //
                // Use loopback to prevent other machines to answer.
                //
                if (communicator.getProperties().getProperty("Ice.IPv6") == "1")
                {
                    endpoint.Append("udp -h \"ff15::1:1\"");
                    if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS)
                    {
                        endpoint.Append(" --interface \"::1\"");
                    }
                }
                else
                {
                    endpoint.Append("udp -h 239.255.1.1");
                    if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS)
                    {
                        endpoint.Append(" --interface 127.0.0.1");
                    }
                }
                endpoint.Append(" -p ");
                endpoint.Append(helper.getTestPort(10));
                @base = communicator.stringToProxy("test -d:" + endpoint.ToString());
                var objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base);

                nRetry = 5;
                while (nRetry-- > 0)
                {
                    replyI.reset();
                    try
                    {
                        objMcast.ping(reply);
                    }
                    catch (Ice.SocketException)
                    {
                        if (communicator.getProperties().getProperty("Ice.IPv6") == "1")
                        {
                            // Multicast IPv6 not supported on the platform. This occurs for example on macOS big_suir
                            Console.Out.Write("(not supported) ");
                            ret = true;
                            break;
                        }
                        throw;
                    }
                    ret = replyI.waitReply(5, 5000);
                    if (ret)
                    {
                        break;
                    }
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                if (!ret)
                {
                    Console.Out.WriteLine("failed(is a firewall enabled?)");
                }
                else
                {
                    Console.Out.WriteLine("ok");
                }

                Console.Out.Write("testing udp bi-dir connection... ");
                Console.Out.Flush();
                obj.ice_getConnection().setAdapter(adapter);
                nRetry = 5;
                while (nRetry-- > 0)
                {
                    replyI.reset();
                    obj.pingBiDir(reply.ice_getIdentity());
                    obj.pingBiDir(reply.ice_getIdentity());
                    obj.pingBiDir(reply.ice_getIdentity());
                    ret = replyI.waitReply(3, 2000);
                    if (ret)
                    {
                        break; // Success
                    }
                    replyI = new PingReplyI();
                    reply  = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                }
                test(ret);
                Console.Out.WriteLine("ok");

                //
                // Sending the replies back on the multicast UDP connection doesn't work for most
                // platform(it works for macOS Leopard but not Snow Leopard, doesn't work on SLES,
                // Windows...). For Windows, see UdpTransceiver constructor for the details. So
                // we don't run this test.
                //
                //         Console.Out.Write("testing udp bi-dir connection... ");
                //         nRetry = 5;
                //         while(nRetry-- > 0)
                //         {
                //             replyI.reset();
                //             objMcast.pingBiDir(reply.ice_getIdentity());
                //             ret = replyI.waitReply(5, 2000);
                //             if(ret)
                //             {
                //                 break; // Success
                //             }
                //             replyI = new PingReplyI();
                //             reply =(PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
                //         }

                //         if(!ret)
                //         {
                //             Console.Out.WriteLine("failed(is a firewall enabled?)");
                //         }
                //         else
                //         {
                //             Console.Out.WriteLine("ok");
                //         }
            }
예제 #5
0
            public static void allTests(global::Test.TestHelper helper, bool collocated)
            {
                Communicator communicator = helper.communicator();

                var p = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator);
                var testController = TestIntfControllerPrx.Parse($"testController:{helper.getTestEndpoint(1)}", communicator);

                var output = helper.getWriter();

                output.Write("testing async invocation...");
                output.Flush();
                {
                    Dictionary <string, string> ctx = new Dictionary <string, string>();

                    test(p.IceIsAAsync("::Test::TestIntf").Result);
                    test(p.IceIsAAsync("::Test::TestIntf", ctx).Result);

                    p.IcePingAsync().Wait();
                    p.IcePingAsync(ctx).Wait();

                    test(p.IceIdAsync().Result.Equals("::Test::TestIntf"));
                    test(p.IceIdAsync(ctx).Result.Equals("::Test::TestIntf"));

                    test(p.IceIdsAsync().Result.Length == 2);
                    test(p.IceIdsAsync(ctx).Result.Length == 2);

                    if (!collocated)
                    {
                        test(p.GetConnectionAsync().Result != null);
                    }

                    p.opAsync().Wait();
                    p.opAsync(ctx).Wait();

                    test(p.opWithResultAsync().Result == 15);
                    test(p.opWithResultAsync(ctx).Result == 15);

                    try
                    {
                        p.opWithUEAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException ae)
                    {
                        ae.Handle(ex => ex is Test.TestIntfException);
                    }

                    try
                    {
                        p.opWithUEAsync(ctx).Wait();
                        test(false);
                    }
                    catch (AggregateException ae)
                    {
                        ae.Handle(ex => ex is Test.TestIntfException);
                    }
                }
                output.WriteLine("ok");

                output.Write("testing async/await...");
                output.Flush();
                {
                    Task.Run(async() =>
                    {
                        Dictionary <string, string> ctx = new Dictionary <string, string>();

                        test(await p.IceIsAAsync("::Test::TestIntf"));
                        test(await p.IceIsAAsync("::Test::TestIntf", ctx));

                        await p.IcePingAsync();
                        await p.IcePingAsync(ctx);

                        var id = await p.IceIdAsync();
                        test(id.Equals("::Test::TestIntf"));
                        id = await p.IceIdAsync(ctx);
                        test(id.Equals("::Test::TestIntf"));

                        var ids = await p.IceIdsAsync();
                        test(ids.Length == 2);
                        ids = await p.IceIdsAsync(ctx);
                        test(ids.Length == 2);

                        if (!collocated)
                        {
                            var conn = await p.GetConnectionAsync();
                            test(conn != null);
                        }

                        await p.opAsync();
                        await p.opAsync(ctx);

                        var result = await p.opWithResultAsync();
                        test(result == 15);
                        result = await p.opWithResultAsync(ctx);
                        test(result == 15);

                        try
                        {
                            await p.opWithUEAsync();
                            test(false);
                        }
                        catch (System.Exception ex)
                        {
                            test(ex is Test.TestIntfException);
                        }

                        try
                        {
                            await p.opWithUEAsync(ctx);
                            test(false);
                        }
                        catch (System.Exception ex)
                        {
                            test(ex is Test.TestIntfException);
                        }
                    }).Wait();
                }
                output.WriteLine("ok");

                output.Write("testing async continuations...");
                output.Flush();
                {
                    Dictionary <string, string> ctx = new Dictionary <string, string>();

                    p.IceIsAAsync("::Test::TestIntf").ContinueWith(previous =>
                    {
                        test(previous.Result);
                    }).Wait();

                    p.IceIsAAsync("::Test::TestIntf", ctx).ContinueWith(previous =>
                    {
                        test(previous.Result);
                    }).Wait();

                    p.IcePingAsync().ContinueWith(previous =>
                    {
                        previous.Wait();
                    }).Wait();

                    p.IcePingAsync(ctx).ContinueWith(previous =>
                    {
                        previous.Wait();
                    }).Wait();

                    p.IceIdAsync().ContinueWith(previous =>
                    {
                        test(previous.Result.Equals("::Test::TestIntf"));
                    }).Wait();

                    p.IceIdAsync(ctx).ContinueWith(previous =>
                    {
                        test(previous.Result.Equals("::Test::TestIntf"));
                    }).Wait();

                    p.IceIdsAsync().ContinueWith(previous =>
                    {
                        test(previous.Result.Length == 2);
                    }).Wait();

                    p.IceIdsAsync(ctx).ContinueWith(previous =>
                    {
                        test(previous.Result.Length == 2);
                    }).Wait();

                    if (!collocated)
                    {
                        p.GetConnectionAsync().ContinueWith(previous =>
                        {
                            test(previous.Result != null);
                        }).Wait();
                    }

                    p.opAsync().ContinueWith(previous => previous.Wait()).Wait();
                    p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait();

                    p.opWithResultAsync().ContinueWith(previous =>
                    {
                        test(previous.Result == 15);
                    }).Wait();

                    p.opWithResultAsync(ctx).ContinueWith(previous =>
                    {
                        test(previous.Result == 15);
                    }).Wait();

                    p.opWithUEAsync().ContinueWith(previous =>
                    {
                        try
                        {
                            previous.Wait();
                        }
                        catch (AggregateException ae)
                        {
                            ae.Handle(ex => ex is Test.TestIntfException);
                        }
                    }).Wait();

                    p.opWithUEAsync(ctx).ContinueWith(previous =>
                    {
                        try
                        {
                            previous.Wait();
                        }
                        catch (AggregateException ae)
                        {
                            ae.Handle(ex => ex is Test.TestIntfException);
                        }
                    }).Wait();
                }
                output.WriteLine("ok");

                output.Write("testing local exceptions with async tasks... ");
                output.Flush();
                {
                    TestIntfPrx indirect = p.Clone(adapterId: "dummy");

                    try
                    {
                        indirect.opAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException ae)
                    {
                        ae.Handle((ex) =>
                        {
                            return(ex is NoEndpointException);
                        });
                    }

                    try
                    {
                        p.Clone(oneway: true).opWithResultAsync();
                        test(false);
                    }
                    catch (TwowayOnlyException)
                    {
                    }

                    //
                    // Check that CommunicatorDestroyedException is raised directly.
                    //
                    if (p.GetConnection() != null)
                    {
                        Communicator ic = helper.initialize(communicator.GetProperties());
                        IObjectPrx   o  = IObjectPrx.Parse(p.ToString(), ic);
                        TestIntfPrx  p2 = Test.TestIntfPrx.CheckedCast(o);
                        ic.destroy();

                        try
                        {
                            p2.opAsync();
                            test(false);
                        }
                        catch (CommunicatorDestroyedException)
                        {
                            // Expected.
                        }
                    }
                }
                output.WriteLine("ok");

                output.Write("testing exception with async task... ");
                output.Flush();
                {
                    TestIntfPrx i = p.Clone(adapterId: "dummy");

                    try
                    {
                        i.IceIsAAsync("::Test::TestIntf").Wait();
                        test(false);
                    }
                    catch (AggregateException)
                    {
                    }

                    try
                    {
                        i.opAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException)
                    {
                    }

                    try
                    {
                        i.opWithResultAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException)
                    {
                    }

                    try
                    {
                        i.opWithUEAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException)
                    {
                    }

                    // Ensures no exception is called when response is received
                    test(p.IceIsAAsync("::Test::TestIntf").Result);
                    p.opAsync().Wait();
                    p.opWithResultAsync().Wait();

                    // If response is a user exception, it should be received.
                    try
                    {
                        p.opWithUEAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException ae)
                    {
                        ae.Handle((ex) =>
                        {
                            return(ex is Test.TestIntfException);
                        });
                    }
                }
                output.WriteLine("ok");

                output.Write("testing progress callback... ");
                output.Flush();
                {
                    {
                        SentCallback cb = new SentCallback();

                        Task t = p.IceIsAAsync("",
                                               progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();

                        t = p.IcePingAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();

                        t = p.IceIdAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();

                        t = p.IceIdsAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();

                        t = p.opAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();
                    }

                    List <Task> tasks = new List <Task>();
                    byte[]      seq   = new byte[10024];
                    (new Random()).NextBytes(seq);
                    testController.holdAdapter();
                    try
                    {
                        Task            t = null;
                        ProgresCallback cb;
                        do
                        {
                            cb = new ProgresCallback();
                            t  = p.opWithPayloadAsync(seq, progress: cb);
                            tasks.Add(t);
                        }while (cb.SentSynchronously);
                    }
                    finally
                    {
                        testController.resumeAdapter();
                    }
                    foreach (Task t in tasks)
                    {
                        t.Wait();
                    }
                }
                output.WriteLine("ok");
                output.Write("testing async/await... ");
                output.Flush();
                Func <Task> task = async() =>
                {
                    try
                    {
                        await p.opAsync();

                        var r = await p.opWithResultAsync();

                        test(r == 15);

                        try
                        {
                            await p.opWithUEAsync();
                        }
                        catch (Test.TestIntfException)
                        {
                        }

                        // Operations implemented with amd and async.
                        await p.opAsyncDispatchAsync();

                        r = await p.opWithResultAsyncDispatchAsync();

                        test(r == 15);

                        try
                        {
                            await p.opWithUEAsyncDispatchAsync();

                            test(false);
                        }
                        catch (Test.TestIntfException)
                        {
                        }
                    }
                    catch (OperationNotExistException)
                    {
                        // Expected with cross testing, this opXxxAsyncDispatch methods are C# only.
                    }
                };

                task().Wait();
                output.WriteLine("ok");

                if (p.GetConnection() != null)
                {
                    output.Write("testing async Task cancellation... ");
                    output.Flush();
                    {
                        var  cs1 = new CancellationTokenSource();
                        var  cs2 = new CancellationTokenSource();
                        var  cs3 = new CancellationTokenSource();
                        Task t1;
                        Task t2;
                        Task t3;
                        try
                        {
                            testController.holdAdapter();
                            ProgresCallback cb  = null;
                            byte[]          seq = new byte[10024];
                            for (int i = 0; i < 200; ++i) // 2MB
                            {
                                cb = new ProgresCallback();
                                p.opWithPayloadAsync(seq, progress: cb);
                            }

                            test(!cb.Sent);

                            t1 = p.IcePingAsync(cancel: cs1.Token);
                            t2 = p.IcePingAsync(cancel: cs2.Token);
                            cs3.Cancel();
                            t3 = p.IcePingAsync(cancel: cs3.Token);
                            cs1.Cancel();
                            cs2.Cancel();
                            try
                            {
                                t1.Wait();
                                test(false);
                            }
                            catch (AggregateException ae)
                            {
                                ae.Handle(ex =>
                                {
                                    return(ex is InvocationCanceledException);
                                });
                            }
                            try
                            {
                                t2.Wait();
                                test(false);
                            }
                            catch (AggregateException ae)
                            {
                                ae.Handle(ex =>
                                {
                                    return(ex is InvocationCanceledException);
                                });
                            }

                            try
                            {
                                t3.Wait();
                                test(false);
                            }
                            catch (AggregateException ae)
                            {
                                ae.Handle(ex =>
                                {
                                    return(ex is InvocationCanceledException);
                                });
                            }
                        }
                        finally
                        {
                            testController.resumeAdapter();
                            p.IcePing();
                        }
                    }
                    output.WriteLine("ok");
                }

                if (p.GetConnection() != null && p.supportsAMD())
                {
                    output.Write("testing graceful close connection with wait... ");
                    output.Flush();
                    {
                        //
                        // Local case: begin a request, close the connection gracefully, and make sure it waits
                        // for the request to complete.
                        //
                        Connection   con = p.GetConnection();
                        CallbackBase cb  = new CallbackBase();
                        con.setCloseCallback(_ =>
                        {
                            cb.called();
                        });
                        Task t = p.sleepAsync(100);
                        con.close(ConnectionClose.GracefullyWithWait);
                        t.Wait(); // Should complete successfully.
                        cb.check();
                    }
                    {
                        //
                        // Remote case.
                        //
                        byte[] seq = new byte[1024 * 10];

                        //
                        // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod.
                        // The goal is to make sure that none of the opWithPayload fail even if the server closes
                        // the connection gracefully in between.
                        //
                        int  maxQueue = 2;
                        bool done     = false;
                        while (!done && maxQueue < 50)
                        {
                            done = true;
                            p.IcePing();
                            List <Task> results = new List <Task>();
                            for (int i = 0; i < maxQueue; ++i)
                            {
                                results.Add(p.opWithPayloadAsync(seq));
                            }

                            ProgresCallback cb = new ProgresCallback();
                            p.closeAsync(Test.CloseMode.GracefullyWithWait, progress: cb);

                            if (!cb.SentSynchronously)
                            {
                                for (int i = 0; i < maxQueue; i++)
                                {
                                    cb = new ProgresCallback();
                                    Task t = p.opWithPayloadAsync(seq, progress: cb);
                                    results.Add(t);
                                    if (cb.SentSynchronously)
                                    {
                                        done      = false;
                                        maxQueue *= 2;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                maxQueue *= 2;
                                done      = false;
                            }
                            foreach (Task q in results)
                            {
                                q.Wait();
                            }
                        }
                    }
                    output.WriteLine("ok");

                    output.Write("testing graceful close connection without wait... ");
                    output.Flush();
                    {
                        //
                        // Local case: start an operation and then close the connection gracefully on the client side
                        // without waiting for the pending invocation to complete. There will be no retry and we expect the
                        // invocation to fail with ConnectionManuallyClosedException.
                        //
                        p = p.Clone(connectionId: "CloseGracefully"); // Start with a new connection.
                        Connection   con = p.GetConnection();
                        CallbackBase cb  = new CallbackBase();
                        Task         t   = p.startDispatchAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.called();
                        }));
                        cb.check(); // Ensure the request was sent before we close the connection.
                        con.close(ConnectionClose.Gracefully);
                        try
                        {
                            t.Wait();
                            test(false);
                        }
                        catch (System.AggregateException ex)
                        {
                            test(ex.InnerException is ConnectionManuallyClosedException);
                            test((ex.InnerException as ConnectionManuallyClosedException).graceful);
                        }
                        p.finishDispatch();

                        //
                        // Remote case: the server closes the connection gracefully, which means the connection
                        // will not be closed until all pending dispatched requests have completed.
                        //
                        con = p.GetConnection();
                        cb  = new CallbackBase();
                        con.setCloseCallback(_ =>
                        {
                            cb.called();
                        });
                        t = p.sleepAsync(100);
                        p.close(Test.CloseMode.Gracefully); // Close is delayed until sleep completes.
                        cb.check();
                        t.Wait();
                    }
                    output.WriteLine("ok");

                    output.Write("testing forceful close connection... ");
                    output.Flush();
                    {
                        //
                        // Local case: start an operation and then close the connection forcefully on the client side.
                        // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException.
                        //
                        p.IcePing();
                        Connection   con = p.GetConnection();
                        CallbackBase cb  = new CallbackBase();
                        Task         t   = p.startDispatchAsync(
                            progress: new Progress(sentSynchronously =>
                        {
                            cb.called();
                        }));
                        cb.check(); // Ensure the request was sent before we close the connection.
                        con.close(ConnectionClose.Forcefully);
                        try
                        {
                            t.Wait();
                            test(false);
                        }
                        catch (AggregateException ex)
                        {
                            test(ex.InnerException is ConnectionManuallyClosedException);
                            test(!(ex.InnerException as ConnectionManuallyClosedException).graceful);
                        }
                        p.finishDispatch();

                        //
                        // Remote case: the server closes the connection forcefully. This causes the request to fail
                        // with a ConnectionLostException. Since the close() operation is not idempotent, the client
                        // will not retry.
                        //
                        try
                        {
                            p.close(Test.CloseMode.Forcefully);
                            test(false);
                        }
                        catch (ConnectionLostException)
                        {
                            // Expected.
                        }
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing ice_scheduler... ");
                output.Flush();
                {
                    p.IcePingAsync().ContinueWith(
                        (t) =>
                    {
                        test(Thread.CurrentThread.Name == null ||
                             !Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                    }).Wait();

                    p.IcePingAsync().ContinueWith(
                        (t) =>
                    {
                        test(Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                    }, p.Scheduler).Wait();

                    {
                        TaskCompletionSource <int> s1 = new TaskCompletionSource <int>();
                        TaskCompletionSource <int> s2 = new TaskCompletionSource <int>();
                        Task t1 = s1.Task;
                        Task t2 = s2.Task;
                        Task t3 = null;
                        Task t4 = null;
                        p.IcePingAsync().ContinueWith(
                            (t) =>
                        {
                            test(Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                            //
                            // t1 Continuation run in the thread that completes it.
                            //
                            var id = Thread.CurrentThread.ManagedThreadId;
                            t3     = t1.ContinueWith(prev =>
                            {
                                test(id == Thread.CurrentThread.ManagedThreadId);
                            },
                                                     CancellationToken.None,
                                                     TaskContinuationOptions.ExecuteSynchronously,
                                                     p.Scheduler);
                            s1.SetResult(1);

                            //
                            // t2 completed from the main thread
                            //
                            t4 = t2.ContinueWith(prev =>
                            {
                                test(id != Thread.CurrentThread.ManagedThreadId);
                                test(Thread.CurrentThread.Name == null ||
                                     !Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                            },
                                                 CancellationToken.None,
                                                 TaskContinuationOptions.ExecuteSynchronously,
                                                 p.Scheduler);
                        }, p.Scheduler).Wait();
                        s2.SetResult(1);
                        Task.WaitAll(t1, t2, t3, t4);
                    }

                    if (!collocated)
                    {
                        ObjectAdapter adapter = communicator.createObjectAdapter("");
                        PingReplyI    replyI  = new PingReplyI();
                        var           reply   = adapter.Add(replyI);
                        adapter.Activate();

                        p.GetConnection().setAdapter(adapter);
                        p.pingBiDir(reply);
                        test(replyI.checkReceived());
                        adapter.Destroy();
                    }
                }
                output.WriteLine("ok");

                output.Write("testing result struct... ");
                output.Flush();
                {
                    var q = Test.Outer.Inner.TestIntfPrx.Parse($"test2:{helper.getTestEndpoint(0)}", communicator);
                    q.opAsync(1).ContinueWith(t =>
                    {
                        var r = t.Result;
                        test(r.returnValue == 1);
                        test(r.j == 1);
                    }).Wait();
                }
                output.WriteLine("ok");

                p.shutdown();
            }
예제 #6
0
        public static void allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            communicator.SetProperty("ReplyAdapter.Endpoints", "udp");
            ObjectAdapter adapter = communicator.CreateObjectAdapter("ReplyAdapter");
            PingReplyI    replyI  = new PingReplyI();
            IPingReplyPrx reply   = adapter.AddWithUUID(replyI, IPingReplyPrx.Factory)
                                    .Clone(invocationMode: InvocationMode.Datagram);

            adapter.Activate();

            Console.Out.Write("testing udp... ");
            Console.Out.Flush();
            var obj = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0, "udp"),
                                         communicator).Clone(invocationMode: InvocationMode.Datagram);

            try
            {
                int val = obj.getValue();
                TestHelper.Assert(false);
            }
            catch (System.InvalidOperationException)
            {
                // expected
            }

            int  nRetry = 5;
            bool ret    = false;

            while (nRetry-- > 0)
            {
                replyI.reset();
                obj.ping(reply);
                obj.ping(reply);
                obj.ping(reply);
                ret = replyI.waitReply(3, 2000);
                if (ret)
                {
                    break; // Success
                }

                // If the 3 datagrams were not received within the 2 seconds, we try again to
                // receive 3 new datagrams using a new object. We give up after 5 retries.
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            TestHelper.Assert(ret == true);

            if (!(communicator.GetPropertyAsBool("Ice.Override.Compress") ?? false))
            {
                //
                // Only run this test if compression is disabled, the test expect fixed message size
                // to be sent over the wire.
                //
                byte[] seq = new byte[1024];;
                try
                {
                    while (true)
                    {
                        seq = new byte[seq.Length * 2 + 10];
                        replyI.reset();
                        obj.sendByteSeq(seq, reply);
                        replyI.waitReply(1, 10000);
                    }
                }
                catch (DatagramLimitException)
                {
                    //
                    // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                    // will be throw when try to send a packet bigger than that.
                    //
                    TestHelper.Assert(seq.Length > 16384);
                }
                obj.GetConnection().Close(ConnectionClose.GracefullyWithWait);
                communicator.SetProperty("Ice.UDP.SndSize", "64000");
                seq = new byte[50000];
                try
                {
                    replyI.reset();
                    obj.sendByteSeq(seq, reply);

                    bool b = replyI.waitReply(1, 500);
                    //
                    // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                    // should not be delivered.
                    //
                    TestHelper.Assert(!b);
                }
                catch (DatagramLimitException)
                {
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine(ex);
                    TestHelper.Assert(false);
                }
            }

            Console.Out.WriteLine("ok");

            Console.Out.Write("testing udp multicast... ");
            Console.Out.Flush();
            StringBuilder endpoint = new StringBuilder();

            //
            // Use loopback to prevent other machines to answer.
            //
            if (communicator.GetProperty("Ice.IPv6") == "1")
            {
                endpoint.Append("udp -h \"ff15::1:1\"");
                if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS)
                {
                    endpoint.Append(" --interface \"::1\"");
                }
            }
            else
            {
                endpoint.Append("udp -h 239.255.1.1");
                if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS)
                {
                    endpoint.Append(" --interface 127.0.0.1");
                }
            }
            endpoint.Append(" -p ");
            endpoint.Append(helper.GetTestPort(10));
            var objMcast = ITestIntfPrx.Parse($"test -d:{endpoint}", communicator);

            nRetry = 5;
            while (nRetry-- > 0)
            {
                replyI.reset();
                objMcast.ping(reply);
                ret = replyI.waitReply(5, 5000);
                if (ret)
                {
                    break;
                }
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            if (!ret)
            {
                Console.Out.WriteLine("failed(is a firewall enabled?)");
            }
            else
            {
                Console.Out.WriteLine("ok");
            }

            Console.Out.Write("testing udp bi-dir connection... ");
            Console.Out.Flush();
            obj.GetConnection().Adapter      = adapter;
            objMcast.GetConnection().Adapter = adapter;
            nRetry = 5;
            while (nRetry-- > 0)
            {
                replyI.reset();
                obj.pingBiDir(reply.Identity);
                obj.pingBiDir(reply.Identity);
                obj.pingBiDir(reply.Identity);
                ret = replyI.waitReply(3, 2000);
                if (ret)
                {
                    break; // Success
                }
                replyI = new PingReplyI();
                reply  = adapter.AddWithUUID(
                    replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram);
            }
            TestHelper.Assert(ret);
            Console.Out.WriteLine("ok");
        }
예제 #7
0
파일: AllTests.cs 프로젝트: pedia/zeroc-ice
    public static void allTests(Ice.Communicator communicator)
    {
        communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp -p 12030");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter");
        PingReplyI replyI = new PingReplyI();
        Test.PingReplyPrx reply =
            (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        adapter.activate();

        Console.Out.Write("testing udp... ");
        Console.Out.Flush();
        Ice.ObjectPrx @base = communicator.stringToProxy("test:udp -p 12010").ice_datagram();
        Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(@base);

        int nRetry = 5;
        bool ret = false;
        while(nRetry-- > 0)
        {
            replyI.reset();
            obj.ping(reply);
            obj.ping(reply);
            obj.ping(reply);
            ret = replyI.waitReply(3, 2000);
            if(ret)
            {
                break; // Success
            }

            // If the 3 datagrams were not received within the 2 seconds, we try again to
            // receive 3 new datagrams using a new object. We give up after 5 retries.
            replyI = new PingReplyI();
            reply =(Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret == true);

        if(communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0)
        {
            //
            // Only run this test if compression is disabled, the test expect fixed message size
            // to be sent over the wire.
            //
            byte[] seq = null;
            try
            {
                seq = new byte[1024];
                while(true)
                {
                    seq = new byte[seq.Length * 2 + 10];
                    replyI.reset();
                    obj.sendByteSeq(seq, reply);
                    replyI.waitReply(1, 10000);
                }
            }
            catch(Ice.DatagramLimitException)
            {
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException
                // will be throw when try to send a packet bigger than that. However, Mono 2.10 bug in setting Socket
                // options could cause the RcvSize/SndSize to contain an arbitrary value so the test might fail 
                // with smaller message sizes.
                //
                test(seq.Length > 16384 || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            obj.ice_getConnection().close(false);
            communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000");
            seq = new byte[50000];
            try
            {
                replyI.reset();
                obj.sendByteSeq(seq, reply);

                bool b = replyI.waitReply(1, 500);
                //
                // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet
                // should not be delivered. However, Mono 2.10 bug in setting Socket options could 
                // cause the RcvSize/SndSize to contain an arbitrary value so the packet might 
                // be delivered successfully.
                //
                test(!b || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            catch(Ice.DatagramLimitException)
            {
                //
                // Mono 2.10 bug in setting Socket options could cause the RcvSize/SndSize to contain
                // an arbitrary value so the message send might fail if the effetive SndSize is minor 
                // than expected.
                //
                test(IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono);
            }
            catch(Ice.LocalException ex)
            {
                Console.Out.WriteLine(ex);
                test(false);
            }
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing udp multicast... ");
        Console.Out.Flush();
        string endpoint;
        if(communicator.getProperties().getProperty("Ice.IPv6").Equals("1"))
        {
            if(IceInternal.AssemblyUtil.osx_)
            {
                endpoint = "udp -h \"ff15::1:1\" -p 12020 --interface \"::1\"";
            }
            else
            {
                endpoint = "udp -h \"ff15::1:1\" -p 12020";
            }
        }
        else
        {
            endpoint = "udp -h 239.255.1.1 -p 12020";
        }
        @base = communicator.stringToProxy("test -d:" + endpoint);
        TestIntfPrx objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base);

        nRetry = 5;
        while(nRetry-- > 0)
        {
            replyI.reset();
            objMcast.ping(reply);
            ret = replyI.waitReply(5, 5000);
            if(ret)
            {
                break;
            }
            replyI = new PingReplyI();
            reply =(Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        if(!ret)
        {
            Console.Out.WriteLine("failed (is a firewall enabled?)");
        }
        else
        {
            Console.Out.WriteLine("ok");
        }

        Console.Out.Write("testing udp bi-dir connection... ");
        Console.Out.Flush();
        obj.ice_getConnection().setAdapter(adapter);
        objMcast.ice_getConnection().setAdapter(adapter);
        nRetry = 5;
        while(nRetry-- > 0)
        {
            replyI.reset();
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            obj.pingBiDir(reply.ice_getIdentity());
            ret = replyI.waitReply(3, 2000);
            if(ret)
            {
                break; // Success
            }
            replyI = new PingReplyI();
            reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
        }
        test(ret);
        Console.Out.WriteLine("ok");

        //
        // Sending the replies back on the multicast UDP connection doesn't work for most
        // platform (it works for OS X Leopard but not Snow Leopard, doesn't work on SLES,
        // Windows...). For Windows, see UdpTransceiver constructor for the details. So
        // we don't run this test.
        //
//         Console.Out.Write("testing udp bi-dir connection... ");
//         nRetry = 5;
//         while(nRetry-- > 0)
//         {
//             replyI.reset();
//             objMcast.pingBiDir(reply.ice_getIdentity());
//             ret = replyI.waitReply(5, 2000);
//             if(ret)
//             {
//                 break; // Success
//             }
//             replyI = new PingReplyI();
//             reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram();
//         }

//         if(!ret)
//         {
//             Console.Out.WriteLine("failed (is a firewall enabled?)");
//         }
//         else
//         {
//             Console.Out.WriteLine("ok");
//         }
    }