示例#1
0
    public static void allTests(Ice.Communicator communicator)
#endif
    {
        string sref = "test:default -p 12010";

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

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

        sref = "testController:tcp -p 12011";
        obj  = communicator.stringToProxy(sref);
        test(obj != null);

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

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

            Callback cb = new Callback();
            p.begin_op().whenCompleted(cb.response, cb.exception);
            cb.check();

            TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
            i.begin_op().whenCompleted(cb.exception);
            cb.check();

            testController.holdAdapter();
            Test.Callback_TestIntf_opWithPayload resp = cb.payload;
            Ice.ExceptionCallback excb = cb.ignoreEx;
            Ice.SentCallback      scb  = cb.sent;

            byte[] seq = new byte[10 * 1024];
            (new System.Random()).NextBytes(seq);
            Ice.AsyncResult r;
            while ((r = p.begin_opWithPayload(seq).whenCompleted(resp, excb).whenSent(scb)).sentSynchronously())
            {
                ;
            }
            testController.resumeAdapter();
            r.waitForCompleted();
        }
        WriteLine("ok");

        p.shutdown();
    }
示例#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 allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        string           sref         = "test:" + app.getTestEndpoint(0);

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

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

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

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

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

            Callback cb = new Callback();
            p.begin_op().whenCompleted(cb.response, cb.exception);
            cb.check();

            TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
            i.begin_op().whenCompleted(cb.exception);
            cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(250));
                to.begin_sleep(500).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception ex) => {
                    test(ex is Ice.InvocationTimeoutException);
                    test(Dispatcher.isDispatcherThread());
                    cb.called();
                });
                cb.check();
            }

            testController.holdAdapter();
            Test.Callback_TestIntf_opWithPayload resp = cb.payload;
            Ice.ExceptionCallback excb = cb.ignoreEx;
            Ice.SentCallback      scb  = cb.sent;

            byte[] seq = new byte[10 * 1024];
            (new System.Random()).NextBytes(seq);
            Ice.AsyncResult r;
            while ((r = p.begin_opWithPayload(seq).whenCompleted(resp, excb).whenSent(scb)).sentSynchronously())
            {
                ;
            }
            testController.resumeAdapter();
            r.waitForCompleted();
        }
        WriteLine("ok");

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

            Callback             cb           = new Callback();
            System.Action <Task> continuation = (Task previous) =>
            {
                try
                {
                    previous.Wait();
                    cb.response();
                }
                catch (System.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(100).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously);
            t.Wait();
            cb.check();

            TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
            i.opAsync().ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously).Wait();
            cb.check();

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

            testController.holdAdapter();
            System.Action <Task> continuation2 = (Task previous) =>
            {
                test(Dispatcher.isDispatcherThread());
                try
                {
                    previous.Wait();
                }
                catch (System.AggregateException ex)
                {
                    test(ex.InnerException is Ice.CommunicatorDestroyedException);
                }
            };

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

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

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

            Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(250));
            try
            {
                await to.sleepAsync(500);
                test(false);
            }
            catch (Ice.InvocationTimeoutException)
            {
                test(Dispatcher.isDispatcherThread());
            }
        }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        WriteLine("ok");

        p.shutdown();
    }
示例#4
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... ");
        output.Flush();
        {
            p.op();

            Callback cb = new Callback(output);
            p.begin_op().whenCompleted(cb.response, cb.exception);
            cb.check();

            TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
            i.begin_op().whenCompleted(cb.exception);
            cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10));
                to.begin_sleep(500).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception ex) => {
                    test(ex is Ice.InvocationTimeoutException);
                    test(Dispatcher.isDispatcherThread());
                    cb.called();
                });
                cb.check();
            }

            testController.holdAdapter();
            Test.Callback_TestIntf_opWithPayload resp = cb.payload;
            Ice.ExceptionCallback excb = cb.ignoreEx;
            Ice.SentCallback      scb  = cb.sent;

            byte[] seq = new byte[10 * 1024];
            (new System.Random()).NextBytes(seq);
            Ice.AsyncResult r;
            while ((r = p.begin_opWithPayload(seq).whenCompleted(resp, excb).whenSent(scb)).sentSynchronously())
            {
                ;
            }
            testController.resumeAdapter();
            r.waitForCompleted();
        }
        output.WriteLine("ok");

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

            Callback             cb           = new Callback(output);
            System.Action <Task> continuation = (Task previous) =>
            {
                try
                {
                    previous.Wait();
                    cb.response();
                }
                catch (System.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.
            //
            {
                Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(20));
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (System.AggregateException ex)
                    {
                        test(ex.InnerException is Ice.InvocationTimeoutException);
                        test(Dispatcher.isDispatcherThread());
                    }
                }, 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.
            //
            {
                Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10));
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (System.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 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_collocationOptimized(false));
            System.Action <Task> continuation2 = (Task previous) =>
            {
                test(Dispatcher.isDispatcherThread());
                try
                {
                    previous.Wait();
                }
                catch (System.AggregateException ex)
                {
                    test(ex.InnerException is Ice.CommunicatorDestroyedException);
                }
            };

            byte[] seq = new byte[10 * 1024];
            (new System.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());
                    }

                    Test.TestIntfPrx to = Test.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();
    }
示例#5
0
文件: AllTests.cs 项目: saxonelf/ice
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        string           sref         = "test:" + app.getTestEndpoint(0);

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

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

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

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

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

            Callback cb = new Callback();
            p.begin_op().whenCompleted(cb.response, cb.exception);
            cb.check();

            TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy");
            i.begin_op().whenCompleted(cb.exception);
            cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(250));
                to.begin_sleep(500).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception ex) => {
                    test(ex is Ice.InvocationTimeoutException);
                    test(Dispatcher.isDispatcherThread());
                    cb.called();
                });
                cb.check();
            }

            testController.holdAdapter();
            Test.Callback_TestIntf_opWithPayload resp = cb.payload;
            Ice.ExceptionCallback excb = cb.ignoreEx;
            Ice.SentCallback      scb  = cb.sent;

            byte[] seq = new byte[10 * 1024];
            (new System.Random()).NextBytes(seq);
            Ice.AsyncResult r;
            while ((r = p.begin_opWithPayload(seq).whenCompleted(resp, excb).whenSent(scb)).sentSynchronously())
            {
                ;
            }
            testController.resumeAdapter();
            r.waitForCompleted();
        }
        WriteLine("ok");

        p.shutdown();
    }
示例#6
0
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.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:" + app.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();

        if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1"))
        {
            endpoint.Append("udp -h \"ff15::1:1\" --interface \"::1\" -p "); // Use loopback to prevent other machines to answer.
        }
        else
        {
            endpoint.Append("udp -h 239.255.1.1 --interface 127.0.0.1 -p "); // Use loopback to prevent other machines to answer.
        }
        endpoint.Append(app.getTestPort(10));
        @base = communicator.stringToProxy("test -d:" + endpoint.ToString());
        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 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");
//         }
    }
示例#7
0
    public static void allTests(Ice.Communicator communicator)
