diff options
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/Ice/build.xml | 2 | ||||
-rw-r--r-- | java/test/Ice/proxy/AllTests.java | 497 | ||||
-rw-r--r-- | java/test/Ice/proxy/Client.java | 81 | ||||
-rw-r--r-- | java/test/Ice/proxy/Collocated.java | 60 | ||||
-rw-r--r-- | java/test/Ice/proxy/MyDerivedClassI.java | 53 | ||||
-rw-r--r-- | java/test/Ice/proxy/Server.java | 62 | ||||
-rw-r--r-- | java/test/Ice/proxy/Test.ice | 33 | ||||
-rw-r--r-- | java/test/Ice/proxy/build.xml | 51 | ||||
-rwxr-xr-x | java/test/Ice/proxy/run.py | 41 | ||||
-rw-r--r-- | java/test/Ice/proxyAMD/MyDerivedClassI.java | 56 | ||||
-rw-r--r-- | java/test/Ice/proxyAMD/Server.java | 63 | ||||
-rw-r--r-- | java/test/Ice/proxyAMD/TestAMD.ice | 33 | ||||
-rw-r--r-- | java/test/Ice/proxyAMD/build.xml | 51 |
13 files changed, 1083 insertions, 0 deletions
diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index 69301dd5b61..cdb13e1c4f0 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -22,6 +22,8 @@ <ant dir="inheritance"/> <ant dir="location"/> <ant dir="objects"/> + <ant dir="proxy"/> + <ant dir="proxyAMD"/> <ant dir="operations"/> <ant dir="operationsAMD"/> <ant dir="slicing"/> diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java new file mode 100644 index 00000000000..c7331e484e2 --- /dev/null +++ b/java/test/Ice/proxy/AllTests.java @@ -0,0 +1,497 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class AllTests +{ + static class AMI_MyClass_opSleepI extends Test.AMI_MyClass_opSleep + { + public void + ice_response() + { + test(false); + } + + synchronized public void + ice_exception(Ice.LocalException ex) + { + assert(!_called); + _called = true; + notify(); + test(ex instanceof Ice.TimeoutException); + } + + synchronized public boolean + check() + { + while(!_called) + { + try + { + wait(5000); + } + catch(InterruptedException ex) + { + continue; + } + + if(!_called) + { + return false; // Must be timeout. + } + } + return true; + } + + private boolean _called = false; + }; + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static Test.MyClassPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + System.out.print("testing stringToProxy... "); + System.out.flush(); + String ref = "test:default -p 12010 -t 10000"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + test(base != null); + + Ice.ObjectPrx b1 = communicator.stringToProxy("test"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getAdapterId().length() == 0 && b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy("test "); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy(" test "); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy(" test"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy("'test -f facet'"); + test(b1.ice_getIdentity().name.equals("test -f facet") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + try + { + b1 = communicator.stringToProxy("\"test -f facet'"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + b1 = communicator.stringToProxy("\"test -f facet\""); + test(b1.ice_getIdentity().name.equals("test -f facet") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy("\"test -f facet@test\""); + test(b1.ice_getIdentity().name.equals("test -f facet@test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + b1 = communicator.stringToProxy("\"test -f facet@test @test\""); + test(b1.ice_getIdentity().name.equals("test -f facet@test @test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().length() == 0); + try + { + b1 = communicator.stringToProxy("test test"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + b1 = communicator.stringToProxy("test\\040test"); + test(b1.ice_getIdentity().name.equals("test test") && b1.ice_getIdentity().category.length() == 0); + try + { + b1 = communicator.stringToProxy("test\\777"); + test(false); + } + catch(Ice.IdentityParseException ex) + { + } + b1 = communicator.stringToProxy("test\\40test"); + test(b1.ice_getIdentity().name.equals("test test")); + + // Test some octal and hex corner cases. + b1 = communicator.stringToProxy("test\\4test"); + test(b1.ice_getIdentity().name.equals("test\4test")); + b1 = communicator.stringToProxy("test\\04test"); + test(b1.ice_getIdentity().name.equals("test\4test")); + b1 = communicator.stringToProxy("test\\004test"); + test(b1.ice_getIdentity().name.equals("test\4test")); + b1 = communicator.stringToProxy("test\\1114test"); + test(b1.ice_getIdentity().name.equals("test\1114test")); + + b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test"); + test(b1.ice_getIdentity().name.equals("test\b\f\n\r\t\'\"\\test") && b1.ice_getIdentity().category.length() == 0); + + b1 = communicator.stringToProxy("category/test"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") && + b1.ice_getAdapterId().length() == 0); + + b1 = communicator.stringToProxy("test@adapter"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getAdapterId().equals("adapter")); + try + { + b1 = communicator.stringToProxy("id@adapter test"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + b1 = communicator.stringToProxy("category/test@adapter"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") && + b1.ice_getAdapterId().equals("adapter")); + b1 = communicator.stringToProxy("category/test@adapter:tcp"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") && + b1.ice_getAdapterId().equals("adapter:tcp")); + b1 = communicator.stringToProxy("'category 1/test'@adapter"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category 1") && + b1.ice_getAdapterId().equals("adapter")); + b1 = communicator.stringToProxy("'category/test 1'@adapter"); + test(b1.ice_getIdentity().name.equals("test 1") && b1.ice_getIdentity().category.equals("category") && + b1.ice_getAdapterId().equals("adapter")); + b1 = communicator.stringToProxy("'category/test'@'adapter 1'"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") && + b1.ice_getAdapterId().equals("adapter 1")); + b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@adapter"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category /test@foo") && + b1.ice_getAdapterId().equals("adapter")); + b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@\"adapter:tcp\""); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category /test@foo") && + b1.ice_getAdapterId().equals("adapter:tcp")); + + b1 = communicator.stringToProxy("id -f facet"); + test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet")); + b1 = communicator.stringToProxy("id -f 'facet x'"); + test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet x")); + b1 = communicator.stringToProxy("id -f \"facet x\""); + test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet x")); + try + { + b1 = communicator.stringToProxy("id -f \"facet x"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + try + { + b1 = communicator.stringToProxy("id -f \'facet x"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + b1 = communicator.stringToProxy("test -f facet:tcp"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet") && b1.ice_getAdapterId().length() == 0); + b1 = communicator.stringToProxy("test -f \"facet:tcp\""); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet:tcp") && b1.ice_getAdapterId().length() == 0); + b1 = communicator.stringToProxy("test -f facet@test"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet") && b1.ice_getAdapterId().equals("test")); + b1 = communicator.stringToProxy("test -f 'facet@test'"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet@test") && b1.ice_getAdapterId().length() == 0); + b1 = communicator.stringToProxy("test -f 'facet@test'@test"); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getFacet().equals("facet@test") && b1.ice_getAdapterId().equals("test")); + try + { + b1 = communicator.stringToProxy("test -f facet@test @test"); + test(false); + } + catch(Ice.ProxyParseException ex) + { + } + b1 = communicator.stringToProxy("test"); + test(b1.ice_isTwoway()); + b1 = communicator.stringToProxy("test -t"); + test(b1.ice_isTwoway()); + b1 = communicator.stringToProxy("test -o"); + test(b1.ice_isOneway()); + b1 = communicator.stringToProxy("test -O"); + test(b1.ice_isBatchOneway()); + b1 = communicator.stringToProxy("test -d"); + test(b1.ice_isDatagram()); + b1 = communicator.stringToProxy("test -D"); + test(b1.ice_isBatchDatagram()); + b1 = communicator.stringToProxy("test"); + test(!b1.ice_isSecure()); + b1 = communicator.stringToProxy("test -s"); + test(b1.ice_isSecure()); + + try + { + b1 = communicator.stringToProxy("test:tcp@adapterId"); + test(false); + } + catch(Ice.EndpointParseException ex) + { + } + // This is an unknown endpoint warning, not a parse exception. + // + //try + //{ + // b1 = communicator.stringToProxy("test -f the:facet:tcp"); + // test(false); + //} + //catch(Ice.EndpointParseException ex) + //{ + //} + try + { + b1 = communicator.stringToProxy("test::tcp"); + test(false); + } + catch(Ice.EndpointParseException ex) + { + } + System.out.println("ok"); + + System.out.print("testing propertyToProxy... "); + System.out.flush(); + Ice.Properties prop = communicator.getProperties(); + String propertyPrefix = "Foo.Proxy"; + prop.setProperty(propertyPrefix, "test:default -p 12010 -t 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 && + b1.ice_getAdapterId().length() == 0 && b1.ice_getFacet().length() == 0); + + // These two properties don't do anything to direct proxies so + // first we test that. + String property = propertyPrefix + ".Locator"; + test(b1.ice_getLocator() == null); + prop.setProperty(property, "locator:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocator() == null); + prop.setProperty(property, ""); + + property = propertyPrefix + ".LocatorCacheTimeout"; + test(b1.ice_getLocatorCacheTimeout() == 0); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocatorCacheTimeout() == 0); + prop.setProperty(property, ""); + + // Now retest with an indirect proxy. + prop.setProperty(propertyPrefix, "test"); + property = propertyPrefix + ".Locator"; + prop.setProperty(property, "locator:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.equals("locator")); + prop.setProperty(property, ""); + + property = propertyPrefix + ".LocatorCacheTimeout"; + test(b1.ice_getLocatorCacheTimeout() == -1); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocatorCacheTimeout() == 1); + prop.setProperty(property, ""); + + // This cannot be tested so easily because the property is cached + // on communicator initialization. + // + //prop.setProperty("Ice.Default.LocatorCacheTimeout", "60"); + //b1 = communicator.propertyToProxy(propertyPrefix); + //test(b1.ice_getLocatorCacheTimeout() == 60); + //prop.setProperty("Ice.Default.LocatorCacheTimeout", ""); + + prop.setProperty(propertyPrefix, "test:default -p 12010 -t 10000"); + + property = propertyPrefix + ".Router"; + test(b1.ice_getRouter() == null); + prop.setProperty(property, "router:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getRouter() != null && b1.ice_getRouter().ice_getIdentity().name.equals("router")); + prop.setProperty(property, ""); + + property = propertyPrefix + ".PreferSecure"; + test(!b1.ice_isPreferSecure()); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_isPreferSecure()); + prop.setProperty(property, ""); + + property = propertyPrefix + ".ConnectionCached"; + test(b1.ice_isConnectionCached()); + prop.setProperty(property, "0"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(!b1.ice_isConnectionCached()); + prop.setProperty(property, ""); + + property = propertyPrefix + ".EndpointSelection"; + test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); + prop.setProperty(property, "Random"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); + prop.setProperty(property, "Ordered"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); + prop.setProperty(property, ""); + + property = propertyPrefix + ".CollocationOptimization"; + test(b1.ice_isCollocationOptimized()); + prop.setProperty(property, "0"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(!b1.ice_isCollocationOptimized()); + prop.setProperty(property, ""); + + property = propertyPrefix + ".ThreadPerConnection"; + test(!b1.ice_isThreadPerConnection()); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_isThreadPerConnection()); + prop.setProperty(property, ""); + + System.out.println("ok"); + + System.out.print("testing ice_getCommunicator... "); + System.out.flush(); + test(base.ice_getCommunicator() == communicator); + System.out.println("ok"); + + System.out.print("testing proxy methods... "); + System.out.flush(); + test(communicator.identityToString( + base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()).equals("other")); + test(base.ice_facet("facet").ice_getFacet().equals("facet")); + test(base.ice_adapterId("id").ice_getAdapterId().equals("id")); + test(base.ice_twoway().ice_isTwoway()); + test(base.ice_oneway().ice_isOneway()); + test(base.ice_batchOneway().ice_isBatchOneway()); + test(base.ice_datagram().ice_isDatagram()); + test(base.ice_batchDatagram().ice_isBatchDatagram()); + test(base.ice_secure(true).ice_isSecure()); + test(!base.ice_secure(false).ice_isSecure()); + test(base.ice_collocationOptimized(true).ice_isCollocationOptimized()); + test(!base.ice_collocationOptimized(false).ice_isCollocationOptimized()); + System.out.println("ok"); + + System.out.print("testing proxy comparison... "); + System.out.flush(); + + test(communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo"))); + test(!communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo2"))); + + Ice.ObjectPrx compObj = communicator.stringToProxy("foo"); + + test(compObj.ice_facet("facet").equals(compObj.ice_facet("facet"))); + test(!compObj.ice_facet("facet").equals(compObj.ice_facet("facet1"))); + + test(compObj.ice_oneway().equals(compObj.ice_oneway())); + test(!compObj.ice_oneway().equals(compObj.ice_twoway())); + + test(compObj.ice_secure(true).equals(compObj.ice_secure(true))); + test(!compObj.ice_secure(false).equals(compObj.ice_secure(true))); + + test(compObj.ice_collocationOptimized(true).equals(compObj.ice_collocationOptimized(true))); + test(!compObj.ice_collocationOptimized(false).equals(compObj.ice_collocationOptimized(true))); + + test(compObj.ice_connectionCached(true).equals(compObj.ice_connectionCached(true))); + test(!compObj.ice_connectionCached(false).equals(compObj.ice_connectionCached(true))); + + test(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals( + compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random))); + test(!compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals( + compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered))); + + test(compObj.ice_connectionId("id2").equals(compObj.ice_connectionId("id2"))); + test(!compObj.ice_connectionId("id1").equals(compObj.ice_connectionId("id2"))); + + test(compObj.ice_compress(true).equals(compObj.ice_compress(true))); + test(!compObj.ice_compress(false).equals(compObj.ice_compress(true))); + + test(compObj.ice_timeout(20).equals(compObj.ice_timeout(20))); + test(!compObj.ice_timeout(10).equals(compObj.ice_timeout(20))); + + Ice.ObjectPrx compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000"); + Ice.ObjectPrx compObj2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001"); + test(!compObj1.equals(compObj2)); + + compObj1 = communicator.stringToProxy("foo@MyAdapter1"); + compObj2 = communicator.stringToProxy("foo@MyAdapter2"); + test(!compObj1.equals(compObj2)); + + test(compObj1.ice_locatorCacheTimeout(20).equals(compObj1.ice_locatorCacheTimeout(20))); + test(!compObj1.ice_locatorCacheTimeout(10).equals(compObj1.ice_locatorCacheTimeout(20))); + + compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 1000"); + compObj2 = communicator.stringToProxy("foo@MyAdapter1"); + test(!compObj1.equals(compObj2)); + + // + // TODO: Ideally we should also test comparison of fixed proxies. + // + System.out.println("ok"); + + System.out.print("testing checked cast... "); + System.out.flush(); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(base); + test(cl != null); + Test.MyDerivedClassPrx derived = Test.MyDerivedClassPrxHelper.checkedCast(cl); + test(derived != null); + test(cl.equals(base)); + test(derived.equals(base)); + test(cl.equals(derived)); + System.out.println("ok"); + + System.out.print("testing checked cast with context... "); + System.out.flush(); + + java.util.Map c = cl.getContext(); + test(c == null || c.size() == 0); + + c = new java.util.HashMap(); + c.put("one", "hello"); + c.put("two", "world"); + cl = Test.MyClassPrxHelper.checkedCast(base, c); + java.util.Map c2 = cl.getContext(); + test(c.equals(c2)); + System.out.println("ok"); + + if(!collocated) + { + System.out.print("testing timeout... "); + System.out.flush(); + Test.MyClassPrx clTimeout = Test.MyClassPrxHelper.uncheckedCast(cl.ice_timeout(500)); + try + { + clTimeout.opSleep(1000); + test(false); + } + catch(Ice.TimeoutException ex) + { + } + System.out.println("ok"); + + AMI_MyClass_opSleepI cb = new AMI_MyClass_opSleepI(); + try + { + clTimeout.opSleep_async(cb, 2000); + } + catch(Ice.LocalException ex) + { + test(false); + } + test(cb.check()); + } + return cl; + } +} diff --git a/java/test/Ice/proxy/Client.java b/java/test/Ice/proxy/Client.java new file mode 100644 index 00000000000..edbeac8bd1f --- /dev/null +++ b/java/test/Ice/proxy/Client.java @@ -0,0 +1,81 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Client +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + Test.MyClassPrx myClass = AllTests.allTests(communicator, false); + myClass.shutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + // + // In this test, we need at least two threads in the + // client side thread pool for nested AMI. + // + Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.ThreadPool.Client.Size", "2"); + initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0"); + + // + // We must set MessageSizeMax to an explicit values, + // because we run tests to check whether + // Ice.MemoryLimitException is raised as expected. + // + initData.properties.setProperty("Ice.MessageSizeMax", "100"); + + // + // We don't want connection warnings because of the timeout test. + // + initData.properties.setProperty("Ice.Warn.Connections", "0"); + + // + // Use a faster connection monitor timeout to test AMI + // timeouts. + // + initData.properties.setProperty("Ice.MonitorConnections", "1"); + + communicator = Ice.Util.initialize(argsH, initData); + status = run(argsH.value, communicator); + } + 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); + } +} diff --git a/java/test/Ice/proxy/Collocated.java b/java/test/Ice/proxy/Collocated.java new file mode 100644 index 00000000000..75c4d5ea7d3 --- /dev/null +++ b/java/test/Ice/proxy/Collocated.java @@ -0,0 +1,60 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Collocated +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyDerivedClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + AllTests.allTests(communicator, true); + + return 0; + } + + public static void + main(String[] args) + { + 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); + communicator = Ice.Util.initialize(argsH, initData); + status = run(args, communicator); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.exit(status); + } +} diff --git a/java/test/Ice/proxy/MyDerivedClassI.java b/java/test/Ice/proxy/MyDerivedClassI.java new file mode 100644 index 00000000000..57ee7406cb7 --- /dev/null +++ b/java/test/Ice/proxy/MyDerivedClassI.java @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public final class MyDerivedClassI extends Test.MyDerivedClass +{ + public + MyDerivedClassI() + { + } + + public void + shutdown(Ice.Current c) + { + c.adapter.getCommunicator().shutdown(); + } + + public void + opSleep(int duration, Ice.Current current) + { + while(true) + { + try + { + Thread.currentThread().sleep(duration); + break; + } + catch(java.lang.InterruptedException ex) + { + } + } + } + + public java.util.Map + getContext(Ice.Current current) + { + return _ctx; + } + + public boolean + ice_isA(String s, Ice.Current current) + { + _ctx = current.ctx; + return super.ice_isA(s, current); + } + + private java.util.Map _ctx; +} diff --git a/java/test/Ice/proxy/Server.java b/java/test/Ice/proxy/Server.java new file mode 100644 index 00000000000..83b6c48698a --- /dev/null +++ b/java/test/Ice/proxy/Server.java @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyDerivedClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + 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); + initData.properties.setProperty("Ice.Warn.Connections", "0"); + + communicator = Ice.Util.initialize(argsH, initData); + status = run(argsH.value, communicator); + } + 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); + } +} diff --git a/java/test/Ice/proxy/Test.ice b/java/test/Ice/proxy/Test.ice new file mode 100644 index 00000000000..b22f136bde2 --- /dev/null +++ b/java/test/Ice/proxy/Test.ice @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +#include <Ice/Current.ice> + +module Test +{ + +["ami"] class MyClass +{ + void shutdown(); + + void opSleep(int duration); + + Ice::Context getContext(); +}; + +["ami"] class MyDerivedClass extends MyClass +{ +}; + +}; + +#endif diff --git a/java/test/Ice/proxy/build.xml b/java/test/Ice/proxy/build.xml new file mode 100644 index 00000000000..9f87499b8ac --- /dev/null +++ b/java/test/Ice/proxy/build.xml @@ -0,0 +1,51 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_operations" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Test.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="${jdk.version}" classpath="${lib.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" source="${jdk.version}" + classpath="${lib.dir}" excludes="generated/**" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Ice/proxy/run.py b/java/test/Ice/proxy/run.py new file mode 100755 index 00000000000..b5ea48f9762 --- /dev/null +++ b/java/test/Ice/proxy/run.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Ice", "proxy") +testdir = os.path.join(toplevel, "test", name) +nameAMD = os.path.join("Ice", "proxyAMD") +testdirAMD = os.path.join(toplevel, "test", nameAMD) + +print "tests with regular server." +classpath = os.getenv("CLASSPATH", "") +os.environ["CLASSPATH"] = os.path.join(testdir, "classes") + TestUtil.sep + classpath +TestUtil.clientServerTest() + +print "tests with AMD server." +TestUtil.clientServerTestWithClasspath(\ + os.path.join(testdirAMD, "classes") + TestUtil.sep + classpath,\ + os.path.join(testdir, "classes") + TestUtil.sep + classpath) + +print "tests with collocated server." +TestUtil.collocatedTest() + +sys.exit(0) diff --git a/java/test/Ice/proxyAMD/MyDerivedClassI.java b/java/test/Ice/proxyAMD/MyDerivedClassI.java new file mode 100644 index 00000000000..0bdcd154685 --- /dev/null +++ b/java/test/Ice/proxyAMD/MyDerivedClassI.java @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public final class MyDerivedClassI extends Test.MyDerivedClass +{ + public + MyDerivedClassI() + { + } + + public void + shutdown_async(Test.AMD_MyClass_shutdown cb, + Ice.Current c) + { + c.adapter.getCommunicator().shutdown(); + cb.ice_response(); + } + + public void + opSleep_async(Test.AMD_MyClass_opSleep cb, int duration, Ice.Current current) + { + while(true) + { + try + { + Thread.currentThread().sleep(duration); + cb.ice_response(); + break; + } + catch(java.lang.InterruptedException ex) + { + } + } + } + + public void + getContext_async(Test.AMD_MyClass_getContext cb, Ice.Current current) + { + cb.ice_response(_ctx); + } + + public boolean + ice_isA(String s, Ice.Current current) + { + _ctx = current.ctx; + return super.ice_isA(s, current); + } + + private java.util.Map _ctx; +} diff --git a/java/test/Ice/proxyAMD/Server.java b/java/test/Ice/proxyAMD/Server.java new file mode 100644 index 00000000000..07f4f92ec98 --- /dev/null +++ b/java/test/Ice/proxyAMD/Server.java @@ -0,0 +1,63 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyDerivedClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + 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); + + initData.properties.setProperty("Ice.Warn.Connections", "0"); + + communicator = Ice.Util.initialize(argsH, initData); + status = run(args, communicator); + } + 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); + } +} diff --git a/java/test/Ice/proxyAMD/TestAMD.ice b/java/test/Ice/proxyAMD/TestAMD.ice new file mode 100644 index 00000000000..24167e40e42 --- /dev/null +++ b/java/test/Ice/proxyAMD/TestAMD.ice @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_AMD_ICE +#define TEST_AMD_ICE + +#include<Ice/Current.ice> + +module Test +{ + +["ami", "amd"] class MyClass +{ + void shutdown(); + + void opSleep(int duration); + + Ice::Context getContext(); +}; + +["ami", "amd"] class MyDerivedClass extends MyClass +{ +}; + +}; + +#endif diff --git a/java/test/Ice/proxyAMD/build.xml b/java/test/Ice/proxyAMD/build.xml new file mode 100644 index 00000000000..79194c94ea3 --- /dev/null +++ b/java/test/Ice/proxyAMD/build.xml @@ -0,0 +1,51 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_operationsAMD" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="TestAMD.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="${jdk.version}" classpath="${lib.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" source="${jdk.version}" + classpath="${lib.dir}" excludes="generated/**" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> |