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.GetPropertyAsBool("Ice.IPv6") ?? false) ? "::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(endpoints.SequenceEqual(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(endpoints.SequenceEqual(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(); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var com = Test.RemoteCommunicatorPrx.Parse($"communicator:{helper.getTestEndpoint(0)}", communicator); var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); var output = helper.getWriter(); output.Write("testing binding with single endpoint... "); output.Flush(); { Test.RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default"); var test1 = adapter.getTestIntf(); var test2 = adapter.getTestIntf(); test(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.deactivateObjectAdapter(adapter); var test3 = Test.TestIntfPrx.UncheckedCast(test1); test(test3.GetConnection() == test1.GetConnection()); test(test3.GetConnection() == test2.GetConnection()); try { test3.IcePing(); test(false); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter11", "default")); adapters.Add(com.createObjectAdapter("Adapter12", "default")); adapters.Add(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.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.IcePing(); test(test1.GetConnection() == test2.GetConnection()); test(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 (var 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++) { ; } test(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((Test.RemoteObjectAdapterPrx)adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test(test1.GetConnection() == test2.GetConnection()); test(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.RemoteObjectAdapterPrx)adapters[2]); var obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new Test.RemoteObjectAdapterPrx[5]; adapters[0] = com.createObjectAdapter("AdapterRandom11", "default"); adapters[1] = com.createObjectAdapter("AdapterRandom12", "default"); adapters[2] = com.createObjectAdapter("AdapterRandom13", "default"); adapters[3] = com.createObjectAdapter("AdapterRandom14", "default"); adapters[4] = com.createObjectAdapter("AdapterRandom15", "default"); int count = 20; int adapterCount = adapters.Length; while (--count > 0) { Test.TestIntfPrx[] proxies; if (count == 1) { com.deactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new Test.TestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new Test.RemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new Test.RemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = createTestIntfPrx(new List <Test.RemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].getAdapterNameAsync(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].IcePing(); } catch (LocalException) { } } List <Connection> 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()); } } } test(connections.Count <= adapterCount); foreach (var a in adapters) { try { a.getTestIntf().GetConnection().close(ConnectionClose.GracefullyWithWait); } catch (LocalException) { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI11", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI12", "default")); adapters.Add(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.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.IcePing(); test(test1.GetConnection() == test2.GetConnection()); test(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++) { ; } test(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.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test(test1.GetConnection() == test2.GetConnection()); test(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); test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter21", "default")); adapters.Add(com.createObjectAdapter("Adapter22", "default")); adapters.Add(com.createObjectAdapter("Adapter23", "default")); var obj = createTestIntfPrx(adapters); test(obj.EndpointSelection == EndpointSelectionType.Random); var names = new List <string>(); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.GetConnection().close(ConnectionClose.GracefullyWithWait); } obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Random); test(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.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter31", "default")); adapters.Add(com.createObjectAdapter("Adapter32", "default")); adapters.Add(com.createObjectAdapter("Adapter33", "default")); var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered); test(obj.EndpointSelection == EndpointSelectionType.Ordered); 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 && obj.getAdapterName().Equals("Adapter31"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } Endpoint[] 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++) { ; } test(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++) { ; } test(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++) { ; } test(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { var adapter = com.createObjectAdapter("Adapter41", "default"); var test1 = adapter.getTestIntf().Clone(connectionCached: false); var test2 = adapter.getTestIntf().Clone(connectionCached: false); test(!test1.IsConnectionCached); test(!test2.IsConnectionCached); test(test1.GetConnection() != null && test2.GetConnection() != null); test(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.deactivateObjectAdapter(adapter); var test3 = Test.TestIntfPrx.UncheckedCast(test1); try { test(test3.GetConnection() == test1.GetConnection()); test(false); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter51", "default")); adapters.Add(com.createObjectAdapter("Adapter52", "default")); adapters.Add(com.createObjectAdapter("Adapter53", "default")); var obj = createTestIntfPrx(adapters).Clone(connectionCached: false); test(!obj.IsConnectionCached); List <string> names = new List <string>(); names.Add("Adapter51"); names.Add("Adapter52"); names.Add("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]); test(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.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI51", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI52", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI53", "default")); var obj = createTestIntfPrx(adapters).Clone(connectionCached: false); test(!obj.IsConnectionCached); var names = new List <string>(); names.Add("AdapterAMI51"); names.Add("AdapterAMI52"); names.Add("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]); test(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.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter61", "default")); adapters.Add(com.createObjectAdapter("Adapter62", "default")); adapters.Add(com.createObjectAdapter("Adapter63", "default")); var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered); test(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(connectionCached: false); test(!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 && obj.getAdapterName().Equals("Adapter61"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } Endpoint[] 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++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++) { ; } test(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.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI61", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI62", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI63", "default")); var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelectionType: EndpointSelectionType.Ordered); test(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(connectionCached: false); test(!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++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } Endpoint[] 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++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter71", "default")); adapters.Add(com.createObjectAdapter("Adapter72", "udp")); var obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter71")); var testUDP = obj.Clone(invocationMode: InvocationMode.Datagram); test(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.getAdapterName(); } catch (TwowayOnlyException) { } } output.WriteLine("ok"); if (communicator.GetProperty("Plugin.IceSSL") != null) { output.Write("testing unsecure vs. secure endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter81", "ssl")); adapters.Add(com.createObjectAdapter("Adapter82", "tcp")); var obj = createTestIntfPrx(adapters); int i; for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter82")); obj.GetConnection().close(ConnectionClose.GracefullyWithWait); } var testSecure = obj.Clone(secure: true); test(testSecure.IsSecure); testSecure = obj.Clone(secure: false); test(!testSecure.IsSecure); testSecure = obj.Clone(secure: true); test(testSecure.IsSecure); test(obj.GetConnection() != testSecure.GetConnection()); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter81")); obj.GetConnection().close(ConnectionClose.GracefullyWithWait); } com.createObjectAdapter("Adapter83", (obj.Endpoints[1]).ToString()); // Reactive tcp OA. for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter83")); obj.GetConnection().close(ConnectionClose.GracefullyWithWait); } com.deactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); test(false); } catch (ConnectFailedException) { } catch (ConnectTimeoutException) { } 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 (SocketException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.destroy(); continue; // IP version not supported. } var prx = oa.CreateProxy("dummy"); try { prx.Clone(collocationOptimized: false).IcePing(); } catch (LocalException) { serverCommunicator.destroy(); continue; // IP version not supported. } string strPrx = prx.ToString(); foreach (var q in clientProps) { Communicator clientCommunicator = new Communicator(q); prx = IObjectPrx.Parse(strPrx, clientCommunicator); try { prx.IcePing(); test(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 (SocketException) { test((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(); }
public static Test.IMyClassPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var cl = Test.IMyClassPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var oneway = cl.Clone(oneway: true); var output = helper.getWriter(); output.Write("testing Invoke... "); output.Flush(); { var request = OutgoingRequestFrame.WithNoParameter(oneway, "opOneway", idempotent: false); // Whether the proxy is oneway or not does not matter for Invoke's oneway parameter. var response = cl.Invoke(request, oneway: true); test(response.ReplyStatus == ReplyStatus.OK); response = cl.Invoke(request, oneway: false); test(response.ReplyStatus == ReplyStatus.UserException); response = oneway.Invoke(request, oneway: true); test(response.ReplyStatus == ReplyStatus.OK); response = oneway.Invoke(request, oneway: false); test(response.ReplyStatus == ReplyStatus.UserException); request = OutgoingRequestFrame.WithParameters(cl, "opString", idempotent: false, format: null, context: null, testString, OutputStream.IceWriterFromString); response = cl.Invoke(request); var result = response.ReadResult(); test(result.ResultType == ResultType.Success); string s = result.InputStream.ReadString(); test(s.Equals(testString)); s = result.InputStream.ReadString(); result.InputStream.EndEncapsulation(); test(s.Equals(testString)); } for (int i = 0; i < 2; ++i) { Dictionary <string, string>?ctx = null; if (i == 1) { ctx = new Dictionary <string, string>(); ctx["raise"] = ""; } var request = OutgoingRequestFrame.WithNoParameter(cl, "opException", idempotent: false, context: ctx); var response = cl.Invoke(request); var result = response.ReadResult(); test(result.ResultType == ResultType.Failure); try { result.InputStream.ThrowException(); } catch (Test.MyException) { result.InputStream.EndEncapsulation(); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("testing InvokeAsync... "); output.Flush(); { var request = OutgoingRequestFrame.WithNoParameter(oneway, "opOneway", idempotent: false); try { oneway.InvokeAsync(request, oneway: true).Wait(); } catch (System.Exception) { test(false); } request = OutgoingRequestFrame.WithParameters(cl, "opString", idempotent: false, format: null, context: null, testString, OutputStream.IceWriterFromString); var response = cl.InvokeAsync(request).Result; var result = response.ReadResult(); test(result.ResultType == ResultType.Success); string s = result.InputStream.ReadString(); test(s.Equals(testString)); s = result.InputStream.ReadString(); result.InputStream.EndEncapsulation(); test(s.Equals(testString)); } { var request = OutgoingRequestFrame.WithNoParameter(cl, "opException", idempotent: false); var response = cl.InvokeAsync(request).Result; var result = response.ReadResult(); test(result.ResultType == ResultType.Failure); try { result.InputStream.ThrowException(); } catch (Test.MyException) { result.InputStream.EndEncapsulation(); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); return(cl); }
internal static void onewaysAMI(global::Test.TestHelper helper, Test.MyClassPrx proxy) { Ice.Communicator communicator = helper.communicator(); Test.MyClassPrx p = Test.MyClassPrxHelper.uncheckedCast(proxy.ice_oneway()); { Callback cb = new Callback(); p.ice_pingAsync(progress: new Progress <bool>( sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); } { Callback cb = new Callback(); p.begin_ice_ping().whenCompleted(cb.noException).whenSent(cb.sent); cb.check(); } { Callback cb = new Callback(); p.begin_ice_ping().whenCompleted( (Ice.Exception ex) => { cb.noException(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); } { try { p.ice_isAAsync("::Test::MyClass"); test(false); } catch (Ice.TwowayOnlyException) { } } { try { p.begin_ice_isA("::Test::MyClass"); test(false); } catch (System.ArgumentException) { } } { try { p.ice_idAsync(); test(false); } catch (Ice.TwowayOnlyException) { } } { try { p.begin_ice_id(); test(false); } catch (ArgumentException) { } } { try { p.ice_idsAsync(); test(false); } catch (Ice.TwowayOnlyException) { } } { try { p.begin_ice_ids(); test(false); } catch (ArgumentException) { } } { Callback cb = new Callback(); p.opVoidAsync(progress: new Progress <bool>( sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); } { Callback cb = new Callback(); p.begin_opVoid().whenCompleted(cb.noException).whenSent(cb.sent); cb.check(); } { Callback cb = new Callback(); p.begin_opVoid().whenCompleted( (Ice.Exception ex) => { cb.noException(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); } { Callback cb = new Callback(); p.opIdempotentAsync(progress: new Progress <bool>( sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); } { Callback cb = new Callback(); p.begin_opIdempotent().whenCompleted(cb.noException).whenSent(cb.sent); cb.check(); } { Callback cb = new Callback(); p.begin_opIdempotent().whenCompleted( (Ice.Exception ex) => { cb.noException(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); } { Callback cb = new Callback(); p.opNonmutatingAsync(progress: new Progress <bool>( sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); } { Callback cb = new Callback(); p.begin_opNonmutating().whenCompleted(cb.noException).whenSent(cb.sent); cb.check(); } { Callback cb = new Callback(); p.begin_opNonmutating().whenCompleted( (Ice.Exception ex) => { cb.noException(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); } { try { p.opByteAsync(0xff, 0x0f); test(false); } catch (Ice.TwowayOnlyException) { } } { try { p.begin_opByte(0xff, 0x0f); test(false); } catch (ArgumentException) { } } }
allTests(global::Test.TestHelper helper) { var output = helper.getWriter(); Communicator communicator = helper.communicator(); ObjectAdapter oa = communicator.CreateObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.Activate(); var servantI = new MyObject(); Disp servantD = (servantI as IObject).Dispatch; // // Register default servant with category "foo" // oa.AddDefaultServant(servantD, "foo"); // // Start test // output.Write("testing single category... "); output.Flush(); Disp r = oa.FindDefaultServant("foo"); test(r == servantD); r = oa.FindDefaultServant("bar"); test(r == null); Identity identity = new Identity("", "foo"); string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; IMyObjectPrx prx = null; for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.getName() == names[idx]); } identity = new Identity("ObjectNotExist", identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (ObjectNotExistException) { // Expected } identity = new Identity("FacetNotExist", identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (FacetNotExistException) { // Expected } try { prx.getName(); test(false); } catch (FacetNotExistException) { // Expected } identity = new Identity(identity.Name, "bar"); for (int idx = 0; idx < 5; idx++) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, Test.IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } oa.RemoveDefaultServant("foo"); identity = new Identity(identity.Name, "foo"); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); } catch (ObjectNotExistException) { // Expected } output.WriteLine("ok"); output.Write("testing default category... "); output.Flush(); oa.AddDefaultServant(servantD, ""); r = oa.FindDefaultServant("bar"); test(r == null); r = oa.FindDefaultServant(""); test(r == servantD); for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.getName() == names[idx]); } output.WriteLine("ok"); }
public static IThrowerPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var output = helper.getWriter(); { output.Write("testing object adapter registration exceptions... "); ObjectAdapter first; try { first = communicator.CreateObjectAdapter("TestAdapter0"); } catch (Ice.InvalidConfigurationException) { // Expected } communicator.SetProperty("TestAdapter0.Endpoints", "tcp -h *"); first = communicator.CreateObjectAdapter("TestAdapter0"); try { communicator.CreateObjectAdapter("TestAdapter0"); test(false); } catch (ArgumentException) { // Expected. } try { ObjectAdapter second = communicator.CreateObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); // // Quell mono error that variable second isn't used. // second.Deactivate(); } catch (ArgumentException) { // Expected } first.Deactivate(); output.WriteLine("ok"); } { output.Write("testing servant registration exceptions... "); communicator.SetProperty("TestAdapter1.Endpoints", "tcp -h *"); ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter1"); var obj = new Empty(); adapter.Add("x", obj); try { adapter.Add("x", obj); test(false); } catch (ArgumentException) { } try { adapter.Add("", obj); test(false); } catch (FormatException) { } adapter.Remove("x"); adapter.Remove("x"); // as of Ice 4.0, can remove multiple times adapter.Deactivate(); output.WriteLine("ok"); } output.Write("testing stringToProxy... "); output.Flush(); string @ref = "thrower:" + helper.getTestEndpoint(0); var @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var thrower = IThrowerPrx.CheckedCast(@base); test(thrower != null); test(thrower.Equals(@base)); output.WriteLine("ok"); output.Write("catching exact types... "); output.Flush(); try { thrower.throwAasA(1); test(false); } catch (A ex) { test(ex.aMem == 1); } catch (Exception ex) { Console.WriteLine(ex); test(false); } try { thrower.throwAorDasAorD(1); test(false); } catch (A ex) { test(ex.aMem == 1); } catch (System.Exception) { test(false); } try { thrower.throwAorDasAorD(-1); test(false); } catch (D ex) { test(ex.dMem == -1); } catch (System.Exception) { test(false); } try { thrower.throwBasB(1, 2); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (System.Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching base types... "); output.Flush(); try { thrower.throwBasB(1, 2); test(false); } catch (A ex) { test(ex.aMem == 1); } catch (System.Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching derived types... "); output.Flush(); try { thrower.throwBasA(1, 2); test(false); } catch (B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (System.Exception) { test(false); } try { thrower.throwCasA(1, 2, 3); test(false); } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } try { thrower.throwCasB(1, 2, 3); test(false); } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching remote exception... "); output.Flush(); try { thrower.throwUndeclaredA(1); test(false); } catch (A) { } catch (System.Exception) { test(false); } try { thrower.throwUndeclaredB(1, 2); test(false); } catch (B) { } catch (System.Exception) { test(false); } try { thrower.throwUndeclaredC(1, 2, 3); test(false); } catch (C) { } catch (System.Exception) { test(false); } output.WriteLine("ok"); if (thrower.GetConnection() != null) { output.Write("testing memory limit marshal exception..."); output.Flush(); try { thrower.throwMemoryLimitException(Array.Empty <byte>()); test(false); } catch (MemoryLimitException) { } catch (System.Exception) { test(false); } try { thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB test(false); } catch (ConnectionLostException) { } catch (UnhandledException) { // Expected with JS bidir server } catch (System.Exception) { test(false); } try { var thrower2 = IThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(1), communicator); try { thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits) } catch (MemoryLimitException) { } var thrower3 = IThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(2), communicator); try { thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit test(false); } catch (ConnectionLostException) { } } catch (ConnectionRefusedException) { // Expected with JS bidir server } output.WriteLine("ok"); } output.Write("catching object not exist exception... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); try { var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id)); thrower2.IcePing(); test(false); } catch (ObjectNotExistException ex) { test(ex.Id.Equals(id)); test(ex.Message.Contains("servant")); // verify we don't get system message } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("catching object not exist exception... "); output.Flush(); try { var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.IcePing(); test(false); } catch (ObjectNotExistException ex) { test(ex.Facet.Equals("no such facet")); test(ex.Message.Contains("with facet")); // verify we don't get system message } } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching operation not exist exception... "); output.Flush(); try { var thrower2 = Test.IWrongOperationPrx.UncheckedCast(thrower); thrower2.noSuchOperation(); test(false); } catch (OperationNotExistException ex) { test(ex.Operation.Equals("noSuchOperation")); test(ex.Message.Contains("could not find operation")); // verify we don't get system message } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unhandled local exception... "); output.Flush(); try { thrower.throwLocalException(); test(false); } catch (UnhandledException ex) { test(ex.Message.Contains("unhandled exception")); // verify we get custom message } catch (System.Exception) { test(false); } try { thrower.throwLocalExceptionIdempotent(); test(false); } catch (UnhandledException) { } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unhandled non-Ice exception... "); output.Flush(); try { thrower.throwNonIceException(); test(false); } catch (UnhandledException ex) { } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unhandled remote exception... "); output.Flush(); try { thrower.throwAConvertedToUnhandled(); test(false); } catch (UnhandledException) { } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("testing asynchronous exceptions... "); output.Flush(); try { thrower.throwAfterResponse(); } catch (System.Exception) { test(false); } try { thrower.throwAfterException(); test(false); } catch (A) { } catch (System.Exception) { test(false); } output.WriteLine("ok"); output.Write("catching exact types with AMI... "); output.Flush(); { try { thrower.throwAasAAsync(1).Wait(); } catch (AggregateException exc) { test(exc.InnerException is A); var ex = exc.InnerException as Test.A; test(ex.aMem == 1); } } { try { thrower.throwAorDasAorDAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (A ex) { test(ex.aMem == 1); } catch (D ex) { test(ex.dMem == -1); } catch (System.Exception) { test(false); } } } { try { thrower.throwAorDasAorDAsync(-1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (A ex) { test(ex.aMem == 1); } catch (D ex) { test(ex.dMem == -1); } catch (System.Exception) { test(false); } } } { try { thrower.throwBasBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (System.Exception) { test(false); } } } { try { thrower.throwCasCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching derived types with AMI... "); output.Flush(); { try { thrower.throwBasAAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (System.Exception) { test(false); } } } { try { thrower.throwCasAAsync(1, 2, 3).Wait(); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } } } { try { thrower.throwCasBAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching remote exception with AMI... "); output.Flush(); { try { thrower.throwUndeclaredAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (A) { } catch (System.Exception) { test(false); } } } { try { thrower.throwUndeclaredBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (B) { } catch (System.Exception) { test(false); } } } { try { thrower.throwUndeclaredCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (C) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching object not exist exception with AMI... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id)); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.Id.Equals(id)); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching object not exist exception with AMI... "); output.Flush(); { var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.Facet.Equals("no such facet")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching operation not exist exception with AMI... "); output.Flush(); { try { var thrower4 = IWrongOperationPrx.UncheckedCast(thrower); thrower4.noSuchOperationAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (OperationNotExistException ex) { test(ex.Operation.Equals("noSuchOperation")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unhandled local exception with AMI... "); output.Flush(); { try { thrower.throwLocalExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } { try { thrower.throwLocalExceptionIdempotentAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unhandled non-Ice exception with AMI... "); output.Flush(); { try { thrower.throwNonIceExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching remote exception with AMI... "); output.Flush(); { try { thrower.throwUndeclaredAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (A) { } catch (System.Exception) { test(false); } } } { try { thrower.throwUndeclaredBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (B) { } catch (System.Exception) { test(false); } } } { try { thrower.throwUndeclaredCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (C) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching object not exist exception with AMI... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id)); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.Id.Equals(id)); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching object not exist exception with AMI... "); output.Flush(); { var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.Facet.Equals("no such facet")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching operation not exist exception with AMI... "); output.Flush(); { var thrower4 = IWrongOperationPrx.UncheckedCast(thrower); try { thrower4.noSuchOperationAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (OperationNotExistException ex) { test(ex.Operation.Equals("noSuchOperation")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unhandled local exception with AMI... "); output.Flush(); { try { thrower.throwLocalExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } { try { thrower.throwLocalExceptionIdempotentAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unhandled non-Ice exception with AMI... "); output.Flush(); { try { thrower.throwNonIceExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unhandled remote exception with AMI... "); output.Flush(); { try { thrower.throwAConvertedToUnhandledAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnhandledException) { } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); return(thrower); }
public static Test.GPrx allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing Ice.Admin.Facets property... "); test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").Length == 0); communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar"); String[] facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); test(facetFilter.Length == 1 && facetFilter[0].Equals("foobar")); communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar"); facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); test(facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar")); communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'"); facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); test(facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto") && facetFilter[2].Equals("titi")); communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'"); facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); test(facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi")); // communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi"); // facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); // test(facetFilter.Length == 0); communicator.getProperties().setProperty("Ice.Admin.Facets", ""); output.WriteLine("ok"); output.Write("testing facet registration exceptions... "); communicator.getProperties().setProperty("FacetExceptionTestAdapter.Endpoints", "tcp -h *"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter"); Ice.Object obj = new EmptyI(); adapter.add(obj, Ice.Util.stringToIdentity("d")); adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD"); try { adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD"); test(false); } catch (Ice.AlreadyRegisteredException) { } adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD"); try { adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD"); test(false); } catch (Ice.NotRegisteredException) { } output.WriteLine("ok"); output.Write("testing removeAllFacets... "); Ice.Object obj1 = new EmptyI(); Ice.Object obj2 = new EmptyI(); adapter.addFacet(obj1, Ice.Util.stringToIdentity("id1"), "f1"); adapter.addFacet(obj2, Ice.Util.stringToIdentity("id1"), "f2"); Ice.Object obj3 = new EmptyI(); adapter.addFacet(obj1, Ice.Util.stringToIdentity("id2"), "f1"); adapter.addFacet(obj2, Ice.Util.stringToIdentity("id2"), "f2"); adapter.addFacet(obj3, Ice.Util.stringToIdentity("id2"), ""); Dictionary <string, Ice.Object> fm = adapter.removeAllFacets(Ice.Util.stringToIdentity("id1")); test(fm.Count == 2); test(fm["f1"] == obj1); test(fm["f2"] == obj2); try { adapter.removeAllFacets(Ice.Util.stringToIdentity("id1")); test(false); } catch (Ice.NotRegisteredException) { } fm = adapter.removeAllFacets(Ice.Util.stringToIdentity("id2")); test(fm.Count == 3); test(fm["f1"] == obj1); test(fm["f2"] == obj2); test(fm[""] == obj3); output.WriteLine("ok"); adapter.deactivate(); output.Write("testing stringToProxy... "); output.Flush(); string @ref = "d:" + helper.getTestEndpoint(0); Ice.ObjectPrx db = communicator.stringToProxy(@ref); test(db != null); output.WriteLine("ok"); output.Write("testing unchecked cast... "); output.Flush(); Ice.ObjectPrx prx = Ice.ObjectPrxHelper.uncheckedCast(db); test(prx.ice_getFacet().Length == 0); prx = Ice.ObjectPrxHelper.uncheckedCast(db, "facetABCD"); test(prx.ice_getFacet() == "facetABCD"); Ice.ObjectPrx prx2 = Ice.ObjectPrxHelper.uncheckedCast(prx); test(prx2.ice_getFacet() == "facetABCD"); Ice.ObjectPrx prx3 = Ice.ObjectPrxHelper.uncheckedCast(prx, ""); test(prx3.ice_getFacet().Length == 0); var d = Test.DPrxHelper.uncheckedCast(db); test(d.ice_getFacet().Length == 0); var df = Test.DPrxHelper.uncheckedCast(db, "facetABCD"); test(df.ice_getFacet() == "facetABCD"); var df2 = Test.DPrxHelper.uncheckedCast(df); test(df2.ice_getFacet() == "facetABCD"); var df3 = Test.DPrxHelper.uncheckedCast(df, ""); test(df3.ice_getFacet().Length == 0); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); prx = Ice.ObjectPrxHelper.checkedCast(db); test(prx.ice_getFacet().Length == 0); prx = Ice.ObjectPrxHelper.checkedCast(db, "facetABCD"); test(prx.ice_getFacet() == "facetABCD"); prx2 = Ice.ObjectPrxHelper.checkedCast(prx); test(prx2.ice_getFacet() == "facetABCD"); prx3 = Ice.ObjectPrxHelper.checkedCast(prx, ""); test(prx3.ice_getFacet().Length == 0); d = Test.DPrxHelper.checkedCast(db); test(d.ice_getFacet().Length == 0); df = Test.DPrxHelper.checkedCast(db, "facetABCD"); test(df.ice_getFacet() == "facetABCD"); df2 = Test.DPrxHelper.checkedCast(df); test(df2.ice_getFacet() == "facetABCD"); df3 = Test.DPrxHelper.checkedCast(df, ""); test(df3.ice_getFacet().Length == 0); output.WriteLine("ok"); output.Write("testing non-facets A, B, C, and D... "); output.Flush(); d = Test.DPrxHelper.checkedCast(db); test(d != null); test(d.Equals(db)); test(d.callA().Equals("A")); test(d.callB().Equals("B")); test(d.callC().Equals("C")); test(d.callD().Equals("D")); output.WriteLine("ok"); output.Write("testing facets A, B, C, and D... "); output.Flush(); df = Test.DPrxHelper.checkedCast(d, "facetABCD"); test(df != null); test(df.callA().Equals("A")); test(df.callB().Equals("B")); test(df.callC().Equals("C")); test(df.callD().Equals("D")); output.WriteLine("ok"); output.Write("testing facets E and F... "); output.Flush(); var ff = Test.FPrxHelper.checkedCast(d, "facetEF"); test(ff != null); test(ff.callE().Equals("E")); test(ff.callF().Equals("F")); output.WriteLine("ok"); output.Write("testing facet G... "); output.Flush(); var gf = Test.GPrxHelper.checkedCast(ff, "facetGH"); test(gf != null); test(gf.callG().Equals("G")); output.WriteLine("ok"); output.Write("testing whether casting preserves the facet... "); output.Flush(); var hf = Test.HPrxHelper.checkedCast(gf); test(hf != null); test(hf.callG().Equals("G")); test(hf.callH().Equals("H")); output.WriteLine("ok"); return(gf); }
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(); }
internal ServerManager(ServerLocatorRegistry registry, global::Test.TestHelper helper) { _registry = registry; _communicators = new ArrayList(); _helper = helper; }
public static Test.IMyClassPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var cl = Test.IMyClassPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var oneway = cl.Clone(oneway: true); var output = helper.getWriter(); output.Write("testing ice_invoke... "); output.Flush(); { byte[] inEncaps, outEncaps; if (!oneway.Invoke("opOneway", OperationMode.Normal, null, out outEncaps)) { test(false); } OutputStream outS = new OutputStream(communicator); outS.StartEncapsulation(); outS.WriteString(testString); outS.EndEncapsulation(); inEncaps = outS.Finished(); if (cl.Invoke("opString", OperationMode.Normal, inEncaps, out outEncaps)) { InputStream inS = new InputStream(communicator, outEncaps); inS.StartEncapsulation(); string s = inS.ReadString(); test(s.Equals(testString)); s = inS.ReadString(); inS.EndEncapsulation(); test(s.Equals(testString)); } else { test(false); } } for (int i = 0; i < 2; ++i) { byte[] outEncaps; Dictionary <string, string> ctx = null; if (i == 1) { ctx = new Dictionary <string, string>(); ctx["raise"] = ""; } if (cl.Invoke("opException", OperationMode.Normal, null, out outEncaps, ctx)) { test(false); } else { InputStream inS = new InputStream(communicator, outEncaps); inS.StartEncapsulation(); try { inS.ThrowException(); } catch (Test.MyException) { inS.EndEncapsulation(); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("testing asynchronous ice_invoke with Async Task API... "); output.Flush(); { try { oneway.InvokeAsync("opOneway", OperationMode.Normal, null).Wait(); } catch (Exception) { test(false); } OutputStream outS = new OutputStream(communicator); outS.StartEncapsulation(); outS.WriteString(testString); outS.EndEncapsulation(); byte[] inEncaps = outS.Finished(); // begin_ice_invoke with no callback var result = cl.InvokeAsync("opString", OperationMode.Normal, inEncaps).Result; if (result.ReturnValue) { InputStream inS = new InputStream(communicator, result.OutEncaps); inS.StartEncapsulation(); string s = inS.ReadString(); test(s.Equals(testString)); s = inS.ReadString(); inS.EndEncapsulation(); test(s.Equals(testString)); } else { test(false); } } { var result = cl.InvokeAsync("opException", OperationMode.Normal, null).Result; if (result.ReturnValue) { test(false); } else { InputStream inS = new InputStream(communicator, result.OutEncaps); inS.StartEncapsulation(); try { inS.ThrowException(); } catch (Test.MyException) { inS.EndEncapsulation(); } catch (Exception) { test(false); } } } output.WriteLine("ok"); return(cl); }
public static void allTests(global::Test.TestHelper helper) { var communicator = helper.communicator(); string sref = "timeout:" + helper.getTestEndpoint(0); var obj = communicator.stringToProxy(sref); test(obj != null); Test.TimeoutPrx timeout = Test.TimeoutPrxHelper.checkedCast(obj); test(timeout != null); Test.ControllerPrx controller = Test.ControllerPrxHelper.checkedCast(communicator.stringToProxy("controller:" + helper.getTestEndpoint(1))); test(controller != null); var output = helper.getWriter(); output.Write("testing connect timeout... "); output.Flush(); { // // Expect ConnectTimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(100)); controller.holdAdapter(-1); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } { // // Expect success. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(-1)); controller.holdAdapter(100); try { to.op(); } catch (Ice.ConnectTimeoutException) { test(false); } } 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. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(250)); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } { // // Expect success. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(2000)); controller.holdAdapter(100); try { to.sendData(new byte[1000000]); } catch (Ice.TimeoutException) { test(false); } } output.WriteLine("ok"); output.Write("testing invocation timeout... "); output.Flush(); { var connection = obj.ice_getConnection(); Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(100)); test(connection == to.ice_getConnection()); try { to.sleep(500); test(false); } catch (Ice.InvocationTimeoutException) { } obj.ice_ping(); to = Test.TimeoutPrxHelper.checkedCast(obj.ice_invocationTimeout(1000)); test(connection == to.ice_getConnection()); try { to.sleep(100); } catch (Ice.InvocationTimeoutException) { test(false); } test(connection == to.ice_getConnection()); } { // // Expect InvocationTimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(100)); Callback cb = new Callback(); to.begin_sleep(500).whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.InvocationTimeoutException); cb.called(); }); cb.check(); obj.ice_ping(); } { // // Expect success. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(1000)); Callback cb = new Callback(); to.begin_sleep(100).whenCompleted( () => { cb.called(); }, (Ice.Exception ex) => { test(false); }); cb.check(); } { // // Backward compatible connection timeouts // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(-2).ice_timeout(250)); var con = connect(to); try { to.sleep(750); test(false); } catch (Ice.TimeoutException) { try { con.getInfo(); test(false); } catch (Ice.TimeoutException) { // Connection got closed as well. } } obj.ice_ping(); try { con = connect(to); to.end_sleep(to.begin_sleep(750)); test(false); } catch (Ice.TimeoutException) { try { con.getInfo(); test(false); } catch (Ice.TimeoutException) { // Connection got closed as well. } } obj.ice_ping(); } output.WriteLine("ok"); output.Write("testing close timeout... "); output.Flush(); { Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(250)); var connection = connect(to); controller.holdAdapter(-1); connection.close(Ice.ConnectionClose.GracefullyWithWait); try { connection.getInfo(); // getInfo() doesn't throw in the closing state. } catch (Ice.LocalException) { test(false); } while (true) { try { connection.getInfo(); Thread.Sleep(10); } catch (Ice.ConnectionManuallyClosedException ex) { // Expected. test(ex.graceful); break; } } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } output.WriteLine("ok"); output.Write("testing timeout overrides... "); output.Flush(); { // // Test Ice.Override.Timeout. This property overrides all // endpoint timeouts. // var initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.ConnectTimeout", "250"); initData.properties.setProperty("Ice.Override.Timeout", "100"); var comm = helper.initialize(initData); Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(comm.stringToProxy(sref)); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Calling ice_timeout() should have no effect. // to = Test.TimeoutPrxHelper.uncheckedCast(to.ice_timeout(1000)); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.destroy(); } { // // Test Ice.Override.ConnectTimeout. // var initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.ConnectTimeout", "250"); var comm = helper.initialize(initData); controller.holdAdapter(-1); Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(comm.stringToProxy(sref)); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Calling ice_timeout() should have no effect on the connect timeout. // controller.holdAdapter(-1); to = Test.TimeoutPrxHelper.uncheckedCast(to.ice_timeout(1000)); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Verify that timeout set via ice_timeout() is still used for requests. // to = Test.TimeoutPrxHelper.uncheckedCast(to.ice_timeout(250)); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.destroy(); } { // // Test Ice.Override.CloseTimeout. // var initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.CloseTimeout", "100"); var comm = helper.initialize(initData); comm.stringToProxy(sref).ice_getConnection(); controller.holdAdapter(-1); long begin = System.DateTime.Now.Ticks; comm.destroy(); test(((long)new System.TimeSpan(System.DateTime.Now.Ticks - begin).TotalMilliseconds - begin) < 1000); controller.resumeAdapter(); } output.WriteLine("ok"); output.Write("testing invocation timeouts with collocated calls... "); output.Flush(); { communicator.getProperties().setProperty("TimeoutCollocated.AdapterId", "timeoutAdapter"); var adapter = communicator.createObjectAdapter("TimeoutCollocated"); adapter.activate(); Test.TimeoutPrx proxy = Test.TimeoutPrxHelper.uncheckedCast(adapter.addWithUUID(new TimeoutI())); proxy = (Test.TimeoutPrx)proxy.ice_invocationTimeout(100); try { proxy.sleep(500); test(false); } catch (Ice.InvocationTimeoutException) { } try { proxy.end_sleep(proxy.begin_sleep(500)); test(false); } catch (Ice.InvocationTimeoutException) { } try { ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-2)).ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-2)).begin_ice_ping().waitForCompleted(); } catch (Ice.Exception) { test(false); } Test.TimeoutPrx batchTimeout = (Test.TimeoutPrx)proxy.ice_batchOneway(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-1)).begin_sleep(300); // Keep the server thread pool busy. try { batchTimeout.ice_flushBatchRequests(); test(false); } catch (Ice.InvocationTimeoutException) { } batchTimeout.ice_ping(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-1)).begin_sleep(300); // Keep the server thread pool busy. try { batchTimeout.end_ice_flushBatchRequests(batchTimeout.begin_ice_flushBatchRequests()); test(false); } catch (Ice.InvocationTimeoutException) { } adapter.destroy(); } output.WriteLine("ok"); controller.shutdown(); }
Run(global::Test.TestHelper helper) { var output = helper.getWriter(); Communicator communicator = helper.communicator(); ObjectAdapter oa = communicator.CreateObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.Activate(); output.Write("testing single category... "); output.Flush(); var servant = new MyObject(); oa.AddDefaultForCategory("foo", servant); try { oa.AddDefaultForCategory("foo", new MyObject()); test(false); // duplicate registration not allowed } catch (System.ArgumentException) { // Expected } IObject?r = oa.Find("foo"); test(r == null); r = oa.Find("foo/someId"); test(r == servant); r = oa.Find("bar/someId"); test(r == null); Identity identity = new Identity("", "foo"); string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; IMyObjectPrx?prx = null; for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.GetName() == names[idx]); } identity = new Identity("ObjectNotExist", identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (ObjectNotExistException) { // Expected } try { prx.GetName(); test(false); } catch (ObjectNotExistException) { // Expected } identity = new Identity(identity.Name, "bar"); for (int idx = 0; idx < 5; idx++) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, Test.IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.GetName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } IObject?removed = oa.RemoveDefaultForCategory("foo"); test(removed == servant); removed = oa.RemoveDefaultForCategory("foo"); test(removed == null); identity = new Identity(identity.Name, "foo"); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); } catch (ObjectNotExistException) { // Expected } output.WriteLine("ok"); output.Write("testing default servant... "); output.Flush(); var defaultServant = new MyObject(); oa.AddDefault(defaultServant); try { oa.AddDefault(servant); test(false); } catch (System.ArgumentException) { // Expected } oa.AddDefaultForCategory("", servant); // associated with empty category r = oa.Find("bar"); test(r == servant); r = oa.Find("x/y"); test(r == defaultServant); for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], ""); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.GetName() == names[idx]); } removed = oa.RemoveDefault(); test(removed == defaultServant); removed = oa.RemoveDefault(); test(removed == null); output.WriteLine("ok"); }
public static void allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); 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); Ice.Endpoint[] endps = p1.Endpoints; Ice.EndpointInfo info = endps[0].getInfo(); Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(info); test(tcpEndpoint.host.Equals("tcphost")); test(tcpEndpoint.port == 10000); test(tcpEndpoint.sourceAddress.Equals("10.10.10.10")); test(tcpEndpoint.timeout == 1200); test(tcpEndpoint.compress); test(!tcpEndpoint.datagram()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value && !tcpEndpoint.secure() || tcpEndpoint.type() == Ice.SSLEndpointType.value && tcpEndpoint.secure() || tcpEndpoint.type() == Ice.WSEndpointType.value && !tcpEndpoint.secure() || tcpEndpoint.type() == Ice.WSSEndpointType.value && tcpEndpoint.secure()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value && info is Ice.TCPEndpointInfo || tcpEndpoint.type() == Ice.SSLEndpointType.value && info is IceSSL.EndpointInfo || tcpEndpoint.type() == Ice.WSEndpointType.value && info is Ice.WSEndpointInfo || tcpEndpoint.type() == Ice.WSSEndpointType.value && info is Ice.WSEndpointInfo); Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo(); test(udpEndpoint.host.Equals("udphost")); test(udpEndpoint.port == 10001); test(udpEndpoint.mcastInterface.Equals("eth0")); test(udpEndpoint.mcastTtl == 5); test(udpEndpoint.sourceAddress.Equals("10.10.10.10")); test(udpEndpoint.timeout == -1); test(!udpEndpoint.compress); test(!udpEndpoint.secure()); test(udpEndpoint.datagram()); test(udpEndpoint.type() == 3); Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo(); test(opaqueEndpoint.rawBytes.Length > 0); test(opaqueEndpoint.rawEncoding.Equals(new Ice.EncodingVersion(1, 8))); } output.WriteLine("ok"); Ice.ObjectAdapter adapter; output.Write("test object adapter endpoint information... "); output.Flush(); { string host = communicator.Properties.getPropertyAsInt("Ice.IPv6") != 0 ? "::1" : "127.0.0.1"; communicator.Properties.setProperty("TestAdapter.Endpoints", "tcp -h \"" + host + "\" -t 15000:udp -h \"" + host + "\""); adapter = communicator.createObjectAdapter("TestAdapter"); Ice.Endpoint[] endpoints = adapter.GetEndpoints(); test(endpoints.Length == 2); Ice.Endpoint[] publishedEndpoints = adapter.GetPublishedEndpoints(); test(Collections.Equals(endpoints, publishedEndpoints)); Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(endpoints[0].getInfo()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value || tcpEndpoint.type() == Ice.SSLEndpointType.value || tcpEndpoint.type() == Ice.WSEndpointType.value || tcpEndpoint.type() == Ice.WSSEndpointType.value); test(tcpEndpoint.host.Equals(host)); test(tcpEndpoint.port > 0); test(tcpEndpoint.timeout == 15000); Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo(); test(udpEndpoint.host.Equals(host)); test(udpEndpoint.datagram()); test(udpEndpoint.port > 0); endpoints = new Ice.Endpoint[] { endpoints[0] }; test(endpoints.Length == 1); adapter.SetPublishedEndpoints(endpoints); publishedEndpoints = adapter.GetPublishedEndpoints(); test(Collections.Equals(endpoints, publishedEndpoints)); adapter.Destroy(); int port = helper.getTestPort(1); communicator.Properties.setProperty("TestAdapter.Endpoints", "default -h * -p " + port); communicator.Properties.setProperty("TestAdapter.PublishedEndpoints", helper.getTestEndpoint(1)); adapter = communicator.createObjectAdapter("TestAdapter"); endpoints = adapter.GetEndpoints(); test(endpoints.Length >= 1); publishedEndpoints = adapter.GetPublishedEndpoints(); test(publishedEndpoints.Length == 1); foreach (Ice.Endpoint endpoint in endpoints) { tcpEndpoint = getTCPEndpointInfo(endpoint.getInfo()); test(tcpEndpoint.port == port); } tcpEndpoint = getTCPEndpointInfo(publishedEndpoints[0].getInfo()); test(tcpEndpoint.host.Equals("127.0.0.1")); test(tcpEndpoint.port == port); adapter.Destroy(); } output.WriteLine("ok"); int endpointPort = helper.getTestPort(0); var @base = IObjectPrx.Parse("test:" + helper.getTestEndpoint(0) + ":" + helper.getTestEndpoint(0, "udp"), communicator); var testIntf = Test.TestIntfPrx.CheckedCast(@base); string defaultHost = communicator.Properties.getProperty("Ice.Default.Host"); output.Write("test connection endpoint information... "); output.Flush(); { Ice.EndpointInfo info = @base.GetConnection().getEndpoint().getInfo(); Ice.TCPEndpointInfo tcpinfo = getTCPEndpointInfo(info); test(tcpinfo.port == endpointPort); test(!tcpinfo.compress); test(tcpinfo.host.Equals(defaultHost)); Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext(); test(ctx["host"].Equals(tcpinfo.host)); test(ctx["compress"].Equals("false")); int port = int.Parse(ctx["port"]); test(port > 0); info = @base.Clone(invocationMode: InvocationMode.Datagram).GetConnection().getEndpoint().getInfo(); Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info; test(udp.port == endpointPort); test(udp.host.Equals(defaultHost)); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { Ice.Connection connection = @base.GetConnection(); connection.setBufferSize(1024, 2048); Ice.ConnectionInfo info = connection.getInfo(); Ice.TCPConnectionInfo ipInfo = getTCPConnectionInfo(info); test(!info.incoming); test(info.adapterName.Length == 0); test(ipInfo.remotePort == endpointPort); test(ipInfo.localPort > 0); if (defaultHost.Equals("127.0.0.1")) { test(ipInfo.localAddress.Equals(defaultHost)); test(ipInfo.remoteAddress.Equals(defaultHost)); } test(ipInfo.rcvSize >= 1024); test(ipInfo.sndSize >= 2048); Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext(); test(ctx["incoming"].Equals("true")); test(ctx["adapterName"].Equals("TestAdapter")); test(ctx["remoteAddress"].Equals(ipInfo.localAddress)); test(ctx["localAddress"].Equals(ipInfo.remoteAddress)); test(ctx["remotePort"].Equals(ipInfo.localPort.ToString())); test(ctx["localPort"].Equals(ipInfo.remotePort.ToString())); if (@base.GetConnection().type().Equals("ws") || @base.GetConnection().type().Equals("wss")) { Dictionary <string, string> headers = ((Ice.WSConnectionInfo)info).headers; test(headers["Upgrade"].Equals("websocket")); test(headers["Connection"].Equals("Upgrade")); test(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); test(headers["Sec-WebSocket-Accept"] != null); test(ctx["ws.Upgrade"].Equals("websocket")); test(ctx["ws.Connection"].Equals("Upgrade")); test(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); test(ctx["ws.Sec-WebSocket-Version"].Equals("13")); test(ctx["ws.Sec-WebSocket-Key"] != null); } connection = @base.Clone(invocationMode: InvocationMode.Datagram).GetConnection(); connection.setBufferSize(2048, 1024); Ice.UDPConnectionInfo udpInfo = (Ice.UDPConnectionInfo)connection.getInfo(); test(!udpInfo.incoming); test(udpInfo.adapterName.Length == 0); test(udpInfo.localPort > 0); test(udpInfo.remotePort == endpointPort); if (defaultHost.Equals("127.0.0.1")) { test(udpInfo.remoteAddress.Equals(defaultHost)); test(udpInfo.localAddress.Equals(defaultHost)); } test(udpInfo.rcvSize >= 2048); test(udpInfo.sndSize >= 1024); } output.WriteLine("ok"); testIntf.shutdown(); communicator.shutdown(); communicator.waitForShutdown(); }
allTests(global::Test.TestHelper helper, Ice.Communicator communicator, Ice.Communicator communicator2, string rf) { Instrumentation.testInvocationReset(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var base1 = communicator.stringToProxy(rf); test(base1 != null); var base2 = communicator.stringToProxy(rf); test(base2 != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); Test.RetryPrx retry1 = Test.RetryPrxHelper.checkedCast(base1); test(retry1 != null); test(retry1.Equals(base1)); Test.RetryPrx retry2 = Test.RetryPrxHelper.checkedCast(base2); test(retry2 != null); test(retry2.Equals(base2)); output.WriteLine("ok"); output.Write("calling regular operation with first proxy... "); output.Flush(); retry1.op(false); output.WriteLine("ok"); Instrumentation.testInvocationCount(3); output.Write("calling operation to kill connection with second proxy... "); output.Flush(); try { retry2.op(true); test(false); } catch (Ice.UnknownLocalException) { // Expected with collocation } catch (Ice.ConnectionLostException) { } Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); output.WriteLine("ok"); output.Write("calling regular operation with first proxy again... "); output.Flush(); retry1.op(false); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(0); Instrumentation.testRetryCount(0); output.WriteLine("ok"); Callback cb = new Callback(); output.Write("calling regular AMI operation with first proxy... "); retry1.begin_op(false).whenCompleted( () => { cb.called(); }, (Ice.Exception ex) => { test(false); }); cb.check(); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(0); Instrumentation.testRetryCount(0); output.WriteLine("ok"); output.Write("calling AMI operation to kill connection with second proxy... "); retry2.begin_op(true).whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.ConnectionLostException || ex is Ice.UnknownLocalException); cb.called(); }); cb.check(); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); output.WriteLine("ok"); output.Write("calling regular AMI operation with first proxy again... "); retry1.begin_op(false).whenCompleted( () => { cb.called(); }, (Ice.Exception ex) => { test(false); }); cb.check(); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(0); Instrumentation.testRetryCount(0); output.WriteLine("ok"); output.Write("testing idempotent operation... "); test(retry1.opIdempotent(4) == 4); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(0); Instrumentation.testRetryCount(4); test(retry1.end_opIdempotent(retry1.begin_opIdempotent(4)) == 4); Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(0); Instrumentation.testRetryCount(4); output.WriteLine("ok"); output.Write("testing non-idempotent operation... "); try { retry1.opNotIdempotent(); test(false); } catch (Ice.LocalException) { } Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); try { retry1.end_opNotIdempotent(retry1.begin_opNotIdempotent()); test(false); } catch (Ice.LocalException) { } Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); output.WriteLine("ok"); if (retry1.ice_getConnection() == null) { Instrumentation.testInvocationCount(1); output.Write("testing system exception... "); try { retry1.opSystemException(); test(false); } catch (SystemFailure) { } Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); try { retry1.end_opSystemException(retry1.begin_opSystemException()); test(false); } catch (SystemFailure) { } Instrumentation.testInvocationCount(1); Instrumentation.testFailureCount(1); Instrumentation.testRetryCount(0); output.WriteLine("ok"); } output.Write("testing invocation timeout and retries... "); output.Flush(); retry2 = Test.RetryPrxHelper.checkedCast(communicator2.stringToProxy(retry1.ToString())); try { // No more than 2 retries before timeout kicks-in ((Test.RetryPrx)retry2.ice_invocationTimeout(500)).opIdempotent(4); test(false); } catch (Ice.InvocationTimeoutException) { Instrumentation.testRetryCount(2); retry2.opIdempotent(-1); // Reset the counter Instrumentation.testRetryCount(-1); } try { // No more than 2 retries before timeout kicks-in Test.RetryPrx prx = (Test.RetryPrx)retry2.ice_invocationTimeout(500); prx.end_opIdempotent(prx.begin_opIdempotent(4)); test(false); } catch (Ice.InvocationTimeoutException) { Instrumentation.testRetryCount(2); retry2.opIdempotent(-1); // Reset the counter Instrumentation.testRetryCount(-1); } output.WriteLine("ok"); return(retry1); }
static public int allTests(global::Test.TestHelper helper) { var communicator = helper.communicator(); InputStream istr; OutputStream ostr; var output = helper.getWriter(); output.Write("testing primitive types... "); output.Flush(); { byte[] data = new byte[0]; istr = new InputStream(communicator, data); } { 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 Test.OptionalClass(); 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 <Test.OptionalClass>(); 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)); Test.MyEnum[][] arrS = { arr, new Test.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 Test.SmallStruct[3]; for (int i = 0; i < smallStructArray.Length; ++i) { smallStructArray[i] = new Test.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 = Test.MyEnum.enum2; smallStructArray[i].p = Test.IMyInterfacePrx.Parse("test:default", communicator); } var myClassArray = new Test.MyClass[4]; for (int i = 0; i < myClassArray.Length; ++i) { myClassArray[i] = new Test.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 = Test.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 Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 }; myClassArray[i].seq10 = new Test.MyClass[4]; // null elements. myClassArray[i].d = new Dictionary <string, Test.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 == Test.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])); } Test.MyClass[][] arrS = { myClassArray, new Test.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 == Test.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 Test.MyClass(); obj.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null); obj.s.e = Test.MyEnum.enum2; ostr.StartEncapsulation(); ostr.WriteClass(obj); ostr.EndEncapsulation(); var data = ostr.ToArray(); istr = new InputStream(communicator, data); istr.StartEncapsulation(); var robj = istr.ReadClass <Test.MyClass>(); istr.EndEncapsulation(); test(robj != null); test(robj.s.e == Test.MyEnum.enum2); } { ostr = new OutputStream(communicator); ostr.StartEncapsulation(ostr.Encoding, FormatType.SlicedFormat); var ex = new Test.MyException(); var c = new Test.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 = Test.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 Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 }; c.seq10 = new Test.MyClass[4]; // null elements. c.d = new Dictionary <string, Test.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 (Test.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(global::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(global::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(global::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(global::Test.Collections.Equals(dict2, dict)); } { var dict = new Dictionary <string, Test.MyClass>(); var c = new Test.MyClass(); c.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null); c.s.e = Test.MyEnum.enum2; dict.Add("key1", c); c = new Test.MyClass(); c.s = new SmallStruct(false, 0, 0, 0, 0, 0.0f, 0.0, "", MyEnum.enum1, null); c.s.e = Test.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 == Test.MyEnum.enum2); test(dict2["key2"].s.e == Test.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 == Test.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 Test.IMyInterfacePrx[2]; arr[0] = Test.IMyInterfacePrx.Parse("zero", communicator); arr[1] = Test.IMyInterfacePrx.Parse("one", communicator); ostr = new OutputStream(communicator); var l = new List <Test.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 <Test.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 <Test.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 Test.IMyInterfacePrx[2]; arr[0] = Test.IMyInterfacePrx.Parse("zero", communicator); arr[1] = Test.IMyInterfacePrx.Parse("one", communicator); ostr = new OutputStream(communicator); var l = new Stack <Test.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 <Test.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(global::Test.Collections.Equals(dict2, dict)); } output.WriteLine("ok"); return(0); }
public static void allTestsWithController(global::Test.TestHelper helper, Test.IControllerPrx controller) { var communicator = helper.communicator(); string sref = "timeout:" + helper.getTestEndpoint(0); var timeout = ITimeoutPrx.Parse(sref, communicator); var output = helper.getWriter(); output.Write("testing connect timeout... "); output.Flush(); { // // Expect ConnectTimeoutException. // var to = timeout.Clone(connectionTimeout: 100); controller.holdAdapter(-1); try { to.op(); test(false); } catch (ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } { // // Expect success. // var to = timeout.Clone(connectionTimeout: -1); controller.holdAdapter(100); try { to.op(); } catch (Ice.ConnectTimeoutException) { test(false); } } 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. // var to = timeout.Clone(connectionTimeout: 250); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } { // // Expect success. // var to = timeout.Clone(connectionTimeout: 2000); controller.holdAdapter(100); try { to.sendData(new byte[1000000]); } catch (TimeoutException) { test(false); } } output.WriteLine("ok"); output.Write("testing invocation timeout... "); output.Flush(); { var connection = timeout.GetConnection(); var to = timeout.Clone(invocationTimeout: 100); test(connection == to.GetConnection()); try { to.sleep(1000); test(false); } catch (InvocationTimeoutException) { } timeout.IcePing(); to = timeout.Clone(invocationTimeout: 1000); test(connection == to.GetConnection()); try { to.sleep(100); } catch (InvocationTimeoutException) { test(false); } test(connection == to.GetConnection()); } { // // Expect InvocationTimeoutException. // var to = timeout.Clone(invocationTimeout: 100); try { to.sleepAsync(1000).Wait(); } catch (System.AggregateException ex) when(ex.InnerException is InvocationTimeoutException) { } timeout.IcePing(); } { // // Expect success. // var to = timeout.Clone(invocationTimeout: 1000); to.sleepAsync(100).Wait(); } { // // Backward compatible connection timeouts // var to = timeout.Clone(invocationTimeout: -2, connectionTimeout: 250); var con = connect(to); try { to.sleep(750); test(false); } catch (TimeoutException) { try { _ = con.GetConnectionInfo(); test(false); } catch (TimeoutException) { // Connection got closed as well. } } timeout.IcePing(); try { con = connect(to); to.sleepAsync(750).Wait(); test(false); } catch (System.AggregateException ex) when(ex.InnerException is TimeoutException) { try { _ = con.GetConnectionInfo(); test(false); } catch (TimeoutException) { // Connection got closed as well. } } timeout.IcePing(); } output.WriteLine("ok"); output.Write("testing close timeout... "); output.Flush(); { var to = timeout.Clone(connectionTimeout: 250); var connection = connect(to); controller.holdAdapter(-1); connection.Close(Ice.ConnectionClose.GracefullyWithWait); try { _ = connection.GetConnectionInfo(); // getInfo() doesn't throw in the closing state. } catch (LocalException) { test(false); } while (true) { try { _ = connection.GetConnectionInfo(); Thread.Sleep(10); } catch (ConnectionManuallyClosedException ex) { // Expected. test(ex.Graceful); break; } } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. } output.WriteLine("ok"); output.Write("testing timeout overrides... "); output.Flush(); { // // Test Ice.Override.Timeout. This property overrides all // endpoint timeouts. // var properties = communicator.GetProperties(); properties["Ice.Override.ConnectTimeout"] = "250"; properties["Ice.Override.Timeout"] = "100"; var comm = helper.initialize(properties); var to = ITimeoutPrx.Parse(sref, comm); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Calling ice_timeout() should have no effect. // to = to.Clone(connectionTimeout: 1000); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.Destroy(); } { // // Test Ice.Override.ConnectTimeout. // var properties = communicator.GetProperties(); properties["Ice.Override.ConnectTimeout"] = "250"; var comm = helper.initialize(properties); controller.holdAdapter(-1); var to = ITimeoutPrx.Parse(sref, comm); try { to.op(); test(false); } catch (ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Calling ice_timeout() should have no effect on the connect timeout. // controller.holdAdapter(-1); to = to.Clone(connectionTimeout: 1000); try { to.op(); test(false); } catch (ConnectTimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. // // Verify that timeout set via ice_timeout() is still used for requests. // to = to.Clone(connectionTimeout: 250); connect(to); controller.holdAdapter(-1); try { to.sendData(seq); test(false); } catch (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.Destroy(); } { // // Test Ice.Override.CloseTimeout. // var properties = communicator.GetProperties(); properties["Ice.Override.CloseTimeout"] = "100"; var comm = helper.initialize(properties); IObjectPrx.Parse(sref, comm).GetConnection(); controller.holdAdapter(-1); long begin = System.DateTime.Now.Ticks; comm.Destroy(); test(((long)new System.TimeSpan(System.DateTime.Now.Ticks - begin).TotalMilliseconds - begin) < 1000); controller.resumeAdapter(); } output.WriteLine("ok"); output.Write("testing invocation timeouts with collocated calls... "); output.Flush(); { communicator.SetProperty("TimeoutCollocated.AdapterId", "timeoutAdapter"); var adapter = communicator.CreateObjectAdapter("TimeoutCollocated"); adapter.Activate(); var proxy = adapter.Add(new Timeout(), ITimeoutPrx.Factory).Clone(invocationTimeout: 100); try { proxy.sleep(500); test(false); } catch (InvocationTimeoutException) { } try { proxy.sleepAsync(500).Wait(); test(false); } catch (System.AggregateException ex) when(ex.InnerException is InvocationTimeoutException) { } try { proxy.Clone(invocationTimeout: -2).IcePing(); proxy.Clone(invocationTimeout: -2).IcePingAsync().Wait(); } catch (System.Exception) { test(false); } adapter.Destroy(); } output.WriteLine("ok"); controller.shutdown(); }
public static Test.ThrowerPrx allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var output = helper.getWriter(); { output.Write("testing object adapter registration exceptions... "); ObjectAdapter first; try { first = communicator.createObjectAdapter("TestAdapter0"); } catch (InitializationException) { // Expected } communicator.SetProperty("TestAdapter0.Endpoints", "tcp -h *"); first = communicator.createObjectAdapter("TestAdapter0"); try { communicator.createObjectAdapter("TestAdapter0"); test(false); } catch (ArgumentException) { // Expected. } try { ObjectAdapter second = communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); // // Quell mono error that variable second isn't used. // second.Deactivate(); } catch (ArgumentException) { // Expected } first.Deactivate(); output.WriteLine("ok"); } { output.Write("testing servant registration exceptions... "); communicator.SetProperty("TestAdapter1.Endpoints", "tcp -h *"); ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1"); var obj = new EmptyI(); adapter.Add(obj, "x"); try { adapter.Add(obj, "x"); test(false); } catch (ArgumentException) { } try { adapter.Add(obj, ""); test(false); } catch (FormatException) { } adapter.Remove("x"); try { adapter.Remove("x"); test(false); } catch (NotRegisteredException) { } adapter.Deactivate(); output.WriteLine("ok"); } { output.Write("testing servant locator registration exceptions... "); communicator.SetProperty("TestAdapter2.Endpoints", "tcp -h *"); ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter2"); ServantLocator loc = new ServantLocatorI(); adapter.AddServantLocator(loc, "x"); try { adapter.AddServantLocator(loc, "x"); test(false); } catch (ArgumentException) { } adapter.Deactivate(); output.WriteLine("ok"); } output.Write("testing stringToProxy... "); output.Flush(); string @ref = "thrower:" + helper.getTestEndpoint(0); var @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var thrower = Test.ThrowerPrx.CheckedCast(@base); test(thrower != null); test(thrower.Equals(@base)); output.WriteLine("ok"); output.Write("catching exact types... "); output.Flush(); try { thrower.throwAasA(1); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception ex) { Console.WriteLine(ex); test(false); } try { thrower.throwAorDasAorD(1); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception) { test(false); } try { thrower.throwAorDasAorD(-1); test(false); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } try { thrower.throwBasB(1, 2); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching base types... "); output.Flush(); try { thrower.throwBasB(1, 2); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching derived types... "); output.Flush(); try { thrower.throwBasA(1, 2); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } try { thrower.throwCasA(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } try { thrower.throwCasB(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception... "); output.Flush(); try { thrower.throwUndeclaredA(1); test(false); } catch (UnknownUserException) { } catch (Exception) { test(false); } try { thrower.throwUndeclaredB(1, 2); test(false); } catch (UnknownUserException) { } catch (Exception) { test(false); } try { thrower.throwUndeclaredC(1, 2, 3); test(false); } catch (UnknownUserException) { } catch (Exception) { test(false); } output.WriteLine("ok"); } if (thrower.GetConnection() != null) { output.Write("testing memory limit marshal exception..."); output.Flush(); try { thrower.throwMemoryLimitException(null); test(false); } catch (MemoryLimitException) { } catch (Exception) { test(false); } try { thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB test(false); } catch (ConnectionLostException) { } catch (UnknownLocalException) { // Expected with JS bidir server } catch (Exception) { test(false); } try { var thrower2 = ThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(1), communicator); try { thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits) } catch (MemoryLimitException) { } var thrower3 = Test.ThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(2), communicator); try { thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit test(false); } catch (ConnectionLostException) { } } catch (ConnectionRefusedException) { // Expected with JS bidir server } output.WriteLine("ok"); } output.Write("catching object not exist exception... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); try { var thrower2 = ThrowerPrx.UncheckedCast(thrower.Clone(id)); thrower2.IcePing(); test(false); } catch (ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("catching facet not exist exception... "); output.Flush(); try { var thrower2 = ThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.IcePing(); test(false); } catch (FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching operation not exist exception... "); output.Flush(); try { var thrower2 = Test.WrongOperationPrx.UncheckedCast(thrower); thrower2.noSuchOperation(); test(false); } catch (OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unknown local exception... "); output.Flush(); try { thrower.throwLocalException(); test(false); } catch (UnknownLocalException) { } catch (Exception) { test(false); } try { thrower.throwLocalExceptionIdempotent(); test(false); } catch (UnknownLocalException) { } catch (OperationNotExistException) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception... "); output.Flush(); try { thrower.throwNonIceException(); test(false); } catch (UnknownException) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("testing asynchronous exceptions... "); output.Flush(); try { thrower.throwAfterResponse(); } catch (Exception) { test(false); } try { thrower.throwAfterException(); test(false); } catch (Test.A) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching exact types with AMI mapping... "); output.Flush(); { try { thrower.throwAasAAsync(1).Wait(); } catch (AggregateException exc) { test(exc.InnerException is Test.A); var ex = exc.InnerException as Test.A; test(ex.aMem == 1); } } { try { thrower.throwAorDasAorDAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.A ex) { test(ex.aMem == 1); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } } } { try { thrower.throwAorDasAorDAsync(-1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.A ex) { test(ex.aMem == 1); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } } } { try { thrower.throwBasBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } } } { try { thrower.throwCasCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching derived types with new AMI mapping... "); output.Flush(); { try { thrower.throwBasAAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } } } { try { thrower.throwCasAAsync(1, 2, 3).Wait(); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } } } { try { thrower.throwCasBAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } } } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception with new AMI mapping... "); output.Flush(); { try { thrower.throwUndeclaredAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } { try { thrower.throwUndeclaredBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } { try { thrower.throwUndeclaredCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); } output.Write("catching object not exist exception with new AMI mapping... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); var thrower2 = Test.ThrowerPrx.UncheckedCast(thrower.Clone(id)); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching facet not exist exception with new AMI mapping... "); output.Flush(); { var thrower2 = ThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching operation not exist exception with new AMI mapping... "); output.Flush(); { try { var thrower4 = Test.WrongOperationPrx.UncheckedCast(thrower); thrower4.noSuchOperationAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unknown local exception with new AMI mapping... "); output.Flush(); { try { thrower.throwLocalExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownLocalException) { } catch (OperationNotExistException) { } catch (Exception) { test(false); } } } { try { thrower.throwLocalExceptionIdempotentAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownLocalException) { } catch (OperationNotExistException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception with new AMI mapping... "); output.Flush(); { try { thrower.throwNonIceExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception with new AMI mapping... "); output.Flush(); { try { thrower.throwUndeclaredAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } { try { thrower.throwUndeclaredBAsync(1, 2).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } { try { thrower.throwUndeclaredCAsync(1, 2, 3).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownUserException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); } output.Write("catching object not exist exception with new AMI mapping... "); output.Flush(); { Identity id = Identity.Parse("does not exist"); var thrower2 = Test.ThrowerPrx.UncheckedCast(thrower.Clone(id)); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching facet not exist exception with new AMI mapping... "); output.Flush(); { var thrower2 = Test.ThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet")); try { thrower2.throwAasAAsync(1).Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching operation not exist exception with new AMI mapping... "); output.Flush(); { var thrower4 = Test.WrongOperationPrx.UncheckedCast(thrower); try { thrower4.noSuchOperationAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unknown local exception with new AMI mapping... "); output.Flush(); { try { thrower.throwLocalExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownLocalException) { } catch (OperationNotExistException) { } catch (Exception) { test(false); } } } { try { thrower.throwLocalExceptionIdempotentAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownLocalException) { } catch (OperationNotExistException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception with new AMI mapping... "); output.Flush(); { try { thrower.throwNonIceExceptionAsync().Wait(); test(false); } catch (AggregateException exc) { try { throw exc.InnerException; } catch (UnknownException) { } catch (Exception) { test(false); } } } output.WriteLine("ok"); return(thrower); }
public static Test.IMyClassPrx allTests(global::Test.TestHelper helper) { var communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string rf = "test:" + helper.getTestEndpoint(0); var baseProxy = IObjectPrx.Parse(rf, communicator); test(baseProxy != null); var b1 = IObjectPrx.Parse("test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("'test -f facet'", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("\"test -f facet'", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("\"test -f facet\"", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator); test(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); test(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); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\040test", communicator); test(b1.Identity.Name.Equals("test test") && b1.Identity.Category.Length == 0); try { b1 = IObjectPrx.Parse("test\\777", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\40test", communicator); test(b1.Identity.Name.Equals("test test")); // Test some octal and hex corner cases. b1 = IObjectPrx.Parse("test\\4test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\04test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\004test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\1114test", communicator); test(b1.Identity.Name.Equals("test\u00494test")); b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator); test(b1.Identity.Name.Equals("test\b\f\n\r\t\'\"\\test") && b1.Identity.Category.Length == 0); b1 = IObjectPrx.Parse("category/test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test:tcp --sourceAddress \"::1\"", communicator); test(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); test(b1.Equals(IObjectPrx.Parse(b1.ToString(), communicator))); try { b1 = IObjectPrx.Parse("", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\"", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\" test", communicator); // Invalid trailing characters. test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("test:", communicator); // Missing endpoint. test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); try { b1 = IObjectPrx.Parse("id@adapter test", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("category/test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category 1") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator); test(b1.Identity.Name.Equals("test 1") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter 1")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator); test(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); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("id -f facet", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet")); b1 = IObjectPrx.Parse("id -f 'facet x'", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); try { b1 = IObjectPrx.Parse("id -f \"facet x", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("id -f \'facet x", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test -f facet:tcp", communicator); test(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); test(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); test(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); test(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); test(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); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test", communicator); test(!b1.IsOneway); b1 = IObjectPrx.Parse("test -t", communicator); test(!b1.IsOneway); b1 = IObjectPrx.Parse("test -o", communicator); test(b1.IsOneway); b1 = IObjectPrx.Parse("test -O", communicator); test(b1.InvocationMode == InvocationMode.BatchOneway); b1 = IObjectPrx.Parse("test -d", communicator); test(b1.InvocationMode == InvocationMode.Datagram); b1 = IObjectPrx.Parse("test -D", communicator); test(b1.InvocationMode == InvocationMode.BatchDatagram); b1 = IObjectPrx.Parse("test", communicator); test(!b1.IsSecure); b1 = IObjectPrx.Parse("test -s", communicator); test(b1.IsSecure); test(b1.Encoding.Equals(Encoding.Latest)); b1 = IObjectPrx.Parse("test -e 1.0", communicator); test(b1.Encoding.Major == 1 && b1.Encoding.Minor == 0); b1 = IObjectPrx.Parse("test -e 6.5", communicator); test(b1.Encoding.Major == 6 && b1.Encoding.Minor == 5); b1 = IObjectPrx.Parse("test -p ice1 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p ice1 -e 1.0")); b1 = IObjectPrx.Parse("test -p 1.0 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p ice1 -e 1.0")); b1 = IObjectPrx.Parse("test -p ice2 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p ice2 -e 1.0")); b1 = IObjectPrx.Parse("test -p 2.0 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p ice2 -e 1.0")); b1 = IObjectPrx.Parse("test -p 6 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p 6 -e 1.0")); b1 = IObjectPrx.Parse("test -p 6.0 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p 6 -e 1.0")); try { IObjectPrx.Parse("test:tcp@adapterId", communicator); test(false); } catch (FormatException) { } // This is an unknown endpoint warning, not a parse exception. // //try //{ // b1 = communicator.stringToProxy("test -f the:facet:tcp"); // test(false); //} //catch(EndpointParseException) //{ //} try { IObjectPrx.Parse("test: :tcp", communicator); test(false); } catch (FormatException) { } // // Test invalid endpoint syntax // try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp"); test(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)); test(id.Equals(id2)); id = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\"); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); id = new Identity("/test", "cat/"); string idStr = id.ToString(communicator.ToStringMode); test(idStr == "cat\\//\\/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); // Input string with various pitfalls id = Identity.Parse("\\342\\x82\\254\\60\\x9\\60\\"); test(id.Name == "€0\t0\\" && id.Category == ""); try { // Illegal character < 32 id = Identity.Parse("xx\01FooBar"); test(false); } catch (FormatException) { } try { // Illegal surrogate id = Identity.Parse("xx\\ud911"); test(false); } catch (FormatException) { } // Testing bytes 127(\x7F, \177) and € id = new Identity("test", "\x7f€"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "\\u007f€/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); test(id.ToString() == idStr); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "\\u007f\\u20ac/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); test(idStr == "\\177\\342\\202\\254/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); // More unicode character id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); id2 = Identity.Parse(idStr); test(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$"); test(id.Equals(id2)); output.WriteLine("ok"); output.Write("testing proxyToString... "); output.Flush(); b1 = IObjectPrx.Parse(rf, communicator); var b2 = IObjectPrx.Parse(b1.ToString(), communicator); test(b1.Equals(b2)); if (b1.GetConnection() != null) // not colloc-optimized target { b2 = b1.GetConnection().CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory); string str = b2.ToString(); test(b2.ToString() == str); string str2 = b1.Clone(b2.Identity).Clone(secure: b2.IsSecure).ToString(); // Verify that the stringified fixed proxy is the same as a regular stringified proxy // but without endpoints test(str2.StartsWith(str)); test(str2[str.Length] == ':'); } 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); test(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"; test(b1.Locator == null); communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(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); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(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); //test(b1.LocatorCacheTimeout == 60); //communicator.SetProperty("Default.LocatorCacheTimeout", ""); communicator.SetProperty(propertyPrefix, "test:" + helper.getTestEndpoint(0)); property = propertyPrefix + ".Router"; test(b1.Router == null); communicator.SetProperty(property, "router:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Router != null && b1.Router.Identity.Name.Equals("router")); communicator.RemoveProperty(property); property = propertyPrefix + ".PreferSecure"; test(!b1.IsPreferSecure); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.IsPreferSecure); communicator.RemoveProperty(property); property = propertyPrefix + ".ConnectionCached"; test(b1.IsConnectionCached); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsConnectionCached); communicator.RemoveProperty(property); property = propertyPrefix + ".InvocationTimeout"; test(b1.InvocationTimeout == -1); communicator.SetProperty(property, "1000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.InvocationTimeout == 1000); communicator.RemoveProperty(property); property = propertyPrefix + ".EndpointSelection"; test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Random"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Ordered"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Ordered); communicator.RemoveProperty(property); property = propertyPrefix + ".CollocationOptimized"; test(b1.IsCollocationOptimized); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsCollocationOptimized); communicator.RemoveProperty(property); property = propertyPrefix + ".Context.c1"; test(!b1.Context.ContainsKey("c1")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Context["c1"].Equals("TEST")); property = propertyPrefix + ".Context.c2"; test(!b1.Context.ContainsKey("c2")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(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, connectionCached: true, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 200, invocationTimeout: 1500); var locator = ILocatorPrx.Parse("locator", communicator).Clone( collocationOptimized: true, connectionCached: false, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 300, invocationTimeout: 1500, router: router); b1 = IObjectPrx.Parse("test", communicator).Clone( collocationOptimized: true, connectionCached: true, preferSecure: false, endpointSelectionType: EndpointSelectionType.Ordered, locatorCacheTimeout: 100, invocationTimeout: 1234, encoding: Encoding.V2_0, locator: locator); Dictionary <string, string> proxyProps = b1.ToProperty("Test"); test(proxyProps.Count == 21); test(proxyProps["Test"].Equals("test -t -p ice1 -e 2.0")); test(proxyProps["Test.CollocationOptimized"].Equals("1")); test(proxyProps["Test.ConnectionCached"].Equals("1")); test(proxyProps["Test.PreferSecure"].Equals("0")); test(proxyProps["Test.EndpointSelection"].Equals("Ordered")); test(proxyProps["Test.LocatorCacheTimeout"].Equals("100")); test(proxyProps["Test.InvocationTimeout"].Equals("1234")); test(proxyProps["Test.Locator"].Equals( "locator -t -p ice1 -e " + Encoding.Latest.ToString())); // Locator collocation optimization is always disabled. //test(proxyProps["Test.Locator.CollocationOptimized"].Equals("1")); test(proxyProps["Test.Locator.ConnectionCached"].Equals("0")); test(proxyProps["Test.Locator.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.LocatorCacheTimeout"].Equals("300")); test(proxyProps["Test.Locator.InvocationTimeout"].Equals("1500")); test(proxyProps["Test.Locator.Router"].Equals( "router -t -p ice1 -e " + Encoding.Latest.ToString())); test(proxyProps["Test.Locator.Router.CollocationOptimized"].Equals("0")); test(proxyProps["Test.Locator.Router.ConnectionCached"].Equals("1")); test(proxyProps["Test.Locator.Router.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.Router.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"].Equals("200")); test(proxyProps["Test.Locator.Router.InvocationTimeout"].Equals("1500")); output.WriteLine("ok"); output.Write("testing ice_getCommunicator... "); output.Flush(); test(baseProxy.Communicator == communicator); output.WriteLine("ok"); output.Write("testing proxy methods... "); test(baseProxy.Clone(facet: "facet").Facet.Equals("facet")); test(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id")); test(!baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Datagram).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode == InvocationMode.BatchOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode == InvocationMode.Datagram); test(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode == InvocationMode.BatchDatagram); test(baseProxy.Clone(secure: true).IsSecure); test(!baseProxy.Clone(secure: false).IsSecure); test(baseProxy.Clone(collocationOptimized: true).IsCollocationOptimized); test(!baseProxy.Clone(collocationOptimized: false).IsCollocationOptimized); test(baseProxy.Clone(preferSecure: true).IsPreferSecure); test(!baseProxy.Clone(preferSecure: false).IsPreferSecure); try { baseProxy.Clone(connectionTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(connectionTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(connectionTimeout: -2); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: -1); baseProxy.Clone(invocationTimeout: -2); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(invocationTimeout: -3); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(locatorCacheTimeout: 0); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -2); test(false); } catch (ArgumentException) { } output.WriteLine("ok"); output.Write("testing proxy comparison... "); output.Flush(); test(object.Equals(IObjectPrx.Parse("foo", communicator), IObjectPrx.Parse("foo", communicator))); test(!IObjectPrx.Parse("foo", communicator).Equals(IObjectPrx.Parse("foo2", communicator))); var compObj = IObjectPrx.Parse("foo", communicator); test(compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet"))); test(!compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet1"))); test(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Oneway))); test(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Twoway))); test(compObj.Clone(secure: true).Equals(compObj.Clone(secure: true))); test(!compObj.Clone(secure: false).Equals(compObj.Clone(secure: true))); test(compObj.Clone(collocationOptimized: true).Equals(compObj.Clone(collocationOptimized: true))); test(!compObj.Clone(collocationOptimized: false).Equals(compObj.Clone(collocationOptimized: true))); test(compObj.Clone(connectionCached: true).Equals(compObj.Clone(connectionCached: true))); test(!compObj.Clone(connectionCached: false).Equals(compObj.Clone(connectionCached: true))); test(compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Random))); test(!compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Ordered))); test(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2"))); test(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2"))); test(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1")); test(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2")); test(compObj.Clone(compress: true).Equals(compObj.Clone(compress: true))); test(!compObj.Clone(compress: false).Equals(compObj.Clone(compress: true))); test(!compObj.Compress.HasValue); test(compObj.Clone(compress: true).Compress.Value == true); test(compObj.Clone(compress: false).Compress.Value == false); test(compObj.Clone(connectionTimeout: 20).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.Clone(connectionTimeout: 10).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.ConnectionTimeout.HasValue); test(compObj.Clone(connectionTimeout: 10).ConnectionTimeout.Value == 10); test(compObj.Clone(connectionTimeout: 20).ConnectionTimeout.Value == 20); ILocatorPrx loc1 = ILocatorPrx.Parse("loc1:default -p 10000", communicator); ILocatorPrx loc2 = ILocatorPrx.Parse("loc2:default -p 10000", communicator); test(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true))); test(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true))); test(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2))); IRouterPrx rtr1 = IRouterPrx.Parse("rtr1:default -p 10000", communicator); IRouterPrx rtr2 = IRouterPrx.Parse("rtr2:default -p 10000", communicator); test(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true))); test(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1))); test(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true))); test(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2))); test(!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"; test(compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1))); test(!compObj.Clone(context: ctx1).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(!compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: ctx2))); test(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2))); test(compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: true))); test(!compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: 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); test(!compObj1.Equals(compObj2)); compObj1 = IObjectPrx.Parse("foo@MyAdapter1", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter2", communicator); test(!compObj1.Equals(compObj2)); test(compObj1.Clone(locatorCacheTimeout: 20).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(!compObj1.Clone(locatorCacheTimeout: 10).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20))); test(!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); test(!compObj1.Equals(compObj2)); IEndpoint[] endpts1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints; IEndpoint[] endpts2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator).Endpoints; test(!endpts1[0].Equals(endpts2[0])); test(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); test(!compObj1.Equals(compObj2)); } output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); Test.IMyClassPrx cl = Test.IMyClassPrx.CheckedCast(baseProxy); test(cl != null); Test.IMyDerivedClassPrx derived = Test.IMyDerivedClassPrx.CheckedCast(cl); test(derived != null); test(cl.Equals(baseProxy)); test(derived.Equals(baseProxy)); test(cl.Equals(derived)); try { Test.IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet")); test(false); } catch (ObjectNotExistException) { } output.WriteLine("ok"); output.Write("testing checked cast with context... "); output.Flush(); Dictionary <string, string> c = cl.getContext(); test(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(); test(global::Test.Collections.Equals(c, c2)); output.WriteLine("ok"); output.Write("testing ice_fixed... "); output.Flush(); { Connection connection = cl.GetConnection(); if (connection != null) { test(!cl.IsFixed); Test.IMyClassPrx prx = cl.Clone(fixedConnection: connection); test(prx.IsFixed); prx.IcePing(); try { cl.Clone(secure: true, fixedConnection: connection); test(false); } catch (ArgumentException) { } test(cl.Clone(facet: "facet", fixedConnection: connection).Facet.Equals("facet")); test(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection).IsOneway); Dictionary <string, string> ctx = new Dictionary <string, string>(); ctx["one"] = "hello"; ctx["two"] = "world"; test(cl.Clone(fixedConnection: connection).Context.Count == 0); test(cl.Clone(context: ctx, fixedConnection: connection).Context.Count == 2); test(cl.Clone(fixedConnection: connection).InvocationTimeout == -1); test(cl.Clone(invocationTimeout: 10, fixedConnection: connection).InvocationTimeout == 10); test(cl.Clone(fixedConnection: connection).GetConnection() == connection); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: connection).GetConnection() == connection); test(!cl.Clone(fixedConnection: connection).ConnectionTimeout.HasValue); test(cl.Clone(compress: true, fixedConnection: connection).Compress.Value); Connection fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection(); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection); try { cl.Clone(secure: !connection.Endpoint.GetInfo().Secure(), fixedConnection: connection); test(false); } catch (ArgumentException) { } try { cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection); test(false); } catch (ArgumentException) { } } } output.WriteLine("ok"); string ref13 = "test -e 1.3:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl13 = Test.IMyClassPrx.Parse(ref13, communicator); try { cl13.IcePing(); test(false); } catch (UnsupportedEncodingException) { // expected } output.Write("testing encoding versioning... "); output.Flush(); string ref21 = "test -e 2.1:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl21 = Test.IMyClassPrx.Parse(ref21, communicator); try { cl21.IcePing(); test(false); } catch (UnsupportedEncodingException) { // 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(); test(false); } catch (UnsupportedProtocolException) { // 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); test(false); } catch (FormatException) { } try { // Missing -t and -v IObjectPrx.Parse("id:opaque", communicator); test(false); } catch (FormatException) { } try { // Repeated -t IObjectPrx.Parse("id:opaque -t 1 -t 1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Repeated -v IObjectPrx.Parse("id:opaque -t 1 -v abcd -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -t IObjectPrx.Parse("id:opaque -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -v IObjectPrx.Parse("id:opaque -t 1", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -t IObjectPrx.Parse("id:opaque -t -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -v IObjectPrx.Parse("id:opaque -t 1 -v", communicator); test(false); } catch (FormatException) { } try { // Not a number for -t IObjectPrx.Parse("id:opaque -t x -v abcd", communicator); test(false); } catch (FormatException) { } try { // < 0 for -t IObjectPrx.Parse("id:opaque -t -1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Invalid char for -v IObjectPrx.Parse("id:opaque -t 99 -v x?c", communicator); test(false); } catch (FormatException) { } try { // Invalid lenght for base64 input IObjectPrx.Parse("id:opaque -t 99 -v xc", communicator); test(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); test(p1.ToString().Equals("test -t -p ice1 -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); if ((communicator.GetPropertyAsInt("IPv6") ?? 0) == 0) { // Working? bool ssl = communicator.GetProperty("Default.Transport") == "ssl"; bool tcp = communicator.GetProperty("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(); test(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) { test(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) { test(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(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); com.Shutdown(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); } output.WriteLine("ok"); return(cl); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = IServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = ITestLocatorPrx.UncheckedCast(communicator.GetDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = ITestLocatorRegistryPrx.CheckedCast(locator.GetRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = 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... "); test(default(ProxyIdentityComparer).Equals(@base.Locator, communicator.GetDefaultLocator())); var anotherLocator = ILocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Equals(@base.Locator, anotherLocator)); communicator.SetDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Equals(@base.Locator, anotherLocator)); communicator.SetDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Equals(@base.Locator, communicator.GetDefaultLocator())); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Equals(@base.Router, anotherRouter)); var router = IRouterPrx.Parse("dummyrouter", communicator); communicator.SetDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Equals(@base.Router, communicator.GetDefaultRouter())); communicator.SetDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.ITestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.ITestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.ITestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.IServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.ITestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.ITestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.ITestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject.Equals("object")); test(ex.Id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject.Equals("object adapter")); test(ex.Id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = ITestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(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 Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(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(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject == "object adapter"); test(ex.Id.Equals("TestAdapter3")); } 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 (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(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(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject == "object adapter"); test(ex.Id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(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; test(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. test(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 (LocalException) { // 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 (LocalException) { // 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 = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.GetConnection().Close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.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(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } 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 = IHelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateIndirectProxy(id, IObjectPrx.Factory)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateDirectProxy(id, IObjectPrx.Factory)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }