Example #1
0
            private static string getAdapterNameWithAMI(Test.TestIntfPrx testIntf)
            {
                object m      = new object();
                string result = null;

                testIntf.begin_getAdapterName().whenCompleted(
                    (string name) =>
                {
                    lock (m)
                    {
                        result = name;
                        System.Threading.Monitor.Pulse(m);
                    }
                },
                    (Ice.Exception ex) =>
                {
                    test(false);
                });
                lock (m)
                {
                    while (result == null)
                    {
                        System.Threading.Monitor.Wait(m);
                    }
                    return(result);
                }
            }
Example #2
0
    public static void allTests(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        string           sref         = "test:" + helper.getTestEndpoint(0);

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

        int proxyPort = communicator.getProperties().getPropertyAsInt("Ice.HTTPProxyPort");

        if (proxyPort == 0)
        {
            proxyPort = communicator.getProperties().getPropertyAsInt("Ice.SOCKSProxyPort");
        }

        Test.TestIntfPrx testPrx = Test.TestIntfPrxHelper.checkedCast(obj);
        test(testPrx != null);
        var output = helper.getWriter();

        output.Write("testing connection... ");
        output.Flush();
        {
            testPrx.ice_ping();
        }
        output.WriteLine("ok");

        output.Write("testing connection information... ");
        output.Flush();
        {
            Ice.IPConnectionInfo info = getIPConnectionInfo(testPrx.ice_getConnection().getInfo());
            test(info.remotePort == proxyPort); // make sure we are connected to the proxy port.
        }
        output.WriteLine("ok");

        output.Write("shutting down server... ");
        output.Flush();
        {
            testPrx.shutdown();
        }
        output.WriteLine("ok");

        output.Write("testing connection failure... ");
        output.Flush();
        {
            try
            {
                testPrx.ice_ping();
                test(false);
            }
            catch (Ice.LocalException)
            {
            }
        }
        output.WriteLine("ok");
    }
Example #3
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 testPrx = Test.TestIntfPrxHelper.checkedCast(obj);
        test(testPrx != null);

        Write("testing connection... ");
        Flush();
        {
            testPrx.ice_ping();
        }
        WriteLine("ok");

        Write("testing connection information... ");
        Flush();
        {
            Ice.IPConnectionInfo info = (Ice.IPConnectionInfo)testPrx.ice_getConnection().getInfo();
            test(info.remotePort == 12030 || info.remotePort == 12031); // make sure we are connected to the proxy port.
        }
        WriteLine("ok");

        Write("shutting down server... ");
        Flush();
        {
            testPrx.shutdown();
        }
        WriteLine("ok");

        Write("testing connection failure... ");
        Flush();
        {
            try
            {
                testPrx.ice_ping();
                test(false);
            }
            catch (Ice.LocalException)
            {
            }
        }
        WriteLine("ok");
    }
Example #4
0
            private static Test.TestIntfPrx createTestIntfPrx(List <Test.RemoteObjectAdapterPrx> adapters)
            {
                List <Ice.Endpoint> endpoints = new List <Ice.Endpoint>();

                Test.TestIntfPrx obj = null;
                IEnumerator <Test.RemoteObjectAdapterPrx> p = adapters.GetEnumerator();

                while (p.MoveNext())
                {
                    obj = p.Current.getTestIntf();
                    foreach (Ice.Endpoint e in obj.ice_getEndpoints())
                    {
                        endpoints.Add(e);
                    }
                }
                return(Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpoints(endpoints.ToArray())));
            }
Example #5
0
            private static Test.TestIntfPrx createTestIntfPrx(List <Test.RemoteObjectAdapterPrx> adapters)
            {
                List <Endpoint> endpoints = new List <Endpoint>();

                Test.TestIntfPrx obj = null;
                IEnumerator <Test.RemoteObjectAdapterPrx> p = adapters.GetEnumerator();

                while (p.MoveNext())
                {
                    obj = p.Current.getTestIntf();
                    foreach (Endpoint e in obj.Endpoints)
                    {
                        endpoints.Add(e);
                    }
                }
                Debug.Assert(obj != null);
                return(obj.Clone(endpoints: endpoints.ToArray()));
            }
Example #6
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    Ice.Connection con = proxy.ice_getCachedConnection();

                    try
                    {
                        con.setACM(-19, Ice.Util.None, Ice.Util.None);
                        test(false);
                    }
                    catch (ArgumentException)
                    {
                    }

                    Ice.ACM acm;
                    acm = con.getACM();
                    test(acm.timeout == 15);
                    test(acm.close == Ice.ACMClose.CloseOnIdleForceful);
                    test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOff);

                    con.setACM(Ice.Util.None, Ice.Util.None, Ice.Util.None);
                    acm = con.getACM();
                    test(acm.timeout == 15);
                    test(acm.close == Ice.ACMClose.CloseOnIdleForceful);
                    test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOff);

                    con.setACM(1, Ice.ACMClose.CloseOnInvocationAndIdle, Ice.ACMHeartbeat.HeartbeatAlways);
                    acm = con.getACM();
                    test(acm.timeout == 1);
                    test(acm.close == Ice.ACMClose.CloseOnInvocationAndIdle);
                    test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatAlways);

                    proxy.startHeartbeatCount();
                    proxy.waitForHeartbeatCount(2);

                    var t1 = new TaskCompletionSource <object>();

                    con.setCloseCallback(_ => { t1.SetResult(null); });

                    con.close(Ice.ConnectionClose.Gracefully);
                    test(t1.Task.Result == null);

                    try
                    {
                        con.throwException();
                        test(false);
                    }
                    catch (Ice.ConnectionManuallyClosedException)
                    {
                    }

                    var t2 = new TaskCompletionSource <object>();

                    con.setCloseCallback(_ => { t2.SetResult(null); });
                    test(t2.Task.Result == null);

                    con.setHeartbeatCallback(_ => { test(false); });
                }
