Пример #1
0
            public override void run(string[] args)
            {
                using (var communicator = initialize(ref args))
                {
                    //
                    // Create OA and servants
                    //
                    communicator.SetProperty("MyOA.AdapterId", "myOA");

                    Ice.ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA2", "tcp -h localhost");

                    var interceptor = new InterceptorI <MyObject, MyObjectTraits>(new MyObjectI());

                    var prx = IMyObjectPrx.UncheckedCast(oa.Add((incoming, current) => interceptor.Dispatch(incoming, current)));

                    var output = getWriter();

                    output.WriteLine("Collocation optimization on");
                    runTest(prx, interceptor);
                    output.WriteLine("Now with AMD");
                    interceptor.clear();
                    runAmdTest(prx, interceptor);

                    oa.Activate(); // Only necessary for non-collocation optimized tests

                    output.WriteLine("Collocation optimization off");
                    interceptor.clear();
                    prx = prx.Clone(collocationOptimized: false);
                    runTest(prx, interceptor);

                    output.WriteLine("Now with AMD");
                    interceptor.clear();
                    runAmdTest(prx, interceptor);
                }
            }
Пример #2
0
            allTests(global::Test.TestHelper helper)
            {
                var           output       = helper.getWriter();
                Communicator  communicator = helper.communicator();
                ObjectAdapter oa           = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");

                oa.Activate();

                var  servantI = new MyObjectI();
                var  servantT = default(MyObjectTraits);
                Disp servantD = (incoming, current) => servantT.Dispatch(servantI, incoming, current);

                //
                // Register default servant with category "foo"
                //
                oa.AddDefaultServant(servantD, "foo");

                //
                // Start test
                //
                output.Write("testing single category... ");
                output.Flush();

                Disp r = oa.FindDefaultServant("foo");

                test(r == servantD);

                r = oa.FindDefaultServant("bar");
                test(r == null);

                Ice.Identity identity = new Ice.Identity();
                identity.category = "foo";

                string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" };

                IMyObjectPrx prx = null;

                for (int idx = 0; idx < 5; ++idx)
                {
                    identity.name = names[idx];
                    prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                    prx.IcePing();
                    test(prx.getName() == names[idx]);
                }

                identity.name = "ObjectNotExist";
                prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                    test(false);
                }
                catch (ObjectNotExistException)
                {
                    // Expected
                }

                try
                {
                    prx.getName();
                    test(false);
                }
                catch (ObjectNotExistException)
                {
                    // Expected
                }

                identity.name = "FacetNotExist";
                prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                    test(false);
                }
                catch (FacetNotExistException)
                {
                    // Expected
                }

                try
                {
                    prx.getName();
                    test(false);
                }
                catch (FacetNotExistException)
                {
                    // Expected
                }

                identity.category = "bar";
                for (int idx = 0; idx < 5; idx++)
                {
                    identity.name = names[idx];
                    prx           = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));

                    try
                    {
                        prx.IcePing();
                        test(false);
                    }
                    catch (Ice.ObjectNotExistException)
                    {
                        // Expected
                    }

                    try
                    {
                        prx.getName();
                        test(false);
                    }
                    catch (Ice.ObjectNotExistException)
                    {
                        // Expected
                    }
                }

                oa.RemoveDefaultServant("foo");
                identity.category = "foo";
                prx = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                }
                catch (Ice.ObjectNotExistException)
                {
                    // Expected
                }

                output.WriteLine("ok");

                output.Write("testing default category... ");
                output.Flush();

                oa.AddDefaultServant(servantD, "");

                r = oa.FindDefaultServant("bar");
                test(r == null);

                r = oa.FindDefaultServant("");
                test(r == servantD);

                for (int idx = 0; idx < 5; ++idx)
                {
                    identity.name = names[idx];
                    prx           = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                    prx.IcePing();
                    test(prx.getName() == names[idx]);
                }

                output.WriteLine("ok");
            }