diff options
Diffstat (limited to 'java/test/Ice/timeout')
-rw-r--r-- | java/test/Ice/timeout/AllTests.java | 768 | ||||
-rw-r--r-- | java/test/Ice/timeout/Client.java | 88 | ||||
-rw-r--r-- | java/test/Ice/timeout/Server.java | 96 | ||||
-rw-r--r-- | java/test/Ice/timeout/TimeoutI.java | 62 |
4 files changed, 507 insertions, 507 deletions
diff --git a/java/test/Ice/timeout/AllTests.java b/java/test/Ice/timeout/AllTests.java index 8a2ff1d6350..6484d7aee2e 100644 --- a/java/test/Ice/timeout/AllTests.java +++ b/java/test/Ice/timeout/AllTests.java @@ -14,414 +14,414 @@ public class AllTests private static void test(boolean b) { - if(!b) - { - throw new RuntimeException(); - } + if(!b) + { + throw new RuntimeException(); + } } private static class Callback { - Callback() - { - _called = false; - } - - public synchronized boolean - check() - { - while(!_called) - { - try - { - wait(5000); - } - catch(InterruptedException ex) - { - continue; - } - - if(!_called) - { - return false; // Must be timeout. - } - } - - _called = false; - return true; - } - - public synchronized void - called() - { - assert(!_called); - _called = true; - notify(); - } - - private boolean _called; + Callback() + { + _called = false; + } + + public synchronized boolean + check() + { + while(!_called) + { + try + { + wait(5000); + } + catch(InterruptedException ex) + { + continue; + } + + if(!_called) + { + return false; // Must be timeout. + } + } + + _called = false; + return true; + } + + public synchronized void + called() + { + assert(!_called); + _called = true; + notify(); + } + + private boolean _called; } private static class AMISendData extends Test.AMI_Timeout_sendData { - public void - ice_response() - { - callback.called(); - } - - public void - ice_exception(Ice.LocalException ex) - { - test(false); - } - - public boolean - check() - { - return callback.check(); - } - - private Callback callback = new Callback(); + public void + ice_response() + { + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(false); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); } private static class AMISendDataEx extends Test.AMI_Timeout_sendData { - public void - ice_response() - { - test(false); - } - - public void - ice_exception(Ice.LocalException ex) - { - test(ex instanceof Ice.TimeoutException); - callback.called(); - } - - public boolean - check() - { - return callback.check(); - } - - private Callback callback = new Callback(); + public void + ice_response() + { + test(false); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.TimeoutException); + callback.called(); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); } private static class AMISleep extends Test.AMI_Timeout_sleep { - public void - ice_response() - { - callback.called(); - } - - public void - ice_exception(Ice.LocalException ex) - { - test(false); - } - - public boolean - check() - { - return callback.check(); - } - - private Callback callback = new Callback(); + public void + ice_response() + { + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(false); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); } private static class AMISleepEx extends Test.AMI_Timeout_sleep { - public void - ice_response() - { - test(false); - } - - public void - ice_exception(Ice.LocalException ex) - { - test(ex instanceof Ice.TimeoutException); - callback.called(); - } - - public boolean - check() - { - return callback.check(); - } - - private Callback callback = new Callback(); + public void + ice_response() + { + test(false); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.TimeoutException); + callback.called(); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); } public static Test.TimeoutPrx allTests(Ice.Communicator communicator, java.io.PrintStream out) { - String sref = "timeout:default -p 12010 -t 10000"; - Ice.ObjectPrx obj = communicator.stringToProxy(sref); - test(obj != null); - - TimeoutPrx timeout = TimeoutPrxHelper.checkedCast(obj); - test(timeout != null); - - out.print("testing connect timeout... "); - out.flush(); - { - // - // Expect ConnectTimeoutException. - // - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); - to.holdAdapter(1000); - to.ice_getConnection().close(true); // Force a reconnect. - try - { - to.op(); - test(false); - } - catch(Ice.ConnectTimeoutException ex) - { - // Expected. - } - } - { - // - // Expect success. - // - timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); - to.holdAdapter(500); - to.ice_getConnection().close(true); // Force a reconnect. - try - { - to.op(); - } - catch(Ice.ConnectTimeoutException ex) - { - test(false); - } - } - out.println("ok"); - - out.print("testing read timeout... "); - out.flush(); - { - // - // Expect TimeoutException. - // - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); - try - { - to.sleep(750); - test(false); - } - catch(Ice.TimeoutException ex) - { - // Expected. - } - } - { - // - // Expect success. - // - timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); - try - { - to.sleep(500); - } - catch(Ice.TimeoutException ex) - { - test(false); - } - } - out.println("ok"); - - out.print("testing write timeout... "); - out.flush(); - { - // - // Expect TimeoutException. - // - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); - to.holdAdapter(750); - try - { - byte[] seq = new byte[100000]; - to.sendData(seq); - test(false); - } - catch(Ice.TimeoutException ex) - { - // Expected. - } - } - { - // - // Expect success. - // - timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); - to.holdAdapter(500); - try - { - byte[] seq = new byte[100000]; - to.sendData(seq); - } - catch(Ice.TimeoutException ex) - { - test(false); - } - } - out.println("ok"); - - out.print("testing AMI read timeout... "); - out.flush(); - { - // - // The resolution of AMI timeouts is limited by the connection monitor - // thread. We set Ice.MonitorConnections=1 (one second) in main(). - // - // Expect TimeoutException. - // - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); - AMISleepEx cb = new AMISleepEx(); - to.sleep_async(cb, 2000); - test(cb.check()); - } - { - // - // Expect success. - // - timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); - AMISleep cb = new AMISleep(); - to.sleep_async(cb, 500); - test(cb.check()); - } - out.println("ok"); - - out.print("testing AMI write timeout... "); - out.flush(); - { - // - // The resolution of AMI timeouts is limited by the connection monitor - // thread. We set Ice.MonitorConnections=1 (one second) in main(). - // - // Expect TimeoutException. - // - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); - to.holdAdapter(2000); - byte[] seq = new byte[100000]; - AMISendDataEx cb = new AMISendDataEx(); - to.sendData_async(cb, seq); - test(cb.check()); - } - { - // - // Expect success. - // - timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); - to.holdAdapter(500); - byte[] seq = new byte[100000]; - AMISendData cb = new AMISendData(); - to.sendData_async(cb, seq); - test(cb.check()); - } - out.println("ok"); - - out.print("testing timeout overrides... "); - out.flush(); - { - // - // Test Ice.Override.Timeout. This property overrides all - // endpoint timeouts. - // - String[] args = new String[0]; - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = communicator.getProperties()._clone(); - initData.properties.setProperty("Ice.Override.Timeout", "500"); - Ice.Communicator comm = Ice.Util.initialize(args, initData); - TimeoutPrx to = TimeoutPrxHelper.checkedCast(comm.stringToProxy(sref)); - try - { - to.sleep(750); - test(false); - } - catch(Ice.TimeoutException ex) - { - // Expected. - } - // - // Calling ice_timeout() should have no effect. - // - timeout.op(); // Ensure adapter is active. - to = TimeoutPrxHelper.checkedCast(to.ice_timeout(1000)); - try - { - to.sleep(750); - test(false); - } - catch(Ice.TimeoutException ex) - { - // Expected. - } - comm.destroy(); - } - { - // - // Test Ice.Override.ConnectTimeout. - // - String[] args = new String[0]; - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = communicator.getProperties()._clone(); - initData.properties.setProperty("Ice.Override.ConnectTimeout", "750"); - Ice.Communicator comm = Ice.Util.initialize(args, initData); - timeout.holdAdapter(1250); - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(comm.stringToProxy(sref)); - try - { - to.op(); - test(false); - } - catch(Ice.ConnectTimeoutException ex) - { - // Expected. - } - // - // Calling ice_timeout() should have no effect on the connect timeout. - // - timeout.op(); // Ensure adapter is active. - timeout.holdAdapter(1250); - to = TimeoutPrxHelper.uncheckedCast(to.ice_timeout(1500)); - try - { - to.op(); - test(false); - } - catch(Ice.ConnectTimeoutException ex) - { - // Expected. - } - // - // Verify that timeout set via ice_timeout() is still used for requests. - // - to.op(); // Force connection. - try - { - to.sleep(1750); - test(false); - } - catch(Ice.TimeoutException ex) - { - // Expected. - } - comm.destroy(); - } - out.println("ok"); - - return timeout; + String sref = "timeout:default -p 12010 -t 10000"; + Ice.ObjectPrx obj = communicator.stringToProxy(sref); + test(obj != null); + + TimeoutPrx timeout = TimeoutPrxHelper.checkedCast(obj); + test(timeout != null); + + out.print("testing connect timeout... "); + out.flush(); + { + // + // Expect ConnectTimeoutException. + // + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); + to.holdAdapter(1000); + to.ice_getConnection().close(true); // Force a reconnect. + try + { + to.op(); + test(false); + } + catch(Ice.ConnectTimeoutException ex) + { + // Expected. + } + } + { + // + // Expect success. + // + timeout.op(); // Ensure adapter is active. + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + to.holdAdapter(500); + to.ice_getConnection().close(true); // Force a reconnect. + try + { + to.op(); + } + catch(Ice.ConnectTimeoutException ex) + { + test(false); + } + } + out.println("ok"); + + out.print("testing read timeout... "); + out.flush(); + { + // + // Expect TimeoutException. + // + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); + try + { + to.sleep(750); + test(false); + } + catch(Ice.TimeoutException ex) + { + // Expected. + } + } + { + // + // Expect success. + // + timeout.op(); // Ensure adapter is active. + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + try + { + to.sleep(500); + } + catch(Ice.TimeoutException ex) + { + test(false); + } + } + out.println("ok"); + + out.print("testing write timeout... "); + out.flush(); + { + // + // Expect TimeoutException. + // + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); + to.holdAdapter(750); + try + { + byte[] seq = new byte[100000]; + to.sendData(seq); + test(false); + } + catch(Ice.TimeoutException ex) + { + // Expected. + } + } + { + // + // Expect success. + // + timeout.op(); // Ensure adapter is active. + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + to.holdAdapter(500); + try + { + byte[] seq = new byte[100000]; + to.sendData(seq); + } + catch(Ice.TimeoutException ex) + { + test(false); + } + } + out.println("ok"); + + out.print("testing AMI read timeout... "); + out.flush(); + { + // + // The resolution of AMI timeouts is limited by the connection monitor + // thread. We set Ice.MonitorConnections=1 (one second) in main(). + // + // Expect TimeoutException. + // + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); + AMISleepEx cb = new AMISleepEx(); + to.sleep_async(cb, 2000); + test(cb.check()); + } + { + // + // Expect success. + // + timeout.op(); // Ensure adapter is active. + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + AMISleep cb = new AMISleep(); + to.sleep_async(cb, 500); + test(cb.check()); + } + out.println("ok"); + + out.print("testing AMI write timeout... "); + out.flush(); + { + // + // The resolution of AMI timeouts is limited by the connection monitor + // thread. We set Ice.MonitorConnections=1 (one second) in main(). + // + // Expect TimeoutException. + // + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(500)); + to.holdAdapter(2000); + byte[] seq = new byte[100000]; + AMISendDataEx cb = new AMISendDataEx(); + to.sendData_async(cb, seq); + test(cb.check()); + } + { + // + // Expect success. + // + timeout.op(); // Ensure adapter is active. + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + to.holdAdapter(500); + byte[] seq = new byte[100000]; + AMISendData cb = new AMISendData(); + to.sendData_async(cb, seq); + test(cb.check()); + } + out.println("ok"); + + out.print("testing timeout overrides... "); + out.flush(); + { + // + // Test Ice.Override.Timeout. This property overrides all + // endpoint timeouts. + // + String[] args = new String[0]; + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties()._clone(); + initData.properties.setProperty("Ice.Override.Timeout", "500"); + Ice.Communicator comm = Ice.Util.initialize(args, initData); + TimeoutPrx to = TimeoutPrxHelper.checkedCast(comm.stringToProxy(sref)); + try + { + to.sleep(750); + test(false); + } + catch(Ice.TimeoutException ex) + { + // Expected. + } + // + // Calling ice_timeout() should have no effect. + // + timeout.op(); // Ensure adapter is active. + to = TimeoutPrxHelper.checkedCast(to.ice_timeout(1000)); + try + { + to.sleep(750); + test(false); + } + catch(Ice.TimeoutException ex) + { + // Expected. + } + comm.destroy(); + } + { + // + // Test Ice.Override.ConnectTimeout. + // + String[] args = new String[0]; + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties()._clone(); + initData.properties.setProperty("Ice.Override.ConnectTimeout", "750"); + Ice.Communicator comm = Ice.Util.initialize(args, initData); + timeout.holdAdapter(1250); + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(comm.stringToProxy(sref)); + try + { + to.op(); + test(false); + } + catch(Ice.ConnectTimeoutException ex) + { + // Expected. + } + // + // Calling ice_timeout() should have no effect on the connect timeout. + // + timeout.op(); // Ensure adapter is active. + timeout.holdAdapter(1250); + to = TimeoutPrxHelper.uncheckedCast(to.ice_timeout(1500)); + try + { + to.op(); + test(false); + } + catch(Ice.ConnectTimeoutException ex) + { + // Expected. + } + // + // Verify that timeout set via ice_timeout() is still used for requests. + // + to.op(); // Force connection. + try + { + to.sleep(1750); + test(false); + } + catch(Ice.TimeoutException ex) + { + // Expected. + } + comm.destroy(); + } + out.println("ok"); + + return timeout; } } diff --git a/java/test/Ice/timeout/Client.java b/java/test/Ice/timeout/Client.java index 18077666e71..3fcec904a74 100644 --- a/java/test/Ice/timeout/Client.java +++ b/java/test/Ice/timeout/Client.java @@ -12,61 +12,61 @@ public class Client public static int run(String[] args, Ice.Communicator communicator, java.io.PrintStream out) { - Test.TimeoutPrx timeout = AllTests.allTests(communicator, out); - timeout.shutdown(); - return 0; + Test.TimeoutPrx timeout = AllTests.allTests(communicator, out); + timeout.shutdown(); + return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; + int status = 0; + Ice.Communicator communicator = null; - try - { - Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = Ice.Util.createProperties(argsH); + try + { + Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); - // - // For this test, we want to disable retries. - // - initData.properties.setProperty("Ice.RetryIntervals", "-1"); + // + // For this test, we want to disable retries. + // + initData.properties.setProperty("Ice.RetryIntervals", "-1"); - // - // This test kills connections, so we don't want warnings. - // - initData.properties.setProperty("Ice.Warn.Connections", "0"); + // + // This test kills connections, so we don't want warnings. + // + initData.properties.setProperty("Ice.Warn.Connections", "0"); - // - // Check for AMI timeouts every second. - // - initData.properties.setProperty("Ice.MonitorConnections", "1"); + // + // Check for AMI timeouts every second. + // + initData.properties.setProperty("Ice.MonitorConnections", "1"); - communicator = Ice.Util.initialize(argsH, initData); - status = run(argsH.value, communicator, System.out); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } + communicator = Ice.Util.initialize(argsH, initData); + status = run(argsH.value, communicator, System.out); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } - System.gc(); - System.exit(status); + System.gc(); + System.exit(status); } } diff --git a/java/test/Ice/timeout/Server.java b/java/test/Ice/timeout/Server.java index 5a52f526046..50f87044eb3 100644 --- a/java/test/Ice/timeout/Server.java +++ b/java/test/Ice/timeout/Server.java @@ -12,64 +12,64 @@ public class Server public static int run(String[] args, Ice.Communicator communicator, java.io.PrintStream out) { - // - // When running as a MIDlet the properties for the server may be - // overridden by configuration. If it isn't then we assume - // defaults. - // - if(communicator.getProperties().getProperty("Ice.OA.TestAdapter.Endpoints").length() == 0) - { - communicator.getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); - } + // + // When running as a MIDlet the properties for the server may be + // overridden by configuration. If it isn't then we assume + // defaults. + // + if(communicator.getProperties().getProperty("Ice.OA.TestAdapter.Endpoints").length() == 0) + { + communicator.getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); + } - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); - adapter.add(new TimeoutI(), communicator.stringToIdentity("timeout")); - adapter.activate(); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new TimeoutI(), communicator.stringToIdentity("timeout")); + adapter.activate(); - communicator.waitForShutdown(); - return 0; + communicator.waitForShutdown(); + return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; + int status = 0; + Ice.Communicator communicator = null; - try - { - Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = Ice.Util.createProperties(argsH); - - // - // This test kills connections, so we don't want warnings. - // - initData.properties.setProperty("Ice.Warn.Connections", "0"); + try + { + Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + + // + // This test kills connections, so we don't want warnings. + // + initData.properties.setProperty("Ice.Warn.Connections", "0"); - communicator = Ice.Util.initialize(argsH, initData); - status = run(argsH.value, communicator, System.out); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } + communicator = Ice.Util.initialize(argsH, initData); + status = run(argsH.value, communicator, System.out); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } - System.gc(); - System.exit(status); + System.gc(); + System.exit(status); } } diff --git a/java/test/Ice/timeout/TimeoutI.java b/java/test/Ice/timeout/TimeoutI.java index 73d26461fde..0221ce830b1 100644 --- a/java/test/Ice/timeout/TimeoutI.java +++ b/java/test/Ice/timeout/TimeoutI.java @@ -13,28 +13,28 @@ class TimeoutI extends _TimeoutDisp { static class ActivateAdapterThread extends Thread { - ActivateAdapterThread(Ice.ObjectAdapter adapter, int timeout) - { - _adapter = adapter; - _timeout = timeout; - } + ActivateAdapterThread(Ice.ObjectAdapter adapter, int timeout) + { + _adapter = adapter; + _timeout = timeout; + } - public void - run() - { - _adapter.waitForHold(); - try - { - sleep(_timeout); - } - catch(InterruptedException ex) - { - } - _adapter.activate(); - } + public void + run() + { + _adapter.waitForHold(); + try + { + sleep(_timeout); + } + catch(InterruptedException ex) + { + } + _adapter.activate(); + } - Ice.ObjectAdapter _adapter; - int _timeout; + Ice.ObjectAdapter _adapter; + int _timeout; } public void @@ -50,26 +50,26 @@ class TimeoutI extends _TimeoutDisp public void sleep(int to, Ice.Current current) { - try - { - Thread.currentThread().sleep(to); - } - catch(InterruptedException ex) - { - } + try + { + Thread.currentThread().sleep(to); + } + catch(InterruptedException ex) + { + } } public void holdAdapter(int to, Ice.Current current) { - current.adapter.hold(); - Thread thread = new ActivateAdapterThread(current.adapter, to); - thread.start(); + current.adapter.hold(); + Thread thread = new ActivateAdapterThread(current.adapter, to); + thread.start(); } public void shutdown(Ice.Current current) { - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } } |