Example #1
0
    private static void initializeTests(Configuration configuration, Test.BackgroundPrx background,
                                        Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        background.ice_getConnection().close(false);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.initializeException(new Ice.SocketException());
            }
            else
            {
                continue;
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : (BackgroundPrx)background.ice_oneway();

            try
            {
                prx.op();
                test(false);
            }
            catch (Ice.SocketException)
            {
            }

            Ice.AsyncResult r = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.Exception)
            {
            }
            test(r.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            r = prx.begin_op().whenCompleted(cbEx.exception);
            test(!r.sentSynchronously());
            cbEx.checkException(true);
            test(r.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.initializeException(null);
            }
        }

        //
        // Now run the same tests with the server side.
        //

        try
        {
            ctl.initializeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.initializeException(false);
        }
        catch (Ice.SecurityException)
        {
            ctl.initializeException(false);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            configuration.initializeException(new Ice.SocketException());
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);
            configuration.initializeException(null);
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            background.ice_getCachedConnection().close(true);
            background.ice_ping();

            ctl.initializeException(true);
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);
            ctl.initializeException(false);
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            try
            {
                background.ice_getCachedConnection().close(true);
                background.op();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Example #2
0
    private static void initializeTests(Configuration configuration, Test.BackgroundPrx background,
                                        Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        background.GetConnection().close(Ice.ConnectionClose.GracefullyWithWait);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.initializeException(new Ice.SocketException());
            }
            else
            {
                continue;
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : background.Clone(oneway: true);

            try
            {
                prx.op();
                test(false);
            }
            catch (Ice.SocketException)
            {
            }

            bool sentSynchronously = false;
            var  t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
            {
            }
            test(t.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = false;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
            }
            catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
            {
                cbEx.exception(ex.InnerException as Ice.Exception);
            }
            cbEx.checkException(true);
            test(t.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.initializeException(null);
            }
        }

        //
        // Now run the same tests with the server side.
        //

        try
        {
            ctl.initializeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.initializeException(false);
        }
        catch (Ice.SecurityException)
        {
            ctl.initializeException(false);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.IcePing();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            configuration.initializeException(new Ice.SocketException());
            background.GetCachedConnection().close(Ice.ConnectionClose.Forcefully);
            Thread.Sleep(10);
            configuration.initializeException(null);
            try
            {
                background.IcePing();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.IcePing();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            background.GetCachedConnection().close(Ice.ConnectionClose.Forcefully);
            background.IcePing();

            ctl.initializeException(true);
            background.GetCachedConnection().close(Ice.ConnectionClose.Forcefully);
            Thread.Sleep(10);
            ctl.initializeException(false);
            try
            {
                background.IcePing();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.IcePing();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            try
            {
                background.GetCachedConnection().close(Ice.ConnectionClose.Forcefully);
                background.op();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }