Пример #1
0
        public static void allTests(global::Test.TestHelper helper)
        {
            var communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var controller = IControllerPrx.Parse($"controller:{helper.GetTestEndpoint(1)}", communicator);

            try
            {
                allTestsWithController(helper, controller);
            }
            catch (Exception)
            {
                // Ensure the adapter is not in the holding state when an unexpected exception occurs to prevent
                // the test from hanging on exit in case a connection which disables timeouts is still opened.
                controller.resumeAdapter();
                throw;
            }
        }
Пример #2
0
        public static void allTests(global::Test.TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var output = helper.GetWriter();

            output.Write("testing proxy endpoint information... ");
            output.Flush();
            {
                var p1 = IObjectPrx.Parse(
                    "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" +
                    "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" +
                    "opaque -e 1.8 -t 100 -v ABCD", communicator);

                var endps = p1.Endpoints;

                Endpoint    endpoint    = endps[0];
                TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint);
                TestHelper.Assert(tcpEndpoint != null);
                TestHelper.Assert(tcpEndpoint.Host.Equals("tcphost"));
                TestHelper.Assert(tcpEndpoint.Port == 10000);
                TestHelper.Assert(tcpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10"));
                TestHelper.Assert(tcpEndpoint.Timeout == 1200);
                TestHelper.Assert(tcpEndpoint.HasCompressionFlag);
                TestHelper.Assert(!tcpEndpoint.IsDatagram);

                TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && !tcpEndpoint.IsSecure ||
                                  tcpEndpoint.Type == EndpointType.SSL && tcpEndpoint.IsSecure ||
                                  tcpEndpoint.Type == EndpointType.WS && !tcpEndpoint.IsSecure ||
                                  tcpEndpoint.Type == EndpointType.WSS && tcpEndpoint.IsSecure);
                TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && endpoint is TcpEndpoint ||
                                  tcpEndpoint.Type == EndpointType.SSL && endpoint is IceSSL.Endpoint ||
                                  tcpEndpoint.Type == EndpointType.WS && endpoint is WSEndpoint ||
                                  tcpEndpoint.Type == EndpointType.WSS && endpoint is WSEndpoint);

                UdpEndpoint udpEndpoint = (UdpEndpoint)endps[1];
                TestHelper.Assert(udpEndpoint.Host.Equals("udphost"));
                TestHelper.Assert(udpEndpoint.Port == 10001);
                TestHelper.Assert(udpEndpoint.McastInterface.Equals("eth0"));
                TestHelper.Assert(udpEndpoint.McastTtl == 5);
                TestHelper.Assert(udpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10"));
                TestHelper.Assert(udpEndpoint.Timeout == -1);
                TestHelper.Assert(!udpEndpoint.HasCompressionFlag);
                TestHelper.Assert(!udpEndpoint.IsSecure);
                TestHelper.Assert(udpEndpoint.IsDatagram);
                TestHelper.Assert(udpEndpoint.Type == EndpointType.UDP);

                OpaqueEndpoint opaqueEndpoint = (OpaqueEndpoint)endps[2];
                TestHelper.Assert(opaqueEndpoint.Bytes.Length > 0);
                TestHelper.Assert(opaqueEndpoint.Encoding.Equals(new Encoding(1, 8)));
            }
            output.WriteLine("ok");

            ObjectAdapter adapter;

            output.Write("test object adapter endpoint information... ");
            output.Flush();
            {
                string host = communicator.GetPropertyAsInt("Ice.IPv6") != 0 ? "::1" : "127.0.0.1";
                communicator.SetProperty("TestAdapter.Endpoints", "tcp -h \"" + host +
                                         "\" -t 15000:udp -h \"" + host + "\"");
                adapter = communicator.CreateObjectAdapter("TestAdapter");

                var endpoints = adapter.GetEndpoints();
                TestHelper.Assert(endpoints.Count == 2);
                var publishedEndpoints = adapter.GetPublishedEndpoints();
                TestHelper.Assert(global::Test.Collections.Equals(endpoints, publishedEndpoints));

                TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoints[0]);
                TestHelper.Assert(tcpEndpoint != null);
                TestHelper.Assert(
                    tcpEndpoint.Type == EndpointType.TCP ||
                    tcpEndpoint.Type == EndpointType.SSL ||
                    tcpEndpoint.Type == EndpointType.WS ||
                    tcpEndpoint.Type == EndpointType.WSS);

                TestHelper.Assert(tcpEndpoint.Host.Equals(host));
                TestHelper.Assert(tcpEndpoint.Port > 0);
                TestHelper.Assert(tcpEndpoint.Timeout == 15000);

                UdpEndpoint udpEndpoint = (UdpEndpoint)endpoints[1];
                TestHelper.Assert(udpEndpoint.Host.Equals(host));
                TestHelper.Assert(udpEndpoint.IsDatagram);
                TestHelper.Assert(udpEndpoint.Port > 0);

                endpoints = new List <Endpoint> {
                    endpoints[0]
                };
                TestHelper.Assert(endpoints.Count == 1);

                adapter.SetPublishedEndpoints(endpoints);
                publishedEndpoints = adapter.GetPublishedEndpoints();
                TestHelper.Assert(Collections.Equals(endpoints, publishedEndpoints));

                adapter.Destroy();

                int port = helper.GetTestPort(1);
                communicator.SetProperty("TestAdapter.Endpoints", $"default -h * -p {port}");
                communicator.SetProperty("TestAdapter.PublishedEndpoints", helper.GetTestEndpoint(1));
                adapter = communicator.CreateObjectAdapter("TestAdapter");

                endpoints = adapter.GetEndpoints();
                TestHelper.Assert(endpoints.Count >= 1);
                publishedEndpoints = adapter.GetPublishedEndpoints();
                TestHelper.Assert(publishedEndpoints.Count == 1);

                foreach (var endpoint in endpoints)
                {
                    tcpEndpoint = getTCPEndpoint(endpoint);
                    TestHelper.Assert(tcpEndpoint !.Port == port);
                }

                tcpEndpoint = getTCPEndpoint(publishedEndpoints[0]);
                TestHelper.Assert(tcpEndpoint !.Host == "127.0.0.1");
                TestHelper.Assert(tcpEndpoint !.Port == port);

                adapter.Destroy();
            }
            output.WriteLine("ok");

            int endpointPort = helper.GetTestPort(0);

            var testIntf = Test.ITestIntfPrx.Parse("test:" +
                                                   helper.GetTestEndpoint(0) + ":" +
                                                   helper.GetTestEndpoint(0, "udp"), communicator);

            string defaultHost = communicator.GetProperty("Ice.Default.Host") ?? "";

            output.Write("test connection endpoint information... ");
            output.Flush();
            {
                Endpoint    endpoint    = testIntf.GetConnection().Endpoint;
                TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint);
                TestHelper.Assert(tcpEndpoint != null);
                TestHelper.Assert(tcpEndpoint.Port == endpointPort);
                TestHelper.Assert(!tcpEndpoint.HasCompressionFlag);
                TestHelper.Assert(tcpEndpoint.Host.Equals(defaultHost));

                Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext();
                TestHelper.Assert(ctx["host"].Equals(tcpEndpoint.Host));
                TestHelper.Assert(ctx["compress"].Equals("false"));
                int port = int.Parse(ctx["port"]);
                TestHelper.Assert(port > 0);

                endpoint = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection().Endpoint;
                UdpEndpoint udp = (UdpEndpoint)endpoint;
                TestHelper.Assert(udp.Port == endpointPort);
                TestHelper.Assert(udp.Host.Equals(defaultHost));
            }
            output.WriteLine("ok");

            output.Write("testing connection information... ");
            output.Flush();
            {
                Connection connection = testIntf.GetConnection();
                connection.SetBufferSize(1024, 2048);

                ConnectionInfo    info   = connection.GetConnectionInfo();
                TCPConnectionInfo ipInfo = getTCPConnectionInfo(info) !;
                TestHelper.Assert(!info.Incoming);
                TestHelper.Assert(info.AdapterName !.Length == 0);
                TestHelper.Assert(ipInfo.RemotePort == endpointPort);
                TestHelper.Assert(ipInfo.LocalPort > 0);
                if (defaultHost.Equals("127.0.0.1"))
                {
                    TestHelper.Assert(ipInfo.LocalAddress.Equals(defaultHost));
                    TestHelper.Assert(ipInfo.RemoteAddress.Equals(defaultHost));
                }
                TestHelper.Assert(ipInfo.RcvSize >= 1024);
                TestHelper.Assert(ipInfo.SndSize >= 2048);

                Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext();
                TestHelper.Assert(ctx["incoming"].Equals("true"));
                TestHelper.Assert(ctx["adapterName"].Equals("TestAdapter"));
                TestHelper.Assert(ctx["remoteAddress"].Equals(ipInfo.LocalAddress));
                TestHelper.Assert(ctx["localAddress"].Equals(ipInfo.RemoteAddress));
                TestHelper.Assert(ctx["remotePort"].Equals(ipInfo.LocalPort.ToString()));
                TestHelper.Assert(ctx["localPort"].Equals(ipInfo.RemotePort.ToString()));

                if (testIntf.GetConnection().Type().Equals("ws") || testIntf.GetConnection().Type().Equals("wss"))
                {
                    Dictionary <string, string> headers = ((WSConnectionInfo)info).Headers !;
                    TestHelper.Assert(headers["Upgrade"].Equals("websocket"));
                    TestHelper.Assert(headers["Connection"].Equals("Upgrade"));
                    TestHelper.Assert(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                    TestHelper.Assert(headers["Sec-WebSocket-Accept"] != null);

                    TestHelper.Assert(ctx["ws.Upgrade"].Equals("websocket"));
                    TestHelper.Assert(ctx["ws.Connection"].Equals("Upgrade"));
                    TestHelper.Assert(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                    TestHelper.Assert(ctx["ws.Sec-WebSocket-Version"].Equals("13"));
                    TestHelper.Assert(ctx["ws.Sec-WebSocket-Key"] != null);
                }

                connection = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection();
                connection.SetBufferSize(2048, 1024);

                UDPConnectionInfo udpInfo = (UDPConnectionInfo)connection.GetConnectionInfo();
                TestHelper.Assert(!udpInfo.Incoming);
                TestHelper.Assert(udpInfo.AdapterName !.Length == 0);
                TestHelper.Assert(udpInfo.LocalPort > 0);
                TestHelper.Assert(udpInfo.RemotePort == endpointPort);

                if (defaultHost.Equals("127.0.0.1"))
                {
                    TestHelper.Assert(udpInfo.RemoteAddress.Equals(defaultHost));
                    TestHelper.Assert(udpInfo.LocalAddress.Equals(defaultHost));
                }
                TestHelper.Assert(udpInfo.RcvSize >= 2048);
                TestHelper.Assert(udpInfo.SndSize >= 1024);
            }
            output.WriteLine("ok");

            testIntf.shutdown();

            communicator.Shutdown();
            communicator.WaitForShutdown();
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static void allTests(global::Test.TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            TextWriter output = helper.GetWriter();

            output.Write("testing communicator operations... ");
            output.Flush();
            {
                //
                // Test: Exercise AddAdminFacet, FindAdminFacet, RemoveAdminFacet with a typical configuration.
                //
                var properties = new Dictionary <string, string>
                {
                    ["Ice.Admin.Endpoints"]    = "tcp -h 127.0.0.1",
                    ["Ice.Admin.InstanceName"] = "Test"
                };
                var com = new Communicator(properties);
                TestFacets(com, true, false);
                com.Destroy();
            }
            {
                //
                // Test: Verify that the operations work correctly in the presence of facet filters.
                //
                var properties = new Dictionary <string, string>
                {
                    ["Ice.Admin.Endpoints"]    = "tcp -h 127.0.0.1",
                    ["Ice.Admin.InstanceName"] = "Test",
                    ["Ice.Admin.Facets"]       = "Properties"
                };
                var com = new Communicator(properties);
                TestFacets(com, false, true);
                com.Destroy();
            }
            {
                //
                // Test: Verify that the operations work correctly with the Admin object disabled.
                //
                var com = new Communicator();
                TestFacets(com, false, false);
                com.Destroy();
            }
            {
                //
                // Test: Verify that the operations work correctly with Ice.Admin.Enabled=1
                //
                var properties = new Dictionary <string, string>()
                {
                    { "Ice.Admin.Enabled", "1" }
                };
                var com = new Communicator(properties);
                TestHelper.Assert(com.GetAdmin() == null);
                var id = Identity.Parse("test-admin");
                try
                {
                    com.CreateAdmin(null, id);
                    TestHelper.Assert(false);
                }
                catch (InvalidConfigurationException)
                {
                }

                ObjectAdapter adapter = com.CreateObjectAdapter();
                TestHelper.Assert(com.CreateAdmin(adapter, id) != null);
                TestHelper.Assert(com.GetAdmin() != null);

                TestFacets(com, true, false);
                com.Destroy();
            }
            {
                //
                // Test: Verify that the operations work correctly when creation of the Admin object is delayed.
                //
                var properties = new Dictionary <string, string>()
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.DelayCreation", "1" }
                };

                var com = new Communicator(properties);
                TestFacets(com, true, false);
                com.GetAdmin();
                TestFacets(com, true, false);
                com.Destroy();
            }
            output.WriteLine("ok");

            var factory = IRemoteCommunicatorFactoryPrx.Parse($"factory:{helper.GetTestEndpoint(0)} -t 10000",
                                                              communicator);

            output.Write("testing process facet... ");
            output.Flush();
            {
                //
                // Test: Verify that Process::shutdown() operation shuts down the communicator.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IProcessPrx proc = obj.Clone("Process", IProcessPrx.Factory);
                proc.Shutdown();
                com.waitForShutdown();
                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing properties facet... ");
            output.Flush();
            {
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Prop1", "1" },
                    { "Prop2", "2" },
                    { "Prop3", "3" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IPropertiesAdminPrx pa = obj.Clone("Properties", IPropertiesAdminPrx.Factory);

                //
                // Test: PropertiesAdmin::getProperty()
                //
                TestHelper.Assert(pa.GetProperty("Prop2") == "2");
                TestHelper.Assert(pa.GetProperty("Bogus") == "");

                //
                // Test: PropertiesAdmin::getProperties()
                //
                Dictionary <string, string> pd = pa.GetPropertiesForPrefix("");
                TestHelper.Assert(pd.Count == 6);
                TestHelper.Assert(pd["Ice.ProgramName"] == "server");
                TestHelper.Assert(pd["Ice.Admin.Endpoints"] == "tcp -h 127.0.0.1");
                TestHelper.Assert(pd["Ice.Admin.InstanceName"] == "Test");
                TestHelper.Assert(pd["Prop1"] == "1");
                TestHelper.Assert(pd["Prop2"] == "2");
                TestHelper.Assert(pd["Prop3"] == "3");

                Dictionary <string, string> changes;

                //
                // Test: PropertiesAdmin::setProperties()
                //
                var setProps = new Dictionary <string, string>
                {
                    { "Prop1", "10" }, // Changed
                    { "Prop2", "20" }, // Changed
                    { "Prop3", "" },   // Removed
                    { "Prop4", "4" },  // Added
                    { "Prop5", "5" } // Added
                };
                pa.SetProperties(setProps);
                TestHelper.Assert(pa.GetProperty("Prop1").Equals("10"));
                TestHelper.Assert(pa.GetProperty("Prop2").Equals("20"));
                TestHelper.Assert(pa.GetProperty("Prop3").Equals(""));
                TestHelper.Assert(pa.GetProperty("Prop4").Equals("4"));
                TestHelper.Assert(pa.GetProperty("Prop5").Equals("5"));
                changes = com.getChanges();
                TestHelper.Assert(changes.Count == 5);
                TestHelper.Assert(changes["Prop1"].Equals("10"));
                TestHelper.Assert(changes["Prop2"].Equals("20"));
                TestHelper.Assert(changes["Prop3"].Equals(""));
                TestHelper.Assert(changes["Prop4"].Equals("4"));
                TestHelper.Assert(changes["Prop5"].Equals("5"));
                pa.SetProperties(setProps);
                changes = com.getChanges();
                TestHelper.Assert(changes.Count == 0);

                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing logger facet... ");
            output.Flush();
            {
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "NullLogger", "1" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                com.trace("testCat", "trace");
                com.warning("warning");
                com.error("error");
                com.print("print");

                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                ILoggerAdminPrx logger = obj.Clone("Logger", ILoggerAdminPrx.Factory);

                //
                // Get all
                //
                (LogMessage[] logMessages, string prefix) =
                    logger.GetLog(Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);

                TestHelper.Assert(logMessages.Length == 4);
                TestHelper.Assert(prefix.Equals("NullLogger"));
                TestHelper.Assert(logMessages[0].TraceCategory.Equals("testCat") && logMessages[0].Message.Equals("trace"));
                TestHelper.Assert(logMessages[1].Message.Equals("warning"));
                TestHelper.Assert(logMessages[2].Message.Equals("error"));
                TestHelper.Assert(logMessages[3].Message.Equals("print"));

                //
                // Get only errors and warnings
                //
                com.error("error2");
                com.print("print2");
                com.trace("testCat", "trace2");
                com.warning("warning2");

                LogMessageType[] messageTypes = { LogMessageType.ErrorMessage, LogMessageType.WarningMessage };

                (logMessages, prefix) = logger.GetLog(messageTypes, Array.Empty <string>(), -1);

                TestHelper.Assert(logMessages.Length == 4);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                foreach (LogMessage msg in logMessages)
                {
                    TestHelper.Assert(msg.Type == LogMessageType.ErrorMessage || msg.Type == LogMessageType.WarningMessage);
                }

                //
                // Get only errors and traces with Cat = "testCat"
                //
                com.trace("testCat2", "A");
                com.trace("testCat", "trace3");
                com.trace("testCat2", "B");

                messageTypes = new LogMessageType[] { LogMessageType.ErrorMessage, LogMessageType.TraceMessage };
                string[] categories = { "testCat" };
                (logMessages, prefix) = logger.GetLog(messageTypes, categories, -1);
                TestHelper.Assert(logMessages.Length == 5);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                foreach (LogMessage msg in logMessages)
                {
                    TestHelper.Assert(msg.Type == LogMessageType.ErrorMessage ||
                                      (msg.Type == LogMessageType.TraceMessage && msg.TraceCategory.Equals("testCat")));
                }

                //
                // Same, but limited to last 2 messages(trace3 + error3)
                //
                com.error("error3");

                (logMessages, prefix) = logger.GetLog(messageTypes, categories, 2);
                TestHelper.Assert(logMessages.Length == 2);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                TestHelper.Assert(logMessages[0].Message.Equals("trace3"));
                TestHelper.Assert(logMessages[1].Message.Equals("error3"));

                //
                // Now, test RemoteLogger
                //
                ObjectAdapter adapter =
                    communicator.CreateObjectAdapterWithEndpoints("RemoteLoggerAdapter", "tcp -h localhost");

                var remoteLogger = new RemoteLogger();

                IRemoteLoggerPrx myProxy = adapter.AddWithUUID(remoteLogger, IRemoteLoggerPrx.Factory);

                adapter.Activate();

                //
                // No filtering
                //
                (logMessages, prefix) = logger.GetLog(Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);

                logger.AttachRemoteLogger(myProxy, Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);
                remoteLogger.Wait(1);

                foreach (LogMessage m in logMessages)
                {
                    remoteLogger.CheckNextInit(prefix, m.Type, m.Message, m.TraceCategory);
                }

                com.trace("testCat", "rtrace");
                com.warning("rwarning");
                com.error("rerror");
                com.print("rprint");

                remoteLogger.Wait(4);

                remoteLogger.CheckNextLog(LogMessageType.TraceMessage, "rtrace", "testCat");
                remoteLogger.CheckNextLog(LogMessageType.WarningMessage, "rwarning", "");
                remoteLogger.CheckNextLog(LogMessageType.ErrorMessage, "rerror", "");
                remoteLogger.CheckNextLog(LogMessageType.PrintMessage, "rprint", "");

                TestHelper.Assert(logger.DetachRemoteLogger(myProxy));
                TestHelper.Assert(!logger.DetachRemoteLogger(myProxy));

                //
                // Use Error + Trace with "traceCat" filter with 4 limit
                //
                (logMessages, prefix) = logger.GetLog(messageTypes, categories, 4);
                TestHelper.Assert(logMessages.Length == 4);

                logger.AttachRemoteLogger(myProxy, messageTypes, categories, 4);
                remoteLogger.Wait(1);

                foreach (LogMessage m in logMessages)
                {
                    remoteLogger.CheckNextInit(prefix, m.Type, m.Message, m.TraceCategory);
                }

                com.warning("rwarning2");
                com.trace("testCat", "rtrace2");
                com.warning("rwarning3");
                com.error("rerror2");
                com.print("rprint2");

                remoteLogger.Wait(2);

                remoteLogger.CheckNextLog(LogMessageType.TraceMessage, "rtrace2", "testCat");
                remoteLogger.CheckNextLog(LogMessageType.ErrorMessage, "rerror2", "");

                //
                // Attempt reconnection with slightly different proxy
                //
                try
                {
                    logger.AttachRemoteLogger(myProxy.Clone(oneway: true), messageTypes, categories, 4);
                    TestHelper.Assert(false);
                }
                catch (RemoteLoggerAlreadyAttachedException)
                {
                    // expected
                }

                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing custom facet... ");
            output.Flush();
            {
                //
                // Test: Verify that the custom facet is present.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                ITestFacetPrx tf = obj.Clone("TestFacet", ITestFacetPrx.Factory);
                tf.op();
                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing facet filtering... ");
            output.Flush();
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the Properties facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Properties" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the Process facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Process" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the TestFacet facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "TestFacet" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the
                // facet names.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Properties TestFacet" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IPropertiesAdminPrx pa = obj.Clone("Properties", IPropertiesAdminPrx.Factory);
                TestHelper.Assert(pa.GetProperty("Ice.Admin.InstanceName").Equals("Test"));
                var tf = ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                tf !.op();
                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the
                // facet names.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "TestFacet, Process" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                var tf = ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                TestHelper.Assert(tf != null);
                tf.op();
                var proc = IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                TestHelper.Assert(proc != null);
                proc.Shutdown();
                com.waitForShutdown();
                com.destroy();
            }
            output.WriteLine("ok");

            factory.shutdown();
        }
Пример #5
0
        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);
        }
Пример #6
0
        public static void allTests(global::Test.TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

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

            Console.WriteLine("registry checkedcast");
            var registry = 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 = ITestIntfPrx.CheckedCast(base1);

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

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

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

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

            TestHelper.Assert(obj5 != null);
            var obj6 = 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 = 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 = ITestIntfPrx.Parse("test@TestAdapter", communicator);
            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 = 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 = 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.
            IHelloPrx?helloPrx;

            helloPrx = 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 = IHelloPrx.CheckedCast(adapter.CreateIndirectProxy(id, IObjectPrx.Factory));
            TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null);

            // Ensure that calls on the direct proxy is collocated
            helloPrx = 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");
        }