Example #7
0
 public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
 {
     proxy.startHeartbeatCount();
     Ice.Connection con = proxy.ice_getConnection();
     con.heartbeat();
     con.heartbeat();
     con.heartbeat();
     con.heartbeat();
     con.heartbeat();
     proxy.waitForHeartbeatCount(5);
 }
Example #8
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        proxy.ice_ping();
                        Thread.Sleep(300);
                    }

                    lock (this)
                    {
                        test(_heartbeat >= 3);
                    }
                }
Example #9
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    Thread.Sleep(3000);

                    lock (this)
                    {
                        test(_heartbeat >= 3);
                    }
                }
Example #10
0
 private static string getAdapterNameWithAMI(Test.TestIntfPrx testIntf)
 {
     return(testIntf.getAdapterNameAsync().Result);
 }
Example #11
0
            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");
                //         }
            }
Example #12
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    adapter.hold();
                    Thread.Sleep(3000); // Idle for 3 seconds

                    waitForClosed();
                    lock (this)
                    {
                        test(_heartbeat == 0);
                    }
                }
Example #13
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    try
                    {
                        // Heartbeats are disabled on the server, the
                        // invocation should fail since heartbeats are
                        // expected.
                        proxy.sleep(10);
                        test(false);
                    }
                    catch (Ice.ConnectionTimeoutException)
                    {
                        proxy.interruptSleep();

                        waitForClosed();
                        lock (this)
                        {
                            test(_heartbeat == 0);
                        }
                    }
                }
Example #14
0
 public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
 {
     try
     {
         // When the OA is put on hold, connections shouldn't
         // send heartbeats, the invocation should therefore
         // fail.
         proxy.sleepAndHold(10);
         test(false);
     }
     catch (Ice.ConnectionTimeoutException)
     {
         adapter.activate();
         proxy.interruptSleep();
         waitForClosed();
     }
 }
Example #15
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    proxy.sleep(4);

                    lock (this)
                    {
                        test(_heartbeat >= 4);
                    }
                }
Example #16
0
 public abstract void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy);
Example #17
0
            public static void allTests(global::Test.TestHelper helper, bool collocated)
            {
                Communicator communicator = helper.communicator();
                string       sref         = "test:" + helper.getTestEndpoint(0);
                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);

                var output = helper.getWriter();

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

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

                    p.ice_pingAsync().Wait();
                    p.ice_pingAsync(ctx).Wait();

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

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

                    if (!collocated)
                    {
                        test(p.ice_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.ice_isAAsync("::Test::TestIntf"));
                        test(await p.ice_isAAsync("::Test::TestIntf", ctx));

                        await p.ice_pingAsync();
                        await p.ice_pingAsync(ctx);

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

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

                        if (!collocated)
                        {
                            var conn = await p.ice_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.ice_isAAsync("::Test::TestIntf").ContinueWith(previous =>
                    {
                        test(previous.Result);
                    }).Wait();

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

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

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

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

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

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

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

                    if (!collocated)
                    {
                        p.ice_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();
                {
                    Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));

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

                    try
                    {
                        ((Test.TestIntfPrx)p.ice_oneway()).opWithResultAsync();
                        test(false);
                    }
                    catch (TwowayOnlyException)
                    {
                    }

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

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

                output.Write("testing exception with async task... ");
                output.Flush();
                {
                    Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));

                    try
                    {
                        i.ice_isAAsync("::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.ice_isAAsync("::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.ice_isAAsync("",
                                                progress: new Progress(sentSynchronously =>
                        {
                            cb.sent(sentSynchronously);
                        }));
                        cb.check();
                        t.Wait();

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

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

                        t = p.ice_idsAsync(
                            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.ice_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.ice_pingAsync(cancel: cs1.Token);
                            t2 = p.ice_pingAsync(cancel: cs2.Token);
                            cs3.Cancel();
                            t3 = p.ice_pingAsync(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.ice_ping();
                        }
                    }
                    output.WriteLine("ok");
                }

                if (p.ice_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.ice_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.ice_ping();
                            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 = (Test.TestIntfPrx)p.ice_connectionId("CloseGracefully"); // Start with a new connection.
                        Connection   con = p.ice_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.ice_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.ice_ping();
                        Connection   con = p.ice_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.ice_pingAsync().ContinueWith(
                        (t) =>
                    {
                        test(Thread.CurrentThread.Name == null ||
                             !Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                    }).Wait();

                    p.ice_pingAsync().ContinueWith(
                        (t) =>
                    {
                        test(Thread.CurrentThread.Name.Contains("ThreadPool.Client"));
                    }, p.ice_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.ice_pingAsync().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.ice_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.ice_scheduler());
                        }, p.ice_scheduler()).Wait();
                        s2.SetResult(1);
                        Task.WaitAll(t1, t2, t3, t4);
                    }

                    if (!collocated)
                    {
                        ObjectAdapter adapter = communicator.createObjectAdapter("");
                        PingReplyI    replyI  = new PingReplyI();
                        var           reply   = Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI));
                        adapter.activate();

                        p.ice_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.TestIntfPrxHelper.uncheckedCast(
                        communicator.stringToProxy("test2:" + helper.getTestEndpoint(0)));
                    q.opAsync(1).ContinueWith(t =>
                    {
                        var r = t.Result;
                        test(r.returnValue == 1);
                        test(r.j == 1);
                    }).Wait();
                }
                output.WriteLine("ok");

                p.shutdown();
            }
