diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2008-10-23 14:42:59 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2008-10-23 14:42:59 -0230 |
commit | 845b03ddfa20fef3b57818086b6ec7266d8db147 (patch) | |
tree | f082980f7fa6c50006f24bedf29423b2bbf9739b /java | |
parent | Fixed locator implementation to not serialize anymore locator request for non... (diff) | |
download | ice-845b03ddfa20fef3b57818086b6ec7266d8db147.tar.bz2 ice-845b03ddfa20fef3b57818086b6ec7266d8db147.tar.xz ice-845b03ddfa20fef3b57818086b6ec7266d8db147.zip |
Bug 3164 - add udp test
Diffstat (limited to 'java')
-rwxr-xr-x | java/allTests.py | 1 | ||||
-rw-r--r-- | java/test/Ice/build.xml | 2 | ||||
-rw-r--r-- | java/test/Ice/udp/AllTests.java | 114 | ||||
-rw-r--r-- | java/test/Ice/udp/Client.java | 55 | ||||
-rw-r--r-- | java/test/Ice/udp/Server.java | 76 | ||||
-rw-r--r-- | java/test/Ice/udp/Test.ice | 29 | ||||
-rw-r--r-- | java/test/Ice/udp/TestIntfI.java | 28 | ||||
-rw-r--r-- | java/test/Ice/udp/build.xml | 48 | ||||
-rwxr-xr-x | java/test/Ice/udp/run.py | 39 |
9 files changed, 392 insertions, 0 deletions
diff --git a/java/allTests.py b/java/allTests.py index 65dc7854728..33871b35e0e 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -48,6 +48,7 @@ tests = [ ("Ice/background", ["core"]), ("Ice/servantLocator", ["core"]), ("Ice/interceptor", ["core"]), + ("Ice/udp", ["core"]), ("IceBox/configuration", ["core", "noipv6"]), ("Freeze/dbmap", ["once"]), ("Freeze/complex", ["once"]), diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index 7b9fc1f7585..86a8b48f886 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -38,6 +38,7 @@ <ant dir="servantLocator"/> <ant dir="servantLocatorAMD"/> <ant dir="interceptor"/> + <ant dir="udp"/> </target> <target name="clean"> @@ -67,6 +68,7 @@ <ant dir="servantLocator" target="clean"/> <ant dir="servantLocatorAMD" target="clean"/> <ant dir="interceptor" target="clean"/> + <ant dir="udp" target="clean"/> </target> </project> diff --git a/java/test/Ice/udp/AllTests.java b/java/test/Ice/udp/AllTests.java new file mode 100644 index 00000000000..ca6d1f1e70c --- /dev/null +++ b/java/test/Ice/udp/AllTests.java @@ -0,0 +1,114 @@ +// ********************************************************************** +// +// 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(); + } + } + + public static class PingReplyI extends Test._PingReplyDisp + { + public synchronized void + reply(Ice.Current current) + { + ++_replies; + notify(); + } + + public synchronized void + reset() + { + _replies = 0; + } + + public synchronized boolean + waitReply(int expectedReplies, long timeout) + { + long end = System.currentTimeMillis() + timeout; + while(_replies < expectedReplies) + { + long delay = end - System.currentTimeMillis(); + if(delay > 0) + { + try + { + wait(delay); + } + catch(java.lang.InterruptedException ex) + { + } + } + else + { + break; + } + } + return _replies == expectedReplies; + } + + private int _replies; + } + + public static Test.TestIntfPrx + allTests(Ice.Communicator communicator) + { + communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp -p 12030"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter"); + PingReplyI replyI = new PingReplyI(); + Test.PingReplyPrx reply = + (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); + adapter.activate(); + + System.out.print("testing udp... "); + System.out.flush(); + 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); + test(ret == true); + System.out.println("ok"); + + System.out.print("testing udp multicast... "); + System.out.flush(); + String host; + if(communicator.getProperties().getProperty("Ice.IPv6") == "1") + { + host = "\"ff01::1:1\""; + } + else + { + host = "239.255.1.1"; + } + base = communicator.stringToProxy("test:udp -h " + host + " -p 12020").ice_datagram(); + obj = Test.TestIntfPrxHelper.uncheckedCast(base); + + replyI.reset(); + obj.ping(reply); + ret = replyI.waitReply(5, 2000); + test(ret == true); + + replyI.reset(); + obj.ping(reply); + ret = replyI.waitReply(5, 2000); + test(ret == true); + System.out.println("ok"); + + return obj; + } +} diff --git a/java/test/Ice/udp/Client.java b/java/test/Ice/udp/Client.java new file mode 100644 index 00000000000..e12fd8918ad --- /dev/null +++ b/java/test/Ice/udp/Client.java @@ -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. +// +// ********************************************************************** + +import Test.*; + +public class Client +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + TestIntfPrx obj = AllTests.allTests(communicator); + obj.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/udp/Server.java b/java/test/Ice/udp/Server.java new file mode 100644 index 00000000000..a0d9e541f0a --- /dev/null +++ b/java/test/Ice/udp/Server.java @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// 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) + { + Ice.Properties properties = communicator.getProperties(); + if(args.length == 1 && args[0].equals("1")) + { + properties.setProperty("TestAdapter.Endpoints", "udp -p 12010"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new TestIntfI(), communicator.stringToIdentity("test")); + adapter.activate(); + } + + String host; + if(properties.getProperty("Ice.IPv6") == "1") + { + host = "\"ff01::1:1\""; + } + else + { + host = "239.255.1.1"; + } + properties.setProperty("McastTestAdapter.Endpoints", "udp -h " + host + " -p 12020"); + Ice.ObjectAdapter mcastAdapter = communicator.createObjectAdapter("McastTestAdapter"); + mcastAdapter.add(new TestIntfI(), communicator.stringToIdentity("test")); + mcastAdapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + Ice.StringSeqHolder argHolder = new Ice.StringSeqHolder(args); + communicator = Ice.Util.initialize(argHolder); + status = run(argHolder.value, 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/udp/Test.ice b/java/test/Ice/udp/Test.ice new file mode 100644 index 00000000000..9955f643124 --- /dev/null +++ b/java/test/Ice/udp/Test.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// 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 +{ + +interface PingReply +{ + void reply(); +}; + +interface TestIntf +{ + void ping(PingReply* reply); + void shutdown(); +}; + +}; + +#endif diff --git a/java/test/Ice/udp/TestIntfI.java b/java/test/Ice/udp/TestIntfI.java new file mode 100644 index 00000000000..28b4ee944f5 --- /dev/null +++ b/java/test/Ice/udp/TestIntfI.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// 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 TestIntfI extends Test._TestIntfDisp +{ + public void ping(Test.PingReplyPrx reply, Ice.Current current) + { + try + { + reply.reply(); + } + catch(Ice.LocalException ex) + { + assert(false); + } + } + + public void shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } +} diff --git a/java/test/Ice/udp/build.xml b/java/test/Ice/udp/build.xml new file mode 100644 index 00000000000..d7ca8e8f235 --- /dev/null +++ b/java/test/Ice/udp/build.xml @@ -0,0 +1,48 @@ +<!-- + ********************************************************************** + + 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_udp" 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"/> + </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/udp/run.py b/java/test/Ice/udp/run.py new file mode 100755 index 00000000000..3bdbd68ab97 --- /dev/null +++ b/java/test/Ice/udp/run.py @@ -0,0 +1,39 @@ +#!/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.addClasspath(os.path.join(os.getcwd(), "classes")) + +num = 5 + +serverProc = [] +for i in range(0, num): + print "starting server #%d..." % (i + 1), + serverProc.append(TestUtil.startServer("Server", "%d" % (i + 1) , adapter="McastTestAdapter")) + print "ok" + +print "starting client...", +clientProc = TestUtil.startClient("Client") +print "ok" + +clientProc.waitTestSuccess() +for p in serverProc: + p.waitTestSuccess() |