예제 #1
0
        public static void Main(string[] args)
        {
            nick = "SecureIRC";
            owner = "SecureIRC";
            server = "irc.entalyan.com";
            port = 6999;
            chan = "#SecureIRC";
            pass = ""; //Enter just the password

            //Connect to irc server and get input and output text streams from TcpClient.
            sock.Connect(server, port);
            if (!sock.Connected)
            {
                Console.WriteLine("Failed to connect!");
                return;
            }
            input = new System.IO.StreamReader(sock.GetStream());
            output = new System.IO.StreamWriter(sock.GetStream());

            //Starting USER and NICK login commands 
            output.Write(
                "PASS " + nick + ":" + pass + "\r\n" +
                "USER " + nick + " 0 * :" + owner + "\r\n" +
                "NICK " + nick + "\r\n" +
                "PRIVMSG #SecureIRC Successful login at: " + DateTime.Now.ToString() + "\r\n"
            );
            output.Flush();

            Listen();

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();

        }
예제 #2
0
 internal static void WriteStackTrace(Exception throwable, System.IO.TextWriter stream)
 {
     stream.WriteLine(throwable);
     stream.Write(throwable.StackTrace);
     stream.Flush();
 }
예제 #3
0
파일: SupportClass.cs 프로젝트: rejc2/utils
 /*******************************/
 public static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter stream)
 {
     stream.Write(throwable.StackTrace);
     stream.Flush();
 }
 protected virtual void Ack()
 {
     @out.WriteLine("ack");
     @out.Flush();
 }
예제 #5
0
        private void runAmdAssert(IMyObjectPrx prx, Interceptor interceptor)
        {
            System.IO.TextWriter output = GetWriter();
            output.Write("testing simple interceptor... ");
            output.Flush();
            Assert(interceptor.getLastOperation() == null);
            Assert(!interceptor.AsyncCompletion);
            Assert(prx.amdAdd(33, 12) == 45);
            Assert(interceptor.getLastOperation() !.Equals("amdAdd"));
            Assert(interceptor.AsyncCompletion);
            output.WriteLine("ok");

            output.Write("testing retry... ");
            output.Flush();
            Assert(prx.amdAddWithRetry(33, 12) == 45);
            Assert(interceptor.getLastOperation() !.Equals("amdAddWithRetry"));
            Assert(interceptor.AsyncCompletion);

            {
                var ctx = new Dictionary <string, string>
                {
                    { "retry", "yes" }
                };
                for (int i = 0; i < 10; ++i)
                {
                    Assert(prx.amdAdd(33, 12, ctx) == 45);
                    Assert(interceptor.getLastOperation() !.Equals("amdAdd"));
                    Assert(interceptor.AsyncCompletion);
                }
            }

            output.WriteLine("ok");

            output.Write("testing user exception... ");
            try
            {
                prx.amdBadAdd(33, 12);
                Assert(false);
            }
            catch (InvalidInputException)
            {
                // expected
            }
            Assert(interceptor.getLastOperation() !.Equals("amdBadAdd"));
            Assert(interceptor.AsyncCompletion);
            Console.WriteLine("ok");

            output.Write("testing ONE... ");
            output.Flush();
            interceptor.clear();
            try
            {
                prx.amdNotExistAdd(33, 12);
                Assert(false);
            }
            catch (ObjectNotExistException)
            {
                // expected
            }
            Assert(interceptor.getLastOperation() !.Equals("amdNotExistAdd"));
            Assert(interceptor.AsyncCompletion);
            output.WriteLine("ok");

            output.Write("testing exceptions raised by the interceptor... ");
            output.Flush();
            TestInterceptorExceptions(prx);
            output.WriteLine("ok");
        }
예제 #6
0
        public string GenerateToFile()
        {
            string exportFileName = string.Empty;

            if (writer == null)
            {
                exportFileName = System.IO.Path.GetTempFileName();
                writer         = System.IO.File.CreateText(exportFileName);
            }

            //OR orFunctionID = null;
            //foreach (ESystemFunction function in SelectedFunctionList)
            //{
            //    if (orFunctionID == null)
            //        orFunctionID = new OR();
            //    orFunctionID.add(new Match("FunctionID", function.FunctionID));
            //}
            //OR orUserID = null;
            //foreach (EUser selectedUser in SelectedUserList)
            //{
            //    if (orUserID == null)
            //        orUserID = new OR();
            //    orUserID.add(new Match("UserID", selectedUser.UserID));
            //}
            DBFilter filter = new DBFilter();

            if (!PeriodFrom.Ticks.Equals(0))
            {
                filter.add(new Match("CreateDate", ">=", PeriodFrom));
            }
            if (!PeriodTo.Ticks.Equals(0))
            {
                filter.add(new Match("CreateDate", "<", PeriodTo.AddDays(1)));
            }

            //if (orFunctionID != null)
            //    filter.add(orFunctionID);

            //if (orUserID != null)
            //    filter.add(orUserID);

            if (!string.IsNullOrEmpty(SelectedFunctionList))
            {
                filter.add(new IN("FunctionID", SelectedFunctionList, null));
            }

            if (!string.IsNullOrEmpty(SelectedUserList))
            {
                filter.add(new IN("UserID", SelectedUserList, null));
            }

            if (!IsShowWithoutDataUpdate)
            {
                filter.add(new IN("AuditTrailID", "select distinct AuditTrailID from " + EAuditTrailDetail.db.dbclass.tableName, new DBFilter()));
            }
            //if (!string.IsNullOrEmpty(EmpNo.Text))
            //{
            //    OR orEmpNoTerm = new OR();

            //    DBFilter empNoFilter = new DBFilter();
            //    empNoFilter.add(new Match("e.EmpNo"," like ","%"+EmpNo.Text.Trim() +"%"));
            //    orEmpNoTerm.add(new IN("EmpID", "Select EmpID from " + EEmpPersonalInfo.db.dbclass.tableName + " e ", empNoFilter));
            //    //orEmpNoTerm.add(new Match("EmpID", 0));
            //    filter.add(orEmpNoTerm);
            //}
            filter.add("CreateDate", true);

            ArrayList auditTrailList = EAuditTrail.db.select(dbConn, filter);


            try
            {
                foreach (EAuditTrail auditTrail in auditTrailList)
                {
                    if (IsClosed)
                    {
                        break;
                    }
                    string logText = auditTrail.GetLogText(dbConn, EmpNo, IsShowHeaderOnly, IsShowKeyIDOnly, IsDoNotConvertID);

                    if (!string.IsNullOrEmpty(logText))
                    {
                        writer.WriteLine(logText);
                    }

                    writer.Flush();
                    if (Updated != null)
                    {
                        Updated(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            writer.Close();
            return(exportFileName);
        }
예제 #7
0
파일: AllTests.cs 프로젝트: cyyever/ice
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            bool ice1    = helper.Protocol == Protocol.Ice1;
            var  manager = IServerManagerPrx.Parse(helper.GetTestProxy("ServerManager", 0), communicator);
            var  locator = communicator.DefaultLocator !.Clone(ITestLocatorPrx.Factory);

            var registry = locator.GetRegistry() !.Clone(ITestLocatorRegistryPrx.Factory);

            TestHelper.Assert(registry != null);

            System.IO.TextWriter output = helper.Output;
            output.Write("testing ice1 string/URI parsing... ");
            output.Flush();
            IObjectPrx base1, base2, base3, base4, base5, base6, base7;

            if (ice1)
            {
                base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
                base2 = IObjectPrx.Parse("test @ TestAdapter", communicator);
                base3 = IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator);
                base4 = IObjectPrx.Parse("ServerManager", communicator);
                base5 = IObjectPrx.Parse("test2", communicator);
                base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator);
                base7 = IObjectPrx.Parse("test3 -f facet", communicator);
            }
            else
            {
                base1 = IObjectPrx.Parse("ice:TestAdapter//test", communicator);
                base2 = IObjectPrx.Parse("ice:TestAdapter//test", communicator);
                base3 = IObjectPrx.Parse("ice:test", communicator);
                base4 = IObjectPrx.Parse("ice:ServerManager", communicator);
                base5 = IObjectPrx.Parse("ice:test2", communicator);
                base6 = IObjectPrx.Parse("ice:ReplicatedAdapter//test", communicator);
                base7 = IObjectPrx.Parse("ice:test3#facet", communicator);
            }
            output.WriteLine("ok");

            output.Write("testing ice_locator and ice_getLocator... ");
            TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !));
            var anotherLocator =
                ILocatorPrx.Parse(ice1 ? "anotherLocator" : "ice:anotherLocator", communicator);

            base1 = base1.Clone(locator: anotherLocator);
            TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator));
            communicator.DefaultLocator = null;
            base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator);
            TestHelper.Assert(base1.Locator == null);
            base1 = base1.Clone(locator: anotherLocator);
            TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator));
            communicator.DefaultLocator = locator;
            base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator);
            TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !));

            if (ice1)
            {
                // TODO: We also test ice_router/ice_getRouter(perhaps we should add a test/Ice/router test?)
                TestHelper.Assert(base1.Router == null);
                var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator);
                base1 = base1.Clone(router: anotherRouter);
                TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter));
                var router = IRouterPrx.Parse("dummyrouter", communicator);
                communicator.DefaultRouter = router;
                base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
                TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !));
                communicator.DefaultRouter = null;
                base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
                TestHelper.Assert(base1.Router == null);
            }

            output.WriteLine("ok");

            output.Write("starting server... ");
            output.Flush();
            manager.StartServer();
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            var obj1 = base1.CheckedCast(ITestIntfPrx.Factory);

            TestHelper.Assert(obj1 != null);
            var obj2 = base2.CheckedCast(ITestIntfPrx.Factory);

            TestHelper.Assert(obj2 != null);
            var obj3 = base3.CheckedCast(ITestIntfPrx.Factory);

            TestHelper.Assert(obj3 != null);
            var obj4 = base4.CheckedCast(IServerManagerPrx.Factory);

            TestHelper.Assert(obj4 != null);
            var obj5 = base5.CheckedCast(ITestIntfPrx.Factory);

            TestHelper.Assert(obj5 != null);
            var obj6 = base6.CheckedCast(ITestIntfPrx.Factory);

            TestHelper.Assert(obj6 != null);
            output.WriteLine("ok");

            output.Write("testing AdapterId//id indirect proxy... ");
            output.Flush();
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj2.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing ReplicaGroupId//id indirect proxy... ");
            output.Flush();
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj6.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing identity indirect proxy... ");
            output.Flush();
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj3.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            try
            {
                obj2.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj2.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            try
            {
                obj3.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj2.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj3.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            obj1.Shutdown();
            manager.StartServer();
            try
            {
                obj5 = base5.CheckedCast(ITestIntfPrx.Factory);
                TestHelper.Assert(obj5 != null);
                obj5.IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing proxy with unknown identity... ");
            output.Flush();
            try
            {
                base1 = IObjectPrx.Parse(ice1 ? "unknown/unknown" : "ice:unknown/unknown", communicator);
                base1.IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing proxy with unknown adapter... ");
            output.Flush();
            try
            {
                base1 = IObjectPrx.Parse(
                    ice1 ? "test @ TestAdapterUnknown" : "ice:TestAdapterUnknown//test", communicator);
                base1.IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing locator cache timeout... ");
            output.Flush();

            IObjectPrx basencc = IObjectPrx.Parse(
                ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(cacheConnection: false);
            int count = locator.GetRequestCount();

            basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing();           // No locator cache.
            TestHelper.Assert(++count == locator.GetRequestCount());
            basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing();           // No locator cache.
            TestHelper.Assert(++count == locator.GetRequestCount());
            basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout.
            TestHelper.Assert(count == locator.GetRequestCount());
            Thread.Sleep(1300);                                                    // 1300ms
            basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout.
            TestHelper.Assert(++count == locator.GetRequestCount());

            IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator)
            .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing();     // No locator cache.
            count += 2;
            TestHelper.Assert(count == locator.GetRequestCount());
            IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator)
            .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout
            TestHelper.Assert(count == locator.GetRequestCount());
            System.Threading.Thread.Sleep(1300);                            // 1300ms
            IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator)
            .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout
            count += 2;
            TestHelper.Assert(count == locator.GetRequestCount());

            IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator)
            .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing();
            TestHelper.Assert(count == locator.GetRequestCount());
            IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing();
            TestHelper.Assert(count == locator.GetRequestCount());
            IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).IcePing();
            TestHelper.Assert(count == locator.GetRequestCount());
            IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).IcePing();
            TestHelper.Assert(count == locator.GetRequestCount());

            TestHelper.Assert(IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator)
                              .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99));

            output.WriteLine("ok");

            output.Write("testing proxy from server... ");
            output.Flush();
            obj1 = ITestIntfPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator);
            IHelloPrx?hello = obj1.GetHello();

            TestHelper.Assert(hello != null);
            TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "TestAdapter");
            hello.SayHello();
            hello = obj1.GetReplicatedHello();
            TestHelper.Assert(hello != null);
            TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "ReplicatedAdapter");
            hello.SayHello();
            output.WriteLine("ok");

            output.Write("testing well-known proxy with facet... ");
            output.Flush();
            hello = IHelloPrx.Parse(ice1 ? "bonjour -f abc" : "ice:bonjour#abc", communicator);
            hello.SayHello();
            hello = IHelloPrx.Parse(ice1 ? "hello -f abc" : "ice:hello#abc", communicator);
            try
            {
                hello.SayHello();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException) // hello does not have an abc facet
            {
            }
            output.WriteLine("ok");

            output.Write("testing locator request queuing... ");
            output.Flush();
            hello = obj1.GetReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false);
            TestHelper.Assert(hello != null);
            count = locator.GetRequestCount();
            hello.IcePing();
            TestHelper.Assert(++count == locator.GetRequestCount());
            var results = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                results.Add(hello.SayHelloAsync());
            }
            Task.WaitAll(results.ToArray());
            results.Clear();
            if (locator.GetRequestCount() > count + 800)
            {
                output.Write("queuing = " + (locator.GetRequestCount() - count));
            }
            TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 999);
            count = locator.GetRequestCount();
            hello = hello.Clone(location: ImmutableArray.Create("unknown"));
            for (int i = 0; i < 1000; i++)
            {
                results.Add(hello.SayHelloAsync().ContinueWith(
                                t =>
                {
                    try
                    {
                        t.Wait();
                    }
                    catch (AggregateException ex) when(ex.InnerException is NoEndpointException)
                    {
                    }
                },
                                TaskScheduler.Default));
            }
            Task.WaitAll(results.ToArray());
            results.Clear();
            // XXX:
            // Take into account the retries.
            TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 1999);
            if (locator.GetRequestCount() > count + 800)
            {
                output.Write("queuing = " + (locator.GetRequestCount() - count));
            }
            output.WriteLine("ok");

            output.Write("testing adapter locator cache... ");
            output.Flush();
            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }

            RegisterAdapterEndpoints(
                registry,
                "TestAdapter3",
                replicaGroupId: "",
                ResolveLocation(locator, "TestAdapter") !);

            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing();

                RegisterAdapterEndpoints(
                    registry,
                    "TestAdapter3",
                    replicaGroupId: "",
                    IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator));

                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).Clone(
                    locatorCacheTimeout: TimeSpan.Zero).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }

            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing();
            }
            catch (ConnectionRefusedException)
            {
            }

            RegisterAdapterEndpoints(
                registry,
                "TestAdapter3",
                "",
                ResolveLocation(locator, "TestAdapter") !);
            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing well-known object locator cache... ");
            output.Flush();
            registry.AddObject(IObjectPrx.Parse(
                                   ice1 ? "test3@TestUnknown" : "ice:TestUnknown//test3", communicator));
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            registry.AddObject(IObjectPrx.Parse(
                                   ice1 ? "test3@TestAdapter4" : "ice:TestAdapter4//test3", communicator)); // Update
            RegisterAdapterEndpoints(
                registry,
                "TestAdapter4",
                "",
                IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator));
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            RegisterAdapterEndpoints(
                registry,
                "TestAdapter4",
                "",
                ResolveLocation(locator, "TestAdapter") !);
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            RegisterAdapterEndpoints(
                registry,
                "TestAdapter4",
                "",
                IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator));
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).Clone(
                    locatorCacheTimeout: TimeSpan.Zero).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            try
            {
                IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            registry.AddObject(IObjectPrx.Parse(
                                   ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator));
            try
            {
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            registry.AddObject(IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator));
            try
            {
                IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing locator cache background updates... ");
            output.Flush();
            {
                Dictionary <string, string> properties = communicator.GetProperties();
                properties["Ice.BackgroundLocatorCacheUpdates"] = "1";
                using Communicator ic = helper.Initialize(properties);

                RegisterAdapterEndpoints(
                    registry,
                    "TestAdapter5",
                    "",
                    ResolveLocation(locator, "TestAdapter") !);
                registry.AddObject(IObjectPrx.Parse(
                                       ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator));

                count = locator.GetRequestCount();
                IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic)
                .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing();                                                   // No locator cache.
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache.
                count += 3;
                TestHelper.Assert(count == locator.GetRequestCount());
                UnregisterAdapterEndpoints(registry, "TestAdapter5", "");
                registry.AddObject(IObjectPrx.Parse(helper.GetTestProxy("test3", 99), communicator));
                IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic)
                .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing();     // 10s timeout.
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic)
                .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing();     // 10s timeout.
                TestHelper.Assert(count == locator.GetRequestCount());
                Thread.Sleep(1200);

                // The following request should trigger the background
                // updates but still use the cached endpoints and
                // therefore succeed.
                IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic)
                .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing();     // 1s timeout.
                IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic)
                .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing();     // 1s timeout.

                try
                {
                    while (true)
                    {
                        IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic)
                        .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing();     // 1s timeout.
                        Thread.Sleep(10);
                    }
                }
                catch
                {
                    // Expected to fail once they endpoints have been updated in the background.
                }
                try
                {
                    while (true)
                    {
                        IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic)
                        .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing();     // 1s timeout.
                        Thread.Sleep(10);
                    }
                }
                catch
                {
                    // Expected to fail once they endpoints have been updated in the background.
                }
            }
            output.WriteLine("ok");

            output.Write("testing proxy from server after shutdown... ");
            output.Flush();
            hello = obj1.GetReplicatedHello();
            TestHelper.Assert(hello != null);
            obj1.Shutdown();
            manager.StartServer();
            hello.SayHello();
            output.WriteLine("ok");

            // TODO: this does not work with ice2 because we currently don't retry on any remote exception, including
            // ONE.
            if (ice1)
            {
                output.Write("testing object migration... ");
                output.Flush();
                hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator);
                obj1.MigrateHello();
                hello.GetConnection().GoAwayAsync();
                hello.SayHello();
                obj1.MigrateHello();
                hello.SayHello();
                obj1.MigrateHello();
                hello.SayHello();
                output.WriteLine("ok");
            }

            output.Write("shutdown server... ");
            output.Flush();
            obj1.Shutdown();
            output.WriteLine("ok");

            output.Write("testing whether server is gone... ");
            output.Flush();
            try
            {
                obj2.IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            try
            {
                obj3.IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            try
            {
                TestHelper.Assert(obj5 != null);
                obj5.IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing indirect proxies to colocated objects... ");
            output.Flush();

            communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString());
            ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints(helper.GetTestEndpoint(ephemeral: true));

            var id = new Identity(Guid.NewGuid().ToString(), "");

            adapter.Add(id, new Hello());
            adapter.Activate();

            // Ensure that calls on the well-known proxy is collocated.
            IHelloPrx?helloPrx;

            if (ice1)
            {
                helloPrx = IHelloPrx.Parse($"{id}", communicator);
            }
            else
            {
                helloPrx = IHelloPrx.Parse($"ice:{id}", communicator);
            }
            TestHelper.Assert(helloPrx.GetConnection() is ColocatedConnection);

            // Ensure that calls on the indirect proxy (with adapter ID) is colocated
            helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory);
            TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() is ColocatedConnection);

            // Ensure that calls on the direct proxy is colocated
            helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).Clone(
                endpoints: adapter.PublishedEndpoints,
                location: ImmutableArray <string> .Empty).CheckedCast(IHelloPrx.Factory);
            TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() is ColocatedConnection);

            output.WriteLine("ok");

            output.Write("shutdown server manager... ");
            output.Flush();
            manager.Shutdown();
            output.WriteLine("ok");
        }
예제 #8
0
파일: AllTests.cs 프로젝트: mreinart/ice
        public static async Task RunAsync(TestHelper helper)
        {
            Communicator communicator = helper.Communicator;

            var proxy = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator);

            System.IO.TextWriter output = helper.Output;

            output.Write("testing enum values... ");
            output.Flush();

            TestHelper.Assert((int)ByteEnum.benum1 == 0);
            TestHelper.Assert((int)ByteEnum.benum2 == 1);
            TestHelper.Assert((int)ByteEnum.benum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ByteEnum.benum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ByteEnum.benum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum7 == Constants.IntConst1);
            TestHelper.Assert((int)ByteEnum.benum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum9 == Constants.LongConst1);
            TestHelper.Assert((int)ByteEnum.benum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum11 == Constants.ByteConst2);

            TestHelper.Assert((int)ShortEnum.senum1 == 3);
            TestHelper.Assert((int)ShortEnum.senum2 == 4);
            TestHelper.Assert((int)ShortEnum.senum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ShortEnum.senum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ShortEnum.senum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum7 == Constants.IntConst1);
            TestHelper.Assert((int)ShortEnum.senum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum9 == Constants.LongConst1);
            TestHelper.Assert((int)ShortEnum.senum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum11 == Constants.ShortConst2);

            TestHelper.Assert((int)IntEnum.ienum1 == 0);
            TestHelper.Assert((int)IntEnum.ienum2 == 1);
            TestHelper.Assert((int)IntEnum.ienum3 == Constants.ByteConst1);
            TestHelper.Assert((int)IntEnum.ienum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum5 == Constants.ShortConst1);
            TestHelper.Assert((int)IntEnum.ienum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum7 == Constants.IntConst1);
            TestHelper.Assert((int)IntEnum.ienum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum9 == Constants.LongConst1);
            TestHelper.Assert((int)IntEnum.ienum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum11 == Constants.IntConst2);
            TestHelper.Assert((int)IntEnum.ienum12 == Constants.LongConst2);

            TestHelper.Assert((int)SimpleEnum.red == 0);
            TestHelper.Assert((int)SimpleEnum.green == 1);
            TestHelper.Assert((int)SimpleEnum.blue == 2);

            output.WriteLine("ok");

            output.Write("testing enum operations... ");
            output.Flush();
            {
                (ByteEnum r, ByteEnum o) = proxy.OpByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
            }

            {
                // 42 does not correspond to a ByteEnum enumerator, so we expect failure since ByteEnum is checked.
                try
                {
                    _ = proxy.OpByte((ByteEnum)42);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException) // unhandled dispatch exception
                {
                    // expected
                }
            }

            {
                (ByteEnum? r, ByteEnum? o) = proxy.OpTaggedByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpTaggedByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
                (r, o) = proxy.OpTaggedByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                try
                {
                    _ = proxy.OpTaggedByte((ByteEnum)42);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException) // unhandled dispatch exception
                {
                    // expected
                }
            }

            {
                (ShortEnum r, ShortEnum o) = proxy.OpShort(ShortEnum.senum1);
                TestHelper.Assert(r == ShortEnum.senum1 && o == ShortEnum.senum1);
                (r, o) = proxy.OpShort(ShortEnum.senum11);
                TestHelper.Assert(r == ShortEnum.senum11 && o == ShortEnum.senum11);
            }

            {
                (IntEnum r, IntEnum o) = proxy.OpInt(IntEnum.ienum1);
                TestHelper.Assert(r == IntEnum.ienum1 && o == IntEnum.ienum1);
                (r, o) = proxy.OpInt(IntEnum.ienum11);
                TestHelper.Assert(r == IntEnum.ienum11 && o == IntEnum.ienum11);
                (r, o) = proxy.OpInt(IntEnum.ienum12);
                TestHelper.Assert(r == IntEnum.ienum12 && o == IntEnum.ienum12);
            }

            {
                (SimpleEnum r, SimpleEnum o) = proxy.OpSimple(SimpleEnum.green);
                TestHelper.Assert(r == SimpleEnum.green && o == SimpleEnum.green);
            }

            {
                (FLByteEnum r, FLByteEnum o) = proxy.OpFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
            }

            {
                (FLByteEnum? r, FLByteEnum? o) = proxy.OpTaggedFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpTaggedFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
                (r, o) = proxy.OpTaggedFLByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                (FLShortEnum r, FLShortEnum o) = proxy.OpFLShort(FLShortEnum.senum1);
                TestHelper.Assert(r == FLShortEnum.senum1 && o == FLShortEnum.senum1);
                (r, o) = proxy.OpFLShort(FLShortEnum.senum11);
                TestHelper.Assert(r == FLShortEnum.senum11 && o == FLShortEnum.senum11);
            }

            {
                (FLUShortEnum r, FLUShortEnum o) = proxy.OpFLUShort(FLUShortEnum.senum1);
                TestHelper.Assert(r == FLUShortEnum.senum1 && o == FLUShortEnum.senum1);
                (r, o) = proxy.OpFLUShort(FLUShortEnum.senum11);
                TestHelper.Assert(r == FLUShortEnum.senum11 && o == FLUShortEnum.senum11);
            }

            {
                (FLIntEnum r, FLIntEnum o) = proxy.OpFLInt(FLIntEnum.ienum1);
                TestHelper.Assert(r == FLIntEnum.ienum1 && o == FLIntEnum.ienum1);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum11);
                TestHelper.Assert(r == FLIntEnum.ienum11 && o == FLIntEnum.ienum11);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum12);
                TestHelper.Assert(r == FLIntEnum.ienum12 && o == FLIntEnum.ienum12);
            }

            {
                (FLUIntEnum r, FLUIntEnum o) = proxy.OpFLUInt(FLUIntEnum.ienum1);
                TestHelper.Assert(r == FLUIntEnum.ienum1 && o == FLUIntEnum.ienum1);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum11);
                TestHelper.Assert(r == FLUIntEnum.ienum11 && o == FLUIntEnum.ienum11);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum12);
                TestHelper.Assert(r == FLUIntEnum.ienum12 && o == FLUIntEnum.ienum12);
            }

            {
                (FLSimpleEnum r, FLSimpleEnum o) = proxy.OpFLSimple(FLSimpleEnum.green);
                TestHelper.Assert(r == FLSimpleEnum.green && o == FLSimpleEnum.green);
            }

            output.WriteLine("ok");

            output.Write("testing enum sequences operations... ");
            output.Flush();

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[] b3, ByteEnum[] b2) = proxy.OpByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var b1 = new ByteEnum[12]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    (ByteEnum)42,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                try
                {
                    _ = proxy.OpByteSeq(b1);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException)
                {
                    // expected
                }
            }

            {
                var s1 = new ShortEnum[11]
                {
                    ShortEnum.senum1,
                    ShortEnum.senum2,
                    ShortEnum.senum3,
                    ShortEnum.senum4,
                    ShortEnum.senum5,
                    ShortEnum.senum6,
                    ShortEnum.senum7,
                    ShortEnum.senum8,
                    ShortEnum.senum9,
                    ShortEnum.senum10,
                    ShortEnum.senum11
                };

                (ShortEnum[] s3, ShortEnum[] s2) = proxy.OpShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new IntEnum[11]
                {
                    IntEnum.ienum1,
                    IntEnum.ienum2,
                    IntEnum.ienum3,
                    IntEnum.ienum4,
                    IntEnum.ienum5,
                    IntEnum.ienum6,
                    IntEnum.ienum7,
                    IntEnum.ienum8,
                    IntEnum.ienum9,
                    IntEnum.ienum10,
                    IntEnum.ienum11
                };

                (IntEnum[] i3, IntEnum[] i2) = proxy.OpIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new SimpleEnum[3]
                {
                    SimpleEnum.red,
                    SimpleEnum.green,
                    SimpleEnum.blue
                };

                (SimpleEnum[] s3, SimpleEnum[] s2) = proxy.OpSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[] b3, FLByteEnum[] b2) = proxy.OpFLByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var s1 = new FLShortEnum[11]
                {
                    FLShortEnum.senum1,
                    FLShortEnum.senum2,
                    FLShortEnum.senum3,
                    FLShortEnum.senum4,
                    FLShortEnum.senum5,
                    FLShortEnum.senum6,
                    FLShortEnum.senum7,
                    FLShortEnum.senum8,
                    FLShortEnum.senum9,
                    FLShortEnum.senum10,
                    FLShortEnum.senum11
                };

                (FLShortEnum[] s3, FLShortEnum[] s2) = proxy.OpFLShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var s1 = new FLUShortEnum[11]
                {
                    FLUShortEnum.senum1,
                    FLUShortEnum.senum2,
                    FLUShortEnum.senum3,
                    FLUShortEnum.senum4,
                    FLUShortEnum.senum5,
                    FLUShortEnum.senum6,
                    FLUShortEnum.senum7,
                    FLUShortEnum.senum8,
                    FLUShortEnum.senum9,
                    FLUShortEnum.senum10,
                    FLUShortEnum.senum11
                };

                (FLUShortEnum[] s3, FLUShortEnum[] s2) = proxy.OpFLUShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[] i3, FLIntEnum[] i2) = proxy.OpFLIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var i1 = new FLUIntEnum[11]
                {
                    FLUIntEnum.ienum1,
                    FLUIntEnum.ienum2,
                    FLUIntEnum.ienum3,
                    FLUIntEnum.ienum4,
                    FLUIntEnum.ienum5,
                    FLUIntEnum.ienum6,
                    FLUIntEnum.ienum7,
                    FLUIntEnum.ienum8,
                    FLUIntEnum.ienum9,
                    FLUIntEnum.ienum10,
                    FLUIntEnum.ienum11
                };

                (FLUIntEnum[] i3, FLUIntEnum[] i2) = proxy.OpFLUIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new FLSimpleEnum[3]
                {
                    FLSimpleEnum.red,
                    FLSimpleEnum.green,
                    FLSimpleEnum.blue
                };

                (FLSimpleEnum[] s3, FLSimpleEnum[] s2) = proxy.OpFLSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[]? b3, ByteEnum[]? b2) = proxy.OpTaggedByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var b1 = new ByteEnum[12]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    (ByteEnum)42,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                try
                {
                    _ = proxy.OpTaggedByteSeq(b1);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException)
                {
                    // expected
                }
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[]? b3, FLByteEnum[]? b2) = proxy.OpTaggedFLByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedFLByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[]? i3, FLIntEnum[]? i2) = proxy.OpTaggedFLIntSeq(i1);
                TestHelper.Assert(i2 != null && i3 != null);

                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));

                (i3, i2) = proxy.OpTaggedFLIntSeq(null);
                TestHelper.Assert(i2 == null && i3 == null);
            }

            output.WriteLine("ok");

            output.Write("testing unchecked enums... ");
            output.Flush();
            {
                (MyFlags r, MyFlags f2) = proxy.OpMyFlags(MyFlags.E31);
                TestHelper.Assert(r == MyFlags.E31 && f2 == r);
                (r, f2) = proxy.OpMyFlags(MyFlags.E10 | MyFlags.E11);
                TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r);
            }

            output.Flush();
            {
                (MyFlags? r, MyFlags? f2) = proxy.OpTaggedMyFlags(null);
                TestHelper.Assert(r == null && f2 == r);
                (r, f2) = proxy.OpTaggedMyFlags(MyFlags.E10 | MyFlags.E11);
                TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r);
            }

            output.Flush();
            {
                var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 };
                (MyFlags[] r, MyFlags[] f2) = proxy.OpMyFlagsSeq(myFlagsSeq);
                TestHelper.Assert(r.SequenceEqual(myFlagsSeq) && f2.SequenceEqual(myFlagsSeq));
            }

            output.Flush();
            {
                var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 };
                (MyFlags[]? r, MyFlags[]? f2) = proxy.OpTaggedMyFlagsSeq(myFlagsSeq);
                TestHelper.Assert(r !.SequenceEqual(myFlagsSeq) && f2 !.SequenceEqual(myFlagsSeq));
            }

            output.WriteLine("ok");
            await proxy.ShutdownAsync();
        }
예제 #9
0
        public static IInitialPrx Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.Output;
            output.Write("testing stringToProxy... ");
            output.Flush();
            var initial = IInitialPrx.Parse(helper.GetTestProxy("initial", 0), communicator);

            output.WriteLine("ok");

            {
                output.Write("testing types without package... ");
                output.Flush();
                NoNamespace.C1?c1 = initial.GetNoNamespaceC2AsC1();
                TestHelper.Assert(c1 != null);
                TestHelper.Assert(c1 is NoNamespace.C2);
                NoNamespace.C2?c2 = initial.GetNoNamespaceC2AsC2();
                TestHelper.Assert(c2 != null);
                try
                {
                    initial.ThrowNoNamespaceE2AsE1();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.E1 ex)
                {
                    TestHelper.Assert(ex is NoNamespace.E2);
                }
                try
                {
                    initial.ThrowNoNamespaceE2AsE2();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.E2)
                {
                    // Expected
                }
                try
                {
                    initial.ThrowNoNamespaceNotify();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.@notify)
                {
                    // Expected
                }
                output.WriteLine("ok");
            }

            {
                output.Write("testing types with package... ");
                output.Flush();

                {
                    WithNamespace.C1?c1 = initial.GetWithNamespaceC2AsC1();
                    TestHelper.Assert(c1 != null);
                    TestHelper.Assert(c1 is WithNamespace.C2);
                    WithNamespace.C2?c2 = initial.GetWithNamespaceC2AsC2();
                    TestHelper.Assert(c2 != null);
                    try
                    {
                        initial.ThrowWithNamespaceE2AsE1();
                        TestHelper.Assert(false);
                    }
                    catch (WithNamespace.E1 ex)
                    {
                        TestHelper.Assert(ex is WithNamespace.E2);
                    }
                    try
                    {
                        initial.ThrowWithNamespaceE2AsE2();
                        TestHelper.Assert(false);
                    }
                    catch (WithNamespace.E2)
                    {
                        // Expected
                    }
                    output.WriteLine("ok");
                }
            }
            return(initial);
        }