Example #18
0
 public override int run(string[] args)
 {
     Test.TestIntfPrx proxy = AllTests.allTests(this);
     proxy.shutdown();
     return(0);
 }
Example #19
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    // No close on invocation, the call should succeed this
                    // time.
                    proxy.sleep(3);

                    lock (this)
                    {
                        test(_heartbeat == 0);
                        test(!_closed);
                    }
                }
Example #20
0
            public static void allTests(global::Test.TestHelper helper)
            {
                Communicator communicator = helper.communicator();
                var          com          = Test.RemoteCommunicatorPrx.Parse($"communicator:{helper.getTestEndpoint(0)}", communicator);

                var rand   = new Random(unchecked ((int)DateTime.Now.Ticks));
                var output = helper.getWriter();

                output.Write("testing binding with single endpoint... ");
                output.Flush();
                {
                    Test.RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default");

                    var test1 = adapter.getTestIntf();
                    var test2 = adapter.getTestIntf();
                    test(test1.GetConnection() == test2.GetConnection());

                    test1.IcePing();
                    test2.IcePing();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrx.UncheckedCast(test1);
                    test(test3.GetConnection() == test1.GetConnection());
                    test(test3.GetConnection() == test2.GetConnection());

                    try
                    {
                        test3.IcePing();
                        test(false);
                    }
                    catch (ConnectFailedException)
                    {
                    }
                    catch (ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter11", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter12", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("Adapter11");
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.IcePing();
                        test(test1.GetConnection() == test2.GetConnection());
                        test(test2.GetConnection() == test3.GetConnection());

                        names.Remove(test1.getAdapterName());
                        test1.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().IcePing();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = t.getAdapterName();
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().GetConnection().close(ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[0]);
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.GetConnection() == test2.GetConnection());
                        test(test2.GetConnection() == test3.GetConnection());

                        names.Remove(test1.getAdapterName());
                        test1.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple random endpoints... ");
                output.Flush();
                {
                    var adapters = new Test.RemoteObjectAdapterPrx[5];
                    adapters[0] = com.createObjectAdapter("AdapterRandom11", "default");
                    adapters[1] = com.createObjectAdapter("AdapterRandom12", "default");
                    adapters[2] = com.createObjectAdapter("AdapterRandom13", "default");
                    adapters[3] = com.createObjectAdapter("AdapterRandom14", "default");
                    adapters[4] = com.createObjectAdapter("AdapterRandom15", "default");

                    int count        = 20;
                    int adapterCount = adapters.Length;
                    while (--count > 0)
                    {
                        Test.TestIntfPrx[] proxies;
                        if (count == 1)
                        {
                            com.deactivateObjectAdapter(adapters[4]);
                            --adapterCount;
                        }
                        proxies = new Test.TestIntfPrx[10];

                        int i;
                        for (i = 0; i < proxies.Length; ++i)
                        {
                            var adpts = new Test.RemoteObjectAdapterPrx[rand.Next(adapters.Length)];
                            if (adpts.Length == 0)
                            {
                                adpts = new Test.RemoteObjectAdapterPrx[1];
                            }
                            for (int j = 0; j < adpts.Length; ++j)
                            {
                                adpts[j] = adapters[rand.Next(adapters.Length)];
                            }
                            proxies[i] = createTestIntfPrx(new List <Test.RemoteObjectAdapterPrx>(adpts));
                        }

                        for (i = 0; i < proxies.Length; i++)
                        {
                            proxies[i].getAdapterNameAsync();
                        }
                        for (i = 0; i < proxies.Length; i++)
                        {
                            try
                            {
                                proxies[i].IcePing();
                            }
                            catch (LocalException)
                            {
                            }
                        }

                        List <Connection> connections = new List <Connection>();
                        for (i = 0; i < proxies.Length; i++)
                        {
                            if (proxies[i].GetCachedConnection() != null)
                            {
                                if (!connections.Contains(proxies[i].GetCachedConnection()))
                                {
                                    connections.Add(proxies[i].GetCachedConnection());
                                }
                            }
                        }
                        test(connections.Count <= adapterCount);

                        foreach (var a in adapters)
                        {
                            try
                            {
                                a.getTestIntf().GetConnection().close(ConnectionClose.GracefullyWithWait);
                            }
                            catch (LocalException)
                            {
                                // Expected if adapter is down.
                            }
                        }
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI11", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI12", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("AdapterAMI11");
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.IcePing();
                        test(test1.GetConnection() == test2.GetConnection());
                        test(test2.GetConnection() == test3.GetConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().IcePing();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = getAdapterNameWithAMI(t);
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().GetConnection().close(ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter(adapters[0]);
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.GetConnection() == test2.GetConnection());
                        test(test2.GetConnection() == test3.GetConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter(adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing random endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter21", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter22", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter23", "default"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.EndpointSelection == EndpointSelectionType.Random);

                    var names = new List <string>();
                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Random);
                    test(obj.EndpointSelection == EndpointSelectionType.Random);

                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    }

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter31", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter32", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter33", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered);
                    test(obj.EndpointSelection == EndpointSelectionType.Ordered);
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (ConnectFailedException)
                    {
                    }
                    catch (ConnectTimeoutException)
                    {
                    }

                    Endpoint[] endpoints = obj.Endpoints;

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with single endpoint... ");
                output.Flush();
                {
                    var adapter = com.createObjectAdapter("Adapter41", "default");

                    var test1 = adapter.getTestIntf().Clone(connectionCached: false);
                    var test2 = adapter.getTestIntf().Clone(connectionCached: false);
                    test(!test1.IsConnectionCached);
                    test(!test2.IsConnectionCached);
                    test(test1.GetConnection() != null && test2.GetConnection() != null);
                    test(test1.GetConnection() == test2.GetConnection());

                    test1.IcePing();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrx.UncheckedCast(test1);
                    try
                    {
                        test(test3.GetConnection() == test1.GetConnection());
                        test(false);
                    }
                    catch (ConnectFailedException)
                    {
                    }
                    catch (ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter51", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter52", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter53", "default"));

                    var obj = createTestIntfPrx(adapters).Clone(connectionCached: false);
                    test(!obj.IsConnectionCached);

                    List <string> names = new List <string>();
                    names.Add("Adapter51");
                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(obj.getAdapterName().Equals("Adapter52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI51", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI52", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI53", "default"));

                    var obj = createTestIntfPrx(adapters).Clone(connectionCached: false);
                    test(!obj.IsConnectionCached);

                    var names = new List <string>();
                    names.Add("AdapterAMI51");
                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter61", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter62", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered);
                    test(obj.EndpointSelection == EndpointSelectionType.Ordered);
                    obj = obj.Clone(connectionCached: false);
                    test(!obj.IsConnectionCached);
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (ConnectFailedException)
                    {
                    }
                    catch (ConnectTimeoutException)
                    {
                    }

                    Endpoint[] endpoints = obj.Endpoints;

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI61", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI62", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered);
                    test(obj.EndpointSelection == EndpointSelectionType.Ordered);
                    obj = obj.Clone(connectionCached: false);
                    test(!obj.IsConnectionCached);
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (ConnectFailedException)
                    {
                    }
                    catch (ConnectTimeoutException)
                    {
                    }

                    Endpoint[] endpoints = obj.Endpoints;

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter71", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter72", "udp"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter71"));

                    var testUDP = obj.Clone(invocationMode: InvocationMode.Datagram);
                    test(obj.GetConnection() != testUDP.GetConnection());
                    try
                    {
                        testUDP.getAdapterName();
                    }
                    catch (TwowayOnlyException)
                    {
                    }
                }
                output.WriteLine("ok");
                if (communicator.GetProperty("Plugin.IceSSL") != null)
                {
                    output.Write("testing unsecure vs. secure endpoints... ");
                    output.Flush();
                    {
                        var adapters = new List <Test.RemoteObjectAdapterPrx>();
                        adapters.Add(com.createObjectAdapter("Adapter81", "ssl"));
                        adapters.Add(com.createObjectAdapter("Adapter82", "tcp"));

                        var obj = createTestIntfPrx(adapters);
                        int i;
                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter82"));
                            obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                        }

                        var testSecure = obj.Clone(secure: true);
                        test(testSecure.IsSecure);
                        testSecure = obj.Clone(secure: false);
                        test(!testSecure.IsSecure);
                        testSecure = obj.Clone(secure: true);
                        test(testSecure.IsSecure);
                        test(obj.GetConnection() != testSecure.GetConnection());

                        com.deactivateObjectAdapter(adapters[1]);

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter81"));
                            obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                        }

                        com.createObjectAdapter("Adapter83", (obj.Endpoints[1]).ToString()); // Reactive tcp OA.

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter83"));
                            obj.GetConnection().close(ConnectionClose.GracefullyWithWait);
                        }

                        com.deactivateObjectAdapter(adapters[0]);
                        try
                        {
                            testSecure.IcePing();
                            test(false);
                        }
                        catch (ConnectFailedException)
                        {
                        }
                        catch (ConnectTimeoutException)
                        {
                        }

                        deactivate(com, adapters);
                    }
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing ipv4 & ipv6 connections... ");
                    output.Flush();

                    var ipv4 = new Dictionary <string, string>()
                    {
                        { "IPv4", "1" },
                        { "IPv6", "0" },
                        { "Adapter.Endpoints", "tcp -h localhost" }
                    };

                    var ipv6 = new Dictionary <string, string>()
                    {
                        { "IPv4", "0" },
                        { "IPv6", "1" },
                        { "Adapter.Endpoints", "tcp -h localhost" }
                    };

                    var bothPreferIPv4 = new Dictionary <string, string>()
                    {
                        { "IPv4", "1" },
                        { "IPv6", "1" },
                        { "PreferIPv6Address", "0" },
                        { "Adapter.Endpoints", "tcp -h localhost" }
                    };

                    var bothPreferIPv6 = new Dictionary <string, string>()
                    {
                        { "IPv4", "1" },
                        { "IPv6", "1" },
                        { "PreferIPv6Address", "1" },
                        { "Adapter.Endpoints", "tcp -h localhost" }
                    };

                    Dictionary <string, string>[] clientProps =
                    {
                        ipv4, ipv6, bothPreferIPv4, bothPreferIPv6
                    };

                    string endpoint = "tcp -p " + helper.getTestPort(2).ToString();

                    var anyipv4 = new Dictionary <string, string>(ipv4);
                    anyipv4["Adapter.Endpoints"]          = endpoint;
                    anyipv4["Adapter.PublishedEndpoints"] = $"{endpoint} -h 127.0.0.1";

                    var anyipv6 = new Dictionary <string, string>(ipv6);
                    anyipv6["Adapter.Endpoints"]          = endpoint;
                    anyipv6["Adapter.PublishedEndpoints"] = $"{endpoint} -h \".1\"";

                    var anyboth = new Dictionary <string, string>()
                    {
                        { "IPv4", "1" },
                        { "IPv6", "1" },
                        { "Adapter.Endpoints", endpoint },
                        { "Adapter.PublishedEndpoints", $"{endpoint} -h \"::1\":{endpoint} -h 127.0.0.1" }
                    };

                    var localipv4 = new Dictionary <string, string>(ipv4);
                    localipv4["Adapter.Endpoints"] = "tcp -h 127.0.0.1";

                    var localipv6 = new Dictionary <string, string>(ipv6);
                    localipv6["Adapter.Endpoints"] = "tcp -h \"::1\"";

                    Dictionary <string, string>[] serverProps =
                    {
                        anyipv4,
                        anyipv6,
                        anyboth,
                        localipv4,
                        localipv6
                    };

                    bool ipv6NotSupported = false;
                    foreach (var p in serverProps)
                    {
                        Communicator  serverCommunicator = new Communicator(p);
                        ObjectAdapter oa;
                        try
                        {
                            oa = serverCommunicator.createObjectAdapter("Adapter");
                            oa.Activate();
                        }
                        catch (DNSException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }
                        catch (SocketException)
                        {
                            if (p == ipv6)
                            {
                                ipv6NotSupported = true;
                            }
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        var prx = oa.CreateProxy("dummy");
                        try
                        {
                            prx.Clone(collocationOptimized: false).IcePing();
                        }
                        catch (LocalException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        string strPrx = prx.ToString();
                        foreach (var q in clientProps)
                        {
                            Communicator clientCommunicator = new Communicator(q);
                            prx = IObjectPrx.Parse(strPrx, clientCommunicator);
                            try
                            {
                                prx.IcePing();
                                test(false);
                            }
                            catch (ObjectNotExistException)
                            {
                                // Expected, no object registered.
                            }
                            catch (DNSException)
                            {
                                // Expected if no IPv4 or IPv6 address is
                                // associated to localhost or if trying to connect
                                // to an any endpoint with the wrong IP version,
                                // e.g.: resolving an IPv4 address when only IPv6
                                // is enabled fails with a DNS exception.
                            }
                            catch (SocketException)
                            {
                                test((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) ||
                                     (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) ||
                                     (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) ||
                                     (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) ||
                                     (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) ||
                                     (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) ||
                                     (p == bothPreferIPv6 && q == ipv6));
                            }
                            clientCommunicator.destroy();
                        }
                        serverCommunicator.destroy();
                    }

                    output.WriteLine("ok");
                }
                com.shutdown();
            }
Example #21
0
            public static void allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                string           @ref         = "communicator:" + helper.getTestEndpoint(0);

                Test.RemoteCommunicatorPrx com = Test.RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

                var rand   = new Random(unchecked ((int)DateTime.Now.Ticks));
                var output = helper.getWriter();

                output.Write("testing binding with single endpoint... ");
                output.Flush();
                {
                    Test.RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default");

                    var test1 = adapter.getTestIntf();
                    var test2 = adapter.getTestIntf();
                    test(test1.ice_getConnection() == test2.ice_getConnection());

                    test1.ice_ping();
                    test2.ice_ping();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1);
                    test(test3.ice_getConnection() == test1.ice_getConnection());
                    test(test3.ice_getConnection() == test2.ice_getConnection());

                    try
                    {
                        test3.ice_ping();
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter11", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter12", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("Adapter11");
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.ice_ping();
                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(test1.getAdapterName());
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_ping();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = t.getAdapterName();
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[0]);
                    names.Add("Adapter12");
                    names.Add("Adapter13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(test1.getAdapterName());
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple random endpoints... ");
                output.Flush();
                {
                    var adapters = new Test.RemoteObjectAdapterPrx[5];
                    adapters[0] = com.createObjectAdapter("AdapterRandom11", "default");
                    adapters[1] = com.createObjectAdapter("AdapterRandom12", "default");
                    adapters[2] = com.createObjectAdapter("AdapterRandom13", "default");
                    adapters[3] = com.createObjectAdapter("AdapterRandom14", "default");
                    adapters[4] = com.createObjectAdapter("AdapterRandom15", "default");

                    int count        = 20;
                    int adapterCount = adapters.Length;
                    while (--count > 0)
                    {
                        Test.TestIntfPrx[] proxies;
                        if (count == 1)
                        {
                            com.deactivateObjectAdapter(adapters[4]);
                            --adapterCount;
                        }
                        proxies = new Test.TestIntfPrx[10];

                        int i;
                        for (i = 0; i < proxies.Length; ++i)
                        {
                            var adpts = new Test.RemoteObjectAdapterPrx[rand.Next(adapters.Length)];
                            if (adpts.Length == 0)
                            {
                                adpts = new Test.RemoteObjectAdapterPrx[1];
                            }
                            for (int j = 0; j < adpts.Length; ++j)
                            {
                                adpts[j] = adapters[rand.Next(adapters.Length)];
                            }
                            proxies[i] = createTestIntfPrx(new List <Test.RemoteObjectAdapterPrx>(adpts));
                        }

                        for (i = 0; i < proxies.Length; i++)
                        {
                            proxies[i].begin_getAdapterName();
                        }
                        for (i = 0; i < proxies.Length; i++)
                        {
                            try
                            {
                                proxies[i].ice_ping();
                            }
                            catch (Ice.LocalException)
                            {
                            }
                        }

                        List <Ice.Connection> connections = new List <Ice.Connection>();
                        for (i = 0; i < proxies.Length; i++)
                        {
                            if (proxies[i].ice_getCachedConnection() != null)
                            {
                                if (!connections.Contains(proxies[i].ice_getCachedConnection()))
                                {
                                    connections.Add(proxies[i].ice_getCachedConnection());
                                }
                            }
                        }
                        test(connections.Count <= adapterCount);

                        foreach (var a in adapters)
                        {
                            try
                            {
                                a.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                            }
                            catch (Ice.LocalException)
                            {
                                // Expected if adapter is down.
                            }
                        }
                    }
                }
                output.WriteLine("ok");

                output.Write("testing binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI11", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI12", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI13", "default"));

                    //
                    // Ensure that when a connection is opened it's reused for new
                    // proxies and that all endpoints are eventually tried.
                    //
                    List <string> names = new List <string>();
                    names.Add("AdapterAMI11");
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);
                        test1.ice_ping();
                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Ensure that the proxy correctly caches the connection(we
                    // always send the request over the same connection.)
                    //
                    {
                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_ping();
                        }

                        var    t      = createTestIntfPrx(adapters);
                        string name   = getAdapterNameWithAMI(t);
                        int    nRetry = 10;
                        int    i;
                        for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++)
                        {
                            ;
                        }
                        test(i == nRetry);

                        foreach (var adpt in adapters)
                        {
                            adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapters.
                    //
                    com.deactivateObjectAdapter(adapters[0]);
                    names.Add("AdapterAMI12");
                    names.Add("AdapterAMI13");
                    while (names.Count > 0)
                    {
                        var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters);

                        var test1 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test2 = createTestIntfPrx(adpts);
                        shuffle(ref adpts);
                        var test3 = createTestIntfPrx(adpts);

                        test(test1.ice_getConnection() == test2.ice_getConnection());
                        test(test2.ice_getConnection() == test3.ice_getConnection());

                        names.Remove(getAdapterNameWithAMI(test1));
                        test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    //
                    // Deactivate an adapter and ensure that we can still
                    // establish the connection to the remaining adapter.
                    //
                    com.deactivateObjectAdapter(adapters[2]);
                    var obj = createTestIntfPrx(adapters);
                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing random endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter21", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter22", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter23", "default"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);

                    var names = new List <string>();
                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Random));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);

                    names.Add("Adapter21");
                    names.Add("Adapter22");
                    names.Add("Adapter23");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                        obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    }

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter31", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter32", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter33", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                    adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with single endpoint... ");
                output.Flush();
                {
                    var adapter = com.createObjectAdapter("Adapter41", "default");

                    var test1 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false));
                    var test2 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false));
                    test(!test1.ice_isConnectionCached());
                    test(!test2.ice_isConnectionCached());
                    test(test1.ice_getConnection() != null && test2.ice_getConnection() != null);
                    test(test1.ice_getConnection() == test2.ice_getConnection());

                    test1.ice_ping();

                    com.deactivateObjectAdapter(adapter);

                    var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1);
                    try
                    {
                        test(test3.ice_getConnection() == test1.ice_getConnection());
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter51", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter52", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter53", "default"));

                    var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());

                    List <string> names = new List <string>();
                    names.Add("Adapter51");
                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("Adapter52");
                    names.Add("Adapter53");
                    while (names.Count > 0)
                    {
                        names.Remove(obj.getAdapterName());
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(obj.getAdapterName().Equals("Adapter52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding with multiple endpoints and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI51", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI52", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI53", "default"));

                    var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());

                    var names = new List <string>();
                    names.Add("AdapterAMI51");
                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[0]);

                    names.Add("AdapterAMI52");
                    names.Add("AdapterAMI53");
                    while (names.Count > 0)
                    {
                        names.Remove(getAdapterNameWithAMI(obj));
                    }

                    com.deactivateObjectAdapter(adapters[2]);

                    test(getAdapterNameWithAMI(obj).Equals("AdapterAMI52"));

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter61", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter62", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing per request binding and ordered endpoint selection and AMI... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("AdapterAMI61", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI62", "default"));
                    adapters.Add(com.createObjectAdapter("AdapterAMI63", "default"));

                    var obj = createTestIntfPrx(adapters);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
                    test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
                    obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false));
                    test(!obj.ice_isConnectionCached());
                    int nRetry = 3;
                    int i;

                    //
                    // Ensure that endpoints are tried in order by deactiving the adapters
                    // one after the other.
                    //
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[0]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[1]);
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    com.deactivateObjectAdapter(adapters[2]);

                    try
                    {
                        obj.getAdapterName();
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                    catch (Ice.ConnectTimeoutException)
                    {
                    }

                    Ice.Endpoint[] endpoints = obj.ice_getEndpoints();

                    adapters.Clear();

                    //
                    // Now, re-activate the adapters with the same endpoints in the opposite
                    // order.
                    //
                    adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);
                    adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString()));
                    for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++)
                    {
                        ;
                    }
                    test(i == nRetry);

                    deactivate(com, adapters);
                }
                output.WriteLine("ok");

                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <Test.RemoteObjectAdapterPrx>();
                    adapters.Add(com.createObjectAdapter("Adapter71", "default"));
                    adapters.Add(com.createObjectAdapter("Adapter72", "udp"));

                    var obj = createTestIntfPrx(adapters);
                    test(obj.getAdapterName().Equals("Adapter71"));

                    var testUDP = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_datagram());
                    test(obj.ice_getConnection() != testUDP.ice_getConnection());
                    try
                    {
                        testUDP.getAdapterName();
                    }
                    catch (Ice.TwowayOnlyException)
                    {
                    }
                }
                output.WriteLine("ok");
                if (communicator.getProperties().getProperty("Ice.Plugin.IceSSL").Length > 0)
                {
                    output.Write("testing unsecure vs. secure endpoints... ");
                    output.Flush();
                    {
                        var adapters = new List <Test.RemoteObjectAdapterPrx>();
                        adapters.Add(com.createObjectAdapter("Adapter81", "ssl"));
                        adapters.Add(com.createObjectAdapter("Adapter82", "tcp"));

                        var obj = createTestIntfPrx(adapters);
                        int i;
                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter82"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        var testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true));
                        test(testSecure.ice_isSecure());
                        testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(false));
                        test(!testSecure.ice_isSecure());
                        testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true));
                        test(testSecure.ice_isSecure());
                        test(obj.ice_getConnection() != testSecure.ice_getConnection());

                        com.deactivateObjectAdapter(adapters[1]);

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter81"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        com.createObjectAdapter("Adapter83", (obj.ice_getEndpoints()[1]).ToString()); // Reactive tcp OA.

                        for (i = 0; i < 5; i++)
                        {
                            test(obj.getAdapterName().Equals("Adapter83"));
                            obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
                        }

                        com.deactivateObjectAdapter(adapters[0]);
                        try
                        {
                            testSecure.ice_ping();
                            test(false);
                        }
                        catch (Ice.ConnectFailedException)
                        {
                        }
                        catch (Ice.ConnectTimeoutException)
                        {
                        }

                        deactivate(com, adapters);
                    }
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing ipv4 & ipv6 connections... ");
                    output.Flush();

                    Ice.Properties ipv4 = Ice.Util.createProperties();
                    ipv4.setProperty("Ice.IPv4", "1");
                    ipv4.setProperty("Ice.IPv6", "0");
                    ipv4.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties ipv6 = Ice.Util.createProperties();
                    ipv6.setProperty("Ice.IPv4", "0");
                    ipv6.setProperty("Ice.IPv6", "1");
                    ipv6.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties bothPreferIPv4 = Ice.Util.createProperties();
                    bothPreferIPv4.setProperty("Ice.IPv4", "1");
                    bothPreferIPv4.setProperty("Ice.IPv6", "1");
                    bothPreferIPv4.setProperty("Ice.PreferIPv6Address", "0");
                    bothPreferIPv4.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    Ice.Properties bothPreferIPv6 = Ice.Util.createProperties();
                    bothPreferIPv6.setProperty("Ice.IPv4", "1");
                    bothPreferIPv6.setProperty("Ice.IPv6", "1");
                    bothPreferIPv6.setProperty("Ice.PreferIPv6Address", "1");
                    bothPreferIPv6.setProperty("Adapter.Endpoints", "tcp -h localhost");

                    List <Ice.Properties> clientProps = new List <Ice.Properties>();
                    clientProps.Add(ipv4);
                    clientProps.Add(ipv6);
                    clientProps.Add(bothPreferIPv4);
                    clientProps.Add(bothPreferIPv6);

                    string endpoint = "tcp -p " + helper.getTestPort(2).ToString();

                    Ice.Properties anyipv4 = ipv4.ice_clone_();
                    anyipv4.setProperty("Adapter.Endpoints", endpoint);
                    anyipv4.setProperty("Adapter.PublishedEndpoints", endpoint + " -h 127.0.0.1");

                    Ice.Properties anyipv6 = ipv6.ice_clone_();
                    anyipv6.setProperty("Adapter.Endpoints", endpoint);
                    anyipv6.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \".1\"");

                    Ice.Properties anyboth = Ice.Util.createProperties();
                    anyboth.setProperty("Ice.IPv4", "1");
                    anyboth.setProperty("Ice.IPv6", "1");
                    anyboth.setProperty("Adapter.Endpoints", endpoint);
                    anyboth.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \"::1\":" + endpoint + " -h 127.0.0.1");

                    Ice.Properties localipv4 = ipv4.ice_clone_();
                    localipv4.setProperty("Adapter.Endpoints", "tcp -h 127.0.0.1");

                    Ice.Properties localipv6 = ipv6.ice_clone_();
                    localipv6.setProperty("Adapter.Endpoints", "tcp -h \"::1\"");

                    List <Ice.Properties> serverProps = new List <Ice.Properties>(clientProps);
                    serverProps.Add(anyipv4);
                    serverProps.Add(anyipv6);
                    serverProps.Add(anyboth);
                    serverProps.Add(localipv4);
                    serverProps.Add(localipv6);

                    bool ipv6NotSupported = false;
                    foreach (Ice.Properties p in serverProps)
                    {
                        Ice.InitializationData serverInitData = new Ice.InitializationData();
                        serverInitData.properties = p;
                        Ice.Communicator  serverCommunicator = Ice.Util.initialize(serverInitData);
                        Ice.ObjectAdapter oa;
                        try
                        {
                            oa = serverCommunicator.createObjectAdapter("Adapter");
                            oa.activate();
                        }
                        catch (Ice.DNSException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }
                        catch (Ice.SocketException)
                        {
                            if (p == ipv6)
                            {
                                ipv6NotSupported = true;
                            }
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        Ice.ObjectPrx prx = oa.createProxy(Ice.Util.stringToIdentity("dummy"));
                        try
                        {
                            prx.ice_collocationOptimized(false).ice_ping();
                        }
                        catch (Ice.LocalException)
                        {
                            serverCommunicator.destroy();
                            continue; // IP version not supported.
                        }

                        string strPrx = prx.ToString();
                        foreach (Ice.Properties q in clientProps)
                        {
                            Ice.InitializationData clientInitData = new Ice.InitializationData();
                            clientInitData.properties = q;
                            Ice.Communicator clientCommunicator = Ice.Util.initialize(clientInitData);
                            prx = clientCommunicator.stringToProxy(strPrx);
                            try
                            {
                                prx.ice_ping();
                                test(false);
                            }
                            catch (Ice.ObjectNotExistException)
                            {
                                // Expected, no object registered.
                            }
                            catch (Ice.DNSException)
                            {
                                // Expected if no IPv4 or IPv6 address is
                                // associated to localhost or if trying to connect
                                // to an any endpoint with the wrong IP version,
                                // e.g.: resolving an IPv4 address when only IPv6
                                // is enabled fails with a DNS exception.
                            }
                            catch (Ice.SocketException)
                            {
                                test((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) ||
                                     (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) ||
                                     (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) ||
                                     (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) ||
                                     (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) ||
                                     (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) ||
                                     (p == bothPreferIPv6 && q == ipv6));
                            }
                            clientCommunicator.destroy();
                        }
                        serverCommunicator.destroy();
                    }

                    output.WriteLine("ok");
                }
                com.shutdown();
            }