#endif
    {
        string sref = "test:default -p 12010";

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

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

        sref = "testController:tcp -p 12011";
        obj  = communicator.stringToProxy(sref);
        test(obj != null);

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

        Write("testing begin/end invocation... ");
        Flush();
        {
            Ice.AsyncResult             result;
            Dictionary <string, string> ctx = new Dictionary <string, string>();

            result = p.begin_ice_isA("::Test::TestIntf");
            test(p.end_ice_isA(result));
            result = p.begin_ice_isA("::Test::TestIntf", ctx);
            test(p.end_ice_isA(result));

            result = p.begin_ice_ping();
            p.end_ice_ping(result);
            result = p.begin_ice_ping(ctx);
            p.end_ice_ping(result);

            result = p.begin_ice_id();
            test(p.end_ice_id(result).Equals("::Test::TestIntf"));
            result = p.begin_ice_id(ctx);
            test(p.end_ice_id(result).Equals("::Test::TestIntf"));

            result = p.begin_ice_ids();
            test(p.end_ice_ids(result).Length == 2);
            result = p.begin_ice_ids(ctx);
            test(p.end_ice_ids(result).Length == 2);

            result = p.begin_op();
            p.end_op(result);
            result = p.begin_op(ctx);
            p.end_op(result);

            result = p.begin_opWithResult();
            test(p.end_opWithResult(result) == 15);
            result = p.begin_opWithResult(ctx);
            test(p.end_opWithResult(result) == 15);

            result = p.begin_opWithUE();
            try
            {
                p.end_opWithUE(result);
                test(false);
            }
            catch (Test.TestIntfException)
            {
            }
            result = p.begin_opWithUE(ctx);
            try
            {
                p.end_opWithUE(result);
                test(false);
            }
            catch (Test.TestIntfException)
            {
            }
        }
        WriteLine("ok");

        Write("testing async callback... ");
        Flush();
        {
            AsyncCallback cb = new AsyncCallback();
            Dictionary <string, string> ctx = new Dictionary <string, string>();
            Cookie        cookie            = new Cookie(5);
            AsyncCallback cbWC = new AsyncCallback(cookie);

            p.begin_ice_isA("::Test::TestIntf", cb.isA, null);
            cb.check();
            p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie);
            cbWC.check();
            p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null);
            cb.check();
            p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie);
            cbWC.check();

            p.begin_ice_ping(cb.ping, null);
            cb.check();
            p.begin_ice_ping(cbWC.ping, cookie);
            cbWC.check();
            p.begin_ice_ping(ctx, cb.ping, null);
            cb.check();
            p.begin_ice_ping(ctx, cbWC.ping, cookie);
            cbWC.check();

            p.begin_ice_id(cb.id, null);
            cb.check();
            p.begin_ice_id(cbWC.id, cookie);
            cbWC.check();
            p.begin_ice_id(ctx, cb.id, null);
            cb.check();
            p.begin_ice_id(ctx, cbWC.id, cookie);
            cbWC.check();

            p.begin_ice_ids(cb.ids, null);
            cb.check();
            p.begin_ice_ids(cbWC.ids, cookie);
            cbWC.check();
            p.begin_ice_ids(ctx, cb.ids, null);
            cb.check();
            p.begin_ice_ids(ctx, cbWC.ids, cookie);
            cbWC.check();

            p.begin_op(cb.op, null);
            cb.check();
            p.begin_op(cbWC.op, cookie);
            cbWC.check();
            p.begin_op(ctx, cb.op, null);
            cb.check();
            p.begin_op(ctx, cbWC.op, cookie);
            cbWC.check();

            p.begin_opWithResult(cb.opWithResult, null);
            cb.check();
            p.begin_opWithResult(cbWC.opWithResult, cookie);
            cbWC.check();
            p.begin_opWithResult(ctx, cb.opWithResult, null);
            cb.check();
            p.begin_opWithResult(ctx, cbWC.opWithResult, cookie);
            cbWC.check();

            p.begin_opWithUE(cb.opWithUE, null);
            cb.check();
            p.begin_opWithUE(cbWC.opWithUE, cookie);
            cbWC.check();
            p.begin_opWithUE(ctx, cb.opWithUE, null);
            cb.check();
            p.begin_opWithUE(ctx, cbWC.opWithUE, cookie);
            cbWC.check();
        }
        WriteLine("ok");

        Write("testing response callback... ");
        Flush();
        {
            ResponseCallback            cb  = new ResponseCallback();
            Dictionary <string, string> ctx = new Dictionary <string, string>();

            p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null);
            cb.check();
            p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null);
            cb.check();

            p.begin_ice_ping().whenCompleted(cb.ping, null);
            cb.check();
            p.begin_ice_ping(ctx).whenCompleted(cb.ping, null);
            cb.check();

            p.begin_ice_id().whenCompleted(cb.id, null);
            cb.check();
            p.begin_ice_id(ctx).whenCompleted(cb.id, null);
            cb.check();

            p.begin_ice_ids().whenCompleted(cb.ids, null);
            cb.check();
            p.begin_ice_ids(ctx).whenCompleted(cb.ids, null);
            cb.check();

            p.begin_op().whenCompleted(cb.op, null);
            cb.check();
            p.begin_op(ctx).whenCompleted(cb.op, null);
            cb.check();

            p.begin_opWithResult().whenCompleted(cb.opWithResult, null);
            cb.check();
            p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null);
            cb.check();

            p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE);
            cb.check();
            p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE);
            cb.check();
        }
        WriteLine("ok");

        Write("testing local exceptions... ");
        Flush();
        {
            Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            Ice.AsyncResult  r;

            r = indirect.begin_op();
            try
            {
                indirect.end_op(r);
                test(false);
            }
            catch (Ice.NoEndpointException)
            {
            }


            try
            {
                r = ((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult();
                test(false);
            }
            catch (System.ArgumentException)
            {
            }

            //
            // Check that CommunicatorDestroyedException is raised directly.
            //
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().ice_clone_();
            Ice.Communicator ic = Ice.Util.initialize(initData);
            Ice.ObjectPrx    o  = ic.stringToProxy(p.ToString());
            Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o);
            ic.destroy();

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

        Write("testing local exceptions with async callback... ");
        Flush();
        {
            Test.TestIntfPrx i      = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            AsyncCallback    cb     = new AsyncCallback();
            Cookie           cookie = new Cookie(5);
            AsyncCallback    cbWC   = new AsyncCallback(cookie);

            i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null);
            cb.check();
            i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie);
            cbWC.check();

            i.begin_ice_ping(cb.pingEx, null);
            cb.check();
            i.begin_ice_ping(cbWC.pingEx, cookie);
            cbWC.check();

            i.begin_ice_id(cb.idEx, null);
            cb.check();
            i.begin_ice_id(cbWC.idEx, cookie);
            cbWC.check();

            i.begin_ice_ids(cb.idsEx, null);
            cb.check();
            i.begin_ice_ids(cbWC.idsEx, cookie);
            cbWC.check();

            i.begin_op(cb.opEx, null);
            cb.check();
            i.begin_op(cbWC.opEx, cookie);
            cbWC.check();
        }
        WriteLine("ok");

        Write("testing local exceptions with response callback... ");
        Flush();
        {
            Test.TestIntfPrx  i  = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex);
            cb.check();

            i.begin_ice_ping().whenCompleted(cb.ping, cb.ex);
            cb.check();

            i.begin_ice_id().whenCompleted(cb.id, cb.ex);
            cb.check();

            i.begin_ice_ids().whenCompleted(cb.ids, cb.ex);
            cb.check();

            i.begin_op().whenCompleted(cb.op, cb.ex);
            cb.check();
        }
        WriteLine("ok");

        Write("testing exception callback... ");
        Flush();
        {
            Test.TestIntfPrx  i  = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex);
            cb.check();

            i.begin_op().whenCompleted(cb.ex);
            cb.check();

            i.begin_opWithResult().whenCompleted(cb.ex);
            cb.check();

            i.begin_opWithUE().whenCompleted(cb.ex);
            cb.check();

            // Ensures no exception is called when response is received
            p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx);
            p.begin_op().whenCompleted(cb.noEx);
            p.begin_opWithResult().whenCompleted(cb.noEx);

            // If response is a user exception, it should be received.
            p.begin_opWithUE().whenCompleted(cb.opWithUE);
            cb.check();
        }
        WriteLine("ok");

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

            p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_op(cb.opAsync, null).whenSent((Ice.AsyncCallback)cb.sentAsync);
            cb.check();

            p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent);
            cb.check();

            List <SentCallback> cbs = new List <SentCallback>();
            byte[] seq = new byte[10024];
            (new System.Random()).NextBytes(seq);
            testController.holdAdapter();
            try
            {
                Ice.AsyncResult r;
                do
                {
                    SentCallback cb2 = new SentCallback();
                    r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent);
                    cbs.Add(cb2);
                }while(r.sentSynchronously());
            }
            finally
            {
                testController.resumeAdapter();
            }
            foreach (SentCallback cb3 in cbs)
            {
                cb3.check();
            }
        }
        WriteLine("ok");

        Write("testing illegal arguments... ");
        Flush();
        {
            Ice.AsyncResult result;

            result = p.begin_op();
            p.end_op(result);
            try
            {
                p.end_op(result);
                test(false);
            }
            catch (System.ArgumentException)
            {
            }

            result = p.begin_op();
            try
            {
                p.end_opWithResult(result);
                test(false);
            }
            catch (System.ArgumentException)
            {
            }

            try
            {
                p.end_op(null);
                test(false);
            }
            catch (System.ArgumentException)
            {
            }
        }
        WriteLine("ok");

        Write("testing unexpected exceptions from callback... ");
        Flush();
        {
            Test.TestIntfPrx q       = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ThrowType[]      throwEx = new ThrowType[] { ThrowType.LocalException, ThrowType.UserException,
                                                         ThrowType.OtherException };

            for (int i = 0; i < 3; ++i)
            {
                Thrower cb = new Thrower(throwEx[i]);

                p.begin_op(cb.opAsync, null);
                cb.check();

                p.begin_op().whenCompleted(cb.op, null);
                cb.check();

                q.begin_op().whenCompleted(cb.op, cb.ex);
                cb.check();

                p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent);
                cb.check();

                q.begin_op().whenCompleted(cb.ex);
                cb.check();
            }
        }
        WriteLine("ok");

        Write("testing batch requests with proxy... ");
        Flush();
        {
            Cookie cookie = new Cookie(5);

            {
                //
                // AsyncResult.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // AsyncResult exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback(cookie);
                Ice.AsyncResult r  = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // Type-safe.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // Type-safe exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback();
                Ice.AsyncResult r  = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }
        }
        WriteLine("ok");

        Write("testing batch requests with connection... ");
        Flush();
        {
            Cookie cookie = new Cookie(5);

            {
                //
                // AsyncResult.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // AsyncResult exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback(cookie);
                Ice.AsyncResult r  = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // Type-safe.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = b1.ice_getConnection().begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // Type-safe exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback();
                Ice.AsyncResult r  = b1.ice_getConnection().begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }
        }
        WriteLine("ok");

        Write("testing batch requests with communicator... ");
        Flush();
        {
            Cookie cookie = new Cookie(5);

            {
                //
                // AsyncResult - 1 connection.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // AsyncResult exception - 1 connection.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // AsyncResult - 2 connections.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b1.opBatch();
                b2.opBatch();
                b2.opBatch();
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(4));
            }

            {
                //
                // AsyncResult exception - 2 connections - 1 failure.
                //
                // All connections should be flushed even if there are failures on some connections.
                // Exceptions should not be reported.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b2.opBatch();
                b1.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.waitForBatch(1));
            }

            {
                //
                // AsyncResult exception - 2 connections - 2 failures.
                //
                // The sent callback should be invoked even if all connections fail.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b2.opBatch();
                b1.ice_getConnection().close(false);
                b2.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback(cookie);
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent((Ice.AsyncCallback)cb.sentAsync);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // Type-safe - 1 connection.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            {
                //
                // Type-safe exception - 1 connection.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // 2 connections.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b1.opBatch();
                b2.opBatch();
                b2.opBatch();
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(4));
            }

            {
                //
                // Exception - 2 connections - 1 failure.
                //
                // All connections should be flushed even if there are failures on some connections.
                // Exceptions should not be reported.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b2.opBatch();
                b1.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.waitForBatch(1));
            }

            {
                //
                // Exception - 2 connections - 2 failures.
                //
                // The sent callback should be invoked even if all connections fail.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                b2.ice_getConnection(); // Ensure connection is established.
                b1.opBatch();
                b2.opBatch();
                b1.ice_getConnection().close(false);
                b2.ice_getConnection().close(false);
                FlushCallback   cb = new FlushCallback();
                Ice.AsyncResult r  = communicator.begin_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent((Ice.SentCallback)cb.sent);
                cb.check();
                test(r.isSent()); // Exceptions are ignored!
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }
        }
        WriteLine("ok");

        Write("testing AsyncResult operations... ");
        Flush();
        {
            {
                testController.holdAdapter();
                Ice.AsyncResult r1;
                Ice.AsyncResult r2;
                try
                {
                    r1 = p.begin_op();
                    byte[] seq = new byte[10024];
                    (new System.Random()).NextBytes(seq);
                    while ((r2 = p.begin_opWithPayload(seq)).sentSynchronously())
                    {
                        ;
                    }

                    test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() ||
                         !r1.sentSynchronously() && !r1.isCompleted_());

                    test(!r2.sentSynchronously() && !r2.isCompleted_());

                    test(!r1.IsCompleted && !r1.CompletedSynchronously);
                    test(!r2.IsCompleted && !r2.CompletedSynchronously);
                }
                finally
                {
                    testController.resumeAdapter();
                }

                WaitHandle w1 = r1.AsyncWaitHandle;
                WaitHandle w2 = r2.AsyncWaitHandle;

                r1.waitForSent();
                test(r1.isSent());

                r2.waitForSent();
                test(r2.isSent());

                r1.waitForCompleted();
                test(r1.isCompleted_());
                w1.WaitOne();

                r2.waitForCompleted();
                test(r2.isCompleted_());
                w2.WaitOne();

                test(r1.getOperation().Equals("op"));
                test(r2.getOperation().Equals("opWithPayload"));
            }

            {
                Ice.AsyncResult r;

                //
                // Twoway
                //
                r = p.begin_ice_ping();
                test(r.getOperation().Equals("ice_ping"));
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p);
                p.end_ice_ping(r);

                Test.TestIntfPrx p2;

                //
                // Oneway
                //
                p2 = p.ice_oneway() as Test.TestIntfPrx;
                r  = p2.begin_ice_ping();
                test(r.getOperation().Equals("ice_ping"));
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p2);

                //
                // Batch request via proxy
                //
                p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                p2.ice_ping();
                r = p2.begin_ice_flushBatchRequests();
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p2);
                p2.end_ice_flushBatchRequests(r);

                //
                // Batch request via connection
                //
                Ice.Connection con = p.ice_getConnection();
                p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                p2.ice_ping();
                r = con.begin_flushBatchRequests();
                test(r.getConnection() == con);
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == null); // Expected
                con.end_flushBatchRequests(r);

                //
                // Batch request via communicator
                //
                p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                p2.ice_ping();
                r = communicator.begin_flushBatchRequests();
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == null);      // Expected
                communicator.end_flushBatchRequests(r);
            }
        }
        WriteLine("ok");

        Write("testing close connection with sending queue... ");
        Flush();
        {
            byte[] seq = new byte[1024 * 10];
            (new System.Random()).NextBytes(seq); // Make sure the request doesn't compress too well.

            //
            // 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.ice_ping();
                List <Ice.AsyncResult> results = new List <Ice.AsyncResult>();
                for (int i = 0; i < maxQueue; ++i)
                {
                    results.Add(p.begin_opWithPayload(seq));
                }
                if (!p.begin_close(false).isSent())
                {
                    for (int i = 0; i < maxQueue; i++)
                    {
                        Ice.AsyncResult r = p.begin_opWithPayload(seq);
                        results.Add(r);
                        if (r.isSent())
                        {
                            done      = false;
                            maxQueue *= 2;
                            break;
                        }
                    }
                }
                else
                {
                    maxQueue *= 2;
                    done      = false;
                }
                foreach (Ice.AsyncResult q in results)
                {
                    q.waitForCompleted();
                    try
                    {
                        q.throwLocalException();
                    }
                    catch (Ice.LocalException)
                    {
                        test(false);
                    }
                }
            }
        }
        WriteLine("ok");

        p.shutdown();
    }