public static void allTests(Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); string sref = "test:" + helper.getTestEndpoint(0); Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); int proxyPort = communicator.getProperties().getPropertyAsInt("Ice.HTTPProxyPort"); if (proxyPort == 0) { proxyPort = communicator.getProperties().getPropertyAsInt("Ice.SOCKSProxyPort"); } Test.TestIntfPrx testPrx = Test.TestIntfPrxHelper.checkedCast(obj); test(testPrx != null); var output = helper.getWriter(); output.Write("testing connection... "); output.Flush(); { testPrx.ice_ping(); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { Ice.IPConnectionInfo info = getIPConnectionInfo(testPrx.ice_getConnection().getInfo()); test(info.remotePort == proxyPort); // make sure we are connected to the proxy port. } output.WriteLine("ok"); output.Write("shutting down server... "); output.Flush(); { testPrx.shutdown(); } output.WriteLine("ok"); output.Write("testing connection failure... "); output.Flush(); { try { testPrx.ice_ping(); test(false); } catch (Ice.LocalException) { } } output.WriteLine("ok"); }
public override void runTestCase(Test.RemoteObjectAdapterPrx adapter, Test.TestIntfPrx proxy) { proxy.startHeartbeatCount(); Ice.Connection con = proxy.ice_getConnection(); con.heartbeat(); con.heartbeat(); con.heartbeat(); con.heartbeat(); con.heartbeat(); proxy.waitForHeartbeatCount(5); }
public static void allTests(Ice.Communicator communicator) #endif { string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx testPrx = Test.TestIntfPrxHelper.checkedCast(obj); test(testPrx != null); Write("testing connection... "); Flush(); { testPrx.ice_ping(); } WriteLine("ok"); Write("testing connection information... "); Flush(); { Ice.IPConnectionInfo info = (Ice.IPConnectionInfo)testPrx.ice_getConnection().getInfo(); test(info.remotePort == 12030 || info.remotePort == 12031); // make sure we are connected to the proxy port. } WriteLine("ok"); Write("shutting down server... "); Flush(); { testPrx.shutdown(); } WriteLine("ok"); Write("testing connection failure... "); Flush(); { try { testPrx.ice_ping(); test(false); } catch (Ice.LocalException) { } } WriteLine("ok"); }
public static void allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); Test.PingReplyPrx reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); adapter.activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test:" + helper.getTestEndpoint(0, "udp")).ice_datagram(); Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(@base); int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret == true); if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = null; try { seq = new byte[1024]; while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (Ice.DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // test(seq.Length > 16384); } obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // test(!b); } catch (Ice.DatagramLimitException) { } catch (Ice.LocalException ex) { Console.Out.WriteLine(ex); test(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); StringBuilder endpoint = new StringBuilder(); // // Use loopback to prevent other machines to answer. // if (communicator.getProperties().getProperty("Ice.IPv6") == "1") { endpoint.Append("udp -h \"ff15::1:1\""); if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS) { endpoint.Append(" --interface \"::1\""); } } else { endpoint.Append("udp -h 239.255.1.1"); if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS) { endpoint.Append(" --interface 127.0.0.1"); } } endpoint.Append(" -p "); endpoint.Append(helper.getTestPort(10)); @base = communicator.stringToProxy("test -d:" + endpoint.ToString()); var objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); try { objMcast.ping(reply); } catch (Ice.SocketException) { if (communicator.getProperties().getProperty("Ice.IPv6") == "1") { // Multicast IPv6 not supported on the platform. This occurs for example on macOS big_suir Console.Out.Write("(not supported) "); ret = true; break; } throw; } ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } if (!ret) { Console.Out.WriteLine("failed(is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.ice_getConnection().setAdapter(adapter); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret); Console.Out.WriteLine("ok"); // // Sending the replies back on the multicast UDP connection doesn't work for most // platform(it works for macOS Leopard but not Snow Leopard, doesn't work on SLES, // Windows...). For Windows, see UdpTransceiver constructor for the details. So // we don't run this test. // // Console.Out.Write("testing udp bi-dir connection... "); // nRetry = 5; // while(nRetry-- > 0) // { // replyI.reset(); // objMcast.pingBiDir(reply.ice_getIdentity()); // ret = replyI.waitReply(5, 2000); // if(ret) // { // break; // Success // } // replyI = new PingReplyI(); // reply =(PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); // } // if(!ret) // { // Console.Out.WriteLine("failed(is a firewall enabled?)"); // } // else // { // Console.Out.WriteLine("ok"); // } }
public static void allTests(global::Test.TestHelper helper, bool collocated) { Communicator communicator = helper.communicator(); string sref = "test:" + helper.getTestEndpoint(0); ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); sref = "testController:" + helper.getTestEndpoint(1); obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); var output = helper.getWriter(); output.Write("testing async invocation..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(p.ice_isAAsync("::Test::TestIntf").Result); test(p.ice_isAAsync("::Test::TestIntf", ctx).Result); p.ice_pingAsync().Wait(); p.ice_pingAsync(ctx).Wait(); test(p.ice_idAsync().Result.Equals("::Test::TestIntf")); test(p.ice_idAsync(ctx).Result.Equals("::Test::TestIntf")); test(p.ice_idsAsync().Result.Length == 2); test(p.ice_idsAsync(ctx).Result.Length == 2); if (!collocated) { test(p.ice_getConnectionAsync().Result != null); } p.opAsync().Wait(); p.opAsync(ctx).Wait(); test(p.opWithResultAsync().Result == 15); test(p.opWithResultAsync(ctx).Result == 15); try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } try { p.opWithUEAsync(ctx).Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } } output.WriteLine("ok"); output.Write("testing async/await..."); output.Flush(); { Task.Run(async() => { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(await p.ice_isAAsync("::Test::TestIntf")); test(await p.ice_isAAsync("::Test::TestIntf", ctx)); await p.ice_pingAsync(); await p.ice_pingAsync(ctx); var id = await p.ice_idAsync(); test(id.Equals("::Test::TestIntf")); id = await p.ice_idAsync(ctx); test(id.Equals("::Test::TestIntf")); var ids = await p.ice_idsAsync(); test(ids.Length == 2); ids = await p.ice_idsAsync(ctx); test(ids.Length == 2); if (!collocated) { var conn = await p.ice_getConnectionAsync(); test(conn != null); } await p.opAsync(); await p.opAsync(ctx); var result = await p.opWithResultAsync(); test(result == 15); result = await p.opWithResultAsync(ctx); test(result == 15); try { await p.opWithUEAsync(); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } try { await p.opWithUEAsync(ctx); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing async continuations..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); p.ice_isAAsync("::Test::TestIntf").ContinueWith(previous => { test(previous.Result); }).Wait(); p.ice_isAAsync("::Test::TestIntf", ctx).ContinueWith(previous => { test(previous.Result); }).Wait(); p.ice_pingAsync().ContinueWith(previous => { previous.Wait(); }).Wait(); p.ice_pingAsync(ctx).ContinueWith(previous => { previous.Wait(); }).Wait(); p.ice_idAsync().ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.ice_idAsync(ctx).ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.ice_idsAsync().ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); p.ice_idsAsync(ctx).ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); if (!collocated) { p.ice_getConnectionAsync().ContinueWith(previous => { test(previous.Result != null); }).Wait(); } p.opAsync().ContinueWith(previous => previous.Wait()).Wait(); p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait(); p.opWithResultAsync().ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithResultAsync(ctx).ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithUEAsync().ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); p.opWithUEAsync(ctx).ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing local exceptions with async tasks... "); output.Flush(); { Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); try { indirect.opAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is NoEndpointException); }); } try { ((Test.TestIntfPrx)p.ice_oneway()).opWithResultAsync(); test(false); } catch (TwowayOnlyException) { } // // Check that CommunicatorDestroyedException is raised directly. // if (p.ice_getConnection() != null) { InitializationData initData = new InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Communicator ic = helper.initialize(initData); ObjectPrx o = ic.stringToProxy(p.ToString()); Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); ic.destroy(); try { p2.opAsync(); test(false); } catch (CommunicatorDestroyedException) { // Expected. } } } output.WriteLine("ok"); output.Write("testing exception with async task... "); output.Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); try { i.ice_isAAsync("::Test::TestIntf").Wait(); test(false); } catch (AggregateException) { } try { i.opAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithResultAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithUEAsync().Wait(); test(false); } catch (AggregateException) { } // Ensures no exception is called when response is received test(p.ice_isAAsync("::Test::TestIntf").Result); p.opAsync().Wait(); p.opWithResultAsync().Wait(); // If response is a user exception, it should be received. try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is Test.TestIntfException); }); } } output.WriteLine("ok"); output.Write("testing progress callback... "); output.Flush(); { { SentCallback cb = new SentCallback(); Task t = p.ice_isAAsync("", progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.ice_pingAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.ice_idAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.ice_idsAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.opAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); } List <Task> tasks = new List <Task>(); byte[] seq = new byte[10024]; (new Random()).NextBytes(seq); testController.holdAdapter(); try { Task t = null; ProgresCallback cb; do { cb = new ProgresCallback(); t = p.opWithPayloadAsync(seq, progress: cb); tasks.Add(t); }while (cb.SentSynchronously); } finally { testController.resumeAdapter(); } foreach (Task t in tasks) { t.Wait(); } } output.WriteLine("ok"); output.Write("testing async/await... "); output.Flush(); Func <Task> task = async() => { try { await p.opAsync(); var r = await p.opWithResultAsync(); test(r == 15); try { await p.opWithUEAsync(); } catch (Test.TestIntfException) { } // Operations implemented with amd and async. await p.opAsyncDispatchAsync(); r = await p.opWithResultAsyncDispatchAsync(); test(r == 15); try { await p.opWithUEAsyncDispatchAsync(); test(false); } catch (Test.TestIntfException) { } } catch (OperationNotExistException) { // Expected with cross testing, this opXxxAsyncDispatch methods are C# only. } }; task().Wait(); output.WriteLine("ok"); if (p.ice_getConnection() != null) { output.Write("testing async Task cancellation... "); output.Flush(); { var cs1 = new CancellationTokenSource(); var cs2 = new CancellationTokenSource(); var cs3 = new CancellationTokenSource(); Task t1; Task t2; Task t3; try { testController.holdAdapter(); ProgresCallback cb = null; byte[] seq = new byte[10024]; for (int i = 0; i < 200; ++i) // 2MB { cb = new ProgresCallback(); p.opWithPayloadAsync(seq, progress: cb); } test(!cb.Sent); t1 = p.ice_pingAsync(cancel: cs1.Token); t2 = p.ice_pingAsync(cancel: cs2.Token); cs3.Cancel(); t3 = p.ice_pingAsync(cancel: cs3.Token); cs1.Cancel(); cs2.Cancel(); try { t1.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t2.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t3.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } } finally { testController.resumeAdapter(); p.ice_ping(); } } output.WriteLine("ok"); } if (p.ice_getConnection() != null && p.supportsAMD()) { output.Write("testing graceful close connection with wait... "); output.Flush(); { // // Local case: begin a request, close the connection gracefully, and make sure it waits // for the request to complete. // Connection con = p.ice_getConnection(); CallbackBase cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); Task t = p.sleepAsync(100); con.close(ConnectionClose.GracefullyWithWait); t.Wait(); // Should complete successfully. cb.check(); } { // // Remote case. // byte[] seq = new byte[1024 * 10]; // // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // int maxQueue = 2; bool done = false; while (!done && maxQueue < 50) { done = true; p.ice_ping(); List <Task> results = new List <Task>(); for (int i = 0; i < maxQueue; ++i) { results.Add(p.opWithPayloadAsync(seq)); } ProgresCallback cb = new ProgresCallback(); p.closeAsync(Test.CloseMode.GracefullyWithWait, progress: cb); if (!cb.SentSynchronously) { for (int i = 0; i < maxQueue; i++) { cb = new ProgresCallback(); Task t = p.opWithPayloadAsync(seq, progress: cb); results.Add(t); if (cb.SentSynchronously) { done = false; maxQueue *= 2; break; } } } else { maxQueue *= 2; done = false; } foreach (Task q in results) { q.Wait(); } } } output.WriteLine("ok"); output.Write("testing graceful close connection without wait... "); output.Flush(); { // // Local case: start an operation and then close the connection gracefully on the client side // without waiting for the pending invocation to complete. There will be no retry and we expect the // invocation to fail with ConnectionManuallyClosedException. // p = (Test.TestIntfPrx)p.ice_connectionId("CloseGracefully"); // Start with a new connection. Connection con = p.ice_getConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Gracefully); try { t.Wait(); test(false); } catch (System.AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test((ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection gracefully, which means the connection // will not be closed until all pending dispatched requests have completed. // con = p.ice_getConnection(); cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); t = p.sleepAsync(100); p.close(Test.CloseMode.Gracefully); // Close is delayed until sleep completes. cb.check(); t.Wait(); } output.WriteLine("ok"); output.Write("testing forceful close connection... "); output.Flush(); { // // Local case: start an operation and then close the connection forcefully on the client side. // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException. // p.ice_ping(); Connection con = p.ice_getConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Forcefully); try { t.Wait(); test(false); } catch (AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test(!(ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection forcefully. This causes the request to fail // with a ConnectionLostException. Since the close() operation is not idempotent, the client // will not retry. // try { p.close(Test.CloseMode.Forcefully); test(false); } catch (ConnectionLostException) { // Expected. } } output.WriteLine("ok"); } output.Write("testing ice_scheduler... "); output.Flush(); { p.ice_pingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }).Wait(); p.ice_pingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, p.ice_scheduler()).Wait(); { TaskCompletionSource <int> s1 = new TaskCompletionSource <int>(); TaskCompletionSource <int> s2 = new TaskCompletionSource <int>(); Task t1 = s1.Task; Task t2 = s2.Task; Task t3 = null; Task t4 = null; p.ice_pingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); // // t1 Continuation run in the thread that completes it. // var id = Thread.CurrentThread.ManagedThreadId; t3 = t1.ContinueWith(prev => { test(id == Thread.CurrentThread.ManagedThreadId); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.ice_scheduler()); s1.SetResult(1); // // t2 completed from the main thread // t4 = t2.ContinueWith(prev => { test(id != Thread.CurrentThread.ManagedThreadId); test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.ice_scheduler()); }, p.ice_scheduler()).Wait(); s2.SetResult(1); Task.WaitAll(t1, t2, t3, t4); } if (!collocated) { ObjectAdapter adapter = communicator.createObjectAdapter(""); PingReplyI replyI = new PingReplyI(); var reply = Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)); adapter.activate(); p.ice_getConnection().setAdapter(adapter); p.pingBiDir(reply); test(replyI.checkReceived()); adapter.destroy(); } } output.WriteLine("ok"); output.Write("testing result struct... "); output.Flush(); { var q = Test.Outer.Inner.TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("test2:" + helper.getTestEndpoint(0))); q.opAsync(1).ContinueWith(t => { var r = t.Result; test(r.returnValue == 1); test(r.j == 1); }).Wait(); } output.WriteLine("ok"); p.shutdown(); }