예제 #10
0
파일: AllTests.cs 프로젝트: yuwenyong/ice
        public static void allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var com = Test.IRemoteCommunicatorPrx.Parse($"communicator:{helper.GetTestEndpoint(0)}", communicator);

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

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing binding with single endpoint... ");
            output.Flush();
            {
                Test.IRemoteObjectAdapterPrx?adapter = com.createObjectAdapter("Adapter", "default");
                TestHelper.Assert(adapter != null);
                Test.ITestIntfPrx?test1 = adapter.getTestIntf();
                Test.ITestIntfPrx?test2 = adapter.getTestIntf();
                TestHelper.Assert(test1 != null && test2 != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

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

                com.deactivateObjectAdapter(adapter);

                var test3 = Test.ITestIntfPrx.UncheckedCast(test1);
                TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                TestHelper.Assert(test3.GetConnection() == test2.GetConnection());

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

            output.Write("testing binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <Test.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("Adapter11", "default") !,
                    com.createObjectAdapter("Adapter12", "default") !,
                    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.IRemoteObjectAdapterPrx>(adapters);

                    var test1 = createTestIntfPrx(adpts);
                    shuffle(ref adpts);
                    var test2 = createTestIntfPrx(adpts);
                    shuffle(ref adpts);
                    var test3 = createTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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 (Test.IRemoteObjectAdapterPrx 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++)
                    {
                        ;
                    }
                    TestHelper.Assert(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("Adapter12");
                names.Add("Adapter13");
                while (names.Count > 0)
                {
                    var adpts = new List <Test.IRemoteObjectAdapterPrx>(adapters);

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

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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.IRemoteObjectAdapterPrx)adapters[2]);
                var obj = createTestIntfPrx(adapters);
                TestHelper.Assert(obj.getAdapterName().Equals("Adapter12"));

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

            output.Write("testing binding with multiple random endpoints... ");
            output.Flush();
            {
                var adapters = new Test.IRemoteObjectAdapterPrx[5]
                {
                    com.createObjectAdapter("AdapterRandom11", "default") !,
                    com.createObjectAdapter("AdapterRandom12", "default") !,
                    com.createObjectAdapter("AdapterRandom13", "default") !,
                    com.createObjectAdapter("AdapterRandom14", "default") !,
                    com.createObjectAdapter("AdapterRandom15", "default") !
                };

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

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

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

                    var 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());
                            }
                        }
                    }
                    TestHelper.Assert(connections.Count <= adapterCount);

                    foreach (Test.IRemoteObjectAdapterPrx a in adapters)
                    {
                        try
                        {
                            a.getTestIntf() !.GetConnection().Close(ConnectionClose.GracefullyWithWait);
                        }
                        catch (Exception)
                        {
                            // Expected if adapter is down.
                        }
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple endpoints and AMI... ");
            output.Flush();
            {
                var adapters = new List <Test.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("AdapterAMI11", "default") !,
                    com.createObjectAdapter("AdapterAMI12", "default") !,
                    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.IRemoteObjectAdapterPrx>(adapters);

                    var test1 = createTestIntfPrx(adpts);
                    shuffle(ref adpts);
                    var test2 = createTestIntfPrx(adpts);
                    shuffle(ref adpts);
                    var test3 = createTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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++)
                    {
                        ;
                    }
                    TestHelper.Assert(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.IRemoteObjectAdapterPrx>(adapters);

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

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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);
                TestHelper.Assert(getAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

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

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

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

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

                obj = obj.Clone(endpointSelection: EndpointSelectionType.Random);
                TestHelper.Assert(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.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("Adapter31", "default") !,
                    com.createObjectAdapter("Adapter32", "default") !,
                    com.createObjectAdapter("Adapter33", "default") !
                };

                var obj = createTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                int nRetry = 3;
                int i;

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

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

                var 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++)
                {
                    ;
                }
                TestHelper.Assert(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++)
                {
                    ;
                }
                TestHelper.Assert(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++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);

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

            output.Write("testing per request binding with single endpoint... ");
            output.Flush();
            {
                Test.IRemoteObjectAdapterPrx?adapter = com.createObjectAdapter("Adapter41", "default");
                TestHelper.Assert(adapter != null);
                Test.ITestIntfPrx test1 = adapter.getTestIntf() !.Clone(cacheConnection: false);
                Test.ITestIntfPrx test2 = adapter.getTestIntf() !.Clone(cacheConnection: false);
                TestHelper.Assert(!test1.IsConnectionCached);
                TestHelper.Assert(!test2.IsConnectionCached);
                TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();

                com.deactivateObjectAdapter(adapter);

                var test3 = Test.ITestIntfPrx.UncheckedCast(test1);
                try
                {
                    TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

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

                Test.ITestIntfPrx obj = createTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "Adapter51",
                    "Adapter52",
                    "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]);

                TestHelper.Assert(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.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("AdapterAMI51", "default") !,
                    com.createObjectAdapter("AdapterAMI52", "default") !,
                    com.createObjectAdapter("AdapterAMI53", "default") !
                };

                Test.ITestIntfPrx obj = createTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "AdapterAMI51",
                    "AdapterAMI52",
                    "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]);

                TestHelper.Assert(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.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("Adapter61", "default") !,
                    com.createObjectAdapter("Adapter62", "default") !,
                    com.createObjectAdapter("Adapter63", "default") !
                };

                var obj = createTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);
                int nRetry = 3;
                int i;

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

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

                var 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++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString()) !);
                for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString()) !);
                for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++)
                {
                    ;
                }
                TestHelper.Assert(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.IRemoteObjectAdapterPrx>
                {
                    com.createObjectAdapter("AdapterAMI61", "default") !,
                    com.createObjectAdapter("AdapterAMI62", "default") !,
                    com.createObjectAdapter("AdapterAMI63", "default") !
                };

                var obj = createTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!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++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                com.deactivateObjectAdapter(adapters[0]);
                for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                com.deactivateObjectAdapter(adapters[1]);
                for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                com.deactivateObjectAdapter(adapters[2]);

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

                var 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++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString()) !);
                for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);
                adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString()) !);
                for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++)
                {
                    ;
                }
                TestHelper.Assert(i == nRetry);

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

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

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

                var testUDP = obj.Clone(invocationMode: InvocationMode.Datagram);
                TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection());
                try
                {
                    testUDP.getAdapterName();
                    TestHelper.Assert(false);
                }
                catch (System.InvalidOperationException)
                {
                    // expected
                }
            }
            output.WriteLine("ok");
            if (communicator.GetProperty("Ice.Plugin.IceSSL") != null)
            {
                output.Write("testing secure and non-secure endpoints... ");
                output.Flush();
                {
                    var adapters = new List <Test.IRemoteObjectAdapterPrx>
                    {
                        com.createObjectAdapter("Adapter81", "ssl") !,
                        com.createObjectAdapter("Adapter82", "tcp") !
                    };

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

                    var testNonSecure = obj.Clone(preferNonSecure: true);
                    // TODO: update when PreferNonSecure default is updated
                    var testSecure = obj.Clone(preferNonSecure: false);
                    TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection());
                    TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection());

                    com.deactivateObjectAdapter(adapters[1]);

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

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

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

                    com.deactivateObjectAdapter(adapters[0]);

                    try
                    {
                        testSecure.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // expected
                    }
                    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 (TransportException)
                    {
                        if (p == ipv6)
                        {
                            ipv6NotSupported = true;
                        }
                        serverCommunicator.Destroy();
                        continue; // IP version not supported.
                    }

                    var prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                    try
                    {
                        prx.Clone(collocationOptimized: false).IcePing();
                    }
                    catch (DNSException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Destroy();
                        continue;
                    }
                    catch (ObjectNotExistException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Destroy();
                        continue;
                    }

                    string strPrx = prx.ToString() !;
                    foreach (var q in clientProps)
                    {
                        Communicator clientCommunicator = new Communicator(q);
                        prx = IObjectPrx.Parse(strPrx, clientCommunicator);
                        try
                        {
                            prx.IcePing();
                            TestHelper.Assert(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 (TransportException)
                        {
                            TestHelper.Assert((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();
        }
예제 #11
0
파일: AllTests.cs 프로젝트: mreinart/ice
        public static async Task RunAsync(TestHelper helper)
        {
            Communicator communicator = helper.Communicator;

            bool        ice1   = helper.Protocol == Protocol.Ice1;
            var         cl     = IMyClassPrx.Parse(helper.GetTestProxy("test", 0), communicator);
            IMyClassPrx oneway = cl.Clone(oneway: true);

            System.IO.TextWriter output = helper.Output;
            output.Write("testing InvokeAsync... ");
            output.Flush();

            {
                using var request = OutgoingRequestFrame.WithEmptyArgs(oneway, "opOneway", idempotent: false);

                try
                {
                    using IncomingResponseFrame response = oneway.InvokeAsync(request, oneway: true).Result;
                }
                catch
                {
                    TestHelper.Assert(false);
                }
            }

            {
                using var request = OutgoingRequestFrame.WithArgs(cl,
                                                                  "opString",
                                                                  idempotent: false,
                                                                  compress: false,
                                                                  format: default,
                                                                  context: null,
                                                                  TestString,
                                                                  OutputStream.IceWriterFromString);

                using IncomingResponseFrame response = cl.InvokeAsync(request).Result;
                (string s1, string s2) = response.ReadReturnValue(cl, istr =>
                {
                    string s1 = istr.ReadString();
                    string s2 = istr.ReadString();
                    return(s1, s2);
                });
                TestHelper.Assert(s1.Equals(TestString));
                TestHelper.Assert(s2.Equals(TestString));
            }

            {
                using var request = OutgoingRequestFrame.WithEmptyArgs(cl, "opException", idempotent: false);
                using IncomingResponseFrame response = cl.InvokeAsync(request).Result;

                try
                {
                    response.ReadVoidReturnValue(cl);
                    TestHelper.Assert(false);
                }
                catch (MyException)
                {
                }
                catch
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");
            await cl.ShutdownAsync();
        }
예제 #12
0
파일: AllTests.cs 프로젝트: yuwenyong/ice
        public static Test.IInitialPrx allTests(global::Test.TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.GetWriter();
            var initial = Test.IInitialPrx.Parse($"initial:{helper.GetTestEndpoint(0)}", communicator);

            output.Write("getting proxies for interface hierarchy... ");
            output.Flush();
            Test.MA.IIAPrx? ia  = initial.iaop();
            Test.MB.IIB1Prx?ib1 = initial.ib1op();
            Test.MB.IIB2Prx?ib2 = initial.ib2op();
            Test.MA.IICPrx? ic  = initial.icop();
            TestHelper.Assert(ia != null);
            TestHelper.Assert(ib1 != null);
            TestHelper.Assert(ib2 != null);
            TestHelper.Assert(ic != null);
            TestHelper.Assert(ia != ib1);
            TestHelper.Assert(ia != ib2);
            TestHelper.Assert(ia != ic);
            TestHelper.Assert(ib1 != ic);
            TestHelper.Assert(ib2 != ic);
            output.WriteLine("ok");

            output.Write("invoking proxy operations on interface hierarchy... ");
            output.Flush();
            Test.MA.IIAPrx? iao;
            Test.MB.IIB1Prx?ib1o;
            Test.MB.IIB2Prx?ib2o;
            Test.MA.IICPrx? ico;

            iao = ia.iaop(ia);
            TestHelper.Assert(iao !.Equals(ia));
            iao = ia.iaop(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            iao = ia.iaop(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            iao = ia.iaop(ic);
            TestHelper.Assert(iao !.Equals(ic));
            iao = ib1.iaop(ia);
            TestHelper.Assert(iao !.Equals(ia));
            iao = ib1.iaop(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            iao = ib1.iaop(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            iao = ib1.iaop(ic);
            TestHelper.Assert(iao !.Equals(ic));
            iao = ib2.iaop(ia);
            TestHelper.Assert(iao !.Equals(ia));
            iao = ib2.iaop(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            iao = ib2.iaop(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            iao = ib2.iaop(ic);
            TestHelper.Assert(iao !.Equals(ic));
            iao = ic.iaop(ia);
            TestHelper.Assert(iao !.Equals(ia));
            iao = ic.iaop(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            iao = ic.iaop(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            iao = ic.iaop(ic);
            TestHelper.Assert(iao !.Equals(ic));

            iao = ib1.ib1op(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            ib1o = ib1.ib1op(ib1);
            TestHelper.Assert(ib1o !.Equals(ib1));
            iao = ib1.ib1op(ic);
            TestHelper.Assert(iao !.Equals(ic));
            ib1o = ib1.ib1op(ic);
            TestHelper.Assert(ib1o !.Equals(ic));
            iao = ic.ib1op(ib1);
            TestHelper.Assert(iao !.Equals(ib1));
            ib1o = ic.ib1op(ib1);
            TestHelper.Assert(ib1o !.Equals(ib1));
            iao = ic.ib1op(ic);
            TestHelper.Assert(iao !.Equals(ic));
            ib1o = ic.ib1op(ic);
            TestHelper.Assert(ib1o !.Equals(ic));

            iao = ib2.ib2op(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            ib2o = ib2.ib2op(ib2);
            TestHelper.Assert(ib2o !.Equals(ib2));
            iao = ib2.ib2op(ic);
            TestHelper.Assert(iao !.Equals(ic));
            ib2o = ib2.ib2op(ic);
            TestHelper.Assert(ib2o !.Equals(ic));
            iao = ic.ib2op(ib2);
            TestHelper.Assert(iao !.Equals(ib2));
            ib2o = ic.ib2op(ib2);
            TestHelper.Assert(ib2o !.Equals(ib2));
            iao = ic.ib2op(ic);
            TestHelper.Assert(iao !.Equals(ic));
            ib2o = ic.ib2op(ic);
            TestHelper.Assert(ib2o !.Equals(ic));

            iao = ic.icop(ic);
            TestHelper.Assert(iao !.Equals(ic));
            ib1o = ic.icop(ic);
            TestHelper.Assert(ib1o !.Equals(ic));
            ib2o = ic.icop(ic);
            TestHelper.Assert(ib2o !.Equals(ic));
            ico = ic.icop(ic);
            TestHelper.Assert(ico !.Equals(ic));
            output.WriteLine("ok");
            return(initial);
        }
예제 #13
0
파일: AllTests.cs 프로젝트: cyyever/ice
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;
            bool         ice1         = helper.Protocol == Protocol.Ice1;

            TestHelper.Assert(communicator != null);
            var    com           = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator);
            string testTransport = helper.Transport;

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

            System.IO.TextWriter output = helper.Output;

            output.Write("testing binding with single endpoint... ");
            output.Flush();
            {
                // Use "default" with ice1 + tcp here to ensure that it still works
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter",
                                                                          (ice1 && testTransport == "tcp") ? "default" : testTransport);
                TestHelper.Assert(adapter != null);
                ITestIntfPrx?test1 = adapter.GetTestIntf();
                ITestIntfPrx?test2 = adapter.GetTestIntf();
                TestHelper.Assert(test1 != null && test2 != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

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

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                TestHelper.Assert(test3.GetCachedConnection() == test1.GetCachedConnection());
                TestHelper.Assert(test3.GetCachedConnection() == test2.GetCachedConnection());

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

            output.Write("testing binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter31", testTransport) !,
                    com.CreateObjectAdapter("Adapter32", testTransport) !,
                    com.CreateObjectAdapter("Adapter33", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter31");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter32");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter33");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }
                adapters.Clear();
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with single endpoint... ");
            output.Flush();
            {
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport);
                TestHelper.Assert(adapter != null);
                ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                TestHelper.Assert(!test1.IsConnectionCached);
                TestHelper.Assert(!test2.IsConnectionCached);
                TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                try
                {
                    TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter61", testTransport) !,
                    com.CreateObjectAdapter("Adapter62", testTransport) !,
                    com.CreateObjectAdapter("Adapter63", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (helper.Protocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter64");
                    }

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

            output.Write("testing connection reuse with multiple endpoints... ");
            output.Flush();
            {
                var adapters1 = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter81", testTransport) !,
                    com.CreateObjectAdapter("Adapter82", testTransport) !,
                    com.CreateObjectAdapter("Adapter83", testTransport) !
                };

                var adapters2 = new List <IRemoteObjectAdapterPrx>
                {
                    adapters1[0],
                    com.CreateObjectAdapter("Adapter84", testTransport) !,
                    com.CreateObjectAdapter("Adapter85", testTransport) !
                };

                ITestIntfPrx obj1 = CreateTestIntfPrx(adapters1);
                ITestIntfPrx obj2 = CreateTestIntfPrx(adapters2);

                com.DeactivateObjectAdapter(adapters1[0]);

                Task <string> t1 = obj1.GetAdapterNameAsync();
                Task <string> t2 = obj2.GetAdapterNameAsync();
                TestHelper.Assert(t1.Result == "Adapter82");
                TestHelper.Assert(t2.Result == "Adapter84");

                Deactivate(com, adapters1);
                Deactivate(com, adapters2);
            }

            {
                var adapters1 = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter91", testTransport) !,
                    com.CreateObjectAdapter("Adapter92", testTransport) !,
                    com.CreateObjectAdapter("Adapter93", testTransport) !
                };

                var adapters2 = new List <IRemoteObjectAdapterPrx>
                {
                    adapters1[0],
                    com.CreateObjectAdapter("Adapter94", testTransport) !,
                    com.CreateObjectAdapter("Adapter95", testTransport) !
                };

                ITestIntfPrx obj1 = CreateTestIntfPrx(adapters1);
                ITestIntfPrx obj2 = CreateTestIntfPrx(adapters2);

                Task <string> t1 = obj1.GetAdapterNameAsync();
                Task <string> t2 = obj2.GetAdapterNameAsync();
                TestHelper.Assert(t1.Result == "Adapter91");
                TestHelper.Assert(t2.Result == "Adapter91");

                Deactivate(com, adapters1);
                Deactivate(com, adapters2);
            }
            output.WriteLine("ok");

            if (helper.Protocol == Protocol.Ice1)
            {
                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter71", testTransport),
                        com.CreateObjectAdapter("Adapter72", "udp")
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                    TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71"));

                    // test that datagram proxies fail if PreferNonSecure is false
                    ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram, preferNonSecure: false);
                    try
                    {
                        testUDP.GetConnection();
                        TestHelper.Assert(false);
                    }
                    catch (NoEndpointException)
                    {
                        // expected
                    }

                    testUDP = obj.Clone(invocationMode: InvocationMode.Datagram, preferNonSecure: true);
                    TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection());
                    try
                    {
                        testUDP.GetAdapterName();
                        TestHelper.Assert(false);
                    }
                    catch (InvalidOperationException)
                    {
                        // expected
                    }
                }
                output.WriteLine("ok");
            }
            if (communicator.GetProperty("Ice.Plugin.IceSSL") != null)
            {
                output.Write("testing secure and non-secure endpoints... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter81", "ssl") !,
                        com.CreateObjectAdapter("Adapter82", "tcp") !
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82"));
                        obj.GetConnection().GoAwayAsync();
                    }

                    ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true);
                    // TODO: update when PreferNonSecure default is updated
                    ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false);
                    TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection());
                    TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection());

                    com.DeactivateObjectAdapter(adapters[1]);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81"));
                        obj.GetConnection().GoAwayAsync();
                    }

                    // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                    if (helper.Protocol == Protocol.Ice1)
                    {
                        com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA.

                        for (int i = 0; i < 5; i++)
                        {
                            TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83"));
                            obj.GetConnection().GoAwayAsync();
                        }
                    }

                    com.DeactivateObjectAdapter(adapters[0]);

                    try
                    {
                        testSecure.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // expected
                    }
                    Deactivate(com, adapters);
                }
                output.WriteLine("ok");
            }

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

                Func <string, string> getEndpoint = host =>
                                                    TestHelper.GetTestEndpoint(
                    new Dictionary <string, string>(communicator.GetProperties())
                {
                    ["Test.Host"] = host
                },
                    2,
                    "tcp");

                Func <string, string, string> getProxy = (identity, host) =>
                                                         TestHelper.GetTestProxy(
                    identity,
                    new Dictionary <string, string>(communicator.GetProperties())
                {
                    ["Test.Host"] = host
                },
                    2,
                    "tcp");

                var anyipv4 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("0.0.0.0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1")
                };

                var anyipv6 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("::0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("::1")
                };

                var anyipv46 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("::0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1")
                };

                var anylocalhost = new Dictionary <string, string>()
                {
                    { "Adapter.Endpoints", getEndpoint("::0") },
                    { "Adapter.PublishedEndpoints", getEndpoint("localhost") }
                };

                var localipv4 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]  = getEndpoint("127.0.0.1"),
                    ["Adapter.ServerName"] = "127.0.0.1"
                };

                var localipv6 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]  = getEndpoint("::1"),
                    ["Adapter.ServerName"] = "::1"
                };

                var localhost = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]  = getEndpoint("localhost"),
                    ["Adapter.ServerName"] = "localhost"
                };

                var serverProps = new Dictionary <string, string>[]
                {
                    anyipv4,
                    anyipv6,
                    anyipv46,
                    anylocalhost,
                    localipv4,
                    localipv6,
                    localhost
                };

                foreach (Dictionary <string, string> p in serverProps)
                {
                    using var serverCommunicator = new Communicator(p);
                    ObjectAdapter oa = serverCommunicator.CreateObjectAdapter("Adapter");
                    oa.Activate();

                    IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                    try
                    {
                        using var clientCommunicator = new Communicator();
                        prx = IObjectPrx.Parse(prx.ToString() !, clientCommunicator);
                        prx.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected. OA is reachable but there's no "dummy" object
                    }
                }

                // Test IPv6 dual mode socket
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::0");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    try
                    {
                        using ObjectAdapter ipv4OA =
                                  serverCommunicator.CreateObjectAdapterWithEndpoints(getEndpoint("0.0.0.0"));
                        ipv4OA.Activate();
                        TestHelper.Assert(false);
                    }
                    catch (TransportException)
                    {
                        // Expected. ::0 is a dual-mode socket so binding 0.0.0.0 will fail
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected, no object registered.
                    }
                }

                // Test IPv6 only endpoints
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::0") + (ice1 ? " --ipv6Only" : "?ipv6-only=true");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    // 0.0.0.0 can still be bound if ::0 is IPv6 only
                    {
                        string ipv4Endpoint = getEndpoint("0.0.0.0");
                        using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint);
                        ipv4OA.Activate();
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // Expected, server socket is IPv6 only.
                    }
                }

                // Listen on IPv4 loopback with IPv6 dual mode socket
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::ffff:127.0.0.1");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    try
                    {
                        string ipv4Endpoint = getEndpoint("127.0.0.1");
                        using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint);
                        ipv4OA.Activate();
                        TestHelper.Assert(false);
                    }
                    catch (TransportException)
                    {
                        // Expected. 127.0.0.1 is already in use
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected, no object registered.
                    }
                }

                output.WriteLine("ok");
            }

            com.Shutdown();
        }
    }
}
예제 #14
0
파일: AllTests.cs 프로젝트: renchuanrc/ice
        public static IGPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing Ice.Admin.Facets property... ");
            TestHelper.Assert(communicator.GetPropertyAsList("Ice.Admin.Facets") == null);
            communicator.SetProperty("Ice.Admin.Facets", "foobar");
            string[]? facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
            communicator.SetProperty("Ice.Admin.Facets", "foo\\'bar");
            facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
            communicator.SetProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
            facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(facetFilter != null && facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") &&
                              facetFilter[1].Equals("toto") && facetFilter[2].Equals("titi"));
            communicator.SetProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
            facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(facetFilter != null && facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") &&
                              facetFilter[1].Equals("titi"));
            // communicator.SetProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
            // facetFilter = communicator.Properties.getPropertyAsList("Ice.Admin.Facets");
            // TestHelper.Assert(facetFilter.Length == 0);
            communicator.SetProperty("Ice.Admin.Facets", "");
            output.WriteLine("ok");

            output.Write("testing facet registration exceptions... ");
            communicator.SetProperty("FacetExceptionTestAdapter.Endpoints", "tcp -h *");
            ObjectAdapter adapter = communicator.CreateObjectAdapter("FacetExceptionTestAdapter");

            var obj = new Empty();

            adapter.Add("d", obj);
            adapter.Add("d", "facetABCD", obj);
            try
            {
                adapter.Add("d", "facetABCD", obj);
                TestHelper.Assert(false);
            }
            catch (System.ArgumentException)
            {
            }
            adapter.Remove("d", "facetABCD");
            adapter.Remove("d", "facetABCD"); // multiple Remove are fine as of Ice 4.0
            output.WriteLine("ok");

            adapter.Dispose();

            var   prx = IObjectPrx.Parse($"d:{helper.GetTestEndpoint(0)}", communicator);
            IDPrx?d;
            IDPrx?df2;
            IDPrx?df3;

            output.Write("testing unchecked cast... ");
            output.Flush();
            d = IDPrx.UncheckedCast(prx);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Facet.Length == 0);
            IDPrx df = prx.Clone("facetABCD", IDPrx.Factory);

            TestHelper.Assert(df.Facet == "facetABCD");
            df2 = IDPrx.UncheckedCast(df);
            TestHelper.Assert(df2 != null);
            TestHelper.Assert(df2.Facet == "facetABCD");
            df3 = df.Clone(facet: "", IDPrx.Factory);
            TestHelper.Assert(df3 != null);
            TestHelper.Assert(df3.Facet.Length == 0);
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            d = IDPrx.CheckedCast(prx);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Facet.Length == 0);
            df = prx.Clone(facet: "facetABCD", IDPrx.Factory);
            TestHelper.Assert(df.Facet == "facetABCD");
            df2 = IDPrx.CheckedCast(df);
            TestHelper.Assert(df2 != null);
            TestHelper.Assert(df2.Facet == "facetABCD");
            df3 = df.Clone(facet: "", IDPrx.Factory);
            TestHelper.Assert(df3.Facet.Length == 0);
            output.WriteLine("ok");

            output.Write("testing non-facets A, B, C, and D... ");
            output.Flush();
            d = IDPrx.CheckedCast(prx);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Equals(prx));
            TestHelper.Assert(d.callA().Equals("A"));
            TestHelper.Assert(d.callB().Equals("B"));
            TestHelper.Assert(d.callC().Equals("C"));
            TestHelper.Assert(d.callD().Equals("D"));
            output.WriteLine("ok");

            output.Write("testing facets A, B, C, and D... ");
            output.Flush();
            df = d.Clone(facet: "facetABCD", IDPrx.Factory);
            TestHelper.Assert(df != null);
            TestHelper.Assert(df.callA().Equals("A"));
            TestHelper.Assert(df.callB().Equals("B"));
            TestHelper.Assert(df.callC().Equals("C"));
            TestHelper.Assert(df.callD().Equals("D"));
            output.WriteLine("ok");

            output.Write("testing facets E and F... ");
            output.Flush();
            IFPrx ff = d.Clone(facet: "facetEF", IFPrx.Factory);

            TestHelper.Assert(ff.callE().Equals("E"));
            TestHelper.Assert(ff.callF().Equals("F"));
            output.WriteLine("ok");

            output.Write("testing facet G... ");
            output.Flush();
            IGPrx gf = ff.Clone(facet: "facetGH", IGPrx.Factory);

            TestHelper.Assert(gf.callG().Equals("G"));
            output.WriteLine("ok");

            output.Write("testing whether casting preserves the facet... ");
            output.Flush();
            var hf = IHPrx.CheckedCast(gf);

            TestHelper.Assert(hf != null);
            TestHelper.Assert(hf.callG().Equals("G"));
            TestHelper.Assert(hf.callH().Equals("H"));
            output.WriteLine("ok");
            return(gf);
        }
