public static void allTestsWithController(global::Test.TestHelper helper, Test.ControllerPrx controller) { 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); 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 (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 (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(1000); 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 (InvocationTimeoutException) { test(false); } test(connection == to.ice_getConnection()); } { // // Expect InvocationTimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(100)); try { to.sleepAsync(1000).Wait(); } catch (System.AggregateException ex) when(ex.InnerException is InvocationTimeoutException) { } obj.ice_ping(); } { // // Expect success. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(1000)); to.sleepAsync(100).Wait(); } { // // 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 (TimeoutException) { try { con.getInfo(); test(false); } catch (TimeoutException) { // Connection got closed as well. } } obj.ice_ping(); try { con = connect(to); to.sleepAsync(750).Wait(); test(false); } catch (System.AggregateException ex) when(ex.InnerException is TimeoutException) { try { con.getInfo(); test(false); } catch (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 (LocalException) { test(false); } while (true) { try { connection.getInfo(); 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 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 (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 (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.destroy(); } { // // Test Ice.Override.ConnectTimeout. // var initData = new 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 (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 (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 (TimeoutException) { // Expected. } controller.resumeAdapter(); timeout.op(); // Ensure adapter is active. comm.destroy(); } { // // Test Ice.Override.CloseTimeout. // var initData = new 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 (InvocationTimeoutException) { } try { proxy.sleepAsync(500).Wait(); test(false); } catch (System.AggregateException ex) when(ex.InnerException is InvocationTimeoutException) { } try { ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-2)).ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-2)).ice_pingAsync().Wait(); } catch (System.Exception) { test(false); } adapter.destroy(); } output.WriteLine("ok"); controller.shutdown(); }