コード例 #1
0
ファイル: AllTests.cs プロジェクト: summer1988/ice
    public static Test.BackgroundPrx allTests(Ice.Communicator communicator)
    {
        string sref = "background:default -p 12010";

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

        BackgroundPrx background = BackgroundPrxHelper.uncheckedCast(obj);

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

        BackgroundControllerPrx backgroundController = BackgroundControllerPrxHelper.uncheckedCast(obj);

        Configuration configuration = Configuration.getInstance();

        Console.Write("testing connect... ");
        Console.Out.Flush();
        {
            connectTests(configuration, background);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing initialization... ");
        Console.Out.Flush();
        {
            initializeTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing connection validation... ");
        Console.Out.Flush();
        {
            validationTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing read/write... ");
        Console.Out.Flush();
        {
            readWriteTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing locator... ");
        Console.Out.Flush();
        {
            Ice.LocatorPrx locator;
            obj     = communicator.stringToProxy("locator:default -p 12010").ice_invocationTimeout(250);
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = communicator.stringToProxy("background@Test").ice_locator(locator).ice_oneway();

            backgroundController.pauseCall("findAdapterById");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("findAdapterById");

            obj     = communicator.stringToProxy("locator:default -p 12010");
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = obj.ice_locator(locator);
            obj.ice_ping();

            obj = communicator.stringToProxy("background@Test").ice_locator(locator);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);

            backgroundController.pauseCall("findAdapterById");
            Ice.AsyncResult r1 = bg.begin_op();
            Ice.AsyncResult r2 = bg.begin_op();
            test(!r1.IsCompleted);
            test(!r2.IsCompleted);
            backgroundController.resumeCall("findAdapterById");
            bg.end_op(r1);
            bg.end_op(r2);
            test(r1.IsCompleted);
            test(r2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing router... ");
        Console.Out.Flush();
        {
            Ice.RouterPrx router;

            obj    = communicator.stringToProxy("router:default -p 12010").ice_invocationTimeout(250);
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router).ice_oneway();

            backgroundController.pauseCall("getClientProxy");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("getClientProxy");

            obj    = communicator.stringToProxy("router:default -p 12010");
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);
            test(bg.ice_getRouter() != null);

            backgroundController.pauseCall("getClientProxy");
            Ice.AsyncResult r1 = bg.begin_op();
            Ice.AsyncResult r2 = bg.begin_op();
            test(!r1.IsCompleted);
            test(!r2.IsCompleted);
            backgroundController.resumeCall("getClientProxy");
            bg.end_op(r1);
            bg.end_op(r2);
            test(r1.IsCompleted);
            test(r2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        bool ws  = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("test-ws");
        bool wss = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("test-wss");

        if (!ws && !wss)
        {
            Console.Write("testing buffered transport... ");
            Console.Out.Flush();

            configuration.buffered(true);
            backgroundController.buffered(true);
            background.begin_op();
            background.ice_getCachedConnection().close(true);
            background.begin_op();

            OpAMICallback          cb      = new OpAMICallback();
            List <Ice.AsyncResult> results = new List <Ice.AsyncResult>();
            for (int i = 0; i < 10000; ++i)
            {
                Ice.AsyncResult r = background.begin_op().whenCompleted(cb.responseNoOp, cb.noException);
                results.Add(r);
                if (i % 50 == 0)
                {
                    backgroundController.holdAdapter();
                    backgroundController.resumeAdapter();
                }
                if (i % 100 == 0)
                {
                    r.waitForCompleted();
                }
            }
            foreach (Ice.AsyncResult r in results)
            {
                r.waitForCompleted();
            }
            Console.Out.WriteLine("ok");
        }

        return(background);
    }
コード例 #2
0
    private static void initializeTests(Configuration configuration, BackgroundPrx background,
                                        BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (LocalException)
        {
            test(false);
        }
        background.GetConnection().close(ConnectionClose.GracefullyWithWait);

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

            try
            {
                prx.op();
                test(false);
            }
            catch (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((Ice.Exception)ex.InnerException);
            }
            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 (ConnectionLostException)
        {
            ctl.initializeException(false);
        }
        catch (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 (LocalException)
            {
                test(false);
            }

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

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

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

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

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

        thread1.Join();
        thread2.Join();
    }
コード例 #3
0
ファイル: AllTests.cs プロジェクト: stick/zeroc-ice
    public static Test.BackgroundPrx allTests(Ice.Communicator communicator)
    {
        string sref = "background:default -p 12010";

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

        BackgroundPrx background = BackgroundPrxHelper.uncheckedCast(obj);

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

        BackgroundControllerPrx backgroundController = BackgroundControllerPrxHelper.uncheckedCast(obj);

        Configuration configuration = Configuration.getInstance();

        Console.Write("testing connect... ");
        Console.Out.Flush();
        {
            connectTests(configuration, background);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing initialization... ");
        Console.Out.Flush();
        {
            initializeTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing connection validation... ");
        Console.Out.Flush();
        {
            validationTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing read/write... ");
        Console.Out.Flush();
        {
            readWriteTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing locator... ");
        Console.Out.Flush();
        {
            Ice.LocatorPrx locator;
            obj     = communicator.stringToProxy("locator:default -p 12010 -t 500");
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = communicator.stringToProxy("background@Test").ice_locator(locator).ice_oneway();

            backgroundController.pauseCall("findAdapterById");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("findAdapterById");

            obj     = communicator.stringToProxy("locator:default -p 12010");
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = obj.ice_locator(locator);
            obj.ice_ping();

            obj = communicator.stringToProxy("background@Test").ice_locator(locator);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);

            backgroundController.pauseCall("findAdapterById");
            Ice.AsyncResult r1 = bg.begin_op();
            Ice.AsyncResult r2 = bg.begin_op();
            test(!r1.IsCompleted);
            test(!r2.IsCompleted);
            backgroundController.resumeCall("findAdapterById");
            bg.end_op(r1);
            bg.end_op(r2);
            test(r1.IsCompleted);
            test(r2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing router... ");
        Console.Out.Flush();
        {
            Ice.RouterPrx router;

            obj    = communicator.stringToProxy("router:default -p 12010 -t 500");
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router).ice_oneway();

            backgroundController.pauseCall("getClientProxy");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("getClientProxy");

            obj    = communicator.stringToProxy("router:default -p 12010");
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);
            test(bg.ice_getRouter() != null);

            backgroundController.pauseCall("getClientProxy");
            Ice.AsyncResult r1 = bg.begin_op();
            Ice.AsyncResult r2 = bg.begin_op();
            test(!r1.IsCompleted);
            test(!r2.IsCompleted);
            backgroundController.resumeCall("getClientProxy");
            bg.end_op(r1);
            bg.end_op(r2);
            test(r1.IsCompleted);
            test(r2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        return(background);
    }
コード例 #4
0
    public static Test.BackgroundPrx allTests(Test.TestHelper helper)
    {
        Communicator communicator = helper.communicator();
        var          background   = BackgroundPrx.Parse($"background:{helper.getTestEndpoint(0)}", communicator);

        var backgroundController = BackgroundControllerPrx.Parse("backgroundController:" + helper.getTestEndpoint(1, "tcp"), communicator);

        Configuration configuration = Configuration.getInstance();

        Console.Write("testing connect... ");
        Console.Out.Flush();
        {
            connectTests(configuration, background);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing initialization... ");
        Console.Out.Flush();
        {
            initializeTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing connection validation... ");
        Console.Out.Flush();
        {
            validationTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing read/write... ");
        Console.Out.Flush();
        {
            readWriteTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing locator... ");
        Console.Out.Flush();
        {
            var locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone(
                invocationTimeout: 250);
            var obj = IObjectPrx.Parse("background@Test", communicator).Clone(locator: locator, oneway: true);

            backgroundController.pauseCall("findAdapterById");
            try
            {
                obj.IcePing();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("findAdapterById");

            locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone(locator: locator);
            locator.IcePing();

            var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(locator: locator);

            backgroundController.pauseCall("findAdapterById");
            var t1 = bg.opAsync();
            var t2 = bg.opAsync();
            test(!t1.IsCompleted);
            test(!t2.IsCompleted);
            backgroundController.resumeCall("findAdapterById");
            t1.Wait();
            t2.Wait();
            test(t1.IsCompleted);
            test(t2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing router... ");
        Console.Out.Flush();
        {
            var router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator).Clone(
                invocationTimeout: 250);
            var obj = IObjectPrx.Parse("background@Test", communicator).Clone(router: router, oneway: true);

            backgroundController.pauseCall("getClientProxy");
            try
            {
                obj.IcePing();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("getClientProxy");

            router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator);
            var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(router: router);
            test(bg.Router != null);

            backgroundController.pauseCall("getClientProxy");
            var t1 = bg.opAsync();
            var t2 = bg.opAsync();
            test(!t1.IsCompleted);
            test(!t2.IsCompleted);
            backgroundController.resumeCall("getClientProxy");
            t1.Wait();
            t2.Wait();
            test(t1.IsCompleted);
            test(t2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        bool ws  = communicator.GetProperty("Ice.Default.Protocol") == "test-ws";
        bool wss = communicator.GetProperty("Ice.Default.Protocol") == "test-wss";

        if (!ws && !wss)
        {
            Console.Write("testing buffered transport... ");
            Console.Out.Flush();

            configuration.buffered(true);
            backgroundController.buffered(true);
            background.opAsync();
            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
            background.opAsync();

            OpAMICallback cb      = new OpAMICallback();
            var           results = new List <Task>();
            for (int i = 0; i < 10000; ++i)
            {
                var t = background.opAsync().ContinueWith((Task p) =>
                {
                    try
                    {
                        p.Wait();
                        cb.responseNoOp();
                    }
                    catch (Ice.Exception ex)
                    {
                        cb.noException(ex);
                    }
                });
                results.Add(t);
                if (i % 50 == 0)
                {
                    backgroundController.holdAdapter();
                    backgroundController.resumeAdapter();
                }
                if (i % 100 == 0)
                {
                    t.Wait();
                }
            }
            Task.WaitAll(results.ToArray());
            Console.Out.WriteLine("ok");
        }

        return(background);
    }
コード例 #5
0
ファイル: AllTests.cs プロジェクト: skyccn/ice
    public static Test.BackgroundPrx allTests(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        string           sref         = "background:" + helper.getTestEndpoint(0);

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

        BackgroundPrx background = BackgroundPrxHelper.uncheckedCast(obj);

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

        BackgroundControllerPrx backgroundController = BackgroundControllerPrxHelper.uncheckedCast(obj);

        Configuration configuration = Configuration.getInstance();

        Console.Write("testing connect... ");
        Console.Out.Flush();
        {
            connectTests(configuration, background);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing initialization... ");
        Console.Out.Flush();
        {
            initializeTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing connection validation... ");
        Console.Out.Flush();
        {
            validationTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing read/write... ");
        Console.Out.Flush();
        {
            readWriteTests(configuration, background, backgroundController);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing locator... ");
        Console.Out.Flush();
        {
            Ice.LocatorPrx locator;
            obj     = communicator.stringToProxy("locator:" + helper.getTestEndpoint(0)).ice_invocationTimeout(250);
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = communicator.stringToProxy("background@Test").ice_locator(locator).ice_oneway();

            backgroundController.pauseCall("findAdapterById");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("findAdapterById");

            obj     = communicator.stringToProxy("locator:" + helper.getTestEndpoint(0));
            locator = Ice.LocatorPrxHelper.uncheckedCast(obj);
            obj     = obj.ice_locator(locator);
            obj.ice_ping();

            obj = communicator.stringToProxy("background@Test").ice_locator(locator);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);

            backgroundController.pauseCall("findAdapterById");
            var t1 = bg.opAsync();
            var t2 = bg.opAsync();
            test(!t1.IsCompleted);
            test(!t2.IsCompleted);
            backgroundController.resumeCall("findAdapterById");
            t1.Wait();
            t2.Wait();
            test(t1.IsCompleted);
            test(t2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        Console.Write("testing router... ");
        Console.Out.Flush();
        {
            Ice.RouterPrx router;

            obj    = communicator.stringToProxy("router:" + helper.getTestEndpoint(0)).ice_invocationTimeout(250);
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router).ice_oneway();

            backgroundController.pauseCall("getClientProxy");
            try
            {
                obj.ice_ping();
                test(false);
            }
            catch (Ice.TimeoutException)
            {
            }
            backgroundController.resumeCall("getClientProxy");

            obj    = communicator.stringToProxy("router:" + helper.getTestEndpoint(0));
            router = Ice.RouterPrxHelper.uncheckedCast(obj);
            obj    = communicator.stringToProxy("background@Test").ice_router(router);
            BackgroundPrx bg = BackgroundPrxHelper.uncheckedCast(obj);
            test(bg.ice_getRouter() != null);

            backgroundController.pauseCall("getClientProxy");
            var t1 = bg.opAsync();
            var t2 = bg.opAsync();
            test(!t1.IsCompleted);
            test(!t2.IsCompleted);
            backgroundController.resumeCall("getClientProxy");
            t1.Wait();
            t2.Wait();
            test(t1.IsCompleted);
            test(t2.IsCompleted);
        }
        Console.Out.WriteLine("ok");

        bool ws  = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("test-ws");
        bool wss = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("test-wss");

        if (!ws && !wss)
        {
            Console.Write("testing buffered transport... ");
            Console.Out.Flush();

            configuration.buffered(true);
            backgroundController.buffered(true);
            background.opAsync();
            background.ice_getCachedConnection().close(Ice.ConnectionClose.Forcefully);
            background.opAsync();

            OpAMICallback cb      = new OpAMICallback();
            var           results = new List <Task>();
            for (int i = 0; i < 10000; ++i)
            {
                var t = background.opAsync().ContinueWith((Task p) => {
                    try
                    {
                        p.Wait();
                        cb.responseNoOp();
                    }
                    catch (Ice.Exception ex)
                    {
                        cb.noException(ex);
                    }
                });
                results.Add(t);
                if (i % 50 == 0)
                {
                    backgroundController.holdAdapter();
                    backgroundController.resumeAdapter();
                }
                if (i % 100 == 0)
                {
                    t.Wait();
                }
            }
            Task.WaitAll(results.ToArray());
            Console.Out.WriteLine("ok");
        }

        return(background);
    }