diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-03-24 11:45:18 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-03-24 11:45:18 +0100 |
commit | 06a08ecf28e205277336a97a6173db7ccbed1adc (patch) | |
tree | a369a5044a63f8cdba9e7c0a461e24ae344486b4 /java/test | |
parent | Merge branch 'R3_3_branch' (diff) | |
parent | Bug 3924: slice2py missing from VC60 installer (diff) | |
download | ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.bz2 ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.xz ice-06a08ecf28e205277336a97a6173db7ccbed1adc.zip |
Merge commit 'origin/R3_3_branch'
Conflicts:
CHANGES
cpp/demo/Freeze/backup/.depend
cpp/demo/Freeze/bench/.depend
cpp/demo/Freeze/casino/.depend
cpp/demo/Freeze/customEvictor/.depend
cpp/demo/Freeze/library/.depend
cpp/demo/Freeze/phonebook/.depend
cpp/demo/Freeze/transform/.depend
cpp/demo/Glacier2/callback/.depend
cpp/demo/Glacier2/chat/.depend
cpp/demo/Ice/async/.depend
cpp/demo/Ice/bidir/.depend
cpp/demo/Ice/callback/.depend
cpp/demo/Ice/converter/.depend
cpp/demo/Ice/hello/.depend
cpp/demo/Ice/invoke/.depend
cpp/demo/Ice/latency/.depend
cpp/demo/Ice/minimal/.depend
cpp/demo/Ice/multicast/.depend
cpp/demo/Ice/nested/.depend
cpp/demo/Ice/nrvo/.depend
cpp/demo/Ice/session/.depend
cpp/demo/Ice/throughput/.depend
cpp/demo/Ice/value/.depend
cpp/demo/IceBox/hello/.depend
cpp/demo/IceGrid/allocate/.depend
cpp/demo/IceGrid/icebox/.depend
cpp/demo/IceGrid/replication/.depend
cpp/demo/IceGrid/sessionActivation/.depend
cpp/demo/IceGrid/simple/.depend
cpp/demo/IceStorm/clock/.depend
cpp/demo/IceStorm/counter/.depend
cpp/demo/IceStorm/replicated/.depend
cpp/demo/IceStorm/replicated2/.depend
cpp/demo/book/freeze_filesystem/.depend
cpp/demo/book/lifecycle/.depend
cpp/demo/book/printer/.depend
cpp/demo/book/simple_filesystem/.depend
cpp/src/Freeze/.depend
cpp/src/FreezeScript/.depend
cpp/src/Ice/.depend
cpp/src/Ice/UdpTransceiver.cpp
cpp/src/Ice/UdpTransceiver.h
cpp/src/IceBox/.depend
cpp/src/IceGrid/.depend
cpp/src/IceGridLib/.depend
cpp/src/IcePatch2/.depend
cpp/src/IceStorm/.depend
cpp/src/slice2freeze/.depend
cpp/test/Freeze/complex/.depend
cpp/test/Freeze/dbmap/.depend
cpp/test/Freeze/evictor/.depend
cpp/test/Freeze/oldevictor/.depend
cpp/test/FreezeScript/dbmap/.depend
cpp/test/FreezeScript/evictor/.depend
cpp/test/Glacier2/attack/.depend
cpp/test/Glacier2/dynamicFiltering/.depend
cpp/test/Glacier2/router/.depend
cpp/test/Glacier2/sessionControl/.depend
cpp/test/Glacier2/ssl/.depend
cpp/test/Glacier2/staticFiltering/.depend
cpp/test/Ice/adapterDeactivation/.depend
cpp/test/Ice/background/.depend
cpp/test/Ice/binding/.depend
cpp/test/Ice/checksum/.depend
cpp/test/Ice/checksum/server/.depend
cpp/test/Ice/custom/.depend
cpp/test/Ice/exceptions/.depend
cpp/test/Ice/facets/.depend
cpp/test/Ice/faultTolerance/.depend
cpp/test/Ice/gc/.depend
cpp/test/Ice/hold/.depend
cpp/test/Ice/inheritance/.depend
cpp/test/Ice/interceptor/.depend
cpp/test/Ice/location/.depend
cpp/test/Ice/objects/.depend
cpp/test/Ice/operations/.depend
cpp/test/Ice/proxy/.depend
cpp/test/Ice/retry/.depend
cpp/test/Ice/servantLocator/.depend
cpp/test/Ice/slicing/exceptions/.depend
cpp/test/Ice/slicing/objects/.depend
cpp/test/Ice/stream/.depend
cpp/test/Ice/stringConverter/.depend
cpp/test/Ice/timeout/.depend
cpp/test/Ice/udp/.depend
cpp/test/IceBox/configuration/.depend
cpp/test/IceGrid/activation/.depend
cpp/test/IceGrid/allocation/.depend
cpp/test/IceGrid/deployer/.depend
cpp/test/IceGrid/distribution/.depend
cpp/test/IceGrid/replicaGroup/.depend
cpp/test/IceGrid/replication/.depend
cpp/test/IceGrid/session/.depend
cpp/test/IceGrid/simple/.depend
cpp/test/IceGrid/update/.depend
cpp/test/IceSSL/configuration/.depend
cpp/test/IceStorm/federation/.depend
cpp/test/IceStorm/federation2/.depend
cpp/test/IceStorm/rep1/.depend
cpp/test/IceStorm/repgrid/.depend
cpp/test/IceStorm/repstress/.depend
cpp/test/IceStorm/single/.depend
cpp/test/IceStorm/stress/.depend
cpp/test/Slice/keyword/.depend
cs/src/Ice/Instance.cs
cs/src/IceSSL/ConnectorI.cs
java/demo/book/simple_filesystem/Filesystem/DirectoryI.java
java/demo/book/simple_filesystem/Filesystem/FileI.java
java/src/IceInternal/TcpConnector.java
java/src/IceSSL/ConnectorI.java
py/modules/IcePy/.depend
rb/src/IceRuby/.depend
Diffstat (limited to 'java/test')
75 files changed, 2967 insertions, 64 deletions
diff --git a/java/test/Freeze/complex/Parser.java b/java/test/Freeze/complex/Parser.java index c654fa371e6..8f4f7e4ec4d 100644 --- a/java/test/Freeze/complex/Parser.java +++ b/java/test/Freeze/complex/Parser.java @@ -128,7 +128,7 @@ public class Parser return; } - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(128); // // Get the next character diff --git a/java/test/Freeze/complex/run.py b/java/test/Freeze/complex/run.py index f293046a8fb..6ebf89e573f 100755 --- a/java/test/Freeze/complex/run.py +++ b/java/test/Freeze/complex/run.py @@ -29,13 +29,15 @@ dbdir = os.path.join(os.getcwd(), "db") TestUtil.cleanDbDir(dbdir) print "starting populate...", -populateProc = TestUtil.startClient("Client", " --dbdir %s populate" % os.getcwd()) +populateProc = TestUtil.startClient("Client", " --dbdir %s populate" % os.getcwd(), startReader = False) print "ok" +populateProc.startReader() populateProc.waitTestSuccess() print "starting verification client...", -clientProc = TestUtil.startClient("Client", " --dbdir %s validate" % os.getcwd()) +clientProc = TestUtil.startClient("Client", " --dbdir %s validate" % os.getcwd(), startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() diff --git a/java/test/Freeze/dbmap/build.xml b/java/test/Freeze/dbmap/build.xml index 70870f6f315..30167c9d4fe 100644 --- a/java/test/Freeze/dbmap/build.xml +++ b/java/test/Freeze/dbmap/build.xml @@ -56,7 +56,11 @@ <target name="compile" depends="generate"> <mkdir dir="${class.dir}"/> <javac srcdir="${generated.dir}" destdir="${class.dir}" - classpathref="ice.classpath" debug="${debug}"> + debug="${debug}"> + <classpath> + <path refid="ice.classpath"/> + <path refid="db.classpath"/> + </classpath> <compilerarg value="${javac.lint}"/> </javac> <javac srcdir="." destdir="${class.dir}" diff --git a/java/test/Freeze/dbmap/run.py b/java/test/Freeze/dbmap/run.py index 9b242c82d04..045d0e62c99 100755 --- a/java/test/Freeze/dbmap/run.py +++ b/java/test/Freeze/dbmap/run.py @@ -26,6 +26,7 @@ dbdir = os.path.join(os.getcwd(), "db") TestUtil.cleanDbDir(dbdir) print "starting client...", -clientProc = TestUtil.startClient("Client", os.getcwd()) +clientProc = TestUtil.startClient("Client", os.getcwd(), startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() diff --git a/java/test/Freeze/evictor/build.xml b/java/test/Freeze/evictor/build.xml index 10713da3f3b..6a3c9920197 100644 --- a/java/test/Freeze/evictor/build.xml +++ b/java/test/Freeze/evictor/build.xml @@ -36,7 +36,11 @@ <compilerarg value="${javac.lint}"/> </javac> <javac srcdir="." destdir="${class.dir}" - classpathref="ice.classpath" excludes="generated/**" debug="${debug}"> + excludes="generated/**" debug="${debug}"> + <classpath> + <path refid="ice.classpath"/> + <path refid="db.classpath"/> + </classpath> <compilerarg value="${javac.lint}"/> </javac> </target> diff --git a/java/test/Freeze/oldevictor/build.xml b/java/test/Freeze/oldevictor/build.xml index 38aae918d72..8245ff30d17 100644 --- a/java/test/Freeze/oldevictor/build.xml +++ b/java/test/Freeze/oldevictor/build.xml @@ -33,7 +33,11 @@ <compilerarg value="${javac.lint}"/> </javac> <javac srcdir="." destdir="${class.dir}" - classpathref="ice.classpath" excludes="generated/**" debug="${debug}"> + excludes="generated/**" debug="${debug}"> + <classpath> + <path refid="ice.classpath"/> + <path refid="db.classpath"/> + </classpath> <compilerarg value="${javac.lint}"/> </javac> </target> diff --git a/java/test/Ice/background/AllTests.java b/java/test/Ice/background/AllTests.java index 737f792c8d0..2c58e1a2ab6 100644 --- a/java/test/Ice/background/AllTests.java +++ b/java/test/Ice/background/AllTests.java @@ -229,13 +229,13 @@ public class AllTests public static Test.BackgroundPrx allTests(Ice.Communicator communicator, java.io.PrintStream out) { - String sref = "background:default -p 12010 -t 10000"; + String sref = "background:default -p 12010 -t 20000"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); BackgroundPrx background = BackgroundPrxHelper.uncheckedCast(obj); - sref = "backgroundController:tcp -p 12011 -t 10000"; + sref = "backgroundController:tcp -p 12011 -t 20000"; obj = communicator.stringToProxy(sref); test(obj != null); diff --git a/java/test/Ice/background/Connector.java b/java/test/Ice/background/Connector.java index 242d45ea7e4..b737a1400ef 100644 --- a/java/test/Ice/background/Connector.java +++ b/java/test/Ice/background/Connector.java @@ -7,7 +7,7 @@ // // ********************************************************************** -final class Connector implements IceInternal.Connector, java.lang.Comparable +final class Connector implements IceInternal.Connector { public IceInternal.Transceiver connect() @@ -43,18 +43,9 @@ final class Connector implements IceInternal.Connector, java.lang.Comparable _connector = connector; } - // - // Compare connectors for sorting purposes - // public boolean equals(java.lang.Object obj) { - return compareTo(obj) == 0; - } - - public int - compareTo(java.lang.Object obj) // From java.lang.Comparable - { Connector p = null; try @@ -63,32 +54,17 @@ final class Connector implements IceInternal.Connector, java.lang.Comparable } catch(ClassCastException ex) { - try - { - IceInternal.Connector c = (IceInternal.Connector)obj; - return type() < c.type() ? -1 : 1; - } - catch(ClassCastException ee) - { - assert(false); - } + return false; } if(this == p) { - return 0; + return true; } - return _connector.compareTo(p._connector); + return _connector.equals(p._connector); } - protected synchronized void - finalize() - throws Throwable - { - super.finalize(); - } - final private IceInternal.Connector _connector; final private Configuration _configuration; } diff --git a/java/test/Ice/binding/AllTests.java b/java/test/Ice/binding/AllTests.java index 753837e762a..2c9db86d7c8 100644 --- a/java/test/Ice/binding/AllTests.java +++ b/java/test/Ice/binding/AllTests.java @@ -20,6 +20,24 @@ public class AllTests } } + static class NoOpGetAdapterNameCB extends AMI_TestIntf_getAdapterName + { + public + void ice_response(String name) + { + } + + public void + ice_exception(Ice.LocalException ex) + { + } + + public void + ice_exception(Ice.UserException ex) + { + } + }; + static class GetAdapterNameCB extends AMI_TestIntf_getAdapterName { synchronized public void @@ -229,6 +247,106 @@ public class AllTests } System.out.println("ok"); + System.out.print("testing binding with multiple random endpoints... "); + System.out.flush(); + { + java.util.Random rand = new java.util.Random(); + + RemoteObjectAdapterPrx[] adapters = new 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; + if(System.getProperty("os.name").startsWith("Windows")) + { + count = 20; + } + else + { + count = 60; + } + + int adapterCount = adapters.length; + while(--count > 0) + { + TestIntfPrx[] proxies; + if(System.getProperty("os.name").startsWith("Windows")) + { + if(count == 10) + { + com.deactivateObjectAdapter(adapters[4]); + --adapterCount; + } + proxies = new TestIntfPrx[10]; + } + else + { + if(count < 60 && count % 10 == 0) + { + com.deactivateObjectAdapter(adapters[count / 10 - 1]); + --adapterCount; + } + proxies = new TestIntfPrx[40]; + } + + int i; + for(i = 0; i < proxies.length; ++i) + { + RemoteObjectAdapterPrx[] adpts = new RemoteObjectAdapterPrx[rand.nextInt(adapters.length)]; + if(adpts.length == 0) + { + adpts = new RemoteObjectAdapterPrx[1]; + } + for(int j = 0; j < adpts.length; ++j) + { + adpts[j] = adapters[rand.nextInt(adapters.length)]; + } + proxies[i] = createTestIntfPrx(java.util.Arrays.asList((adpts))); + } + + for(i = 0; i < proxies.length; i++) + { + proxies[i].getAdapterName_async(new NoOpGetAdapterNameCB()); + } + for(i = 0; i < proxies.length; i++) + { + try + { + proxies[i].ice_ping(); + } + catch(Ice.LocalException ex) + { + } + } + + java.util.Set<Ice.Connection> connections = new java.util.HashSet<Ice.Connection>(); + for(i = 0; i < proxies.length; i++) + { + if(proxies[i].ice_getCachedConnection() != null) + { + connections.add(proxies[i].ice_getCachedConnection()); + } + } + test(connections.size() <= adapterCount); + + for(RemoteObjectAdapterPrx a : adapters) + { + try + { + a.getTestIntf().ice_getConnection().close(false); + } + catch(Ice.LocalException ex) + { + // Expected if adapter is down. + } + } + } + } + System.out.println("ok"); + System.out.print("testing binding with multiple endpoints and AMI... "); System.out.flush(); { diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index af5f5fb57bb..6d3c477d5af 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -27,6 +27,8 @@ <ant dir="proxyAMD"/> <ant dir="operations"/> <ant dir="operationsAMD"/> + <ant dir="seqMapping"/> + <ant dir="seqMappingAMD"/> <ant dir="slicing"/> <ant dir="custom"/> <ant dir="translator"/> @@ -39,6 +41,7 @@ <ant dir="servantLocatorAMD"/> <ant dir="interceptor"/> <ant dir="udp"/> + <ant dir="serialize"/> </target> <target name="clean"> @@ -57,6 +60,8 @@ <ant dir="proxyAMD" target="clean"/> <ant dir="operations" target="clean"/> <ant dir="operationsAMD" target="clean"/> + <ant dir="seqMapping" target="clean"/> + <ant dir="seqMappingAMD" target="clean"/> <ant dir="slicing" target="clean"/> <ant dir="custom" target="clean"/> <ant dir="translator" target="clean"/> @@ -69,6 +74,7 @@ <ant dir="servantLocatorAMD" target="clean"/> <ant dir="interceptor" target="clean"/> <ant dir="udp" target="clean"/> + <ant dir="serialize" target="clean"/> </target> </project> diff --git a/java/test/Ice/faultTolerance/run.py b/java/test/Ice/faultTolerance/run.py index 19eae076894..f6938cbae86 100755 --- a/java/test/Ice/faultTolerance/run.py +++ b/java/test/Ice/faultTolerance/run.py @@ -35,8 +35,9 @@ ports = "" for i in range(0, num): ports = "%s %d" % (ports, base + i) print "starting client...", -clientProc = TestUtil.startClient("Client", ports) +clientProc = TestUtil.startClient("Client", ports, startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() for p in serverProc: diff --git a/java/test/Ice/interceptor/run.py b/java/test/Ice/interceptor/run.py index bd197e05b8f..e47acfdef1e 100755 --- a/java/test/Ice/interceptor/run.py +++ b/java/test/Ice/interceptor/run.py @@ -23,7 +23,8 @@ from scripts import * TestUtil.addClasspath(os.path.join(os.getcwd(), "classes")) print "starting client...", -clientProc = TestUtil.startClient("Client", "--Ice.Warn.Dispatch=0") +clientProc = TestUtil.startClient("Client", "--Ice.Warn.Dispatch=0", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() diff --git a/java/test/Ice/location/AllTests.java b/java/test/Ice/location/AllTests.java index 13257baffec..74082fe0a85 100644 --- a/java/test/Ice/location/AllTests.java +++ b/java/test/Ice/location/AllTests.java @@ -111,6 +111,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } System.out.println("ok"); @@ -126,6 +127,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } System.out.println("ok"); @@ -141,6 +143,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } try @@ -150,6 +153,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } obj.shutdown(); @@ -161,6 +165,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } try @@ -170,6 +175,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } obj.shutdown(); @@ -181,6 +187,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } obj.shutdown(); @@ -192,6 +199,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } obj.shutdown(); @@ -203,6 +211,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } @@ -310,6 +319,7 @@ public class AllTests public void ice_exception(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } @@ -320,7 +330,12 @@ public class AllTests }; hello.sayHello_async(new AMICallback()); } - test(locator.getRequestCount() > count && locator.getRequestCount() < count + 500); + hello.ice_ping(); + test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); + if(locator.getRequestCount() > count + 800) + { + System.out.print("queuing = " + (locator.getRequestCount() - count)); + } count = locator.getRequestCount(); hello = (HelloPrx)hello.ice_adapterId("unknown"); for(int i = 0; i < 1000; i++) @@ -341,7 +356,20 @@ public class AllTests }; hello.sayHello_async(new AMICallback()); } - test(locator.getRequestCount() > count && locator.getRequestCount() < count + 500); + try + { + hello.ice_ping(); + test(false); + } + catch(Ice.NotRegisteredException ex) + { + } + // We need to take into account the retries. + test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); + if(locator.getRequestCount() > count + 800) + { + System.out.print("queuing = " + (locator.getRequestCount() - count)); + } System.out.println("ok"); System.out.print("testing adapter locator cache... "); @@ -383,6 +411,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } @@ -418,6 +447,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } System.out.println("ok"); @@ -471,6 +501,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } @@ -490,6 +521,7 @@ public class AllTests } catch(Ice.LocalException ex) { + ex.printStackTrace(); test(false); } @@ -574,8 +606,8 @@ public class AllTests { } registry.addObject(communicator.stringToProxy("test3:tcp")); - ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. - ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. + ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. + ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. test(count == locator.getRequestCount()); try { diff --git a/java/test/Ice/location/ServerLocator.java b/java/test/Ice/location/ServerLocator.java index 644af6227dc..edea41c35f6 100644 --- a/java/test/Ice/location/ServerLocator.java +++ b/java/test/Ice/location/ServerLocator.java @@ -22,6 +22,15 @@ public class ServerLocator extends Test._TestLocatorDisp throws Ice.AdapterNotFoundException { ++_requestCount; + // We add a small delay to make sure locator request queuing gets tested when + // running the test on a fast machine + try + { + Thread.sleep(1); + } + catch(java.lang.InterruptedException ex) + { + } response.ice_response(_registry.getAdapter(adapter)); } @@ -30,6 +39,15 @@ public class ServerLocator extends Test._TestLocatorDisp throws Ice.ObjectNotFoundException { ++_requestCount; + // We add a small delay to make sure locator request queuing gets tested when + // running the test on a fast machine + try + { + Thread.sleep(1); + } + catch(java.lang.InterruptedException ex) + { + } response.ice_response(_registry.getObject(id)); } diff --git a/java/test/Ice/location/ServerManagerI.java b/java/test/Ice/location/ServerManagerI.java index 197b8abbe42..f1936dfe3be 100644 --- a/java/test/Ice/location/ServerManagerI.java +++ b/java/test/Ice/location/ServerManagerI.java @@ -1,3 +1,4 @@ + // ********************************************************************** // // Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. @@ -17,11 +18,9 @@ public class ServerManagerI extends _ServerManagerDisp _registry = registry; _communicators = new java.util.ArrayList<Ice.Communicator>(); _initData = initData; - - _initData.properties.setProperty("TestAdapter.Endpoints", "default"); + _initData.properties.setProperty("TestAdapter.AdapterId", "TestAdapter"); _initData.properties.setProperty("TestAdapter.ReplicaGroupId", "ReplicatedAdapter"); - _initData.properties.setProperty("TestAdapter2.Endpoints", "default"); _initData.properties.setProperty("TestAdapter2.AdapterId", "TestAdapter2"); } @@ -48,8 +47,14 @@ public class ServerManagerI extends _ServerManagerDisp Ice.Communicator serverCommunicator = Ice.Util.initialize(_initData); _communicators.add(serverCommunicator); - Ice.ObjectAdapter adapter = serverCommunicator.createObjectAdapter("TestAdapter"); + // + // Use fixed port to ensure that OA re-activation doesn't re-use previous port from + // another OA (e.g.: TestAdapter2 is re-activated using port of TestAdapter). + // + serverCommunicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p " + _nextPort++); + serverCommunicator.getProperties().setProperty("TestAdapter2.Endpoints", "default -p " + _nextPort++); + Ice.ObjectAdapter adapter = serverCommunicator.createObjectAdapter("TestAdapter"); Ice.ObjectAdapter adapter2 = serverCommunicator.createObjectAdapter("TestAdapter2"); Ice.ObjectPrx locator = serverCommunicator.stringToProxy("locator:default -p 12010 -t 30000"); @@ -80,4 +85,5 @@ public class ServerManagerI extends _ServerManagerDisp private ServerLocatorRegistry _registry; private java.util.List<Ice.Communicator> _communicators; private Ice.InitializationData _initData; + private int _nextPort = 12011; } diff --git a/java/test/Ice/operations/MyDerivedClassI.java b/java/test/Ice/operations/MyDerivedClassI.java index 13ea6a2c086..025b466dd58 100644 --- a/java/test/Ice/operations/MyDerivedClassI.java +++ b/java/test/Ice/operations/MyDerivedClassI.java @@ -284,6 +284,18 @@ public final class MyDerivedClassI extends Test.MyDerivedClass return r; } + public java.util.Map<Test.MyStruct, Test.MyEnum> + opMyStructMyEnumD(java.util.Map p1, java.util.Map p2, + Test.MyStructMyEnumDHolder p3, + Ice.Current current) + { + p3.value = p1; + java.util.Map<Test.MyStruct, Test.MyEnum> r = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + r.putAll(p1); + r.putAll(p2); + return r; + } + public int[] opIntS(int[] s, Ice.Current current) { diff --git a/java/test/Ice/operations/Test.ice b/java/test/Ice/operations/Test.ice index 447b3c8b17b..ea771c12ff3 100644 --- a/java/test/Ice/operations/Test.ice +++ b/java/test/Ice/operations/Test.ice @@ -60,11 +60,18 @@ sequence<MyClassS> MyClassSS; sequence<StringSS> StringSSS; +struct MyStruct +{ + int i; + int j; +}; + dictionary<byte, bool> ByteBoolD; dictionary<short, int> ShortIntD; dictionary<long, float> LongFloatD; dictionary<string, string> StringStringD; dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; ["ami"] class MyClass { @@ -143,6 +150,9 @@ dictionary<string, MyEnum> StringMyEnumD; StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, out StringMyEnumD p3); + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + IntS opIntS(IntS s); void opByteSOneway(ByteS s); diff --git a/java/test/Ice/operations/Twoways.java b/java/test/Ice/operations/Twoways.java index fe316198d93..dff64d1eabd 100644 --- a/java/test/Ice/operations/Twoways.java +++ b/java/test/Ice/operations/Twoways.java @@ -599,6 +599,31 @@ class Twoways } { + Test.MyStruct s11 = new Test.MyStruct(1, 1); + Test.MyStruct s12 = new Test.MyStruct(1, 2); + java.util.Map<Test.MyStruct, Test.MyEnum> di1 = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + di1.put(s11, Test.MyEnum.enum1); + di1.put(s12, Test.MyEnum.enum2); + + Test.MyStruct s22 = new Test.MyStruct(2, 2); + Test.MyStruct s23 = new Test.MyStruct(2, 3); + java.util.Map<Test.MyStruct, Test.MyEnum> di2 = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + di2.put(s11, Test.MyEnum.enum1); + di2.put(s22, Test.MyEnum.enum3); + di2.put(s23, Test.MyEnum.enum2); + + Test.MyStructMyEnumDHolder _do = new Test.MyStructMyEnumDHolder(); + java.util.Map<Test.MyStruct, Test.MyEnum> ro = p.opMyStructMyEnumD(di1, di2, _do); + + test(_do.value.equals(di1)); + test(ro.size() == 4); + test(ro.get(s11) == Test.MyEnum.enum1); + test(ro.get(s12) == Test.MyEnum.enum2); + test(ro.get(s22) == Test.MyEnum.enum3); + test(ro.get(s23) == Test.MyEnum.enum2); + } + + { int[] lengths = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; for(int l = 0; l < lengths.length; ++l) diff --git a/java/test/Ice/operations/TwowaysAMI.java b/java/test/Ice/operations/TwowaysAMI.java index 2aa9ed11b7d..600f7a31242 100644 --- a/java/test/Ice/operations/TwowaysAMI.java +++ b/java/test/Ice/operations/TwowaysAMI.java @@ -949,6 +949,45 @@ class TwowaysAMI private Callback callback = new Callback(); } + private static class AMI_MyClass_opMyStructMyEnumDI extends Test.AMI_MyClass_opMyStructMyEnumD + { + public void + ice_response(java.util.Map _ro, java.util.Map __do) + { + // TODO: Fix the parameters and remove the casts below when the Java2 mapping is removed. + Test.MyStruct s11 = new Test.MyStruct(1, 1); + Test.MyStruct s12 = new Test.MyStruct(1, 2); + java.util.Map<Test.MyStruct, Test.MyEnum> ro = (java.util.Map<Test.MyStruct, Test.MyEnum>)_ro; + java.util.Map<Test.MyStruct, Test.MyEnum> _do = (java.util.Map<Test.MyStruct, Test.MyEnum>)__do; + java.util.Map<Test.MyStruct, Test.MyEnum> di1 = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + di1.put(s11, Test.MyEnum.enum1); + di1.put(s12, Test.MyEnum.enum2); + test(_do.equals(di1)); + Test.MyStruct s22 = new Test.MyStruct(2, 2); + Test.MyStruct s23 = new Test.MyStruct(2, 3); + test(ro.size() == 4); + test(ro.get(s11) == Test.MyEnum.enum1); + test(ro.get(s12) == Test.MyEnum.enum2); + test(ro.get(s22) == Test.MyEnum.enum3); + test(ro.get(s23) == Test.MyEnum.enum2); + 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 AMI_MyClass_opIntSI extends Test.AMI_MyClass_opIntS { AMI_MyClass_opIntSI(int l) @@ -1441,6 +1480,24 @@ class TwowaysAMI } { + Test.MyStruct s11 = new Test.MyStruct(1, 1); + Test.MyStruct s12 = new Test.MyStruct(1, 2); + java.util.Map<Test.MyStruct, Test.MyEnum> di1 = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + di1.put(s11, Test.MyEnum.enum1); + di1.put(s12, Test.MyEnum.enum2); + Test.MyStruct s22 = new Test.MyStruct(2, 2); + Test.MyStruct s23 = new Test.MyStruct(2, 3); + java.util.Map<Test.MyStruct, Test.MyEnum> di2 = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + di2.put(s11, Test.MyEnum.enum1); + di2.put(s22, Test.MyEnum.enum3); + di2.put(s23, Test.MyEnum.enum2); + + AMI_MyClass_opMyStructMyEnumDI cb = new AMI_MyClass_opMyStructMyEnumDI(); + p.opMyStructMyEnumD_async(cb, di1, di2); + test(cb.check()); + } + + { int[] lengths = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; for(int l = 0; l < lengths.length; ++l) diff --git a/java/test/Ice/operationsAMD/MyDerivedClassI.java b/java/test/Ice/operationsAMD/MyDerivedClassI.java index 8a56485e129..d787e41965f 100644 --- a/java/test/Ice/operationsAMD/MyDerivedClassI.java +++ b/java/test/Ice/operationsAMD/MyDerivedClassI.java @@ -322,6 +322,18 @@ public final class MyDerivedClassI extends Test.MyDerivedClass } public void + opMyStructMyEnumD_async(Test.AMD_MyClass_opMyStructMyEnumD cb, + java.util.Map p1, java.util.Map p2, + Ice.Current current) + { + java.util.Map<Test.MyStruct, Test.MyEnum> p3 = p1; + java.util.Map<Test.MyStruct, Test.MyEnum> r = new java.util.HashMap<Test.MyStruct, Test.MyEnum>(); + r.putAll(p1); + r.putAll(p2); + cb.ice_response(r, p3); + } + + public void opIntS_async(Test.AMD_MyClass_opIntS cb, int[] s, Ice.Current current) { int[] r = new int[s.length]; diff --git a/java/test/Ice/operationsAMD/TestAMD.ice b/java/test/Ice/operationsAMD/TestAMD.ice index 6ad25e0be3c..ae666e15480 100644 --- a/java/test/Ice/operationsAMD/TestAMD.ice +++ b/java/test/Ice/operationsAMD/TestAMD.ice @@ -60,11 +60,18 @@ sequence<MyClassS> MyClassSS; sequence<StringSS> StringSSS; +struct MyStruct +{ + int i; + int j; +}; + dictionary<byte, bool> ByteBoolD; dictionary<short, int> ShortIntD; dictionary<long, float> LongFloatD; dictionary<string, string> StringStringD; dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; ["ami", "amd"] class MyClass { @@ -143,6 +150,9 @@ dictionary<string, MyEnum> StringMyEnumD; StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, out StringMyEnumD p3); + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + IntS opIntS(IntS s); void opByteSOneway(ByteS s); diff --git a/java/test/Ice/protobuf/AllTests.java b/java/test/Ice/protobuf/AllTests.java new file mode 100644 index 00000000000..a5ce93d0fca --- /dev/null +++ b/java/test/Ice/protobuf/AllTests.java @@ -0,0 +1,162 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 +{ + private static void + test(boolean b) + { + 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; + } + + private static class AMI_MyClass_opMessage extends Test.AMI_MyClass_opMessage + { + public void + ice_response(test.TestPB.Message r, test.TestPB.Message o) + { + test(o.getI() == 99); + test(r.getI() == 99); + 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 AMI_MyClass_opMessageAMD extends Test.AMI_MyClass_opMessageAMD + { + public void + ice_response(test.TestPB.Message r, test.TestPB.Message o) + { + test(o.getI() == 99); + test(r.getI() == 99); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(false); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + public static Test.MyClassPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + String ref = "test:default -p 12010 -t 10000"; + Ice.ObjectPrx baseProxy = communicator.stringToProxy(ref); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy); + + System.out.print("testing twoway operations... "); + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + Ice.Holder<test.TestPB.Message> o = new Ice.Holder<test.TestPB.Message>(); + test.TestPB.Message r; + + r = cl.opMessage(i, o); + + test(o.value.getI() == 99); + test(r.getI() == 99); + } + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + Ice.Holder<test.TestPB.Message> o = new Ice.Holder<test.TestPB.Message>(); + test.TestPB.Message r; + + r = cl.opMessageAMD(i, o); + + test(o.value.getI() == 99); + test(r.getI() == 99); + } + System.out.println("ok"); + + System.out.print("testing twoway AMI operations... "); + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + + AMI_MyClass_opMessage cb = new AMI_MyClass_opMessage(); + cl.opMessage_async(cb, i); + test(cb.check()); + } + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + + AMI_MyClass_opMessageAMD cb = new AMI_MyClass_opMessageAMD(); + cl.opMessageAMD_async(cb, i); + test(cb.check()); + } + System.out.println("ok"); + + return cl; + } +} diff --git a/java/test/Ice/protobuf/Client.java b/java/test/Ice/protobuf/Client.java new file mode 100644 index 00000000000..9381242aacf --- /dev/null +++ b/java/test/Ice/protobuf/Client.java @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/protobuf/Collocated.java b/java/test/Ice/protobuf/Collocated.java new file mode 100644 index 00000000000..64843c27243 --- /dev/null +++ b/java/test/Ice/protobuf/Collocated.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI(), 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 + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/protobuf/MyClassI.java b/java/test/Ice/protobuf/MyClassI.java new file mode 100644 index 00000000000..29e637d532b --- /dev/null +++ b/java/test/Ice/protobuf/MyClassI.java @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI extends Test.MyClass +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public test.TestPB.Message opMessage(test.TestPB.Message i, Ice.Holder<test.TestPB.Message> o, Ice.Current current) + { + o.value = i; + return i; + } + + public void opMessageAMD_async(Test.AMD_MyClass_opMessageAMD amdCB, test.TestPB.Message i, Ice.Current current) + { + amdCB.ice_response(i, i); + } +} diff --git a/java/test/Ice/protobuf/Server.java b/java/test/Ice/protobuf/Server.java new file mode 100644 index 00000000000..e77a401ddca --- /dev/null +++ b/java/test/Ice/protobuf/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/protobuf/Test.ice b/java/test/Ice/protobuf/Test.ice new file mode 100644 index 00000000000..f30fca97b31 --- /dev/null +++ b/java/test/Ice/protobuf/Test.ice @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 + +module Test +{ + +["java:protobuf:test.TestPB.Message"] sequence<byte> Message; + +["ami"] class MyClass +{ + void shutdown(); + + Message opMessage(Message i, out Message o); + + ["amd"] Message opMessageAMD(Message i, out Message o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<Message> SLS; +sequence<SLS> SLSS; +dictionary<int, Message> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + Message SLmem; + SLS SLSmem; +}; + +exception Bar +{ + Message SLmem; + SLS SLSmem; +}; + +class Baz +{ + Message SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/protobuf/Test.proto b/java/test/Ice/protobuf/Test.proto new file mode 100644 index 00000000000..fea4c801ddd --- /dev/null +++ b/java/test/Ice/protobuf/Test.proto @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package test; + +option java_outer_classname = "TestPB"; + +message Message { + required int32 i = 1; +} diff --git a/java/test/Ice/protobuf/ant/ProtocTask.java b/java/test/Ice/protobuf/ant/ProtocTask.java new file mode 100644 index 00000000000..d1ea695bbb4 --- /dev/null +++ b/java/test/Ice/protobuf/ant/ProtocTask.java @@ -0,0 +1,369 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +//package Ice.Ant; + +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.taskdefs.ExecTask; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.PumpStreamHandler; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Commandline.Argument; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.BufferedWriter; + +/** + * An ant task for protoc. + * + * Attributes specific to protoc: + * + * translator - The pathname of the translator (default: "protoc"). + * protocpath - The value for the --proto_path translator option. + * outputdir - The value for the --java_out translator option. + * dependencyfile - The file in which dependencies are stored (default: ".pbdepend"). + * + * Example: + * + * <project ...> + * <taskdef name="protoc" classname="ProtocTask" /> + * <property name="protoc.dir" value="../include/protoc"/> + * <target name="generate"> + * <mkdir dir="tags" /> + * <protoc tagdir="tags" outputdir="out"> + * <fileset dir="${protoc.dir}"> + * <include name="*.ice" /> + * </fileset> + * </protoc> + * </target> + * </project> + * + * The <taskdef> element installs the protoctask task. + */ +public class ProtocTask extends org.apache.tools.ant.Task +{ + public + ProtocTask() + { + _translator = null; + _outputDir = null; + _protocPath = null; + _outputDirString = null; + } + + public void + setDependencyFile(File file) + { + _dependencyFile = file; + } + + public void + setOutputdir(File dir) + { + _outputDir = dir; + _outputDirString = _outputDir.toString(); + if(_outputDirString.indexOf(' ') != -1) + { + _outputDirString = '"' + _outputDirString + '"'; + } + } + + public void + setProtocpath(File dir) + { + _protocPath = dir.toString(); + } + + public void + setTranslator(File prog) + { + _translator = prog; + } + + public FileSet + createFileset() + { + FileSet fileset = new FileSet(); + _fileSets.add(fileset); + + return fileset; + } + + public void + execute() + throws BuildException + { + if(_fileSets.isEmpty()) + { + throw new BuildException("No fileset specified"); + } + + // + // Read the set of dependencies for this task. + // + java.util.HashMap dependencies = readDependencies(); + + // + // Compose a list of the files that need to be translated. A + // file needs to translated if we can't find a dependency in + // the dependency table or if its dependency is not up-to-date + // anymore (the proto file changed since the dependency was + // last updated) + // + java.util.Vector buildList = new java.util.Vector(); + java.util.Vector skipList = new java.util.Vector(); + java.util.Iterator p = _fileSets.iterator(); + while(p.hasNext()) + { + FileSet fileset = (FileSet)p.next(); + + DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); + scanner.scan(); + String[] files = scanner.getIncludedFiles(); + for(int i = 0; i < files.length; i++) + { + File proto = new File(fileset.getDir(getProject()), files[i]); + + ProtoDependency depend = (ProtoDependency)dependencies.get(getTargetKey(proto.toString())); + if(depend == null || !depend.isUpToDate()) + { + buildList.addElement(proto); + } + else + { + skipList.addElement(proto); + } + } + + java.util.Iterator i = skipList.iterator(); + while(i.hasNext()) + { + File file = (File)i.next(); + log("skipping " + file.getName()); + } + } + + // + // Run the translator + // + if(!buildList.isEmpty()) + { + String translator; + if(_translator == null) + { + translator = "protoc"; + } + else + { + translator = _translator.toString(); + } + + StringBuilder cmd = new StringBuilder(128); + + // + // Add --java_out. + // + if(_outputDir != null) + { + cmd.append(" --java_out="); + cmd.append(stripDriveLetter(_outputDirString)); + } + + // + // Add --proto_path + // + if(_protocPath != null) + { + cmd.append(" --proto_path="); + cmd.append(stripDriveLetter(_protocPath)); + } + + // + // Add files to be translated + // + for(int i = 0; i < buildList.size(); i++) + { + File f = (File)buildList.elementAt(i); + cmd.append(" "); + String s = stripDriveLetter(f.toString()); + if(s.indexOf(' ') != -1) + { + cmd.append('"'); + cmd.append(s); + cmd.append('"'); + } + else + { + cmd.append(s); + } + } + + // + // Execute + // + log(translator + " " + cmd); + ExecTask task = (ExecTask)getProject().createTask("exec"); + task.setFailonerror(true); + Argument arg = task.createArg(); + arg.setLine(cmd.toString()); + task.setExecutable(translator); + task.execute(); + + // + // Update dependency file. + // + for(int i = 0; i < buildList.size(); i++) + { + ProtoDependency depend = new ProtoDependency(); + depend._timeStamp = new java.util.Date().getTime(); + depend._dependency = ((File)buildList.elementAt(i)).toString(); + dependencies.put(getTargetKey(depend._dependency), depend); + } + + writeDependencies(dependencies); + } + } + + private String + getTargetKey(String proto) + { + // + // Since the dependency file can be shared by several proto + // tasks we need to make sure that each dependency has a + // unique key. We use the name of the task, the output + // directory and the name of the proto file to be compiled. + // + // If there's two protoc tasks using the same dependency + // file, with the same output dir and which compiles the same + // protoc file they'll use the same dependency. + // + return "protoc " + _outputDir.toString() + " " + proto; + } + + // This is to work around a bug with protoc, where it does not + // accept drive letters in path names. See + // http://bugzilla/bugzilla/show_bug.cgi?id=3349 + // + private String + stripDriveLetter(String s) + { + if(s.length() > 1 && s.charAt(1) == ':') + { + return s.substring(2); + } + return s; + } + + // + // Read the dependency file. + // + private java.util.HashMap + readDependencies() + { + if(_dependencyFile == null) + { + if(_outputDir != null) + { + _dependencyFile = new File(_outputDir, ".pbdepend"); + } + else + { + _dependencyFile = new File(".pbdepend"); + } + } + + try + { + java.io.ObjectInputStream in = new java.io.ObjectInputStream(new java.io.FileInputStream(_dependencyFile)); + java.util.HashMap dependencies = (java.util.HashMap)in.readObject(); + in.close(); + return dependencies; + } + catch(java.io.IOException ex) + { + } + catch(java.lang.ClassNotFoundException ex) + { + } + + return new java.util.HashMap(); + } + + private void + writeDependencies(java.util.HashMap dependencies) + { + try + { + java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new FileOutputStream(_dependencyFile)); + out.writeObject(dependencies); + out.close(); + } + catch(java.io.IOException ex) + { + throw new BuildException("Unable to write dependencies in file " + _dependencyFile.getPath() + ": " + ex); + } + } + + // + // A proto dependency. + // + // * the _timeStamp attribute contains the last time the proto + // file was compiled. + // + // * the _dependency attribute contains the .proto file. + // + private class ProtoDependency implements java.io.Serializable + { + private void writeObject(java.io.ObjectOutputStream out) + throws java.io.IOException + { + out.writeObject(_dependency); + out.writeLong(_timeStamp); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, java.lang.ClassNotFoundException + { + _dependency = (String)in.readObject(); + _timeStamp = in.readLong(); + } + + public boolean + isUpToDate() + { + File dep = new File(_dependency); + if(!dep.exists() || _timeStamp < dep.lastModified()) + { + return false; + } + + return true; + } + + public String _dependency; + public long _timeStamp; + } + + private File _translator; + private File _dependencyFile; + private File _outputDir; + private String _outputDirString; + private String _protocPath; + private java.util.List _fileSets = new java.util.LinkedList(); +} diff --git a/java/test/Ice/protobuf/build.xml b/java/test/Ice/protobuf/build.xml new file mode 100644 index 00000000000..8e992925cee --- /dev/null +++ b/java/test/Ice/protobuf/build.xml @@ -0,0 +1,68 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 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_seqMapping" 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="protoc" depends="init"> + <!-- Build protoc task --> + <mkdir dir="${class.dir}"/> + <javac srcdir="ant" destdir="${class.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="generate" depends="protoc"> + <!-- Add the protoc task --> + <taskdef name="protoc" classpath="${class.dir}" classname="ProtocTask" /> + <!-- 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> + <protoc outputdir="${generated.dir}" protocpath="."> + <fileset dir="." includes="Test.proto"/> + </protoc> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </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/protobuf/run.py b/java/test/Ice/protobuf/run.py new file mode 100755 index 00000000000..70bca77e564 --- /dev/null +++ b/java/test/Ice/protobuf/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 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 + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +TestUtil.clientServerTest() + diff --git a/java/test/Ice/seqMapping/AllTests.java b/java/test/Ice/seqMapping/AllTests.java new file mode 100644 index 00000000000..e95f38943cc --- /dev/null +++ b/java/test/Ice/seqMapping/AllTests.java @@ -0,0 +1,34 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 +{ + public static Test.MyClassPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + String ref = "test:default -p 12010 -t 10000"; + Ice.ObjectPrx baseProxy = communicator.stringToProxy(ref); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy); + + System.out.print("testing twoway operations... "); + System.out.flush(); + Twoways.twoways(communicator, cl); + System.out.println("ok"); + + if(!collocated) + { + System.out.print("testing twoway operations with AMI... "); + System.out.flush(); + TwowaysAMI.twowaysAMI(communicator, cl); + System.out.println("ok"); + } + + return cl; + } +} diff --git a/java/test/Ice/seqMapping/Client.java b/java/test/Ice/seqMapping/Client.java new file mode 100644 index 00000000000..dff52ec6dd6 --- /dev/null +++ b/java/test/Ice/seqMapping/Client.java @@ -0,0 +1,58 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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); + + System.out.print("shutting down server... "); + System.out.flush(); + myClass.shutdown(); + System.out.println("ok"); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/seqMapping/Collocated.java b/java/test/Ice/seqMapping/Collocated.java new file mode 100644 index 00000000000..64843c27243 --- /dev/null +++ b/java/test/Ice/seqMapping/Collocated.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI(), 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 + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/seqMapping/MyClassI.java b/java/test/Ice/seqMapping/MyClassI.java new file mode 100644 index 00000000000..5622e7415d2 --- /dev/null +++ b/java/test/Ice/seqMapping/MyClassI.java @@ -0,0 +1,44 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI extends Test.MyClass +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public Serialize.Small opSerialSmallJava(Serialize.Small i, Ice.Holder<Serialize.Small> o, Ice.Current current) + { + o.value = i; + return i; + } + + public Serialize.Large opSerialLargeJava(Serialize.Large i, Ice.Holder<Serialize.Large> o, Ice.Current current) + { + o.value = i; + return i; + } + + public Serialize.Struct opSerialStructJava(Serialize.Struct i, Ice.Holder<Serialize.Struct> o, Ice.Current current) + { + o.value = i; + return i; + } +} diff --git a/java/test/Ice/seqMapping/Serialize/Large.java b/java/test/Ice/seqMapping/Serialize/Large.java new file mode 100644 index 00000000000..188bbe59fac --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Large.java @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Large implements java.io.Serializable // More than 254 bytes when serialized. +{ + public double d1; + public double d2; + public double d3; + public double d4; + public double d5; + public double d6; + public double d7; + public double d8; + public double d9; + public double d10; +} diff --git a/java/test/Ice/seqMapping/Serialize/Small.java b/java/test/Ice/seqMapping/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/seqMapping/Serialize/Struct.java b/java/test/Ice/seqMapping/Serialize/Struct.java new file mode 100644 index 00000000000..c40d95b3c75 --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Struct.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Struct implements java.io.Serializable // Used to test that null members marshal correctly. +{ + public Object o; + public Object o2; + public String s; + public String s2; +} diff --git a/java/test/Ice/seqMapping/Server.java b/java/test/Ice/seqMapping/Server.java new file mode 100644 index 00000000000..e77a401ddca --- /dev/null +++ b/java/test/Ice/seqMapping/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/seqMapping/Test.ice b/java/test/Ice/seqMapping/Test.ice new file mode 100644 index 00000000000..3ffe3a4140b --- /dev/null +++ b/java/test/Ice/seqMapping/Test.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 + +module Test +{ + +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; +["java:serializable:Serialize.Large"] sequence<byte> SerialLarge; +["java:serializable:Serialize.Struct"] sequence<byte> SerialStruct; + +["ami"] class MyClass +{ + void shutdown(); + + SerialSmall opSerialSmallJava(SerialSmall i, out SerialSmall o); + SerialLarge opSerialLargeJava(SerialLarge i, out SerialLarge o); + SerialStruct opSerialStructJava(SerialStruct i, out SerialStruct o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<SerialLarge> SLS; +sequence<SLS> SLSS; +dictionary<int, SerialLarge> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +exception Bar +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +class Baz +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/seqMapping/Twoways.java b/java/test/Ice/seqMapping/Twoways.java new file mode 100644 index 00000000000..4e88edaa74d --- /dev/null +++ b/java/test/Ice/seqMapping/Twoways.java @@ -0,0 +1,132 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +class Twoways +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + static void + twoways(Ice.Communicator communicator, Test.MyClassPrx p) + { + { + Serialize.Small i = null; + Ice.Holder<Serialize.Small> o = new Ice.Holder<Serialize.Small>(); + Serialize.Small r; + + r = p.opSerialSmallJava(i, o); + + test(o.value == null); + test(r == null); + } + + { + Serialize.Small i = new Serialize.Small(); + i.i = 99; + Ice.Holder<Serialize.Small> o = new Ice.Holder<Serialize.Small>(); + Serialize.Small r; + + try + { + r = p.opSerialSmallJava(i, o); + + test(o.value.i == 99); + test(r.i == 99); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + + { + Serialize.Large i = new Serialize.Large(); + i.d1 = 1.0; + i.d2 = 2.0; + i.d3 = 3.0; + i.d4 = 4.0; + i.d5 = 5.0; + i.d6 = 6.0; + i.d7 = 7.0; + i.d8 = 8.0; + i.d9 = 9.0; + i.d10 = 10.0; + Ice.Holder<Serialize.Large> o = new Ice.Holder<Serialize.Large>(); + Serialize.Large r; + + try + { + r = p.opSerialLargeJava(i, o); + + test(o.value.d1 == 1.0); + test(o.value.d2 == 2.0); + test(o.value.d3 == 3.0); + test(o.value.d4 == 4.0); + test(o.value.d5 == 5.0); + test(o.value.d6 == 6.0); + test(o.value.d7 == 7.0); + test(o.value.d8 == 8.0); + test(o.value.d9 == 9.0); + test(o.value.d10 == 10.0); + test(r.d1 == 1.0); + test(r.d2 == 2.0); + test(r.d3 == 3.0); + test(r.d4 == 4.0); + test(r.d5 == 5.0); + test(r.d6 == 6.0); + test(r.d7 == 7.0); + test(r.d8 == 8.0); + test(r.d9 == 9.0); + test(r.d10 == 10.0); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + + { + Serialize.Struct i = new Serialize.Struct(); + i.o = null; + i.o2 = i; + i.s = null; + i.s2 = "Hello"; + Ice.Holder<Serialize.Struct> o = new Ice.Holder<Serialize.Struct>(); + Serialize.Struct r; + + try + { + r = p.opSerialStructJava(i, o); + + test(o.value.o == null); + test(o.value.o2 != null); + test(((Serialize.Struct)(o.value.o2)).o == null); + test(((Serialize.Struct)(o.value.o2)).o2 == o.value.o2); + test(o.value.s == null); + test(o.value.s2.equals("Hello")); + test(r.o == null); + test(r.o2 != null); + test(((Serialize.Struct)(r.o2)).o == null); + test(((Serialize.Struct)(r.o2)).o2 == r.o2); + test(r.s == null); + test(r.s2.equals("Hello")); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + } +} diff --git a/java/test/Ice/seqMapping/TwowaysAMI.java b/java/test/Ice/seqMapping/TwowaysAMI.java new file mode 100644 index 00000000000..ca3af245cb5 --- /dev/null +++ b/java/test/Ice/seqMapping/TwowaysAMI.java @@ -0,0 +1,241 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +class TwowaysAMI +{ + private static void + test(boolean b) + { + 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; + } + + private static class AMI_MyClass_opSerialSmallJavaNull extends Test.AMI_MyClass_opSerialSmallJava + { + public void + ice_response(Serialize.Small r, Serialize.Small o) + { + test(o == null); + test(r == null); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialSmallJava extends Test.AMI_MyClass_opSerialSmallJava + { + public void + ice_response(Serialize.Small r, Serialize.Small o) + { + test(o.i == 99); + test(r.i == 99); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialLargeJava extends Test.AMI_MyClass_opSerialLargeJava + { + public void + ice_response(Serialize.Large r, Serialize.Large o) + { + test(o.d1 == 1.0); + test(o.d2 == 2.0); + test(o.d3 == 3.0); + test(o.d4 == 4.0); + test(o.d5 == 5.0); + test(o.d6 == 6.0); + test(o.d7 == 7.0); + test(o.d8 == 8.0); + test(o.d9 == 9.0); + test(o.d10 == 10.0); + test(r.d1 == 1.0); + test(r.d2 == 2.0); + test(r.d3 == 3.0); + test(r.d4 == 4.0); + test(r.d5 == 5.0); + test(r.d6 == 6.0); + test(r.d7 == 7.0); + test(r.d8 == 8.0); + test(r.d9 == 9.0); + test(r.d10 == 10.0); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialStructJava extends Test.AMI_MyClass_opSerialStructJava + { + public void + ice_response(Serialize.Struct r, Serialize.Struct o) + { + test(o.o == null); + test(o.o2 != null); + test(((Serialize.Struct)(o.o2)).o == null); + test(((Serialize.Struct)(o.o2)).o2 == o.o2); + test(o.s == null); + test(o.s2.equals("Hello")); + test(r.o == null); + test(r.o2 != null); + test(((Serialize.Struct)(r.o2)).o == null); + test(((Serialize.Struct)(r.o2)).o2 == r.o2); + test(r.s == null); + test(r.s2.equals("Hello")); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + static void + twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p) + { + { + Serialize.Small i = null; + + AMI_MyClass_opSerialSmallJavaNull cb = new AMI_MyClass_opSerialSmallJavaNull(); + p.opSerialSmallJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Small i = new Serialize.Small(); + i.i = 99; + + AMI_MyClass_opSerialSmallJava cb = new AMI_MyClass_opSerialSmallJava(); + p.opSerialSmallJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Large i = new Serialize.Large(); + i.d1 = 1.0; + i.d2 = 2.0; + i.d3 = 3.0; + i.d4 = 4.0; + i.d5 = 5.0; + i.d6 = 6.0; + i.d7 = 7.0; + i.d8 = 8.0; + i.d9 = 9.0; + i.d10 = 10.0; + + AMI_MyClass_opSerialLargeJava cb = new AMI_MyClass_opSerialLargeJava(); + p.opSerialLargeJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Struct i = new Serialize.Struct(); + i.o = null; + i.o2 = i; + i.s = null; + i.s2 = "Hello"; + + AMI_MyClass_opSerialStructJava cb = new AMI_MyClass_opSerialStructJava(); + p.opSerialStructJava_async(cb, i); + test(cb.check()); + } + } +} diff --git a/java/test/Ice/seqMapping/build.xml b/java/test/Ice/seqMapping/build.xml new file mode 100644 index 00000000000..a12392802de --- /dev/null +++ b/java/test/Ice/seqMapping/build.xml @@ -0,0 +1,55 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 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_seqMapping" 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="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </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/seqMapping/run.py b/java/test/Ice/seqMapping/run.py new file mode 100755 index 00000000000..09d700b9f48 --- /dev/null +++ b/java/test/Ice/seqMapping/run.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 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 + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "tests with regular server." +TestUtil.clientServerTest() + +print "tests with AMD server." +import copy +amdenv = copy.deepcopy(os.environ) +TestUtil.addClasspath(os.path.join(os.getcwd(), "..", "seqMappingAMD", "classes"), amdenv) +TestUtil.clientServerTest(serverenv = amdenv) + +print "tests with collocated server." +TestUtil.collocatedTest() diff --git a/java/test/Ice/seqMappingAMD/MyClassI.java b/java/test/Ice/seqMappingAMD/MyClassI.java new file mode 100644 index 00000000000..61bbde13d70 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/MyClassI.java @@ -0,0 +1,42 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI extends Test.MyClass +{ + public void + shutdown_async(Test.AMD_MyClass_shutdown cb, + Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + cb.ice_response(); + } + + public void + opSerialSmallJava_async(Test.AMD_MyClass_opSerialSmallJava cb, + Serialize.Small i, + Ice.Current current) + { + cb.ice_response(i, i); + } + + public void + opSerialLargeJava_async(Test.AMD_MyClass_opSerialLargeJava cb, + Serialize.Large i, + Ice.Current current) + { + cb.ice_response(i, i); + } + + public void opSerialStructJava_async(Test.AMD_MyClass_opSerialStructJava cb, + Serialize.Struct i, + Ice.Current current) + { + cb.ice_response(i, i); + } +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Large.java b/java/test/Ice/seqMappingAMD/Serialize/Large.java new file mode 100644 index 00000000000..188bbe59fac --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Large.java @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Large implements java.io.Serializable // More than 254 bytes when serialized. +{ + public double d1; + public double d2; + public double d3; + public double d4; + public double d5; + public double d6; + public double d7; + public double d8; + public double d9; + public double d10; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Small.java b/java/test/Ice/seqMappingAMD/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java b/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java new file mode 100644 index 00000000000..66776ade146 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class SmallHolder +{ + public Small value; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Struct.java b/java/test/Ice/seqMappingAMD/Serialize/Struct.java new file mode 100644 index 00000000000..c40d95b3c75 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Struct.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Struct implements java.io.Serializable // Used to test that null members marshal correctly. +{ + public Object o; + public Object o2; + public String s; + public String s2; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java b/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java new file mode 100644 index 00000000000..8bf50b75215 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class StructHolder +{ + public Struct value; +} diff --git a/java/test/Ice/seqMappingAMD/Server.java b/java/test/Ice/seqMappingAMD/Server.java new file mode 100644 index 00000000000..ab531a55a60 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/seqMappingAMD/TestAMD.ice b/java/test/Ice/seqMappingAMD/TestAMD.ice new file mode 100644 index 00000000000..88a987c9eec --- /dev/null +++ b/java/test/Ice/seqMappingAMD/TestAMD.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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 + +module Test +{ + +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; +["java:serializable:Serialize.Large"] sequence<byte> SerialLarge; +["java:serializable:Serialize.Struct"] sequence<byte> SerialStruct; + +["ami", "amd"] class MyClass +{ + void shutdown(); + + SerialSmall opSerialSmallJava(SerialSmall i, out SerialSmall o); + SerialLarge opSerialLargeJava(SerialLarge i, out SerialLarge o); + SerialStruct opSerialStructJava(SerialStruct i, out SerialStruct o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<SerialLarge> SLS; +sequence<SLS> SLSS; +dictionary<int, SerialLarge> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +exception Bar +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +class Baz +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/seqMappingAMD/build.xml b/java/test/Ice/seqMappingAMD/build.xml new file mode 100644 index 00000000000..e98924112fc --- /dev/null +++ b/java/test/Ice/seqMappingAMD/build.xml @@ -0,0 +1,55 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 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_seqMappingAMD" 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="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </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/serialize/AllTests.java b/java/test/Ice/serialize/AllTests.java new file mode 100644 index 00000000000..2a540d546df --- /dev/null +++ b/java/test/Ice/serialize/AllTests.java @@ -0,0 +1,148 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 Test.*; +import java.io.*; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static InitialPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + String ref = "initial:default -p 12010 -t 10000"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + InitialPrx initial = InitialPrxHelper.checkedCast(base); + + System.out.print("testing serialization... "); + System.out.flush(); + + // + // Call getStruct1 and force an error. + // + try + { + // + // We expect this test to raise an exception: we are attempting to deserialize + // an instance of Struct1 using java.io.ObjectInputStream. However, we must + // use Ice.ObjectInputStream instead because Struct1 contains a proxy. + // + byte[] bytes = initial.getStruct1(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bais); + ois.readObject(); + test(false); + } + catch(IOException ex) + { + // Expected. + } + catch(Throwable ex) + { + test(false); + } + + // + // Call getStruct1. + // + try + { + byte[] bytes = initial.getStruct1(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais); + Struct1 s = (Struct1)ois.readObject(); + checkStruct1(s); + } + catch(Throwable ex) + { + test(false); + } + + // + // Call getBase. + // + try + { + byte[] bytes = initial.getBase(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais); + Base b = (Base)ois.readObject(); + checkBase(b); + } + catch(Throwable ex) + { + test(false); + } + + // + // Call getEx. + // + try + { + byte[] bytes = initial.getEx(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais); + Ex ex = (Ex)ois.readObject(); + checkStruct1(ex.s); + checkBase(ex.b); + } + catch(Throwable ex) + { + test(false); + } + + System.out.println("ok"); + + return initial; + } + + private static void + checkStruct1(Struct1 s) + { + test(s.bo); + test(s.by == (byte)1); + test(s.sh == (short)2); + test(s.i == 3); + test(s.l == 4); + test(s.f == (float)5.0); + test(s.d == 6.0); + test(s.str.equals("7")); + test(s.e == MyEnum.enum2); + test(s.p != null); + s.p.ice_ping(); // Make sure the deserialized proxy is usable. + } + + private static void + checkBase(Base b) + { + test(b.b == b); + test(b.o == b); + checkStruct1(b.s); + test(java.util.Arrays.equals(b.seq1, new byte[] { 0, 1, 2, 3, 4 })); + test(java.util.Arrays.equals(b.seq2, new int[] { 5, 6, 7, 8, 9 })); + test(java.util.Arrays.equals(b.seq3, new MyEnum[] { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1 })); + test(java.util.Arrays.equals(b.seq4, new Base[] { b })); + test(b.d1.get(new Byte((byte)1)).equals(Boolean.TRUE)); + test(b.d2.get(new Short((short)2)).equals(new Integer(3))); + test(b.d3.get("enum3") == MyEnum.enum3); + test(b.d4.get("b") == b); + test(b instanceof Derived); + Derived d = (Derived)b; + test(d.p != null); + d.p.ice_ping(); + } +} diff --git a/java/test/Ice/serialize/Client.java b/java/test/Ice/serialize/Client.java new file mode 100644 index 00000000000..74ab7531339 --- /dev/null +++ b/java/test/Ice/serialize/Client.java @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 Test.*; + +public class Client +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + InitialPrx initial = AllTests.allTests(communicator, false); + initial.shutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/serialize/InitialI.java b/java/test/Ice/serialize/InitialI.java new file mode 100644 index 00000000000..7973076b65e --- /dev/null +++ b/java/test/Ice/serialize/InitialI.java @@ -0,0 +1,114 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 Test.*; +import java.io.*; + +public final class InitialI extends _InitialDisp +{ + InitialI(Ice.ObjectAdapter adapter, Ice.Identity ident) + { + _s = new Struct1(); + _s.bo = true; + _s.by = (byte)1; + _s.sh = (short)2; + _s.i = 3; + _s.l = 4; + _s.f = (float)5.0; + _s.d = 6.0; + _s.str = "7"; + _s.e = Test.MyEnum.enum2; + _s.p = Test.InitialPrxHelper.uncheckedCast(adapter.createProxy(ident)); + + _d = new Derived(); + _d.b = _d; + _d.o = _d; + _d.s = _s; + _d.seq1 = new byte[] { 0, 1, 2, 3, 4 }; + _d.seq2 = new int[] { 5, 6, 7, 8, 9 }; + _d.seq3 = new MyEnum[] { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1 }; + _d.seq4 = new Base[] { _d }; + _d.d1 = new java.util.HashMap<Byte, Boolean>(); + _d.d1.put((byte)1, true); + _d.d2 = new java.util.HashMap<Short, Integer>(); + _d.d2.put((short)2, 3); + _d.d3 = new java.util.HashMap<String, MyEnum>(); + _d.d3.put("enum3", MyEnum.enum3); + _d.d4 = new java.util.HashMap<String, Base>(); + _d.d4.put("b", _d); + _d.p = _s.p; + } + + public byte[] + getStruct1(Ice.Current current) + { + try + { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + ObjectOutputStream stream = new ObjectOutputStream(byteStream); + stream.writeObject(_s); + return byteStream.toByteArray(); + } + catch(IOException ex) + { + Ice.UnknownException e = new Ice.UnknownException(); + e.initCause(ex); + throw e; + } + } + + public byte[] + getBase(Ice.Current current) + { + try + { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + ObjectOutputStream stream = new ObjectOutputStream(byteStream); + stream.writeObject(_d); + return byteStream.toByteArray(); + } + catch(IOException ex) + { + Ice.UnknownException e = new Ice.UnknownException(); + e.initCause(ex); + throw e; + } + } + + public byte[] + getEx(Ice.Current current) + { + try + { + Ex ex = new Ex(); + ex.s = _s; + ex.b = _d; + + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + ObjectOutputStream stream = new ObjectOutputStream(byteStream); + stream.writeObject(ex); + return byteStream.toByteArray(); + } + catch(IOException ex) + { + Ice.UnknownException e = new Ice.UnknownException(); + e.initCause(ex); + throw e; + } + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + private Struct1 _s; + private Derived _d; +} diff --git a/java/test/Ice/serialize/Server.java b/java/test/Ice/serialize/Server.java new file mode 100644 index 00000000000..23e27a80f7d --- /dev/null +++ b/java/test/Ice/serialize/Server.java @@ -0,0 +1,58 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.Identity ident = communicator.stringToIdentity("initial"); + Ice.Object object = new InitialI(adapter, ident); + adapter.add(object, ident); + adapter.activate(); + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception 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/serialize/Test.ice b/java/test/Ice/serialize/Test.ice new file mode 100644 index 00000000000..bb64105b0cd --- /dev/null +++ b/java/test/Ice/serialize/Test.ice @@ -0,0 +1,86 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 + +module Test +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +interface Initial; +class Base; + +struct Struct1 +{ + bool bo; + byte by; + short sh; + int i; + long l; + float f; + double d; + string str; + MyEnum e; + Initial* p; +}; + +sequence<byte> ByteS; +sequence<int> IntS; +sequence<MyEnum> MyEnumS; +sequence<Base> BaseS; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<string, MyEnum> StringMyEnumD; +dictionary<string, Base> StringBaseD; + +class Base +{ + Base b; + Object o; + Struct1 s; + ByteS seq1; + IntS seq2; + MyEnumS seq3; + BaseS seq4; + ByteBoolD d1; + ShortIntD d2; + StringMyEnumD d3; + StringBaseD d4; +}; + +class Derived extends Base +{ + Object* p; +}; + +exception Ex +{ + Struct1 s; + Base b; +}; + +interface Initial +{ + ByteS getStruct1(); + ByteS getBase(); + ByteS getEx(); + void shutdown(); +}; + +}; + +#endif diff --git a/java/test/Ice/serialize/build.xml b/java/test/Ice/serialize/build.xml new file mode 100644 index 00000000000..1e4d16935c6 --- /dev/null +++ b/java/test/Ice/serialize/build.xml @@ -0,0 +1,48 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2009 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_objects" 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 stream="on" outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Test.ice"/> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </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/serialize/run.py b/java/test/Ice/serialize/run.py new file mode 100755 index 00000000000..bb34e7d35b7 --- /dev/null +++ b/java/test/Ice/serialize/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 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 + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +TestUtil.clientServerTest() diff --git a/java/test/Ice/stream/Client.java b/java/test/Ice/stream/Client.java index 8c1993fc612..ebeb12378df 100644 --- a/java/test/Ice/stream/Client.java +++ b/java/test/Ice/stream/Client.java @@ -325,6 +325,19 @@ public class Client } { + Serialize.Small small = new Serialize.Small(); + small.i = 99; + out = Ice.Util.createOutputStream(communicator); + out.writeSerializable(small); + byte[] data = out.finished(); + in = Ice.Util.createInputStream(communicator, data); + Serialize.Small small2 = (Serialize.Small)in.readSerializable(); + test(small2.i == 99); + out.destroy(); + in.destroy(); + } + + { final short[] arr = { (short)0x01, diff --git a/java/test/Ice/stream/Serialize/Small.java b/java/test/Ice/stream/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/stream/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/stream/Test.ice b/java/test/Ice/stream/Test.ice index dafd2f02d41..03ac2d92dc3 100644 --- a/java/test/Ice/stream/Test.ice +++ b/java/test/Ice/stream/Test.ice @@ -22,6 +22,8 @@ enum MyEnum class MyClass; +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; + struct SmallStruct { bool bo; @@ -34,6 +36,7 @@ struct SmallStruct string str; MyEnum e; MyClass* p; + SerialSmall ss; }; sequence<bool> BoolS; diff --git a/java/test/Ice/stream/build.xml b/java/test/Ice/stream/build.xml index f3283a483ba..e719c890777 100644 --- a/java/test/Ice/stream/build.xml +++ b/java/test/Ice/stream/build.xml @@ -28,12 +28,16 @@ <target name="compile" depends="generate"> <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> <javac srcdir="${generated.dir}" destdir="${class.dir}" classpathref="ice.classpath" debug="${debug}"> <compilerarg value="${javac.lint}"/> </javac> - <javac srcdir="." destdir="${class.dir}" - classpathref="ice.classpath" excludes="generated/**" debug="${debug}"> + <javac srcdir="." destdir="${class.dir}" excludes="${generated.dir}/** Serialize/**" + classpathref="ice.classpath" debug="${debug}"> <compilerarg value="${javac.lint}"/> </javac> </target> diff --git a/java/test/Ice/stream/run.py b/java/test/Ice/stream/run.py index 2ba8e124049..47e0b8dafab 100755 --- a/java/test/Ice/stream/run.py +++ b/java/test/Ice/stream/run.py @@ -23,7 +23,8 @@ from scripts import * TestUtil.addClasspath(os.path.join(os.getcwd(), "classes")) print "starting test...", -clientProc = TestUtil.startClient("Client") +clientProc = TestUtil.startClient("Client", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() diff --git a/java/test/Ice/timeout/AllTests.java b/java/test/Ice/timeout/AllTests.java index 73cf9dffb5c..1f827eb9e47 100644 --- a/java/test/Ice/timeout/AllTests.java +++ b/java/test/Ice/timeout/AllTests.java @@ -190,7 +190,7 @@ public class AllTests // Expect success. // timeout.op(); // Ensure adapter is active. - TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); + TimeoutPrx to = TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(2000)); to.holdAdapter(500); to.ice_getConnection().close(true); // Force a reconnect. try diff --git a/java/test/Ice/udp/AllTests.java b/java/test/Ice/udp/AllTests.java index e374478f2ea..53f10f5a633 100644 --- a/java/test/Ice/udp/AllTests.java +++ b/java/test/Ice/udp/AllTests.java @@ -76,11 +76,25 @@ public class AllTests Ice.ObjectPrx base = communicator.stringToProxy("test:udp -p 12010").ice_datagram(); Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(base); - replyI.reset(); - obj.ping(reply); - obj.ping(reply); - obj.ping(reply); - boolean ret = replyI.waitReply(3, 2000); + int nRetry = 5; + boolean 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) diff --git a/java/test/Ice/udp/run.py b/java/test/Ice/udp/run.py index 1ba78b079a2..108318b7896 100755 --- a/java/test/Ice/udp/run.py +++ b/java/test/Ice/udp/run.py @@ -31,8 +31,9 @@ for i in range(0, num): print "ok" print "starting client...", -clientProc = TestUtil.startClient("Client") +clientProc = TestUtil.startClient("Client", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() for p in serverProc: diff --git a/java/test/IceBox/configuration/AllTests.java b/java/test/IceBox/configuration/AllTests.java index 488fe4f7c7f..7c71df16120 100644 --- a/java/test/IceBox/configuration/AllTests.java +++ b/java/test/IceBox/configuration/AllTests.java @@ -59,13 +59,13 @@ public class AllTests test(service3.getProperty("Service").equals("4")); test(service3.getProperty("Prop").equals("")); test(service3.getProperty("Service3.Prop").equals("1")); - test(service3.getProperty("Ice.Trace.Network").equals("3")); + test(service3.getProperty("Ice.Trace.Slicing").equals("3")); test(service4.getProperty("Ice.ProgramName").equals("IceBox-SharedCommunicator")); test(service4.getProperty("Service").equals("4")); test(service4.getProperty("Prop").equals("")); test(service4.getProperty("Service3.Prop").equals("1")); - test(service4.getProperty("Ice.Trace.Network").equals("3")); + test(service4.getProperty("Ice.Trace.Slicing").equals("3")); String[] args4 = {"--Service3.Prop=2"}; test(java.util.Arrays.equals(service4.getArgs(), args4)); diff --git a/java/test/IceBox/configuration/config.icebox b/java/test/IceBox/configuration/config.icebox index 0cc9851d84c..fc46a5c60e3 100644 --- a/java/test/IceBox/configuration/config.icebox +++ b/java/test/IceBox/configuration/config.icebox @@ -8,6 +8,6 @@ IceBox.Service.Service2=TestServiceI --Ice.Config=config.service2 --Service1.Arg IceBox.UseSharedCommunicator.Service3=1 IceBox.Service.Service3=TestServiceI --Ice.Config=config.service3 IceBox.UseSharedCommunicator.Service4=1 -IceBox.Service.Service4=TestServiceI --Ice.Config=config.service4 --Service3.Prop=2 --Ice.Trace.Network=3 +IceBox.Service.Service4=TestServiceI --Ice.Config=config.service4 --Service3.Prop=2 --Ice.Trace.Slicing=3 IceBox.LoadOrder=Service1 Service2 Service3 Service4 diff --git a/java/test/IceBox/configuration/config.service3 b/java/test/IceBox/configuration/config.service3 index f1930e3d8fb..c93ed144701 100644 --- a/java/test/IceBox/configuration/config.service3 +++ b/java/test/IceBox/configuration/config.service3 @@ -5,4 +5,4 @@ Service=3 Prop=2 Service3.Prop=1 -Ice.Trace.Network=2 +Ice.Trace.Slicing=2 diff --git a/java/test/IceSSL/certs/makecerts.py b/java/test/IceSSL/certs/makecerts.py index 5e6fbb7300f..f81f472105f 100755 --- a/java/test/IceSSL/certs/makecerts.py +++ b/java/test/IceSSL/certs/makecerts.py @@ -12,7 +12,7 @@ import os, sys, shutil for toplevel in [".", "..", "../..", "../../..", "../../../..", "../../../../.."]: toplevel = os.path.normpath(toplevel) - if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + if os.path.exists(os.path.join(toplevel, "scripts", "TestUtil.py")): break else: raise "can't find toplevel directory!" diff --git a/java/test/IceUtil/inputUtil/run.py b/java/test/IceUtil/inputUtil/run.py index cae7681d14d..71b051bbc73 100755 --- a/java/test/IceUtil/inputUtil/run.py +++ b/java/test/IceUtil/inputUtil/run.py @@ -23,6 +23,7 @@ from scripts import * TestUtil.addClasspath(os.path.join(os.getcwd(), "classes")) print "starting client...", -clientProc = TestUtil.startClient("Client") +clientProc = TestUtil.startClient("Client", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() diff --git a/java/test/Slice/keyword/Key.ice b/java/test/Slice/keyword/Key.ice index f1ce1a558a9..173b28832e6 100644 --- a/java/test/Slice/keyword/Key.ice +++ b/java/test/Slice/keyword/Key.ice @@ -32,6 +32,7 @@ interface default class else { + int if; ["ami"] void foo(default* equals, out int final); }; diff --git a/java/test/Slice/keyword/run.py b/java/test/Slice/keyword/run.py index cae7681d14d..71b051bbc73 100755 --- a/java/test/Slice/keyword/run.py +++ b/java/test/Slice/keyword/run.py @@ -23,6 +23,7 @@ from scripts import * TestUtil.addClasspath(os.path.join(os.getcwd(), "classes")) print "starting client...", -clientProc = TestUtil.startClient("Client") +clientProc = TestUtil.startClient("Client", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() |