Example #22
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    Thread.Sleep(3000); // Idle for 3 seconds

                    lock (this)
                    {
                        test(_heartbeat == 0);
                        test(!_closed);
                    }
                }
Example #23
0
            public static void testExceptions(Test.TestIntfPrx obj)
            {
                try
                {
                    obj.requestFailedException();
                    test(false);
                }
                catch (Ice.ObjectNotExistException ex)
                {
                    test(ex.id.Equals(obj.ice_getIdentity()));
                    test(ex.facet.Equals(obj.ice_getFacet()));
                    test(ex.operation.Equals("requestFailedException"));
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.unknownUserException();
                    test(false);
                }
                catch (Ice.UnknownUserException ex)
                {
                    test(ex.unknown.Equals("reason"));
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.unknownLocalException();
                    test(false);
                }
                catch (Ice.UnknownLocalException ex)
                {
                    test(ex.unknown.Equals("reason"));
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.unknownException();
                    test(false);
                }
                catch (Ice.UnknownException ex)
                {
                    test(ex.unknown.Equals("reason"));
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.userException();
                    test(false);
                }
                catch (Ice.UnknownUserException ex)
                {
                    //Console.Error.WriteLine(ex.unknown);
                    test(ex.unknown.IndexOf("Test::TestIntfUserException") >= 0);
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.localException();
                    test(false);
                }
                catch (Ice.UnknownLocalException ex)
                {
                    test(ex.unknown.IndexOf("Ice::SocketException") >= 0 ||
                         ex.unknown.IndexOf("Ice.SocketException") >= 0);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.csException();
                    test(false);
                }
                catch (Ice.UnknownException ex)
                {
                    test(ex.unknown.IndexOf("System.Exception") >= 0);
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.unknownExceptionWithServantException();
                    test(false);
                }
                catch (Ice.UnknownException ex)
                {
                    test(ex.unknown.Equals("reason"));
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.impossibleException(false);
                    test(false);
                }
                catch (Ice.UnknownUserException)
                {
                    // Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.impossibleException(true);
                    test(false);
                }
                catch (Ice.UnknownUserException)
                {
                    // Operation throws TestImpossibleException, but locate() and finished() throw TestIntfUserException.
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    obj.intfUserException(false);
                    test(false);
                }
                catch (Test.TestImpossibleException)
                {
                    // Operation doesn't throw, but locate() and finished() throw TestImpossibleException.
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    test(false);
                }

                try
                {
                    obj.intfUserException(true);
                    test(false);
                }
                catch (Test.TestImpossibleException)
                {
                    // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException.
                }
                catch (Exception)
                {
                    test(false);
                }
            }
Example #24
0
                public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
                {
                    //
                    // Put the adapter on hold. The server will not respond to
                    // the graceful close. This allows to test whether or not
                    // the close is graceful or forceful.
                    //
                    adapter.hold();
                    Thread.Sleep(5000); // Idle for 5 seconds

                    lock (this)
                    {
                        test(_heartbeat == 0);
                        test(!_closed); // Not closed yet because of graceful close.
                    }

                    adapter.activate();
                    waitForClosed();
                }
Example #25
0
 private static int run(string[] args, Ice.Communicator communicator)
 {
     Test.TestIntfPrx proxy = AllTests.allTests(communicator);
     proxy.shutdown();
     return(0);
 }
Example #26
0
 public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy)
 {
     adapter.hold();
     waitForClosed();
     lock (this)
     {
         test(_heartbeat == 0);
     }
 }