예제 #15
0
        public static void RunWithController(TestHelper helper, IControllerPrx controller)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);

            var timeout = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), communicator);

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing connect timeout... ");
            output.Flush();
            {
                Dictionary <string, string>?properties = communicator.GetProperties();
                properties["Ice.ConnectTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), comm);

                // Expect ConnectTimeoutException.
                controller.HoldAdapter(-1);
                try
                {
                    to.Op();
                    TestHelper.Assert(false);
                }
                catch (ConnectTimeoutException)
                {
                    // Expected.
                }
                controller.ResumeAdapter();
                timeout.Op(); // Ensure adapter is active.
            }
            {
                //
                // Expect success.
                //
                controller.HoldAdapter(100);
                timeout.Op();
            }
            output.WriteLine("ok");

            // The sequence needs to be large enough to fill the write/recv buffers
            byte[] seq = new byte[2000000];

            output.Write("testing connection timeout... ");
            output.Flush();
            {
                //
                // Expect TimeoutException.
                //
                controller.HoldAdapter(-1);
                timeout.GetConnection() !.Acm = new Acm(TimeSpan.FromMilliseconds(50),
                                                        AcmClose.OnInvocationAndIdle,
                                                        AcmHeartbeat.Off);
                try
                {
                    timeout.SendData(seq);
                    TestHelper.Assert(false);
                }
                catch (ConnectionTimeoutException)
                {
                    // Expected.
                }
                controller.ResumeAdapter();
                timeout.Op(); // Ensure adapter is active.
            }
            {
                //
                // Expect success.
                //
                controller.HoldAdapter(100);
                try
                {
                    timeout.SendData(new byte[1000000]);
                }
                catch (ConnectionTimeoutException)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("testing invocation timeout... ");
            output.Flush();
            {
                timeout.IcePing(); // Makes sure a working connection is associated with the proxy
                Connection? connection = timeout.GetConnection();
                ITimeoutPrx?to         = timeout.Clone(invocationTimeout: 100);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.Sleep(1000);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }
                timeout.IcePing();
                to = timeout.Clone(invocationTimeout: 1000);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.Sleep(100);
                }
                catch (TimeoutException)
                {
                    TestHelper.Assert(false);
                }
                TestHelper.Assert(connection == to.GetConnection());
            }
            {
                //
                // Expect TimeoutException.
                //
                ITimeoutPrx to = timeout.Clone(invocationTimeout: 100);
                try
                {
                    to.SleepAsync(1000).Wait();
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                timeout.IcePing();
            }
            {
                // Expect success.
                ITimeoutPrx to = timeout.Clone(invocationTimeout: 1000);
                to.SleepAsync(100).Wait();
            }

            output.WriteLine("ok");

            output.Write("testing close timeout... ");
            output.Flush();
            {
                Dictionary <string, string> properties = communicator.GetProperties();
                properties["Ice.CloseTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), comm);

                Connection?connection  = to.GetConnection();
                Connection?connection2 = timeout.GetConnection();  // No close timeout

                TestHelper.Assert(connection != null && connection2 != null);

                controller.HoldAdapter(-1);

                // Make sure there's no ReadAsync pending
                _ = to.IcePingAsync();
                _ = timeout.IcePingAsync();

                var semaphore = new System.Threading.SemaphoreSlim(0);
                connection.Closed += (sender, args) => semaphore.Release();
                connection.Close(ConnectionClose.Gracefully);
                TestHelper.Assert(semaphore.Wait(500));

                connection2.Closed += (sender, args) => semaphore.Release();
                connection2.Close(ConnectionClose.Gracefully);
                TestHelper.Assert(!semaphore.Wait(500));

                controller.ResumeAdapter();
                timeout.Op(); // Ensure adapter is active.
            }
            output.WriteLine("ok");

            output.Write("testing invocation timeouts with collocated calls... ");
            output.Flush();
            {
                communicator.SetProperty("TimeoutCollocated.AdapterId", "timeoutAdapter");

                ObjectAdapter adapter = communicator.CreateObjectAdapter("TimeoutCollocated");
                adapter.Activate();

                ITimeoutPrx proxy =
                    adapter.AddWithUUID(new Timeout(), ITimeoutPrx.Factory).Clone(invocationTimeout: 100);
                try
                {
                    proxy.Sleep(500);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }

                try
                {
                    proxy.SleepAsync(500).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                adapter.Dispose();
            }
            output.WriteLine("ok");

            controller.Shutdown();
        }
예제 #16
0
 /// <summary>
 /// Uses the configured formatter to write the supplied <see cref="LogEvent"/> instance to the stream.
 /// </summary>
 /// <param name="logEvent">The <see cref="LogEvent"/> instance to write.</param>
 protected override void WriteEventInternal(LogEvent logEvent)
 {
     _LogEventFormatter.FormatToTextWriter(logEvent, _Writer);
     _Writer.Flush();
 }
예제 #17
0
        public static int Run(TestHelper helper)
        {
            //Communicator? communicator = helper.Communicator();

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing primitive types... ");
            output.Flush();

            // TODO rework this once the new streaming API is finished

            /*{
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation();
             *  ostr.WriteBool(true);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  test(istr.ReadBool());
             *  istr.EndEncapsulation();
             *
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  test(istr.ReadBool());
             *  istr.EndEncapsulation();
             * }
             *
             * {
             *  var data = new byte[0];
             *  istr = new InputStream(communicator, data);
             *  try
             *  {
             *      istr.ReadBool();
             *      test(false);
             *  }
             *  catch (System.ArgumentOutOfRangeException)
             *  {
             *  }
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteBool(true);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadBool());
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteByte(1);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadByte() == 1);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteShort(2);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadShort() == 2);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteInt(3);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadInt() == 3);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteLong(4);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadLong() == 4);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteFloat((float)5.0);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadFloat() == (float)5.0);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteDouble(6.0);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadDouble() == 6.0);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteString("hello world");
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  test(istr.ReadString().Equals("hello world"));
             * }
             *
             * output.WriteLine("ok");
             *
             * output.Write("testing constructed types... ");
             * output.Flush();
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(MyEnum.enum3);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  MyEnum e = istr.ReadMyEnum();
             *  test(e == MyEnum.enum3);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var s = new SmallStruct();
             *  s.bo = true;
             *  s.by = 1;
             *  s.sh = 2;
             *  s.i = 3;
             *  s.l = 4;
             *  s.f = 5.0f;
             *  s.d = 6.0;
             *  s.str = "7";
             *  s.e = MyEnum.enum2;
             *  s.p = IMyInterfacePrx.Parse("test:default", communicator);
             *  ostr.WriteStruct(s);
             *  var data = ostr.ToArray();
             *  var s2 = new SmallStruct(new InputStream(communicator, data));
             *  test(s2.Equals(s));
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var o = new ClassWithTaggedMembers();
             *  o.bo = true;
             *  o.by = 5;
             *  o.sh = 4;
             *  o.i = 3;
             *  // Can only read/write classes within encaps
             *  ostr.StartEncapsulation();
             *  ostr.WriteClass(o);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var o2 = istr.ReadClass<ClassWithTaggedMembers>();
             *  istr.EndEncapsulation();
             *  test(o2.bo == o.bo);
             *  test(o2.by == o.by);
             *  test(o2.sh == o.sh);
             *  test(o2.i == o.i);
             * }
             *
             * {
             *  bool[] arr = { true, false, true, false };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteBoolSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadBoolArray();
             *  test(Compare(arr2, arr));
             *
             *  bool[][] arrS = { arr, new bool[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadBoolSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  byte[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteByteSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadByteArray();
             *  test(Compare(arr2, arr));
             *
             *  byte[][] arrS = { arr, new byte[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadByteSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  var small = new Serialize.Small();
             *  small.i = 99;
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteSerializable(small);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var small2 = (Serialize.Small)istr.ReadSerializable();
             *  test(small2.i == 99);
             * }
             *
             * {
             *  short[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteShortSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadShortArray();
             *  test(Compare(arr2, arr));
             *
             *  short[][] arrS = { arr, new short[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadShortSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  int[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteIntSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadIntArray();
             *  test(Compare(arr2, arr));
             *
             *  int[][] arrS = { arr, new int[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadIntSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  long[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteLongSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadLongArray();
             *  test(Compare(arr2, arr));
             *
             *  long[][] arrS = { arr, new long[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadLongSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  float[] arr = { 1, 2, 3, 4 };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteFloatSeq(arr);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  float[] arr2 = istr.ReadFloatArray();
             *  test(Compare(arr2, arr));
             *
             *  float[][] arrS = { arr, new float[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadFloatSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  double[] arr =
             *      {
             *          1,
             *          2,
             *          3,
             *          4
             *      };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteDoubleSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadDoubleArray();
             *  test(Compare(arr2, arr));
             *
             *  double[][] arrS = { arr, new double[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadDoubleSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  string[] arr = { "string1", "string2", "string3", "string4" };
             *  ostr = new OutputStream(communicator);
             *  ostr.WriteStringSeq(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadStringArray();
             *  test(Compare(arr2, arr));
             *
             *  string[][] arrS = { arr, new string[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadStringSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * {
             *  MyEnum[] arr = {
             *      MyEnum.enum3,
             *      MyEnum.enum2,
             *      MyEnum.enum1,
             *      MyEnum.enum2
             *  };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arr);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2 = istr.ReadMyEnumS();
             *  test(Compare(arr2, arr));
             *
             *  MyEnum[][] arrS = { arr, new MyEnum[0], arr };
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(arrS);
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var arr2S = istr.ReadMyEnumSS();
             *  test(Compare(arr2S, arrS));
             * }
             *
             * var smallStructArray = new SmallStruct[3];
             * for (int i = 0; i < smallStructArray.Length; ++i)
             * {
             *  smallStructArray[i] = new SmallStruct();
             *  smallStructArray[i].bo = true;
             *  smallStructArray[i].by = 1;
             *  smallStructArray[i].sh = 2;
             *  smallStructArray[i].i = 3;
             *  smallStructArray[i].l = 4;
             *  smallStructArray[i].f = 5.0f;
             *  smallStructArray[i].d = 6.0;
             *  smallStructArray[i].str = "7";
             *  smallStructArray[i].e = MyEnum.enum2;
             *  smallStructArray[i].p = IMyInterfacePrx.Parse("test:default", communicator);
             * }
             *
             * var myClassArray = new MyClass[4];
             * for (int i = 0; i < myClassArray.Length; ++i)
             * {
             *  myClassArray[i] = new MyClass();
             *  myClassArray[i].c = myClassArray[i];
             *  myClassArray[i].o = myClassArray[i];
             *  myClassArray[i].s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null);
             *  myClassArray[i].s.e = MyEnum.enum2;
             *  myClassArray[i].seq1 = new bool[] { true, false, true, false };
             *  myClassArray[i].seq2 = new byte[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq3 = new short[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq4 = new int[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq5 = new long[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq6 = new float[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq7 = new double[] { 1, 2, 3, 4 };
             *  myClassArray[i].seq8 = new string[] { "string1", "string2", "string3", "string4" };
             *  myClassArray[i].seq9 = new MyEnum[] { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1 };
             *  myClassArray[i].seq10 = new MyClass[4]; // null elements.
             *  myClassArray[i].d = new Dictionary<string, MyClass>();
             *  myClassArray[i].d["hi"] = myClassArray[i];
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation();
             *  ostr.Write(myClassArray);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var arr2 = istr.ReadMyClassS();
             *  istr.EndEncapsulation();
             *  test(arr2.Length == myClassArray.Length);
             *  for (int i = 0; i < arr2.Length; ++i)
             *  {
             *      test(arr2[i] != null);
             *      test(arr2[i].c == arr2[i]);
             *      test(arr2[i].o == arr2[i]);
             *      test(arr2[i].s.e == MyEnum.enum2);
             *      test(Compare(arr2[i].seq1, myClassArray[i].seq1));
             *      test(Compare(arr2[i].seq2, myClassArray[i].seq2));
             *      test(Compare(arr2[i].seq3, myClassArray[i].seq3));
             *      test(Compare(arr2[i].seq4, myClassArray[i].seq4));
             *      test(Compare(arr2[i].seq5, myClassArray[i].seq5));
             *      test(Compare(arr2[i].seq6, myClassArray[i].seq6));
             *      test(Compare(arr2[i].seq7, myClassArray[i].seq7));
             *      test(Compare(arr2[i].seq8, myClassArray[i].seq8));
             *      test(Compare(arr2[i].seq9, myClassArray[i].seq9));
             *      test(arr2[i].d["hi"].Equals(arr2[i]));
             *  }
             *
             *  MyClass[][] arrS = { myClassArray, new MyClass[0], myClassArray };
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation();
             *  ostr.Write(arrS);
             *  ostr.EndEncapsulation();
             *  data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var arr2S = istr.ReadMyClassSS();
             *  istr.EndEncapsulation();
             *  test(arr2S.Length == arrS.Length);
             *  test(arr2S[0].Length == arrS[0].Length);
             *  test(arr2S[1].Length == arrS[1].Length);
             *  test(arr2S[2].Length == arrS[2].Length);
             *
             *  for (int j = 0; j < arr2S.Length; ++j)
             *  {
             *      for (int k = 0; k < arr2S[j].Length; ++k)
             *      {
             *          test(arr2S[j][k].c == arr2S[j][k]);
             *          test(arr2S[j][k].o == arr2S[j][k]);
             *          test(arr2S[j][k].s.e == MyEnum.enum2);
             *          test(Compare(arr2S[j][k].seq1, myClassArray[k].seq1));
             *          test(Compare(arr2S[j][k].seq2, myClassArray[k].seq2));
             *          test(Compare(arr2S[j][k].seq3, myClassArray[k].seq3));
             *          test(Compare(arr2S[j][k].seq4, myClassArray[k].seq4));
             *          test(Compare(arr2S[j][k].seq5, myClassArray[k].seq5));
             *          test(Compare(arr2S[j][k].seq6, myClassArray[k].seq6));
             *          test(Compare(arr2S[j][k].seq7, myClassArray[k].seq7));
             *          test(Compare(arr2S[j][k].seq8, myClassArray[k].seq8));
             *          test(Compare(arr2S[j][k].seq9, myClassArray[k].seq9));
             *          test(arr2S[j][k].d["hi"].Equals(arr2S[j][k]));
             *      }
             *  }
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var obj = new MyClass();
             *  obj.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null);
             *  obj.s.e = MyEnum.enum2;
             *  ostr.StartEncapsulation();
             *  ostr.WriteClass(obj);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var robj = istr.ReadClass<MyClass>();
             *  istr.EndEncapsulation();
             *  test(robj != null);
             *  test(robj.s.e == MyEnum.enum2);
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation(ostr.Encoding, FormatType.Sliced);
             *  var ex = new MyException();
             *
             *  var c = new MyClass();
             *  c.c = c;
             *  c.o = c;
             *  c.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null);
             *  c.s.e = MyEnum.enum2;
             *  c.seq1 = new bool[] { true, false, true, false };
             *  c.seq2 = new byte[] { 1, 2, 3, 4 };
             *  c.seq3 = new short[] { 1, 2, 3, 4 };
             *  c.seq4 = new int[] { 1, 2, 3, 4 };
             *  c.seq5 = new long[] { 1, 2, 3, 4 };
             *  c.seq6 = new float[] { 1, 2, 3, 4 };
             *  c.seq7 = new double[] { 1, 2, 3, 4 };
             *  c.seq8 = new string[] { "string1", "string2", "string3", "string4" };
             *  c.seq9 = new MyEnum[] { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1 };
             *  c.seq10 = new MyClass[4]; // null elements.
             *  c.d = new Dictionary<string, MyClass>();
             *  c.d.Add("hi", c);
             *
             *  ex.c = c;
             *
             *  ostr.WriteException(ex);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  try
             *  {
             *      istr.ThrowException();
             *      test(false);
             *  }
             *  catch (MyException ex1)
             *  {
             *      test(ex1.c.s.e == c.s.e);
             *      test(Compare(ex1.c.seq1, c.seq1));
             *      test(Compare(ex1.c.seq2, c.seq2));
             *      test(Compare(ex1.c.seq3, c.seq3));
             *      test(Compare(ex1.c.seq4, c.seq4));
             *      test(Compare(ex1.c.seq5, c.seq5));
             *      test(Compare(ex1.c.seq6, c.seq6));
             *      test(Compare(ex1.c.seq7, c.seq7));
             *      test(Compare(ex1.c.seq8, c.seq8));
             *      test(Compare(ex1.c.seq9, c.seq9));
             *  }
             *  catch (RemoteException)
             *  {
             *      test(false);
             *  }
             *  istr.EndEncapsulation();
             * }
             *
             * {
             *  var dict = new Dictionary<byte, bool>();
             *  dict.Add(4, true);
             *  dict.Add(1, false);
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(dict);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var dict2 = istr.ReadByteBoolD();
             *  test(Collections.Equals(dict2, dict));
             * }
             *
             * {
             *  var dict = new Dictionary<short, int>();
             *  dict.Add(1, 9);
             *  dict.Add(4, 8);
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(dict);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var dict2 = istr.ReadShortIntD();
             *  test(Collections.Equals(dict2, dict));
             * }
             *
             * {
             *  var dict = new Dictionary<long, float>();
             *  dict.Add(123809828, 0.51f);
             *  dict.Add(123809829, 0.56f);
             *  ostr = new OutputStream(communicator);
             *  ostr.Write(dict);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var dict2 = istr.ReadLongFloatD();
             *  test(Collections.Equals(dict2, dict));
             * }
             *
             * {
             *  var dict = new Dictionary<string, string>();
             *  dict.Add("key1", "value1");
             *  dict.Add("key2", "value2");
             *  ostr = new OutputStream(communicator);
             *  StringStringDHelper.Write(ostr, dict);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var dict2 = istr.ReadStringStringD();
             *  test(Collections.Equals(dict2, dict));
             * }
             *
             * {
             *  var dict = new Dictionary<string, MyClass>();
             *  var c = new MyClass();
             *  c.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null);
             *  c.s.e = MyEnum.enum2;
             *  dict.Add("key1", c);
             *  c = new MyClass();
             *  c.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null);
             *  c.s.e = MyEnum.enum3;
             *  dict.Add("key2", c);
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation();
             *  ostr.Write(dict);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var dict2 = istr.ReadStringMyClassD();
             *  istr.EndEncapsulation();
             *  test(dict2.Count == dict.Count);
             *  test(dict2["key1"].s.e == MyEnum.enum2);
             *  test(dict2["key2"].s.e == MyEnum.enum3);
             * }
             *
             * {
             *  bool[] arr = { true, false, true, false };
             *  ostr = new OutputStream(communicator);
             *  var l = new List<bool>(arr);
             *  ostr.StartEncapsulation();
             *  ostr.WriteBoolSeq(l);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var l2 = new List<bool>(istr.ReadBoolArray());
             *  istr.EndEncapsulation();
             *  test(Compare(l, l2));
             * }
             *
             * {
             *  byte[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  var l = new List<byte>(arr);
             *  ostr.WriteByteSeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new List<byte>(istr.ReadByteArray());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  MyEnum[] arr = { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1, MyEnum.enum2 };
             *  ostr = new OutputStream(communicator);
             *  var l = new List<MyEnum>(arr);
             *  ostr.Write(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadMyEnumList();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var l = new List<SmallStruct>(smallStructArray);
             *  ostr.Write(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadSmallStructList();
             *  test(l2.Count == l.Count);
             *  for (int i = 0; i < l2.Count; ++i)
             *  {
             *      test(l2[i].Equals(smallStructArray[i]));
             *  }
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  ostr.StartEncapsulation();
             *  var l = new List<MyClass>(myClassArray);
             *  ostr.Write(l);
             *  ostr.EndEncapsulation();
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  istr.StartEncapsulation();
             *  var l2 = istr.ReadMyClassList();
             *  istr.EndEncapsulation();
             *  test(l2.Count == l.Count);
             *  for (int i = 0; i < l2.Count; ++i)
             *  {
             *      test(l2[i] != null);
             *      test(l2[i].c == l2[i]);
             *      test(l2[i].o == l2[i]);
             *      test(l2[i].s.e == MyEnum.enum2);
             *      test(Compare(l2[i].seq1, l[i].seq1));
             *      test(Compare(l2[i].seq2, l[i].seq2));
             *      test(Compare(l2[i].seq3, l[i].seq3));
             *      test(Compare(l2[i].seq4, l[i].seq4));
             *      test(Compare(l2[i].seq5, l[i].seq5));
             *      test(Compare(l2[i].seq6, l[i].seq6));
             *      test(Compare(l2[i].seq7, l[i].seq7));
             *      test(Compare(l2[i].seq8, l[i].seq8));
             *      test(Compare(l2[i].seq9, l[i].seq9));
             *      test(l2[i].d["hi"].Equals(l2[i]));
             *  }
             * }
             *
             * {
             *  var arr = new IObjectPrx[2];
             *  arr[0] = IObjectPrx.Parse("zero", communicator);
             *  arr[1] = IObjectPrx.Parse("one", communicator);
             *  ostr = new OutputStream(communicator);
             *  var l = new List<IObjectPrx>(arr);
             *  ostr.Write(arr);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new List<IObjectPrx>(istr.ReadObjectProxySeq());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  var arr = new IMyInterfacePrx[2];
             *  arr[0] = IMyInterfacePrx.Parse("zero", communicator);
             *  arr[1] = IMyInterfacePrx.Parse("one", communicator);
             *  ostr = new OutputStream(communicator);
             *  var l = new List<IMyInterfacePrx>(arr);
             *  ostr.WriteProxySeq(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadMyInterfaceProxyList();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  short[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  var l = new LinkedList<short>(arr);
             *  ostr.WriteShortSeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new LinkedList<short>(istr.ReadShortArray());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  int[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  var l = new LinkedList<int>(arr);
             *  ostr.WriteIntSeq(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new LinkedList<int>(istr.ReadIntArray());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  MyEnum[] arr = { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1, MyEnum.enum2 };
             *  ostr = new OutputStream(communicator);
             *  var l = new LinkedList<MyEnum>(arr);
             *  ostr.Write(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadMyEnumLinkedList();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var l = new LinkedList<SmallStruct>(smallStructArray);
             *  ostr.Write(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadSmallStructLinkedList();
             *  test(l2.Count == l.Count);
             *  var e = l.GetEnumerator();
             *  var e2 = l2.GetEnumerator();
             *  while (e.MoveNext() && e2.MoveNext())
             *  {
             *      test(e.Current.Equals(e2.Current));
             *  }
             * }
             *
             * {
             *  long[] arr = { 0x01, 0x11, 0x12, 0x22 };
             *  ostr = new OutputStream(communicator);
             *  var l = new Stack<long>(arr);
             *  ostr.WriteLongSeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new Stack<long>(istr.ReadLongArray().Reverse());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  float[] arr = { 1, 2, 3, 4 };
             *  ostr = new OutputStream(communicator);
             *  var l = new Stack<float>(arr);
             *  ostr.WriteFloatSeq(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new Stack<float>(istr.ReadFloatArray().Reverse());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var l = new Stack<SmallStruct>(smallStructArray);
             *  ostr.Write(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadSmallStructStack();
             *  test(l2.Count == l.Count);
             *  var e = l.GetEnumerator();
             *  var e2 = l2.GetEnumerator();
             *  while (e.MoveNext() && e2.MoveNext())
             *  {
             *      test(e.Current.Equals(e2.Current));
             *  }
             * }
             *
             * {
             *  var arr = new IMyInterfacePrx[2];
             *  arr[0] = IMyInterfacePrx.Parse("zero", communicator);
             *  arr[1] = IMyInterfacePrx.Parse("one", communicator);
             *  ostr = new OutputStream(communicator);
             *  var l = new Stack<IMyInterfacePrx>(arr);
             *  ostr.WriteProxySeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadMyInterfaceProxyStack();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  double[] arr = { 1, 2, 3, 4 };
             *  ostr = new OutputStream(communicator);
             *  var l = new Queue<double>(arr);
             *  ostr.WriteDoubleSeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new Queue<double>(istr.ReadDoubleArray());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  string[] arr = { "string1", "string2", "string3", "string4" };
             *  ostr = new OutputStream(communicator);
             *  var l = new Queue<string>(arr);
             *  ostr.WriteStringSeq(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = new Queue<string>(istr.ReadStringCollection());
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  ostr = new OutputStream(communicator);
             *  var l = new Queue<SmallStruct>(smallStructArray);
             *  ostr.Write(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadSmallStructQueue();
             *  test(l2.Count == l.Count);
             *  var e = l.GetEnumerator();
             *  var e2 = l2.GetEnumerator();
             *  while (e.MoveNext() && e2.MoveNext())
             *  {
             *      test(e.Current.Equals(e2.Current));
             *  }
             * }
             *
             * {
             *  string[] arr = { "string1", "string2", "string3", "string4" };
             *  string[][] arrS = { arr, new string[0], arr };
             *  ostr = new OutputStream(communicator);
             *  var l = new List<string[]>(arrS);
             *  ostr.Write(l);
             *  byte[] data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadStringSList();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  string[] arr = { "string1", "string2", "string3", "string4" };
             *  string[][] arrS = { arr, new string[0], arr };
             *  ostr = new OutputStream(communicator);
             *  var l = new Stack<string[]>(arrS);
             *  ostr.Write(l);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var l2 = istr.ReadStringSStack();
             *  test(Compare(l2, l));
             * }
             *
             * {
             *  var dict = new SortedDictionary<string, string>();
             *  dict.Add("key1", "value1");
             *  dict.Add("key2", "value2");
             *  ostr = new OutputStream(communicator);
             *  Ice.ContextHelper.Write(ostr, dict);
             *  var data = ostr.ToArray();
             *  istr = new InputStream(communicator, data);
             *  var dict2 = istr.ReadSortedStringStringD();
             *  test(Collections.Equals(dict2, dict));
             * }*/

            output.WriteLine("ok");
            return(0);
        }
예제 #18
0
        public static Test.ITestIntfPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            string sref = "test:" + helper.GetTestEndpoint(0);
            var    obj  = IObjectPrx.Parse(sref, communicator);

            TestHelper.Assert(obj != null);
            var proxy = Test.ITestIntfPrx.UncheckedCast(obj);

            TestHelper.Assert(proxy != null);

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing enum values... ");
            output.Flush();

            TestHelper.Assert((int)Test.ByteEnum.benum1 == 0);
            TestHelper.Assert((int)Test.ByteEnum.benum2 == 1);
            TestHelper.Assert((int)Test.ByteEnum.benum3 == Test.ByteConst1.value);
            TestHelper.Assert((int)Test.ByteEnum.benum4 == Test.ByteConst1.value + 1);
            TestHelper.Assert((int)Test.ByteEnum.benum5 == Test.ShortConst1.value);
            TestHelper.Assert((int)Test.ByteEnum.benum6 == Test.ShortConst1.value + 1);
            TestHelper.Assert((int)Test.ByteEnum.benum7 == Test.IntConst1.value);
            TestHelper.Assert((int)Test.ByteEnum.benum8 == Test.IntConst1.value + 1);
            TestHelper.Assert((int)Test.ByteEnum.benum9 == Test.LongConst1.value);
            TestHelper.Assert((int)Test.ByteEnum.benum10 == Test.LongConst1.value + 1);
            TestHelper.Assert((int)Test.ByteEnum.benum11 == Test.ByteConst2.value);

            TestHelper.Assert((int)Test.ShortEnum.senum1 == 3);
            TestHelper.Assert((int)Test.ShortEnum.senum2 == 4);
            TestHelper.Assert((int)Test.ShortEnum.senum3 == Test.ByteConst1.value);
            TestHelper.Assert((int)Test.ShortEnum.senum4 == Test.ByteConst1.value + 1);
            TestHelper.Assert((int)Test.ShortEnum.senum5 == Test.ShortConst1.value);
            TestHelper.Assert((int)Test.ShortEnum.senum6 == Test.ShortConst1.value + 1);
            TestHelper.Assert((int)Test.ShortEnum.senum7 == Test.IntConst1.value);
            TestHelper.Assert((int)Test.ShortEnum.senum8 == Test.IntConst1.value + 1);
            TestHelper.Assert((int)Test.ShortEnum.senum9 == Test.LongConst1.value);
            TestHelper.Assert((int)Test.ShortEnum.senum10 == Test.LongConst1.value + 1);
            TestHelper.Assert((int)Test.ShortEnum.senum11 == Test.ShortConst2.value);

            TestHelper.Assert((int)Test.IntEnum.ienum1 == 0);
            TestHelper.Assert((int)Test.IntEnum.ienum2 == 1);
            TestHelper.Assert((int)Test.IntEnum.ienum3 == Test.ByteConst1.value);
            TestHelper.Assert((int)Test.IntEnum.ienum4 == Test.ByteConst1.value + 1);
            TestHelper.Assert((int)Test.IntEnum.ienum5 == Test.ShortConst1.value);
            TestHelper.Assert((int)Test.IntEnum.ienum6 == Test.ShortConst1.value + 1);
            TestHelper.Assert((int)Test.IntEnum.ienum7 == Test.IntConst1.value);
            TestHelper.Assert((int)Test.IntEnum.ienum8 == Test.IntConst1.value + 1);
            TestHelper.Assert((int)Test.IntEnum.ienum9 == Test.LongConst1.value);
            TestHelper.Assert((int)Test.IntEnum.ienum10 == Test.LongConst1.value + 1);
            TestHelper.Assert((int)Test.IntEnum.ienum11 == Test.IntConst2.value);
            TestHelper.Assert((int)Test.IntEnum.ienum12 == Test.LongConst2.value);

            TestHelper.Assert((int)Test.SimpleEnum.red == 0);
            TestHelper.Assert((int)Test.SimpleEnum.green == 1);
            TestHelper.Assert((int)Test.SimpleEnum.blue == 2);

            output.WriteLine("ok");

            output.Write("testing enum operations... ");
            output.Flush();
            {
                (Test.ByteEnum r, Test.ByteEnum o) = proxy.opByte(Test.ByteEnum.benum1);
                TestHelper.Assert(r == Test.ByteEnum.benum1 && o == Test.ByteEnum.benum1);
                (r, o) = proxy.opByte(Test.ByteEnum.benum11);
                TestHelper.Assert(r == Test.ByteEnum.benum11 && o == Test.ByteEnum.benum11);
            }

            {
                (Test.ShortEnum r, Test.ShortEnum o) = proxy.opShort(Test.ShortEnum.senum1);
                TestHelper.Assert(r == Test.ShortEnum.senum1 && o == Test.ShortEnum.senum1);
                (r, o) = proxy.opShort(Test.ShortEnum.senum11);
                TestHelper.Assert(r == Test.ShortEnum.senum11 && o == Test.ShortEnum.senum11);
            }

            {
                (Test.IntEnum r, Test.IntEnum o) = proxy.opInt(Test.IntEnum.ienum1);
                TestHelper.Assert(r == Test.IntEnum.ienum1 && o == Test.IntEnum.ienum1);
                (r, o) = proxy.opInt(Test.IntEnum.ienum11);
                TestHelper.Assert(r == Test.IntEnum.ienum11 && o == Test.IntEnum.ienum11);
                (r, o) = proxy.opInt(Test.IntEnum.ienum12);
                TestHelper.Assert(r == Test.IntEnum.ienum12 && o == Test.IntEnum.ienum12);
            }

            {
                (Test.SimpleEnum r, Test.SimpleEnum o) = proxy.opSimple(Test.SimpleEnum.green);
                TestHelper.Assert(r == Test.SimpleEnum.green && o == Test.SimpleEnum.green);
            }

            output.WriteLine("ok");

            output.Write("testing enum sequences operations... ");
            output.Flush();

            {
                var b1 = new Test.ByteEnum[11]
                {
                    Test.ByteEnum.benum1,
                    Test.ByteEnum.benum2,
                    Test.ByteEnum.benum3,
                    Test.ByteEnum.benum4,
                    Test.ByteEnum.benum5,
                    Test.ByteEnum.benum6,
                    Test.ByteEnum.benum7,
                    Test.ByteEnum.benum8,
                    Test.ByteEnum.benum9,
                    Test.ByteEnum.benum10,
                    Test.ByteEnum.benum11
                };

                (Test.ByteEnum[] b3, Test.ByteEnum[] b2) = proxy.opByteSeq(b1);

                for (int i = 0; i < b1.Length; ++i)
                {
                    TestHelper.Assert(b1[i] == b2[i]);
                    TestHelper.Assert(b1[i] == b3[i]);
                }
            }

            {
                var s1 = new Test.ShortEnum[11]
                {
                    Test.ShortEnum.senum1,
                    Test.ShortEnum.senum2,
                    Test.ShortEnum.senum3,
                    Test.ShortEnum.senum4,
                    Test.ShortEnum.senum5,
                    Test.ShortEnum.senum6,
                    Test.ShortEnum.senum7,
                    Test.ShortEnum.senum8,
                    Test.ShortEnum.senum9,
                    Test.ShortEnum.senum10,
                    Test.ShortEnum.senum11
                };

                (Test.ShortEnum[] s3, Test.ShortEnum[] s2) = proxy.opShortSeq(s1);

                for (int i = 0; i < s1.Length; ++i)
                {
                    TestHelper.Assert(s1[i] == s2[i]);
                    TestHelper.Assert(s1[i] == s3[i]);
                }
            }

            {
                var i1 = new Test.IntEnum[11]
                {
                    Test.IntEnum.ienum1,
                    Test.IntEnum.ienum2,
                    Test.IntEnum.ienum3,
                    Test.IntEnum.ienum4,
                    Test.IntEnum.ienum5,
                    Test.IntEnum.ienum6,
                    Test.IntEnum.ienum7,
                    Test.IntEnum.ienum8,
                    Test.IntEnum.ienum9,
                    Test.IntEnum.ienum10,
                    Test.IntEnum.ienum11
                };

                (Test.IntEnum[] i3, Test.IntEnum[] i2) = proxy.opIntSeq(i1);

                for (int i = 0; i < i1.Length; ++i)
                {
                    TestHelper.Assert(i1[i] == i2[i]);
                    TestHelper.Assert(i1[i] == i3[i]);
                }
            }

            {
                var s1 = new Test.SimpleEnum[3]
                {
                    Test.SimpleEnum.red,
                    Test.SimpleEnum.green,
                    Test.SimpleEnum.blue
                };

                (Test.SimpleEnum[] s3, Test.SimpleEnum[] s2) = proxy.opSimpleSeq(s1);

                for (int i = 0; i < s1.Length; ++i)
                {
                    TestHelper.Assert(s1[i] == s2[i]);
                    TestHelper.Assert(s1[i] == s3[i]);
                }
            }

            output.WriteLine("ok");
            return(proxy);
        }
예제 #19
0
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;
            bool         ice1         = helper.Protocol == Protocol.Ice1;

            TestHelper.Assert(communicator != null);
            var    com           = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator);
            string testTransport = helper.Transport;

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

            System.IO.TextWriter output = helper.Output;

            output.Write("testing binding with single endpoint... ");
            output.Flush();
            {
                // Use "default" here to ensure that it still works
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default");
                TestHelper.Assert(adapter != null);
                ITestIntfPrx?test1 = adapter.GetTestIntf();
                ITestIntfPrx?test2 = adapter.GetTestIntf();
                TestHelper.Assert(test1 != null && test2 != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

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

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                TestHelper.Assert(test3.GetConnection() == test2.GetConnection());

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

            output.Write("testing binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter11", testTransport) !,
                    com.CreateObjectAdapter("Adapter12", testTransport) !,
                    com.CreateObjectAdapter("Adapter13", testTransport) !
                };

                // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are
                // eventually tried.
                var names = new List <string>
                {
                    "Adapter11",
                    "Adapter12",
                    "Adapter13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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 (IRemoteObjectAdapterPrx adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = t.GetAdapterName();

                    for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++)
                    {
                        TestHelper.Assert(t.GetAdapterName() == name);
                    }

                    foreach (IRemoteObjectAdapterPrx 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("Adapter12");
                names.Add("Adapter13");
                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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(adapters[2]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12"));

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

            output.Write("testing binding with multiple random endpoints... ");
            output.Flush();
            {
                var adapters = new IRemoteObjectAdapterPrx[5]
                {
                    com.CreateObjectAdapter("AdapterRandom11", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom12", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom13", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom14", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom15", testTransport) !
                };

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

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

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

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

                    foreach (IRemoteObjectAdapterPrx a in adapters)
                    {
                        try
                        {
                            a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                        catch
                        {
                            // Expected if adapter is down.
                        }
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple endpoints and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI11", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI12", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI13", testTransport) !
                };

                //
                // Ensure that when a connection is opened it's reused for new
                // proxies and that all endpoints are eventually tried.
                //
                var names = new List <string>
                {
                    "AdapterAMI11",
                    "AdapterAMI12",
                    "AdapterAMI13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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 (IRemoteObjectAdapterPrx?adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = GetAdapterNameWithAMI(t);

                    for (int i = 0; i < 10; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(t) == name);
                    }

                    foreach (IRemoteObjectAdapterPrx?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 <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

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

            output.Write("testing random endpoint selection... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter21", testTransport) !,
                    com.CreateObjectAdapter("Adapter22", testTransport) !,
                    com.CreateObjectAdapter("Adapter23", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random);

                var names = new List <string>
                {
                    "Adapter21",
                    "Adapter22",
                    "Adapter23"
                };

                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                obj = obj.Clone(endpointSelection: EndpointSelectionType.Random);
                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter31", testTransport) !,
                    com.CreateObjectAdapter("Adapter32", testTransport) !,
                    com.CreateObjectAdapter("Adapter33", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);

                // Ensure that endpoints are tried in order by deactivating the adapters
                // one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter31");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter32");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter33");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter36", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter36");
                    }
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter35", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter35");
                    }
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter34", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter34");
                    }
                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with single endpoint... ");
            output.Flush();
            {
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport);
                TestHelper.Assert(adapter != null);
                ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                TestHelper.Assert(!test1.IsConnectionCached);
                TestHelper.Assert(!test2.IsConnectionCached);
                TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                try
                {
                    TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter51", testTransport) !,
                    com.CreateObjectAdapter("Adapter52", testTransport) !,
                    com.CreateObjectAdapter("Adapter53", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "Adapter51",
                    "Adapter52",
                    "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]);

                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI51", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI52", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI53", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "AdapterAMI51",
                    "AdapterAMI52",
                    "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]);

                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter61", testTransport) !,
                    com.CreateObjectAdapter("Adapter62", testTransport) !,
                    com.CreateObjectAdapter("Adapter63", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (helper.Protocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter64");
                    }

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

            output.Write("testing per request binding and ordered endpoint selection and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI61", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI62", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI63", testTransport) !
                };

                ITestIntfPrx?obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (helper.Protocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64");
                    }
                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            if (helper.Protocol == Protocol.Ice1)
            {
                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter71", testTransport),
                        com.CreateObjectAdapter("Adapter72", "udp")
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                    TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71"));

                    ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram);
                    TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection());
                    try
                    {
                        testUDP.GetAdapterName();
                        TestHelper.Assert(false);
                    }
                    catch (InvalidOperationException)
                    {
                        // expected
                    }
                }
                output.WriteLine("ok");
            }
            if (communicator.GetProperty("Ice.Plugin.IceSSL") != null)
            {
                output.Write("testing secure and non-secure endpoints... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter81", "ssl") !,
                        com.CreateObjectAdapter("Adapter82", "tcp") !
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true);
                    // TODO: update when PreferNonSecure default is updated
                    ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false);
                    TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection());
                    TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection());

                    com.DeactivateObjectAdapter(adapters[1]);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                    if (helper.Protocol == Protocol.Ice1)
                    {
                        com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA.

                        for (int i = 0; i < 5; i++)
                        {
                            TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83"));
                            obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                    }

                    com.DeactivateObjectAdapter(adapters[0]);

                    try
                    {
                        testSecure.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // expected
                    }
                    Deactivate(com, adapters);
                }
                output.WriteLine("ok");
            }

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

                var ipv4 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "0" }
                };

                var ipv6 = new Dictionary <string, string>()
                {
                    { "IPv4", "0" },
                    { "IPv6", "1" }
                };

                var bothPreferIPv4 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "PreferIPv6Address", "0" }
                };

                var bothPreferIPv6 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "PreferIPv6Address", "1" }
                };

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

                Func <string, string> getEndpoint = host =>
                                                    TestHelper.GetTestEndpoint(new Dictionary <string, string>(communicator.GetProperties())
                {
                    ["Test.Host"] = host
                },
                                                                               2,
                                                                               "tcp");

                var anyipv4 = new Dictionary <string, string>(ipv4)
                {
                    ["Adapter.Endpoints"]          = getEndpoint("0.0.0.0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1")
                };

                var anyipv6 = new Dictionary <string, string>(ipv6)
                {
                    ["Adapter.Endpoints"]          = getEndpoint("::0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("::1")
                };

                var anyboth = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "Adapter.Endpoints", getEndpoint("::0") },
                    { "Adapter.PublishedEndpoints", getEndpoint("localhost") }
                };

                var localipv4 = new Dictionary <string, string>(ipv4)
                {
                    ["Adapter.Endpoints"] = getEndpoint("127.0.0.1")
                };

                var localipv6 = new Dictionary <string, string>(ipv6)
                {
                    ["Adapter.Endpoints"] = getEndpoint("::1")
                };

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

                bool ipv6NotSupported = false;
                foreach (Dictionary <string, string> p in serverProps)
                {
                    var           serverCommunicator = new Communicator(p);
                    ObjectAdapter oa;
                    try
                    {
                        oa = serverCommunicator.CreateObjectAdapter("Adapter");
                        oa.Activate();
                    }
                    catch (DNSException)
                    {
                        serverCommunicator.Dispose();
                        continue; // IP version not supported.
                    }
                    catch (TransportException)
                    {
                        if (p == ipv6)
                        {
                            ipv6NotSupported = true;
                        }
                        serverCommunicator.Dispose();
                        continue; // IP version not supported.
                    }

                    IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                    try
                    {
                        prx.IcePing();
                    }
                    catch (DNSException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Dispose();
                        continue;
                    }
                    catch (ObjectNotExistException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Dispose();
                        continue;
                    }

                    string strPrx = prx.ToString() !;
                    foreach (Dictionary <string, string> q in clientProps)
                    {
                        var clientCommunicator = new Communicator(q);
                        prx = IObjectPrx.Parse(strPrx, clientCommunicator);
                        try
                        {
                            prx.IcePing();
                            TestHelper.Assert(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 (TransportException)
                        {
                            TestHelper.Assert((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.Dispose();
                    }
                    serverCommunicator.Dispose();
                }

                output.WriteLine("ok");
            }

            com.Shutdown();
        }
예제 #20
0
 public override void FlushAndClose()
 {
     writer.Flush();
     writer.Close();
 }
예제 #21
0
파일: Logger.cs 프로젝트: wpmyj/Zhuangkao
 public static void Log(string str)
 {
     sw.WriteLine(str);
     sw.Flush();
 }
예제 #22
0
        private void runTest(IMyObjectPrx prx, Interceptor interceptor)
        {
            System.IO.TextWriter output = GetWriter();
            output.Write("testing simple interceptor... ");
            output.Flush();
            Assert(interceptor.getLastOperation() == null);
            Assert(!interceptor.AsyncCompletion);
            prx.IcePing();
            Assert(interceptor.getLastOperation() !.Equals("ice_ping"));
            Assert(!interceptor.AsyncCompletion);
            string typeId = prx.IceId();

            Assert(interceptor.getLastOperation() !.Equals("ice_id"));
            Assert(!interceptor.AsyncCompletion);
            Assert(prx.IceIsA(typeId));
            Assert(interceptor.getLastOperation() !.Equals("ice_isA"));
            Assert(!interceptor.AsyncCompletion);
            Assert(prx.add(33, 12) == 45);
            Assert(interceptor.getLastOperation() !.Equals("add"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing retry... ");
            output.Flush();
            Assert(prx.addWithRetry(33, 12) == 45);
            Assert(interceptor.getLastOperation() !.Equals("addWithRetry"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing remote exception... ");
            output.Flush();
            try
            {
                prx.badAdd(33, 12);
                Assert(false);
            }
            catch (InvalidInputException)
            {
                // expected
            }
            Assert(interceptor.getLastOperation() !.Equals("badAdd"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing ONE... ");
            output.Flush();
            interceptor.clear();
            try
            {
                prx.notExistAdd(33, 12);
                Assert(false);
            }
            catch (ObjectNotExistException)
            {
                // expected
            }
            Assert(interceptor.getLastOperation() !.Equals("notExistAdd"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");

            output.Write("testing exceptions raised by the interceptor... ");
            output.Flush();
            TestInterceptorExceptions(prx);
            output.WriteLine("ok");
        }
예제 #23
0
파일: AllTests.cs 프로젝트: lmf07120057/ice
        public static Test.IMyClassPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing stringToProxy... ");
            output.Flush();
            string rf        = "test:" + helper.GetTestEndpoint(0);
            var    baseProxy = IObjectPrx.Parse(rf, communicator);

            TestHelper.Assert(baseProxy != null);

            IObjectPrx?b1;

            b1 = IObjectPrx.Parse("test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.AdapterId.Length == 0 && b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse("test ", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse(" test ", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse(" test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse("'test -f facet'", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            try
            {
                b1 = IObjectPrx.Parse("\"test -f facet'", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("\"test -f facet\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test -f facet@test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            b1 = IObjectPrx.Parse("\"test -f facet@test @test\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test -f facet@test @test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Length == 0);
            try
            {
                b1 = IObjectPrx.Parse("test test", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("test\\040test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test test") && b1.Identity.Category.Length == 0);
            try
            {
                b1 = IObjectPrx.Parse("test\\777", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("test\\40test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test test"));

            // Test some octal and hex corner cases.
            b1 = IObjectPrx.Parse("test\\4test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test"));
            b1 = IObjectPrx.Parse("test\\04test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test"));
            b1 = IObjectPrx.Parse("test\\004test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test"));
            b1 = IObjectPrx.Parse("test\\1114test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test\u00494test"));

            b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test\b\f\n\r\t\'\"\\test") && b1.Identity.Category.Length == 0);

            b1 = IObjectPrx.Parse("category/test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") &&
                              b1.AdapterId.Length == 0);

            b1 = IObjectPrx.Parse("test:tcp --sourceAddress \"::1\"", communicator);
            TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator)));

            b1 = IObjectPrx.Parse("test:udp --sourceAddress \"::1\" --interface \"0:0:0:0:0:0:0:1%lo\"", communicator);
            TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator)));

            try
            {
                b1 = IObjectPrx.Parse("", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                b1 = IObjectPrx.Parse("\"\"", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                b1 = IObjectPrx.Parse("\"\" test", communicator); // Invalid trailing characters.
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                b1 = IObjectPrx.Parse("test:", communicator); // Missing endpoint.
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            b1 = IObjectPrx.Parse("test@adapter", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.AdapterId.Equals("adapter"));
            try
            {
                b1 = IObjectPrx.Parse("id@adapter test", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("category/test@adapter", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") &&
                              b1.AdapterId.Equals("adapter"));
            b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") &&
                              b1.AdapterId.Equals("adapter:tcp"));
            b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category 1") &&
                              b1.AdapterId.Equals("adapter"));
            b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test 1") && b1.Identity.Category.Equals("category") &&
                              b1.AdapterId.Equals("adapter"));
            b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") &&
                              b1.AdapterId.Equals("adapter 1"));
            b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") &&
                              b1.AdapterId.Equals("adapter"));
            b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@\"adapter:tcp\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") &&
                              b1.AdapterId.Equals("adapter:tcp"));

            b1 = IObjectPrx.Parse("id -f facet", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet"));
            b1 = IObjectPrx.Parse("id -f 'facet x'", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet x"));
            b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet x"));
            try
            {
                b1 = IObjectPrx.Parse("id -f \"facet x", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            try
            {
                b1 = IObjectPrx.Parse("id -f \'facet x", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("test -f facet:tcp", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet") && b1.AdapterId.Length == 0);
            b1 = IObjectPrx.Parse("test -f \"facet:tcp\"", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet:tcp") && b1.AdapterId.Length == 0);
            b1 = IObjectPrx.Parse("test -f facet@test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet") && b1.AdapterId.Equals("test"));
            b1 = IObjectPrx.Parse("test -f 'facet@test'", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet@test") && b1.AdapterId.Length == 0);
            b1 = IObjectPrx.Parse("test -f 'facet@test'@test", communicator);
            TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.Facet.Equals("facet@test") && b1.AdapterId.Equals("test"));
            try
            {
                b1 = IObjectPrx.Parse("test -f facet@test @test", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            b1 = IObjectPrx.Parse("test", communicator);
            TestHelper.Assert(!b1.IsOneway);
            b1 = IObjectPrx.Parse("test -t", communicator);
            TestHelper.Assert(!b1.IsOneway);
            b1 = IObjectPrx.Parse("test -o", communicator);
            TestHelper.Assert(b1.IsOneway);
            b1 = IObjectPrx.Parse("test -O", communicator);
            TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchOneway);
            b1 = IObjectPrx.Parse("test -d", communicator);
            TestHelper.Assert(b1.InvocationMode == InvocationMode.Datagram);
            b1 = IObjectPrx.Parse("test -D", communicator);
            TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchDatagram);
            b1 = IObjectPrx.Parse("test", communicator);

            TestHelper.Assert(b1.Encoding.Equals(Encoding.Latest));

            b1 = IObjectPrx.Parse("test -e 1.0", communicator);
            TestHelper.Assert(b1.Encoding.Major == 1 && b1.Encoding.Minor == 0);

            b1 = IObjectPrx.Parse("test -e 6.5", communicator);
            TestHelper.Assert(b1.Encoding.Major == 6 && b1.Encoding.Minor == 5);

            b1 = IObjectPrx.Parse("test -p ice1 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice1 -e 1.0"));

            b1 = IObjectPrx.Parse("test -p 1.0 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice1 -e 1.0"));

            b1 = IObjectPrx.Parse("test -p ice2 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice2 -e 1.0"));

            b1 = IObjectPrx.Parse("test -p 2.0 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice2 -e 1.0"));

            b1 = IObjectPrx.Parse("test -p 6 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p 6 -e 1.0"));

            b1 = IObjectPrx.Parse("test -p 6.0 -e 1.0", communicator);
            TestHelper.Assert(b1.ToString() !.Equals("test -t -p 6 -e 1.0"));

            try
            {
                IObjectPrx.Parse("test:tcp@adapterId", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }
            // This is an unknown endpoint warning, not a parse exception.
            //
            //try
            //{
            //   b1 = communicator.stringToProxy("test -f the:facet:tcp");
            //   TestHelper.Assert(false);
            //}
            //catch(EndpointParseException)
            //{
            //}
            try
            {
                IObjectPrx.Parse("test: :tcp", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            //
            // Test invalid endpoint syntax
            //
            try
            {
                communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : ");
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: ");
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp");
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            //
            // Test for bug ICE-5543: escaped escapes in stringToIdentity
            //
            var id  = new Identity("test", ",X2QNUAzSBcJ_e$AV;E\\");
            var id2 = Identity.Parse(id.ToString(communicator.ToStringMode));

            TestHelper.Assert(id.Equals(id2));

            id  = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\");
            id2 = Identity.Parse(id.ToString(communicator.ToStringMode));
            TestHelper.Assert(id.Equals(id2));

            id = new Identity("/test", "cat/");
            string idStr = id.ToString(communicator.ToStringMode);

            TestHelper.Assert(idStr == "cat\\//\\/test");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));

            // Input string with various pitfalls
            id = Identity.Parse("\\342\\x82\\254\\60\\x9\\60\\");
            TestHelper.Assert(id.Name == "€0\t0\\" && id.Category == "");

            try
            {
                // Illegal character < 32
                id = Identity.Parse("xx\01FooBar");
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Illegal surrogate
                id = Identity.Parse("xx\\ud911");
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            // Testing bytes 127(\x7F, \177) and €
            id = new Identity("test", "\x7f€");

            idStr = id.ToString(ToStringMode.Unicode);
            TestHelper.Assert(idStr == "\\u007f€/test");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));
            TestHelper.Assert(id.ToString() == idStr);

            idStr = id.ToString(ToStringMode.ASCII);
            TestHelper.Assert(idStr == "\\u007f\\u20ac/test");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));

            idStr = id.ToString(ToStringMode.Compat);
            TestHelper.Assert(idStr == "\\177\\342\\202\\254/test");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));

            id2 = Identity.Parse(id.ToString(communicator.ToStringMode));
            TestHelper.Assert(id.Equals(id2));

            // More unicode character
            id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a");

            idStr = id.ToString(ToStringMode.Unicode);
            TestHelper.Assert(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));

            idStr = id.ToString(ToStringMode.ASCII);
            TestHelper.Assert(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$");
            id2 = Identity.Parse(idStr);
            TestHelper.Assert(id.Equals(id2));

            idStr = id.ToString(ToStringMode.Compat);
            id2   = Identity.Parse(idStr);
            TestHelper.Assert(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$");
            TestHelper.Assert(id.Equals(id2));

            output.WriteLine("ok");

            output.Write("testing proxyToString... ");
            output.Flush();
            b1 = IObjectPrx.Parse(rf, communicator);
            var b2 = IObjectPrx.Parse(b1.ToString() !, communicator);

            TestHelper.Assert(b1.Equals(b2));

            if (b1.GetConnection() != null) // not colloc-optimized target
            {
                b2 = b1.GetConnection().CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory);
                TestHelper.Assert(b2.ToString() == b2.ToString());
            }
            output.WriteLine("ok");

            output.Write("testing propertyToProxy... ");
            output.Flush();

            string propertyPrefix = "Foo.Proxy";

            communicator.SetProperty(propertyPrefix, "test:" + helper.GetTestEndpoint(0));
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null &&
                              b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 &&
                              b1.AdapterId.Length == 0 && b1.Facet.Length == 0);

            string property;

            property = propertyPrefix + ".Locator";
            TestHelper.Assert(b1.Locator == null);
            communicator.SetProperty(property, "locator:default -p 10000");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator"));
            communicator.SetProperty(property, "");
            property = propertyPrefix + ".LocatorCacheTimeout";
            TestHelper.Assert(b1.LocatorCacheTimeout == -1);
            communicator.SetProperty(property, "1");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.LocatorCacheTimeout == 1);
            communicator.SetProperty(property, "");

            // Now retest with an indirect proxy.
            communicator.SetProperty(propertyPrefix, "test");
            property = propertyPrefix + ".Locator";
            communicator.SetProperty(property, "locator:default -p 10000");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator"));
            communicator.SetProperty(property, "");

            property = propertyPrefix + ".LocatorCacheTimeout";
            TestHelper.Assert(b1.LocatorCacheTimeout == -1);
            communicator.SetProperty(property, "1");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.LocatorCacheTimeout == 1);
            communicator.SetProperty(property, "");

            // This cannot be tested so easily because the property is cached
            // on communicator initialization.
            //
            //communicator.SetProperty("Default.LocatorCacheTimeout", "60");
            //b1 = communicator.propertyToProxy(propertyPrefix);
            //TestHelper.Assert(b1.LocatorCacheTimeout == 60);
            //communicator.SetProperty("Default.LocatorCacheTimeout", "");

            communicator.SetProperty(propertyPrefix, "test:" + helper.GetTestEndpoint(0));

            property = propertyPrefix + ".Router";
            TestHelper.Assert(b1.Router == null);
            communicator.SetProperty(property, "router:default -p 10000");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.Router != null && b1.Router.Identity.Name.Equals("router"));
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".PreferNonSecure";
            TestHelper.Assert(b1.PreferNonSecure);
            communicator.SetProperty(property, "0");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && !b1.PreferNonSecure);
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".ConnectionCached";
            TestHelper.Assert(b1.IsConnectionCached);
            communicator.SetProperty(property, "0");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && !b1.IsConnectionCached);
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".InvocationTimeout";
            TestHelper.Assert(b1.InvocationTimeout == -1);
            communicator.SetProperty(property, "1000");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.InvocationTimeout == 1000);
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".EndpointSelection";
            TestHelper.Assert(b1.EndpointSelection == EndpointSelectionType.Random);
            communicator.SetProperty(property, "Random");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.EndpointSelection == EndpointSelectionType.Random);
            communicator.SetProperty(property, "Ordered");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.EndpointSelection == EndpointSelectionType.Ordered);
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".CollocationOptimized";
            TestHelper.Assert(b1.IsCollocationOptimized);
            communicator.SetProperty(property, "0");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && !b1.IsCollocationOptimized);
            communicator.RemoveProperty(property);

            property = propertyPrefix + ".Context.c1";
            TestHelper.Assert(!b1.Context.ContainsKey("c1"));
            communicator.SetProperty(property, "TEST");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.Context["c1"].Equals("TEST"));

            property = propertyPrefix + ".Context.c2";
            TestHelper.Assert(!b1.Context.ContainsKey("c2"));
            communicator.SetProperty(property, "TEST");
            b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory);
            TestHelper.Assert(b1 != null && b1.Context["c2"].Equals("TEST"));

            communicator.SetProperty(propertyPrefix + ".Context.c1", "");
            communicator.SetProperty(propertyPrefix + ".Context.c2", "");

            output.WriteLine("ok");

            output.Write("testing proxyToProperty... ");
            output.Flush();

            var router = IRouterPrx.Parse("router", communicator).Clone(
                collocationOptimized: false,
                cacheConnection: true,
                preferNonSecure: true,
                endpointSelection: EndpointSelectionType.Random,
                locatorCacheTimeout: 200,
                invocationTimeout: 1500);

            var locator = ILocatorPrx.Parse("locator", communicator).Clone(
                collocationOptimized: true,
                cacheConnection: false,
                preferNonSecure: true,
                endpointSelection: EndpointSelectionType.Random,
                locatorCacheTimeout: 300,
                invocationTimeout: 1500,
                router: router);

            b1 = IObjectPrx.Parse("test", communicator).Clone(
                collocationOptimized: true,
                cacheConnection: true,
                preferNonSecure: false,
                endpointSelection: EndpointSelectionType.Ordered,
                locatorCacheTimeout: 100,
                invocationTimeout: 1234,
                encoding: Encoding.V2_0,
                locator: locator);

            Dictionary <string, string> proxyProps = b1.ToProperty("Test");

            TestHelper.Assert(proxyProps.Count == 21);

            TestHelper.Assert(proxyProps["Test"].Equals("test -t -p ice1 -e 2.0"));
            TestHelper.Assert(proxyProps["Test.CollocationOptimized"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.ConnectionCached"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.PreferNonSecure"].Equals("0"));
            TestHelper.Assert(proxyProps["Test.EndpointSelection"].Equals("Ordered"));
            TestHelper.Assert(proxyProps["Test.LocatorCacheTimeout"].Equals("100"));
            TestHelper.Assert(proxyProps["Test.InvocationTimeout"].Equals("1234"));

            TestHelper.Assert(proxyProps["Test.Locator"].Equals($"locator -t -p ice1 -e {Encoding.V2_0}"));
            // Locator collocation optimization is always disabled.
            //TestHelper.Assert(proxyProps["Test.Locator.CollocationOptimized"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.Locator.ConnectionCached"].Equals("0"));
            TestHelper.Assert(proxyProps["Test.Locator.PreferNonSecure"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.Locator.EndpointSelection"].Equals("Random"));
            TestHelper.Assert(proxyProps["Test.Locator.LocatorCacheTimeout"].Equals("300"));
            TestHelper.Assert(proxyProps["Test.Locator.InvocationTimeout"].Equals("1500"));

            TestHelper.Assert(proxyProps["Test.Locator.Router"].Equals(
                                  "router -t -p ice1 -e " + Encoding.Latest.ToString()));
            TestHelper.Assert(proxyProps["Test.Locator.Router.CollocationOptimized"].Equals("0"));
            TestHelper.Assert(proxyProps["Test.Locator.Router.ConnectionCached"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.Locator.Router.PreferNonSecure"].Equals("1"));
            TestHelper.Assert(proxyProps["Test.Locator.Router.EndpointSelection"].Equals("Random"));
            TestHelper.Assert(proxyProps["Test.Locator.Router.LocatorCacheTimeout"].Equals("200"));
            TestHelper.Assert(proxyProps["Test.Locator.Router.InvocationTimeout"].Equals("1500"));

            output.WriteLine("ok");

            output.Write("testing ice_getCommunicator... ");
            output.Flush();
            TestHelper.Assert(baseProxy.Communicator == communicator);
            output.WriteLine("ok");

            output.Write("testing proxy methods... ");

            TestHelper.Assert(baseProxy.Clone(facet: "facet", IObjectPrx.Factory).Facet.Equals("facet"));
            TestHelper.Assert(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id"));
            TestHelper.Assert(!baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsOneway);
            TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway);
            TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).IsOneway);
            TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode ==
                              InvocationMode.BatchOneway);
            TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode ==
                              InvocationMode.Datagram);
            TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode ==
                              InvocationMode.BatchDatagram);
            TestHelper.Assert(baseProxy.Clone(collocationOptimized: true).IsCollocationOptimized);
            TestHelper.Assert(!baseProxy.Clone(collocationOptimized: false).IsCollocationOptimized);
            TestHelper.Assert(baseProxy.Clone(preferNonSecure: true).PreferNonSecure);
            TestHelper.Assert(!baseProxy.Clone(preferNonSecure: false).PreferNonSecure);

            try
            {
                baseProxy.Clone(connectionTimeout: 0);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                baseProxy.Clone(connectionTimeout: -1);
            }
            catch (ArgumentException)
            {
                TestHelper.Assert(false);
            }

            try
            {
                baseProxy.Clone(connectionTimeout: -2);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                baseProxy.Clone(invocationTimeout: 0);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                baseProxy.Clone(invocationTimeout: -1);
            }
            catch (ArgumentException)
            {
                TestHelper.Assert(false);
            }

            try
            {
                baseProxy.Clone(invocationTimeout: -2);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                baseProxy.Clone(locatorCacheTimeout: 0);
            }
            catch (ArgumentException)
            {
                TestHelper.Assert(false);
            }

            try
            {
                baseProxy.Clone(locatorCacheTimeout: -1);
            }
            catch (ArgumentException)
            {
                TestHelper.Assert(false);
            }

            try
            {
                baseProxy.Clone(locatorCacheTimeout: -2);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }

            output.WriteLine("ok");

            output.Write("testing proxy comparison... ");
            output.Flush();

            TestHelper.Assert(Equals(IObjectPrx.Parse("foo", communicator), IObjectPrx.Parse("foo", communicator)));
            TestHelper.Assert(!IObjectPrx.Parse("foo", communicator).Equals(IObjectPrx.Parse("foo2", communicator)));

            var compObj = IObjectPrx.Parse("foo", communicator);

            TestHelper.Assert(compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals(
                                  compObj.Clone(facet: "facet", IObjectPrx.Factory)));
            TestHelper.Assert(!compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals(
                                  compObj.Clone(facet: "facet1", IObjectPrx.Factory)));

            TestHelper.Assert(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals(
                                  compObj.Clone(invocationMode: InvocationMode.Oneway)));
            TestHelper.Assert(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals(
                                  compObj.Clone(invocationMode: InvocationMode.Twoway)));

            TestHelper.Assert(compObj.Clone(collocationOptimized: true).Equals(compObj.Clone(collocationOptimized: true)));
            TestHelper.Assert(!compObj.Clone(collocationOptimized: false).Equals(compObj.Clone(collocationOptimized: true)));

            TestHelper.Assert(compObj.Clone(cacheConnection: true).Equals(compObj.Clone(cacheConnection: true)));
            TestHelper.Assert(!compObj.Clone(cacheConnection: false).Equals(compObj.Clone(cacheConnection: true)));

            TestHelper.Assert(compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals(
                                  compObj.Clone(endpointSelection: EndpointSelectionType.Random)));
            TestHelper.Assert(!compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals(
                                  compObj.Clone(endpointSelection: EndpointSelectionType.Ordered)));

            TestHelper.Assert(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2")));
            TestHelper.Assert(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2")));
            TestHelper.Assert(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1"));
            TestHelper.Assert(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2"));

            TestHelper.Assert(compObj.Clone(compress: true).Equals(compObj.Clone(compress: true)));
            TestHelper.Assert(!compObj.Clone(compress: false).Equals(compObj.Clone(compress: true)));

            TestHelper.Assert(!compObj.Compress.HasValue);
            TestHelper.Assert(compObj.Clone(compress: true).Compress !.Value == true);
            TestHelper.Assert(compObj.Clone(compress: false).Compress !.Value == false);

            TestHelper.Assert(compObj.Clone(connectionTimeout: 20).Equals(compObj.Clone(connectionTimeout: 20)));
            TestHelper.Assert(!compObj.Clone(connectionTimeout: 10).Equals(compObj.Clone(connectionTimeout: 20)));

            TestHelper.Assert(!compObj.ConnectionTimeout.HasValue);
            TestHelper.Assert(compObj.Clone(connectionTimeout: 10).ConnectionTimeout !.Value == 10);
            TestHelper.Assert(compObj.Clone(connectionTimeout: 20).ConnectionTimeout !.Value == 20);

            var loc1 = ILocatorPrx.Parse("loc1:default -p 10000", communicator);
            var loc2 = ILocatorPrx.Parse("loc2:default -p 10000", communicator);

            TestHelper.Assert(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true)));
            TestHelper.Assert(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1)));
            TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true)));
            TestHelper.Assert(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2)));
            TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2)));

            var rtr1 = IRouterPrx.Parse("rtr1:default -p 10000", communicator);
            var rtr2 = IRouterPrx.Parse("rtr2:default -p 10000", communicator);

            TestHelper.Assert(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true)));
            TestHelper.Assert(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1)));
            TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true)));
            TestHelper.Assert(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2)));
            TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr2)));

            Dictionary <string, string> ctx1 = new Dictionary <string, string>();

            ctx1["ctx1"] = "v1";
            Dictionary <string, string> ctx2 = new Dictionary <string, string>();

            ctx2["ctx2"] = "v2";
            TestHelper.Assert(compObj.Clone(context: new Dictionary <string, string>()).Equals(
                                  compObj.Clone(context: new Dictionary <string, string>())));
            TestHelper.Assert(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1)));
            TestHelper.Assert(!compObj.Clone(context: ctx1).Equals(
                                  compObj.Clone(context: new Dictionary <string, string>())));
            TestHelper.Assert(!compObj.Clone(context: new Dictionary <string, string>()).Equals(
                                  compObj.Clone(context: ctx2)));
            TestHelper.Assert(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2)));

            TestHelper.Assert(compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: true)));
            TestHelper.Assert(!compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: false)));

            var compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator);
            var compObj2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator);

            TestHelper.Assert(!compObj1.Equals(compObj2));

            compObj1 = IObjectPrx.Parse("foo@MyAdapter1", communicator);
            compObj2 = IObjectPrx.Parse("foo@MyAdapter2", communicator);
            TestHelper.Assert(!compObj1.Equals(compObj2));

            TestHelper.Assert(compObj1.Clone(locatorCacheTimeout: 20).Equals(compObj1.Clone(locatorCacheTimeout: 20)));
            TestHelper.Assert(!compObj1.Clone(locatorCacheTimeout: 10).Equals(compObj1.Clone(locatorCacheTimeout: 20)));

            TestHelper.Assert(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20)));
            TestHelper.Assert(!compObj1.Clone(invocationTimeout: 10).Equals(compObj1.Clone(invocationTimeout: 20)));

            compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 1000", communicator);
            compObj2 = IObjectPrx.Parse("foo@MyAdapter1", communicator);
            TestHelper.Assert(!compObj1.Equals(compObj2));

            var endpts1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints;
            var endpts2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator).Endpoints;

            TestHelper.Assert(!endpts1[0].Equals(endpts2[0]));
            TestHelper.Assert(endpts1[0].Equals(IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints[0]));

            Connection baseConnection = baseProxy.GetConnection();

            if (baseConnection != null)
            {
                Connection baseConnection2 = baseProxy.Clone(connectionId: "base2").GetConnection();
                compObj1 = compObj1.Clone(fixedConnection: baseConnection);
                compObj2 = compObj2.Clone(fixedConnection: baseConnection2);
                TestHelper.Assert(!compObj1.Equals(compObj2));
            }
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            var cl = Test.IMyClassPrx.CheckedCast(baseProxy);

            TestHelper.Assert(cl != null);
            var derived = Test.IMyDerivedClassPrx.CheckedCast(cl);

            TestHelper.Assert(derived != null);
            TestHelper.Assert(cl.Equals(baseProxy));
            TestHelper.Assert(derived.Equals(baseProxy));
            TestHelper.Assert(cl.Equals(derived));
            try
            {
                Test.IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet", IObjectPrx.Factory));
                TestHelper.Assert(false);
            }
            catch (ObjectNotExistException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing checked cast with context... ");
            output.Flush();

            Dictionary <string, string> c = cl.getContext();

            TestHelper.Assert(c == null || c.Count == 0);

            c        = new Dictionary <string, string>();
            c["one"] = "hello";
            c["two"] = "world";
            cl       = Test.IMyClassPrx.CheckedCast(baseProxy, c);
            Dictionary <string, string> c2 = cl !.getContext();

            TestHelper.Assert(Collections.Equals(c, c2));
            output.WriteLine("ok");

            output.Write("testing ice_fixed... ");
            output.Flush();
            {
                Connection connection = cl.GetConnection();
                if (connection != null)
                {
                    TestHelper.Assert(!cl.IsFixed);
                    Test.IMyClassPrx prx = cl.Clone(fixedConnection: connection);
                    TestHelper.Assert(prx.IsFixed);
                    prx.IcePing();
                    TestHelper.Assert(cl.Clone("facet", IObjectPrx.Factory, fixedConnection: connection).Facet.Equals("facet"));
                    TestHelper.Assert(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection).IsOneway);
                    Dictionary <string, string> ctx = new Dictionary <string, string>();
                    ctx["one"] = "hello";
                    ctx["two"] = "world";
                    TestHelper.Assert(cl.Clone(fixedConnection: connection).Context.Count == 0);
                    TestHelper.Assert(cl.Clone(context: ctx, fixedConnection: connection).Context.Count == 2);
                    TestHelper.Assert(cl.Clone(fixedConnection: connection).InvocationTimeout == -1);
                    TestHelper.Assert(cl.Clone(invocationTimeout: 10, fixedConnection: connection).InvocationTimeout == 10);
                    TestHelper.Assert(cl.Clone(fixedConnection: connection).GetConnection() == connection);
                    TestHelper.Assert(cl.Clone(fixedConnection: connection).Clone(fixedConnection: connection).GetConnection() == connection);
                    TestHelper.Assert(!cl.Clone(fixedConnection: connection).ConnectionTimeout.HasValue);
                    TestHelper.Assert(cl.Clone(compress: true, fixedConnection: connection).Compress !.Value);
                    Connection fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection();
                    TestHelper.Assert(cl.Clone(fixedConnection: connection).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection);
                    try
                    {
                        cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection);
                        TestHelper.Assert(false);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("testing encoding versioning... ");
            string ref13 = "test -e 1.3:" + helper.GetTestEndpoint(0);
            var    cl13  = Test.IMyClassPrx.Parse(ref13, communicator);

            try
            {
                cl13.IcePing();
                TestHelper.Assert(false);
            }
            catch (NotSupportedException)
            {
                // expected
            }
            output.WriteLine("ok");

            output.Write("testing protocol versioning... ");
            output.Flush();
            string ref3 = "test -p 3:" + helper.GetTestEndpoint(0);
            var    cl3  = Test.IMyClassPrx.Parse(ref3, communicator);

            try
            {
                cl3.IcePing();
                TestHelper.Assert(false);
            }
            catch (NotSupportedException)
            {
                // expected
            }
            output.WriteLine("ok");

            output.Write("testing opaque endpoints... ");
            output.Flush();

            try
            {
                // Invalid -x option
                IObjectPrx.Parse("id:opaque -t 99 -v abcd -x abc", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Missing -t and -v
                IObjectPrx.Parse("id:opaque", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Repeated -t
                IObjectPrx.Parse("id:opaque -t 1 -t 1 -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Repeated -v
                IObjectPrx.Parse("id:opaque -t 1 -v abcd -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Missing -t
                IObjectPrx.Parse("id:opaque -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Missing -v
                IObjectPrx.Parse("id:opaque -t 1", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Missing arg for -t
                IObjectPrx.Parse("id:opaque -t -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Missing arg for -v
                IObjectPrx.Parse("id:opaque -t 1 -v", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Not a number for -t
                IObjectPrx.Parse("id:opaque -t x -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // < 0 for -t
                IObjectPrx.Parse("id:opaque -t -1 -v abcd", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Invalid char for -v
                IObjectPrx.Parse("id:opaque -t 99 -v x?c", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            try
            {
                // Invalid lenght for base64 input
                IObjectPrx.Parse("id:opaque -t 99 -v xc", communicator);
                TestHelper.Assert(false);
            }
            catch (FormatException)
            {
            }

            // Legal TCP endpoint expressed as opaque endpoint
            // Opaque endpoint encoded with 1.1 encoding.
            var p1 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==",
                                      communicator);

            TestHelper.Assert(p1.ToString() !.Equals("test -t -p ice1 -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"));

            if (!(communicator.GetPropertyAsBool("Ice.IPv6") ?? false))
            {
                // Working?
                bool ssl = communicator.GetProperty("Ice.Default.Transport") == "ssl";
                bool tcp = communicator.GetProperty("Ice.Default.Transport") == "tcp";

                // Two legal TCP endpoints expressed as opaque endpoints
                p1 = IObjectPrx.Parse("test -e 1.1:" + "" +
                                      "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:" +
                                      "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==", communicator);
                var pstr = p1.ToString() !;
                TestHelper.Assert(pstr.Equals("test -t -p ice1 -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"));

                // Test that an SSL endpoint and a nonsense endpoint get written back out as an opaque endpoint.
                p1 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.1 -t 99 -v abch",
                                      communicator);
                pstr = p1.ToString() !;
                if (ssl)
                {
                    TestHelper.Assert(pstr.Equals("test -t -p ice1 -e 1.1:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.1 -v abch"));
                }
                else if (tcp)
                {
                    TestHelper.Assert(pstr.Equals(
                                          "test -t -p ice1 -e 1.1:opaque -t 2 -e 1.1 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.1 -v abch"));
                }
            }

            output.WriteLine("ok");

            output.Write("testing communicator shutdown/destroy... ");
            output.Flush();
            {
                Communicator com = new Communicator();
                com.Shutdown();
                TestHelper.Assert(com.IsShutdown());
                com.WaitForShutdown();
                com.Destroy();
                com.Shutdown();
                TestHelper.Assert(com.IsShutdown());
                com.WaitForShutdown();
                com.Destroy();
            }
            output.WriteLine("ok");

            return(cl);
        }
예제 #24
0
        public static IMyObjectPrx Run(TestHelper helper)
        {
            bool ice2 = helper.Protocol == Protocol.Ice2;
            var  prx  = IMyObjectPrx.Parse(helper.GetTestProxy("test"), helper.Communicator !);

            System.IO.TextWriter output = helper.Output;

            output.Write("testing retry... ");
            output.Flush();
            TestHelper.Assert(prx.AddWithRetry(33, 12) == 45);
            output.WriteLine("ok");

            output.Write("testing remote exception... ");
            output.Flush();
            try
            {
                prx.BadAdd(33, 12);
                TestHelper.Assert(false);
            }
            catch (InvalidInputException)
            {
                // expected
            }
            output.WriteLine("ok");

            output.Write("testing ONE... ");
            output.Flush();
            try
            {
                prx.NotExistAdd(33, 12);
                TestHelper.Assert(false);
            }
            catch (ObjectNotExistException)
            {
                // expected
            }
            output.WriteLine("ok");

            output.Write("testing exceptions raised by the interceptor... ");
            output.Flush();
            var exceptions = new List <(string operation, string kind)>
            {
                ("raiseBeforeDispatch", "invalidInput"),
                ("raiseBeforeDispatch", "notExist"),
                ("raiseAfterDispatch", "invalidInput"),
                ("raiseAfterDispatch", "notExist")
            };

            foreach ((string operation, string kind) in exceptions)
            {
                var ctx = new Dictionary <string, string>
                {
                    { operation, kind }
                };

                try
                {
                    prx.IcePing(ctx);
                    TestHelper.Assert(false);
                }
                catch (InvalidInputException) when(kind == "invalidInput")
                {
                }
                catch (ObjectNotExistException) when(kind == "notExist")
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing invocation interceptors... ");
            output.Flush();
            {
                var tasks             = new List <Task>();
                var invocationContext = new AsyncLocal <int>();
                using var communicator = new Communicator(
                          prx.Communicator.GetProperties(),
                          invocationInterceptors: new InvocationInterceptor[]
                {
                    (target, request, next) =>
                    {
                        if (ice2)
                        {
                            request.ContextOverride["interceptor-1"] = "interceptor-1";
                            request.AddBinaryContextEntry(110, 110, (ostr, v) => ostr.WriteInt(v));
                        }
                        return(next(target, request));
                    },
                    async(target, request, next) =>
                    {
                        if (ice2)
                        {
                            TestHelper.Assert(request.Context["interceptor-1"] == "interceptor-1");
                            request.ContextOverride["interceptor-2"] = "interceptor-2";
                            request.AddBinaryContextEntry(120, 120, (ostr, v) => ostr.WriteInt(v));
                        }
                        IncomingResponseFrame response = await next(target, request);
                        TestHelper.Assert(invocationContext.Value == int.Parse(request.Context["local-user"]));
                        if (ice2)
                        {
                            TestHelper.Assert(response.BinaryContext.ContainsKey(110));
                            TestHelper.Assert(response.BinaryContext[110].Read(istr => istr.ReadInt()) == 110);
                            TestHelper.Assert(response.BinaryContext.ContainsKey(120));
                            TestHelper.Assert(response.BinaryContext[120].Read(istr => istr.ReadInt()) == 120);
                        }
                        return(response);
                    }
                });

                for (int i = 0; i < 10; ++i)
                {
                    invocationContext.Value = i;
                    var  prx1 = IMyObjectPrx.Parse(prx.ToString() !, communicator);
                    Task t    = prx1.Op1Async(new Dictionary <string, string> {
                        { "local-user", $"{i}" }
                    });
                    tasks.Add(t);
                }
                Task.WaitAll(tasks.ToArray());
            }

            {
                IncomingResponseFrame?response = null;
                int invocations = 0;
                // An interceptor can stop the chain and directly return a response without calling next,
                // the first invocation calls next and subsequent invocations reuse the first response.
                using var communicator = new Communicator(
                          prx.Communicator.GetProperties(),
                          invocationInterceptors: new InvocationInterceptor[]
                {
                    (target, request, next) =>
                    {
                        if (ice2)
                        {
                            request.ContextOverride["interceptor-1"] = "interceptor-1";
                        }
                        return(next(target, request));
                    },
                    async(target, request, next) =>
                    {
                        if (response == null)
                        {
                            response = await next(target, request);
                        }
                        return(response);
                    },
                    (target, request, next) =>
                    {
                        invocations++;
                        TestHelper.Assert(response == null);
                        return(next(target, request));
                    }
                });

                var prx1 = IMyObjectPrx.Parse(prx.ToString() !, communicator);
                prx1.Op1(new Dictionary <string, string> {
                    { "local-user", "10" }
                });
                prx1.Op1(new Dictionary <string, string> {
                    { "local-user", "11" }
                });
                prx1.Op1(new Dictionary <string, string> {
                    { "local-user", "12" }
                });
                TestHelper.Assert(invocations == 1);
            }

            {
                // throwing from an interceptor stops the interceptor chain
                using var communicator = new Communicator(
                          prx.Communicator.GetProperties(),
                          invocationInterceptors: new InvocationInterceptor[]
                {
                    (target, request, next) =>
                    {
                        request.ContextOverride["interceptor-1"] = "interceptor-1";
                        return(next(target, request));
                    },
                    (target, request, next) =>
                    {
                        TestHelper.Assert(request.Context["interceptor-1"] == "interceptor-1");
                        throw new InvalidOperationException("stop interceptor chain");
                    },
                    (target, request, next) =>
                    {
                        TestHelper.Assert(false);
                        return(next(target, request));
                    }
                });

                var prx1 = IMyObjectPrx.Parse(prx.ToString() !, communicator);
                try
                {
                    prx1.Op1();
                    TestHelper.Assert(false);
                }
                catch (InvalidOperationException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing binary context... ");
            output.Flush();

            if (ice2)
            {
                for (int size = 128; size < 4096; size *= 2)
                {
                    var token   = new Token(1, "mytoken", Enumerable.Range(0, size).Select(i => (byte)2).ToArray());
                    var request = OutgoingRequestFrame.WithArgs(prx,
                                                                "opWithBinaryContext",
                                                                idempotent: false,
                                                                compress: false,
                                                                format: default,
예제 #25
0
파일: AllTests.cs 프로젝트: yuwenyong/ice
        public static Test.IInitialPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing stringToProxy... ");
            output.Flush();
            var @base = IObjectPrx.Parse($"initial:{helper.GetTestEndpoint(0)}", communicator);

            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            var initial = Test.IInitialPrx.CheckedCast(@base);

            TestHelper.Assert(initial != null);
            TestHelper.Assert(initial.Equals(@base));
            output.WriteLine("ok");

            {
                output.Write("testing types without package... ");
                output.Flush();
                NoNamespace.C1?c1 = initial.getNoNamespaceC2AsC1();
                TestHelper.Assert(c1 != null);
                TestHelper.Assert(c1 is NoNamespace.C2);
                NoNamespace.C2?c2 = initial.getNoNamespaceC2AsC2();
                TestHelper.Assert(c2 != null);
                try
                {
                    initial.throwNoNamespaceE2AsE1();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.E1 ex)
                {
                    TestHelper.Assert(ex is NoNamespace.E2);
                }
                try
                {
                    initial.throwNoNamespaceE2AsE2();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.E2)
                {
                    // Expected
                }
                try
                {
                    initial.throwNoNamespaceNotify();
                    TestHelper.Assert(false);
                }
                catch (NoNamespace.@notify)
                {
                    // Expected
                }
                output.WriteLine("ok");
            }

            {
                output.Write("testing types with package... ");
                output.Flush();

                {
                    WithNamespace.C1?c1 = initial.getWithNamespaceC2AsC1();
                    TestHelper.Assert(c1 != null);
                    TestHelper.Assert(c1 is WithNamespace.C2);
                    WithNamespace.C2?c2 = initial.getWithNamespaceC2AsC2();
                    TestHelper.Assert(c2 != null);
                    try
                    {
                        initial.throwWithNamespaceE2AsE1();
                        TestHelper.Assert(false);
                    }
                    catch (WithNamespace.E1 ex)
                    {
                        TestHelper.Assert(ex is WithNamespace.E2);
                    }
                    try
                    {
                        initial.throwWithNamespaceE2AsE2();
                        TestHelper.Assert(false);
                    }
                    catch (WithNamespace.E2)
                    {
                        // Expected
                    }
                    output.WriteLine("ok");
                }
            }
            return(initial);
        }
예제 #26
0
파일: AllTests.cs 프로젝트: sgrzegorz/ice
        public static Test.IMyClassPrx allTests(global::Test.TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var cl = Test.IMyClassPrx.Parse($"test:{helper.GetTestEndpoint(0)}", communicator);

            Test.IMyClassPrx oneway = cl.Clone(oneway: true);

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing Invoke... ");
            output.Flush();

            {
                var request = OutgoingRequestFrame.WithEmptyParamList(oneway, "opOneway", idempotent: false);

                // Whether the proxy is oneway or not does not matter for Invoke's oneway parameter.

                IncomingResponseFrame response = cl.Invoke(request, oneway: true);
                TestHelper.Assert(response.ReplyStatus == ReplyStatus.OK);

                response = cl.Invoke(request, oneway: false);
                TestHelper.Assert(response.ReplyStatus == ReplyStatus.UserException);

                response = oneway.Invoke(request, oneway: true);
                TestHelper.Assert(response.ReplyStatus == ReplyStatus.OK);

                response = oneway.Invoke(request, oneway: false);
                TestHelper.Assert(response.ReplyStatus == ReplyStatus.UserException);

                request = OutgoingRequestFrame.WithParamList(cl, "opString", idempotent: false,
                                                             format: null, context: null, _testString, OutputStream.IceWriterFromString);
                response = cl.Invoke(request);
                (string s1, string s2) = response.ReadReturnValue(istr =>
                {
                    string s1 = istr.ReadString();
                    string s2 = istr.ReadString();
                    return(s1, s2);
                });
                TestHelper.Assert(s1.Equals(_testString) && s2.Equals(_testString));
            }

            for (int i = 0; i < 2; ++i)
            {
                Dictionary <string, string>?ctx = null;
                if (i == 1)
                {
                    ctx = new Dictionary <string, string>
                    {
                        ["raise"] = ""
                    };
                }

                var request = OutgoingRequestFrame.WithEmptyParamList(cl, "opException", idempotent: false, context: ctx);
                IncomingResponseFrame response = cl.Invoke(request);
                try
                {
                    response.ReadVoidReturnValue();
                }
                catch (Test.MyException)
                {
                    // expected
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");

            output.Write("testing InvokeAsync... ");
            output.Flush();

            {
                var request = OutgoingRequestFrame.WithEmptyParamList(oneway, "opOneway", idempotent: false);
                try
                {
                    oneway.InvokeAsync(request, oneway: true).Wait();
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }

                request = OutgoingRequestFrame.WithParamList(cl, "opString", idempotent: false,
                                                             format: null, context: null, _testString, OutputStream.IceWriterFromString);

                IncomingResponseFrame response = cl.InvokeAsync(request).Result;
                (string s1, string s2) = response.ReadReturnValue(istr =>
                {
                    string s1 = istr.ReadString();
                    string s2 = istr.ReadString();
                    return(s1, s2);
                });
                TestHelper.Assert(s1.Equals(_testString));
                TestHelper.Assert(s2.Equals(_testString));
            }

            {
                var request = OutgoingRequestFrame.WithEmptyParamList(cl, "opException", idempotent: false);
                IncomingResponseFrame response = cl.InvokeAsync(request).Result;

                try
                {
                    response.ReadVoidReturnValue();
                    TestHelper.Assert(false);
                }
                catch (Test.MyException)
                {
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");
            return(cl);
        }
예제 #27
0
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;
            bool         ice1         = helper.Protocol == Protocol.Ice1;

            TestHelper.Assert(communicator != null);
            var    com           = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator);
            string testTransport = helper.Transport;

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

            System.IO.TextWriter output = helper.Output;

            output.Write("testing binding with single endpoint... ");
            output.Flush();
            {
                // Use "default" here to ensure that it still works
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default");
                TestHelper.Assert(adapter != null);
                ITestIntfPrx?test1 = adapter.GetTestIntf();
                ITestIntfPrx?test2 = adapter.GetTestIntf();
                TestHelper.Assert(test1 != null && test2 != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

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

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                TestHelper.Assert(test3.GetConnection() == test2.GetConnection());

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

            output.Write("testing binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter11", testTransport) !,
                    com.CreateObjectAdapter("Adapter12", testTransport) !,
                    com.CreateObjectAdapter("Adapter13", testTransport) !
                };

                // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are
                // eventually tried.
                var names = new List <string>
                {
                    "Adapter11",
                    "Adapter12",
                    "Adapter13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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 (IRemoteObjectAdapterPrx adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = t.GetAdapterName();

                    for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++)
                    {
                        TestHelper.Assert(t.GetAdapterName() == name);
                    }

                    foreach (IRemoteObjectAdapterPrx 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("Adapter12");
                names.Add("Adapter13");
                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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(adapters[2]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12"));

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

            output.Write("testing binding with multiple random endpoints... ");
            output.Flush();
            {
                var adapters = new IRemoteObjectAdapterPrx[5]
                {
                    com.CreateObjectAdapter("AdapterRandom11", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom12", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom13", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom14", testTransport) !,
                    com.CreateObjectAdapter("AdapterRandom15", testTransport) !
                };

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

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

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

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

                    foreach (IRemoteObjectAdapterPrx a in adapters)
                    {
                        try
                        {
                            a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                        catch
                        {
                            // Expected if adapter is down.
                        }
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple endpoints and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI11", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI12", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI13", testTransport) !
                };

                // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are
                // eventually tried.
                var names = new List <string>
                {
                    "AdapterAMI11",
                    "AdapterAMI12",
                    "AdapterAMI13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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 (IRemoteObjectAdapterPrx?adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = GetAdapterNameWithAMI(t);

                    for (int i = 0; i < 10; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(t) == name);
                    }

                    foreach (IRemoteObjectAdapterPrx?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 <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(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]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

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

            output.Write("testing random endpoint selection... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter21", testTransport) !,
                    com.CreateObjectAdapter("Adapter22", testTransport) !,
                    com.CreateObjectAdapter("Adapter23", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random);

                var names = new List <string>
                {
                    "Adapter21",
                    "Adapter22",
                    "Adapter23"
                };

                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                obj = obj.Clone(endpointSelection: EndpointSelectionType.Random);
                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter31", testTransport) !,
                    com.CreateObjectAdapter("Adapter32", testTransport) !,
                    com.CreateObjectAdapter("Adapter33", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);

                // Ensure that endpoints are tried in order by deactivating the adapters
                // one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter31");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter32");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter33");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }
                adapters.Clear();
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with single endpoint... ");
            output.Flush();
            {
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport);
                TestHelper.Assert(adapter != null);
                ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                TestHelper.Assert(!test1.IsConnectionCached);
                TestHelper.Assert(!test2.IsConnectionCached);
                TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();

                com.DeactivateObjectAdapter(adapter);

                var test3 = test1.Clone(ITestIntfPrx.Factory);
                try
                {
                    TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter51", testTransport) !,
                    com.CreateObjectAdapter("Adapter52", testTransport) !,
                    com.CreateObjectAdapter("Adapter53", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "Adapter51",
                    "Adapter52",
                    "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]);

                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI51", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI52", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI53", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "AdapterAMI51",
                    "AdapterAMI52",
                    "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]);

                TestHelper.Assert(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 <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter61", testTransport) !,
                    com.CreateObjectAdapter("Adapter62", testTransport) !,
                    com.CreateObjectAdapter("Adapter63", testTransport) !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (helper.Protocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter64");
                    }

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

            output.Write("testing per request binding and ordered endpoint selection and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI61", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI62", testTransport) !,
                    com.CreateObjectAdapter("AdapterAMI63", testTransport) !
                };

                ITestIntfPrx?obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (helper.Protocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64");
                    }
                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            if (helper.Protocol == Protocol.Ice1)
            {
                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter71", testTransport),
                        com.CreateObjectAdapter("Adapter72", "udp")
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                    TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71"));

                    ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram);
                    TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection());
                    try
                    {
                        testUDP.GetAdapterName();
                        TestHelper.Assert(false);
                    }
                    catch (InvalidOperationException)
                    {
                        // expected
                    }
                }
                output.WriteLine("ok");
            }
            if (communicator.GetProperty("Ice.Plugin.IceSSL") != null)
            {
                output.Write("testing secure and non-secure endpoints... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter81", "ssl") !,
                        com.CreateObjectAdapter("Adapter82", "tcp") !
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true);
                    // TODO: update when PreferNonSecure default is updated
                    ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false);
                    TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection());
                    TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection());

                    com.DeactivateObjectAdapter(adapters[1]);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                    if (helper.Protocol == Protocol.Ice1)
                    {
                        com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA.

                        for (int i = 0; i < 5; i++)
                        {
                            TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83"));
                            obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                    }

                    com.DeactivateObjectAdapter(adapters[0]);

                    try
                    {
                        testSecure.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // expected
                    }
                    Deactivate(com, adapters);
                }
                output.WriteLine("ok");
            }

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

                Func <string, string> getEndpoint = host =>
                                                    TestHelper.GetTestEndpoint(
                    new Dictionary <string, string>(communicator.GetProperties())
                {
                    ["Test.Host"] = host
                },
                    2,
                    "tcp");

                Func <string, string, string> getProxy = (identity, host) =>
                                                         TestHelper.GetTestProxy(
                    identity,
                    new Dictionary <string, string>(communicator.GetProperties())
                {
                    ["Test.Host"] = host
                },
                    2,
                    "tcp");

                var anyipv4 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("0.0.0.0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1")
                };

                var anyipv6 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("::0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("::1")
                };

                var anyipv46 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"]          = getEndpoint("::0"),
                    ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1")
                };

                var anylocalhost = new Dictionary <string, string>()
                {
                    { "Adapter.Endpoints", getEndpoint("::0") },
                    { "Adapter.PublishedEndpoints", getEndpoint("localhost") }
                };

                var localipv4 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"] = getEndpoint("127.0.0.1")
                };

                var localipv6 = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"] = getEndpoint("::1")
                };

                var localhost = new Dictionary <string, string>()
                {
                    ["Adapter.Endpoints"] = getEndpoint("localhost")
                };

                var serverProps = new Dictionary <string, string>[]
                {
                    anyipv4,
                    anyipv6,
                    anyipv46,
                    anylocalhost,
                    localipv4,
                    localipv6,
                    localhost
                };

                foreach (Dictionary <string, string> p in serverProps)
                {
                    using var serverCommunicator = new Communicator(p);
                    ObjectAdapter oa = serverCommunicator.CreateObjectAdapter("Adapter");
                    oa.Activate();

                    IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                    try
                    {
                        using var clientCommunicator = new Communicator();
                        prx = IObjectPrx.Parse(prx.ToString() !, clientCommunicator);
                        prx.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected. OA is reachable but there's no "dummy" object
                    }
                }

                // Test IPv6 dual mode socket
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::0");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    try
                    {
                        using ObjectAdapter ipv4OA =
                                  serverCommunicator.CreateObjectAdapterWithEndpoints(getEndpoint("0.0.0.0"));
                        ipv4OA.Activate();
                        TestHelper.Assert(false);
                    }
                    catch (TransportException)
                    {
                        // Expected. ::0 is a dual-mode socket so binding 0.0.0.0 will fail
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected, no object registered.
                    }
                }

                // Test IPv6 only socket
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::0") + (ice1 ? " --ipv6Only" : "?ipv6-only=true");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    // Returned endpoints must be IPv6
                    {
                        IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                        TestHelper.Assert(prx.Endpoints.Count > 0);
                        TestHelper.Assert(prx.Endpoints.All(e => e.Host.Contains(":")));
                    }

                    // 0.0.0.0 can still be bound if ::0 is IPv6 only
                    {
                        string ipv4Endpoint = getEndpoint("0.0.0.0");
                        using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint);
                        ipv4OA.Activate();
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // Expected, server socket is IPv6 only.
                    }
                }

                // Listen on IPv4 loopback with IPv6 dual mode socket
                {
                    using Communicator serverCommunicator = new Communicator();
                    string        endpoint = getEndpoint("::ffff:127.0.0.1");
                    ObjectAdapter oa       = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint);
                    oa.Activate();

                    try
                    {
                        string ipv4Endpoint = getEndpoint("127.0.0.1");
                        using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint);
                        ipv4OA.Activate();
                        TestHelper.Assert(false);
                    }
                    catch (TransportException)
                    {
                        // Expected. 127.0.0.1 is already in use
                    }

                    // Returned endpoint must be IPv6
                    {
                        IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                        TestHelper.Assert(prx.Endpoints.Count == 1);
                        TestHelper.Assert(prx.Endpoints.All(e => e.Host.Contains(":")));
                    }

                    try
                    {
                        using Communicator clientCommunicator = new Communicator();
                        var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator);
                        prx.IcePing();
                    }
                    catch (ObjectNotExistException)
                    {
                        // Expected, no object registered.
                    }
                }

                output.WriteLine("ok");
            }

            com.Shutdown();
        }
예제 #28
0
파일: AllTests.cs 프로젝트: nail-lian/ice
        public static void allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var manager = Test.IServerManagerPrx.Parse($"ServerManager :{helper.GetTestEndpoint(0)}", communicator);
            var locator = Test.ITestLocatorPrx.UncheckedCast(communicator.DefaultLocator !);

            Console.WriteLine("registry checkedcast");
            var registry = Test.ITestLocatorRegistryPrx.CheckedCast(locator.GetRegistry() !);

            TestHelper.Assert(registry != null);

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing stringToProxy... ");
            output.Flush();
            var base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            var base3 = IObjectPrx.Parse("test", communicator);
            var base4 = IObjectPrx.Parse("ServerManager", communicator);
            var base5 = IObjectPrx.Parse("test2", communicator);
            var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator);

            output.WriteLine("ok");

            output.Write("testing ice_locator and ice_getLocator... ");
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Locator !, communicator.DefaultLocator !));
            var anotherLocator = ILocatorPrx.Parse("anotherLocator", communicator);

            base1 = base1.Clone(locator: anotherLocator);
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Locator !, anotherLocator));
            communicator.DefaultLocator = null;
            base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            TestHelper.Assert(base1.Locator == null);
            base1 = base1.Clone(locator: anotherLocator);
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Locator !, anotherLocator));
            communicator.DefaultLocator = locator;
            base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Locator !, communicator.DefaultLocator !));

            //
            // We also test ice_router/ice_getRouter(perhaps we should add a
            // test/Ice/router test?)
            //
            TestHelper.Assert(base1.Router == null);
            var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator);

            base1 = base1.Clone(router: anotherRouter);
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Router !, anotherRouter));
            var router = IRouterPrx.Parse("dummyrouter", communicator);

            communicator.DefaultRouter = router;
            base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            TestHelper.Assert(default(ProxyIdentityComparer).Equals(base1.Router !, communicator.DefaultRouter !));
            communicator.DefaultRouter = null;
            base1 = IObjectPrx.Parse("test @ TestAdapter", communicator);
            TestHelper.Assert(base1.Router == null);
            output.WriteLine("ok");

            output.Write("starting server... ");
            output.Flush();
            manager.startServer();
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            var obj1 = Test.ITestIntfPrx.CheckedCast(base1);

            TestHelper.Assert(obj1 != null);
            var obj2 = Test.ITestIntfPrx.CheckedCast(base2);

            TestHelper.Assert(obj2 != null);
            var obj3 = Test.ITestIntfPrx.CheckedCast(base3);

            TestHelper.Assert(obj3 != null);
            var obj4 = Test.IServerManagerPrx.CheckedCast(base4);

            TestHelper.Assert(obj4 != null);
            var obj5 = Test.ITestIntfPrx.CheckedCast(base5);

            TestHelper.Assert(obj5 != null);
            var obj6 = Test.ITestIntfPrx.CheckedCast(base6);

            TestHelper.Assert(obj6 != null);
            output.WriteLine("ok");

            output.Write("testing id@AdapterId indirect proxy... ");
            output.Flush();
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj2.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing id@ReplicaGroupId indirect proxy... ");
            output.Flush();
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj6.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing identity indirect proxy... ");
            output.Flush();
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj3.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            try
            {
                obj2.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj2.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            try
            {
                obj3.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj2.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj3.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            obj1.shutdown();
            manager.startServer();
            try
            {
                obj5 = Test.ITestIntfPrx.CheckedCast(base5);
                TestHelper.Assert(obj5 != null);
                obj5.IcePing();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing proxy with unknown identity... ");
            output.Flush();
            try
            {
                base1 = IObjectPrx.Parse("unknown/unknown", communicator);
                base1.IcePing();
                TestHelper.Assert(false);
            }
            catch (ObjectNotFoundException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing proxy with unknown adapter... ");
            output.Flush();
            try
            {
                base1 = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator);
                base1.IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing locator cache timeout... ");
            output.Flush();

            IObjectPrx basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(cacheConnection: false);
            int        count   = locator.getRequestCount();

            basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache.
            TestHelper.Assert(++count == locator.getRequestCount());
            basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache.
            TestHelper.Assert(++count == locator.getRequestCount());
            basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout.
            TestHelper.Assert(count == locator.getRequestCount());
            System.Threading.Thread.Sleep(1300);             // 1300ms
            basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout.
            TestHelper.Assert(++count == locator.getRequestCount());

            IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache.
            count += 2;
            TestHelper.Assert(count == locator.getRequestCount());
            IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout
            TestHelper.Assert(count == locator.getRequestCount());
            System.Threading.Thread.Sleep(1300);                                            // 1300ms
            IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout
            count += 2;
            TestHelper.Assert(count == locator.getRequestCount());

            IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing();
            TestHelper.Assert(count == locator.getRequestCount());
            IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing();
            TestHelper.Assert(count == locator.getRequestCount());
            IObjectPrx.Parse("test@TestAdapter", communicator).IcePing();
            TestHelper.Assert(count == locator.getRequestCount());
            IObjectPrx.Parse("test", communicator).IcePing();
            TestHelper.Assert(count == locator.getRequestCount());

            TestHelper.Assert(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99);

            output.WriteLine("ok");

            output.Write("testing proxy from server... ");
            output.Flush();
            obj1 = Test.ITestIntfPrx.Parse("test@TestAdapter", communicator);
            Test.IHelloPrx?hello = obj1.getHello();
            TestHelper.Assert(hello != null);
            TestHelper.Assert(hello.AdapterId.Equals("TestAdapter"));
            hello.sayHello();
            hello = obj1.getReplicatedHello();
            TestHelper.Assert(hello != null);
            TestHelper.Assert(hello.AdapterId.Equals("ReplicatedAdapter"));
            hello.sayHello();
            output.WriteLine("ok");

            output.Write("testing locator request queuing... ");
            output.Flush();
            hello = obj1.getReplicatedHello() !.Clone(locatorCacheTimeout: 0, cacheConnection: false);
            TestHelper.Assert(hello != null);
            count = locator.getRequestCount();
            hello.IcePing();
            TestHelper.Assert(++count == locator.getRequestCount());
            var results = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                results.Add(hello.sayHelloAsync());
            }
            Task.WaitAll(results.ToArray());
            results.Clear();
            TestHelper.Assert(locator.getRequestCount() > count && locator.getRequestCount() < count + 999);
            if (locator.getRequestCount() > count + 800)
            {
                output.Write("queuing = " + (locator.getRequestCount() - count));
            }
            count = locator.getRequestCount();
            hello = hello.Clone(adapterId: "unknown");
            for (int i = 0; i < 1000; i++)
            {
                results.Add(hello.sayHelloAsync().ContinueWith((Task t) =>
                {
                    try
                    {
                        t.Wait();
                    }
                    catch (AggregateException ex) when(ex.InnerException is AdapterNotFoundException)
                    {
                    }
                }));
            }
            Task.WaitAll(results.ToArray());
            results.Clear();
            // XXX:
            // Take into account the retries.
            TestHelper.Assert(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999);
            if (locator.getRequestCount() > count + 800)
            {
                output.Write("queuing = " + (locator.getRequestCount() - count));
            }
            output.WriteLine("ok");

            output.Write("testing adapter locator cache... ");
            output.Flush();
            try
            {
                IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter"));
            try
            {
                IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing();
                registry.SetAdapterDirectProxy("TestAdapter3",
                                               IObjectPrx.Parse($"dummy:{helper.GetTestEndpoint(99)}", communicator));
                IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing();
            }
            catch (System.Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }

            try
            {
                IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing();
            }
            catch (ConnectionRefusedException)
            {
            }

            registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter"));
            try
            {
                IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing();
            }
            catch (System.Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing well-known object locator cache... ");
            output.Flush();
            registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator));
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update
            registry.SetAdapterDirectProxy("TestAdapter4",
                                           IObjectPrx.Parse($"dummy:{helper.GetTestEndpoint(99)}", communicator));
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter"));
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
            }
            catch (System.Exception)
            {
                TestHelper.Assert(false);
            }

            registry.SetAdapterDirectProxy("TestAdapter4",
                                           IObjectPrx.Parse($"dummy:{helper.GetTestEndpoint(99)}", communicator));
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
            }
            catch (System.Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            try
            {
                IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (ConnectionRefusedException)
            {
            }
            registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator));
            try
            {
                IObjectPrx.Parse("test3", communicator).IcePing();
            }
            catch (System.Exception)
            {
                TestHelper.Assert(false);
            }

            registry.addObject(IObjectPrx.Parse("test4", communicator));
            try
            {
                IObjectPrx.Parse("test4", communicator).IcePing();
                TestHelper.Assert(false);
            }
            catch (NoEndpointException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing locator cache background updates... ");
            output.Flush();
            {
                Dictionary <string, string> properties = communicator.GetProperties();
                properties["Ice.BackgroundLocatorCacheUpdates"] = "1";
                Communicator ic = helper.Initialize(properties);

                registry.SetAdapterDirectProxy("TestAdapter5", locator.FindAdapterById("TestAdapter"));
                registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator));

                count = locator.getRequestCount();
                IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache.
                IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing();             // No locator cache.
                count += 3;
                TestHelper.Assert(count == locator.getRequestCount());
                registry.SetAdapterDirectProxy("TestAdapter5", null);
                registry.addObject(IObjectPrx.Parse($"test3:{helper.GetTestEndpoint(99)}", communicator));
                IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout.
                IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing();             // 10s timeout.
                TestHelper.Assert(count == locator.getRequestCount());
                System.Threading.Thread.Sleep(1200);

                // The following request should trigger the background
                // updates but still use the cached endpoints and
                // therefore succeed.
                IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout.
                IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing();             // 1s timeout.

                try
                {
                    while (true)
                    {
                        IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout.
                        System.Threading.Thread.Sleep(10);
                    }
                }
                catch (System.Exception)
                {
                    // Expected to fail once they endpoints have been updated in the background.
                }
                try
                {
                    while (true)
                    {
                        IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout.
                        System.Threading.Thread.Sleep(10);
                    }
                }
                catch (System.Exception)
                {
                    // Expected to fail once they endpoints have been updated in the background.
                }
                ic.Destroy();
            }
            output.WriteLine("ok");

            output.Write("testing proxy from server after shutdown... ");
            output.Flush();
            hello = obj1.getReplicatedHello();
            TestHelper.Assert(hello != null);
            obj1.shutdown();
            manager.startServer();
            hello.sayHello();
            output.WriteLine("ok");

            output.Write("testing object migration... ");
            output.Flush();
            hello = Test.IHelloPrx.Parse("hello", communicator);
            obj1.migrateHello();
            hello.GetConnection().Close(ConnectionClose.GracefullyWithWait);
            hello.sayHello();
            obj1.migrateHello();
            hello.sayHello();
            obj1.migrateHello();
            hello.sayHello();
            output.WriteLine("ok");

            output.Write("testing locator encoding resolution... ");
            output.Flush();
            hello = Test.IHelloPrx.Parse("hello", communicator);
            count = locator.getRequestCount();
            IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encoding: Encoding.V1_1).IcePing();
            TestHelper.Assert(count == locator.getRequestCount());
            output.WriteLine("ok");

            output.Write("shutdown server... ");
            output.Flush();
            obj1.shutdown();
            output.WriteLine("ok");

            output.Write("testing whether server is gone... ");
            output.Flush();
            try
            {
                obj2.IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            try
            {
                obj3.IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            try
            {
                TestHelper.Assert(obj5 != null);
                obj5.IcePing();
                TestHelper.Assert(false);
            }
            catch (AdapterNotFoundException)
            {
            }
            output.WriteLine("ok");

            output.Write("testing indirect proxies to collocated objects... ");
            output.Flush();

            communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString());
            ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("Hello", "default");

            var id = new Identity(Guid.NewGuid().ToString(), "");

            adapter.Add(id, new Hello());
            adapter.Activate();

            // Ensure that calls on the well-known proxy is collocated.
            Test.IHelloPrx?helloPrx;
            helloPrx = Test.IHelloPrx.Parse($"\"{id.ToString(communicator.ToStringMode)}\"", communicator);
            TestHelper.Assert(helloPrx.GetConnection() == null);

            // Ensure that calls on the indirect proxy (with adapter ID) is collocated
            helloPrx = Test.IHelloPrx.CheckedCast(adapter.CreateIndirectProxy(id, IObjectPrx.Factory));
            TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null);

            // Ensure that calls on the direct proxy is collocated
            helloPrx = Test.IHelloPrx.CheckedCast(adapter.CreateDirectProxy(id, IObjectPrx.Factory));
            TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null);

            output.WriteLine("ok");

            output.Write("shutdown server manager... ");
            output.Flush();
            manager.shutdown();
            output.WriteLine("ok");
        }
예제 #29
0
        public static void RunWithController(TestHelper helper, IControllerPrx controller)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            bool ice1 = TestHelper.GetTestProtocol(communicator.GetProperties()) == Protocol.Ice1;

            var timeout = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), communicator);

            System.IO.TextWriter output = helper.Output;
            output.Write("testing connect timeout... ");
            output.Flush();
            {
                Dictionary <string, string>?properties = communicator.GetProperties();
                properties["Ice.ConnectTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), comm);

                // Expect ConnectTimeoutException.
                controller.HoldAdapter(-1);
                try
                {
                    to.Op();
                    TestHelper.Assert(false);
                }
                catch (ConnectTimeoutException)
                {
                    // Expected.
                }
                controller.ResumeAdapter();
                timeout.Op(); // Ensure adapter is active.
            }
            {
                // Expect success.
                controller.HoldAdapter(100);
                timeout.Op();
            }
            output.WriteLine("ok");

            output.Write("testing invocation timeout... ");
            output.Flush();
            {
                timeout.IcePing(); // Makes sure a working connection is associated with the proxy
                Connection?connection = timeout.GetConnection();
                try
                {
                    timeout.Clone(invocationTimeout: TimeSpan.FromMilliseconds(100)).SleepAsync(1000).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ex) when(ex.InnerException is OperationCanceledException)
                {
                }
                timeout.IcePing();

                TestHelper.Assert(connection == timeout.GetConnection());
                try
                {
                    timeout.Clone(invocationTimeout: TimeSpan.FromMilliseconds(1000)).SleepAsync(100).Wait();
                }
                catch (AggregateException ex) when(ex.InnerException is OperationCanceledException)
                {
                    TestHelper.Assert(false);
                }
                TestHelper.Assert(connection == timeout.GetConnection());

                try
                {
                    timeout.Clone(invocationTimeout: TimeSpan.FromMilliseconds(100)).Sleep(1000);
                    TestHelper.Assert(false);
                }
                catch (OperationCanceledException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing close timeout... ");
            output.Flush();
            {
                Dictionary <string, string> properties = communicator.GetProperties();
                properties["Ice.CloseTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), comm);

                Connection?connection  = to.GetConnection();
                Connection?connection2 = timeout.GetConnection();  // No close timeout

                TestHelper.Assert(connection != null && connection2 != null);

                controller.HoldAdapter(-1);

                // Make sure there's no ReadAsync pending
                _ = to.IcePingAsync();
                _ = timeout.IcePingAsync();

                var semaphore = new System.Threading.SemaphoreSlim(0);
                connection.Closed += (sender, args) => semaphore.Release();
                connection.GoAwayAsync();
                TestHelper.Assert(semaphore.Wait(500));

                connection2.Closed += (sender, args) => semaphore.Release();
                connection2.GoAwayAsync();
                TestHelper.Assert(!semaphore.Wait(500));

                controller.ResumeAdapter();
                timeout.Op(); // Ensure adapter is active.
            }
            output.WriteLine("ok");

            if (!ice1)
            {
                output.Write("testing deadlines... ");
                output.Flush();
                {
                    var comm1 = new Communicator(
                        communicator.GetProperties(),
                        invocationInterceptors: new InvocationInterceptor[]
                    {
                        (target, request, next, cancel) =>
                        {
                            request.AddBinaryContextEntry(10, request.Deadline, (ostr, value) =>
                            {
                                var deadline = (value - DateTime.UnixEpoch).TotalMilliseconds;
                                ostr.WriteVarLong((long)deadline);
                            });
                            return(next(target, request, cancel));
                        }
                    });

                    for (int i = 1000; i < 5000;)
                    {
                        i += 33;
                        ITimeoutPrx to = ITimeoutPrx.Parse(helper.GetTestProxy("timeout", 0), comm1).Clone(
                            invocationTimeout: TimeSpan.FromMilliseconds(i));
                        TestHelper.Assert(to.CheckDeadline());
                    }
                }
                output.WriteLine("ok");
            }
            controller.Shutdown();
        }
예제 #30
0
        public global::UseCase1.SelectedSubmission[] Search <TCondition>(ISpecification <TCondition> specification, int?limit, int?offset)
        {
            Revenj.Utility.ChunkedMemoryStream cms = null;
            System.IO.TextWriter sw = null;
            var selectType          = "SELECT _it";
            var lookup = PrepareLocalFind(Locator);
            var result = lookup.list;

            if (specification == null)
            {
                cms = lookup.cms;
                sw  = cms.GetWriter();
                sw.Write(@"SELECT _r FROM ""UseCase1"".""SelectedSubmission"" _r");
            }


            else if (specification is global::UseCase1.SelectedSubmission.Where)
            {
                var spec = specification as global::UseCase1.SelectedSubmission.Where;
                cms = Common.Utility.UseThreadLocalStream();
                sw  = cms.GetWriter();
                sw.Write(selectType);
                sw.Write(@" FROM ""UseCase1"".""SelectedSubmission.Where""(");

                sw.Write('\'');
                _DatabaseCommon.Utility.StringToTuple(spec.uri).InsertRecord(sw, cms.SmallBuffer, string.Empty, PostgresTuple.EscapeQuote);
                sw.Write('\'');
                sw.Write(") _it");
            }

            if (cms == null)
            {
                var query = Query(specification);
                if (limit != null && limit.Value >= 0)
                {
                    query = query.Take(limit.Value);
                }
                if (offset != null && offset.Value >= 0)
                {
                    query = query.Skip(offset.Value);
                }
                result.AddRange(query);
            }
            else
            {
                //TODO: dynamic security
                if (limit != null && limit.Value >= 0)
                {
                    sw.Write(" LIMIT ");
                    sw.Write(limit.Value);
                }
                if (offset != null && offset.Value >= 0)
                {
                    sw.Write(" OFFSET ");
                    sw.Write(offset.Value);
                }
                sw.Flush();
                lookup.ExecuteAll(DatabaseQuery, lookup.NoTemplateCommand);
            }

            var found = result.ToArray();

            return(found);
        }
예제 #31
0
        private void Run(IMyObjectPrx prx, Interceptor interceptor)
        {
            System.IO.TextWriter output = GetWriter();
            output.Write("testing simple interceptor... ");
            output.Flush();
            Assert(interceptor.GetLastOperation() == null);
            Assert(!interceptor.AsyncCompletion);
            prx.IcePing();
            Assert(interceptor.GetLastOperation() !.Equals("ice_ping"));
            Assert(!interceptor.AsyncCompletion);
            string typeId = prx.IceId();

            Assert(interceptor.GetLastOperation() !.Equals("ice_id"));
            Assert(!interceptor.AsyncCompletion);
            Assert(prx.IceIsA(typeId));
            Assert(interceptor.GetLastOperation() !.Equals("ice_isA"));
            Assert(!interceptor.AsyncCompletion);
            Assert(prx.Add(33, 12) == 45);
            Assert(interceptor.GetLastOperation() !.Equals("add"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing retry... ");
            output.Flush();
            Assert(prx.AddWithRetry(33, 12) == 45);
            Assert(interceptor.GetLastOperation() !.Equals("addWithRetry"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing remote exception... ");
            output.Flush();
            try
            {
                prx.BadAdd(33, 12);
                Assert(false);
            }
            catch (InvalidInputException)
            {
                // expected
            }
            Assert(interceptor.GetLastOperation() !.Equals("badAdd"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");
            output.Write("testing ONE... ");
            output.Flush();
            interceptor.Clear();
            try
            {
                prx.NotExistAdd(33, 12);
                Assert(false);
            }
            catch (ObjectNotExistException)
            {
                // expected
            }
            Assert(interceptor.GetLastOperation() !.Equals("notExistAdd"));
            Assert(!interceptor.AsyncCompletion);
            output.WriteLine("ok");

            output.Write("testing exceptions raised by the interceptor... ");
            output.Flush();
            TestInterceptorExceptions(prx);
            output.WriteLine("ok");

            output.Write("testing binary context... ");
            output.Flush();
            bool ice2 = Communicator() !.DefaultProtocol != Protocol.Ice1;

            if (ice2)
            {
                for (int size = 128; size < 4096; size *= 2)
                {
                    var token   = new Token(1, "mytoken", Enumerable.Range(0, size).Select(i => (byte)2).ToArray());
                    var request = OutgoingRequestFrame.WithParamList(prx,
                                                                     "opWithBinaryContext",
                                                                     idempotent: false,
                                                                     compress: false,
                                                                     format: default,