summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/build.xml8
-rw-r--r--java/config/TestUtil.py75
-rw-r--r--java/test/Glacier/build.xml11
-rw-r--r--java/test/Glacier/starter/Callback.ice38
-rw-r--r--java/test/Glacier/starter/CallbackClient.java184
-rw-r--r--java/test/Glacier/starter/CallbackI.java38
-rw-r--r--java/test/Glacier/starter/CallbackReceiverI.java60
-rw-r--r--java/test/Glacier/starter/CallbackServer.java24
-rw-r--r--java/test/Glacier/starter/Client.java20
-rw-r--r--java/test/Glacier/starter/Server.java20
-rw-r--r--java/test/Glacier/starter/build.xml44
-rwxr-xr-xjava/test/Glacier/starter/run.py73
-rw-r--r--java/test/build.xml2
13 files changed, 597 insertions, 0 deletions
diff --git a/java/build.xml b/java/build.xml
index faf9ab84701..865116fd216 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -48,6 +48,14 @@
<includepath>
<pathelement path="${slice.dir}" />
</includepath>
+ <fileset dir="${slice.dir}/Glacier">
+ <include name="Glacier.ice" />
+ </fileset>
+ </slice2java>
+ <slice2java tagdir="${tags.dir}" outputdir="${generated.dir}">
+ <includepath>
+ <pathelement path="${slice.dir}" />
+ </includepath>
<fileset dir="${slice.dir}/Freeze">
<include name="DB.ice" />
<include name="DBException.ice" />
diff --git a/java/config/TestUtil.py b/java/config/TestUtil.py
index 80e4401e95b..50f116bb81a 100644
--- a/java/config/TestUtil.py
+++ b/java/config/TestUtil.py
@@ -64,6 +64,48 @@ clientOptions = clientProtocol + defaultHost
clientServerOptions = commonServerOptions + clientServerProtocol + defaultHost
collocatedOptions = clientServerProtocol
+serverPids = []
+
+#
+# Only used for C++ programs
+#
+def killServers():
+
+ global serverPids
+
+ for pid in serverPids:
+ if sys.platform == "cygwin":
+ print "killServers(): not implemented for cygwin python."
+ sys.exit(1)
+ elif sys.platform == "win32":
+ try:
+ import win32api
+ handle = win32api.OpenProcess(1, 0, pid)
+ win32api.TerminateProcess(handle, 0)
+ except:
+ pass # Ignore errors, such as non-existing processes.
+ else:
+ try:
+ os.kill(pid, 9)
+ except:
+ pass # Ignore errors, such as non-existing processes.
+
+ serverPids = []
+
+#
+# Only used for C++ programs
+#
+def getServerPid(serverPipe):
+
+ output = serverPipe.readline().strip()
+
+ if not output:
+ print "failed!"
+ killServers()
+ sys.exit(1)
+
+ serverPids.append(int(output))
+
def getAdapterReady(serverPipe):
output = serverPipe.readline().strip()
@@ -105,6 +147,39 @@ def clientServerTest(toplevel, name):
serverPipe.close()
clientPipe.close()
+def clientServerHybridTest(toplevel, name):
+
+ testdir = os.path.join(toplevel, "test", name)
+ classpath = os.path.join(toplevel, "lib") + sep + os.path.join(testdir, "classes") + sep + os.environ['CLASSPATH']
+ server = "java -classpath \"" + classpath + "\" Server "
+ client = "java -classpath \"" + classpath + "\" Client "
+
+ updatedServerOptions = clientServerOptions.replace("TOPLEVELDIR", toplevel)
+ updatedClientOptions = updatedServerOptions
+
+ print "starting server...",
+ serverPipe = os.popen(server + updatedServerOptions)
+ getAdapterReady(serverPipe)
+ print "ok"
+
+ print "starting client...",
+ clientPipe = os.popen(client + updatedClientOptions)
+ output = clientPipe.readline()
+ if not output:
+ print "failed!"
+ serverPipe.close()
+ clientPipe.close()
+ sys.exit(1)
+ print "ok"
+ while 1:
+ output = clientPipe.readline()
+ if not output:
+ break;
+ print output,
+ killServers()
+ serverPipe.close()
+ clientPipe.close()
+
def collocatedTest(toplevel, name):
testdir = os.path.join(toplevel, "test", name)
diff --git a/java/test/Glacier/build.xml b/java/test/Glacier/build.xml
new file mode 100644
index 00000000000..ab3922b1caa
--- /dev/null
+++ b/java/test/Glacier/build.xml
@@ -0,0 +1,11 @@
+<project name="test_Ice" default="all" basedir=".">
+
+ <target name="all">
+ <ant dir="starter"/>
+ </target>
+
+ <target name="clean">
+ <ant dir="starter" target="clean"/>
+ </target>
+
+</project>
diff --git a/java/test/Glacier/starter/Callback.ice b/java/test/Glacier/starter/Callback.ice
new file mode 100644
index 00000000000..b43b245a1bd
--- /dev/null
+++ b/java/test/Glacier/starter/Callback.ice
@@ -0,0 +1,38 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef CALLBACK_ICE
+#define CALLBACK_ICE
+
+exception CallbackException
+{
+ double someValue;
+ string someString;
+};
+
+class CallbackReceiver
+{
+ void callback();
+
+ void callbackEx()
+ throws CallbackException;
+};
+
+class Callback
+{
+ void initiateCallback(CallbackReceiver* proxy);
+
+ void initiateCallbackEx(CallbackReceiver* proxy)
+ throws CallbackException;
+
+ void shutdown();
+};
+
+#endif
diff --git a/java/test/Glacier/starter/CallbackClient.java b/java/test/Glacier/starter/CallbackClient.java
new file mode 100644
index 00000000000..e50a9abb56d
--- /dev/null
+++ b/java/test/Glacier/starter/CallbackClient.java
@@ -0,0 +1,184 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class CallbackClient extends Ice.Application
+{
+ public int
+ run(String[] args)
+ {
+ String ref;
+
+ System.out.print("creating and activating callback receiver adapter... ");
+ System.out.flush();
+ Ice.ObjectAdapter adapter =
+ communicator().createObjectAdapterWithEndpoints("CallbackReceiverAdapter", "default");
+ adapter.activate();
+ System.out.println("ok");
+
+ System.out.print("creating and adding callback receiver object... ");
+ System.out.flush();
+ CallbackReceiverI callbackReceiverImpl = new CallbackReceiverI();
+ Ice.Object callbackReceiver = callbackReceiverImpl;
+ adapter.add(callbackReceiver, Ice.Util.stringToIdentity("callbackReceiver"));
+ System.out.println("ok");
+
+ System.out.print("testing stringToProxy for glacier starter... ");
+ System.out.flush();
+ ref = "Glacier#starter:default -p 12346 -t 5000";
+ Ice.ObjectPrx starterBase = communicator().stringToProxy(ref);
+ System.out.println("ok");
+
+ System.out.print("testing checked cast for glacier starter... ");
+ System.out.flush();
+ Glacier.StarterPrx starter = Glacier.StarterPrxHelper.checkedCast(starterBase);
+ test(starter != null);
+ System.out.println("ok");
+
+ Ice.ByteSeqHolder privateKey = new Ice.ByteSeqHolder();
+ Ice.ByteSeqHolder publicKey = new Ice.ByteSeqHolder();
+ Ice.ByteSeqHolder routerCert = new Ice.ByteSeqHolder();
+
+ System.out.print("starting up glacier router... ");
+ System.out.flush();
+ Ice.RouterPrx router;
+ try
+ {
+ router = starter.startRouter("", "", privateKey, publicKey, routerCert);
+ }
+ catch (Glacier.CannotStartRouterException ex)
+ {
+ System.out.println(appName() + ": " + ex + ":\n" + ex.reason);
+ return 1;
+ }
+ catch (Glacier.InvalidPasswordException ex)
+ {
+ System.out.println(appName() + ": " + ex);
+ return 1;
+ }
+
+ test(router != null);
+ System.out.println("ok");
+
+ System.out.print("pinging glacier router... ");
+ System.out.flush();
+ router.ice_ping();
+ System.out.println("ok");
+
+ System.out.print("installing glacier router... ");
+ System.out.flush();
+ communicator().setDefaultRouter(router);
+ adapter.addRouter(router);
+ System.out.println("ok");
+
+ System.out.print("testing stringToProxy... ");
+ System.out.flush();
+ ref = "callback:tcp -p 12345 -t 5000";
+ Ice.ObjectPrx base = communicator().stringToProxy(ref);
+ System.out.println("ok");
+
+ System.out.print("testing checked cast... ");
+ System.out.flush();
+ CallbackPrx twoway = CallbackPrxHelper.checkedCast(base.ice_twoway().ice_timeout(-1).ice_secure(false));
+ test(twoway != null);
+ System.out.println("ok");
+
+ CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
+ adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver")));
+
+ {
+ System.out.print("testing oneway callback... ");
+ System.out.flush();
+ CallbackPrx oneway = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
+ CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());
+ java.util.Map context = new java.util.HashMap();
+ context.put("_fwd", "o");
+ oneway.initiateCallback(onewayR, context);
+ test(callbackReceiverImpl.callbackOK());
+ System.out.println("ok");
+ }
+
+ {
+ System.out.print("testing twoway callback... ");
+ System.out.flush();
+ java.util.Map context = new java.util.HashMap();
+ context.put("_fwd", "t");
+ twoway.initiateCallback(twowayR, context);
+ test(callbackReceiverImpl.callbackOK());
+ System.out.println("ok");
+ }
+
+ {
+ System.out.print("ditto, but with user exception... ");
+ System.out.flush();
+ java.util.Map context = new java.util.HashMap();
+ context.put("_fwd", "t");
+ try
+ {
+ twoway.initiateCallbackEx(twowayR, context);
+ test(false);
+ }
+ catch (CallbackException ex)
+ {
+ test(ex.someValue == 3.14);
+ test(ex.someString.equals("3.14"));
+ }
+ test(callbackReceiverImpl.callbackOK());
+ System.out.println("ok");
+ }
+
+ System.out.print("testing server shutdown... ");
+ System.out.flush();
+ twoway.shutdown();
+ // No ping, otherwise the glacier router prints a warning
+ // message if it's started with --Ice.ConnectionWarnings.
+ System.out.println("ok");
+ /*
+ try
+ {
+ twoway.ice_ping();
+ test(false);
+ }
+ // If we use the glacier router, the exact exception reason gets
+ // lost.
+ //catch (Ice.ConnectFailedException ex)
+ catch (Ice.UnknownLocalException ex)
+ {
+ System.out.println("ok");
+ }
+ */
+
+ System.out.print("shutting down glacier router... ");
+ System.out.flush();
+ router.shutdown();
+ // No ping, otherwise the glacier router prints a warning
+ // message if it's started with --Ice.ConnectionWarnings.
+ System.out.println("ok");
+ try
+ {
+ router.ice_ping();
+ test(false);
+ }
+ catch (Ice.ConnectFailedException ex)
+ {
+ System.out.println("ok");
+ }
+
+ return 0;
+ }
+
+ private static void
+ test(boolean b)
+ {
+ if (!b)
+ {
+ throw new RuntimeException();
+ }
+ }
+}
diff --git a/java/test/Glacier/starter/CallbackI.java b/java/test/Glacier/starter/CallbackI.java
new file mode 100644
index 00000000000..807c9a22093
--- /dev/null
+++ b/java/test/Glacier/starter/CallbackI.java
@@ -0,0 +1,38 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+final class CallbackI extends Callback
+{
+ CallbackI(Ice.Communicator communicator)
+ {
+ _communicator = communicator;
+ }
+
+ public void
+ initiateCallback(CallbackReceiverPrx proxy, Ice.Current current)
+ {
+ proxy.callback(current.context);
+ }
+
+ public void
+ initiateCallbackEx(CallbackReceiverPrx proxy, Ice.Current current)
+ throws CallbackException
+ {
+ proxy.callbackEx(current.context);
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ _communicator.shutdown();
+ }
+
+ private Ice.Communicator _communicator;
+}
diff --git a/java/test/Glacier/starter/CallbackReceiverI.java b/java/test/Glacier/starter/CallbackReceiverI.java
new file mode 100644
index 00000000000..12fa512cb25
--- /dev/null
+++ b/java/test/Glacier/starter/CallbackReceiverI.java
@@ -0,0 +1,60 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+final class CallbackReceiverI extends CallbackReceiver
+{
+ CallbackReceiverI()
+ {
+ _callback = false;
+ }
+
+ public synchronized void
+ callback(Ice.Current current)
+ {
+ assert(!_callback);
+ _callback = true;
+ notify();
+ }
+
+ public void
+ callbackEx(Ice.Current current)
+ throws CallbackException
+ {
+ callback(current);
+ CallbackException ex = new CallbackException();
+ ex.someValue = 3.14;
+ ex.someString = "3.14";
+ throw ex;
+ }
+
+ synchronized boolean
+ callbackOK()
+ {
+ while (!_callback)
+ {
+ try
+ {
+ wait(5000);
+ if (!_callback)
+ {
+ return false;
+ }
+ }
+ catch (InterruptedException ex)
+ {
+ }
+ }
+
+ _callback = false;
+ return true;
+ }
+
+ private boolean _callback;
+}
diff --git a/java/test/Glacier/starter/CallbackServer.java b/java/test/Glacier/starter/CallbackServer.java
new file mode 100644
index 00000000000..1a702cbb8cd
--- /dev/null
+++ b/java/test/Glacier/starter/CallbackServer.java
@@ -0,0 +1,24 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class CallbackServer extends Ice.Application
+{
+ public int
+ run(String[] args)
+ {
+ String endpts = "tcp -p 12345 -t 2000";
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints("CallbackAdapter", endpts);
+ CallbackPrx self = CallbackPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("callback")));
+ adapter.add(new CallbackI(communicator()), Ice.Util.stringToIdentity("callback"));
+ adapter.activate();
+ communicator().waitForShutdown();
+ return 0;
+ }
+}
diff --git a/java/test/Glacier/starter/Client.java b/java/test/Glacier/starter/Client.java
new file mode 100644
index 00000000000..52eecd3a7a3
--- /dev/null
+++ b/java/test/Glacier/starter/Client.java
@@ -0,0 +1,20 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+public class Client
+{
+ public static void
+ main(String[] args)
+ {
+ CallbackClient app = new CallbackClient();
+ int status = app.main("Client", args);
+ System.exit(status);
+ }
+}
diff --git a/java/test/Glacier/starter/Server.java b/java/test/Glacier/starter/Server.java
new file mode 100644
index 00000000000..43248a3150d
--- /dev/null
+++ b/java/test/Glacier/starter/Server.java
@@ -0,0 +1,20 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+public class Server
+{
+ public static void
+ main(String[] args)
+ {
+ CallbackServer app = new CallbackServer();
+ int status = app.main("Server", args);
+ System.exit(status);
+ }
+}
diff --git a/java/test/Glacier/starter/build.xml b/java/test/Glacier/starter/build.xml
new file mode 100644
index 00000000000..26172698dcc
--- /dev/null
+++ b/java/test/Glacier/starter/build.xml
@@ -0,0 +1,44 @@
+<project name="test_Glacier_starter" default="all" basedir=".">
+
+ <!-- set global properties for this build -->
+ <property name="top.dir" value="../../.."/>
+ <property name="lib.dir" value="${top.dir}/lib"/>
+ <property name="class.dir" value="classes"/>
+ <property name="generated.dir" value="generated"/>
+ <property name="tags.dir" value="${generated.dir}/.tags"/>
+
+ <!-- install slice2java task -->
+ <taskdef name="slice2java" classpath="${top.dir}/ant"
+ classname="Slice2JavaTask" />
+
+ <target name="init">
+ <!-- Create the time stamp -->
+ <tstamp/>
+ </target>
+
+ <target name="generate" depends="init">
+ <!-- Create the output directory for generated code -->
+ <mkdir dir="${generated.dir}"/>
+ <mkdir dir="${tags.dir}"/>
+ <slice2java tagdir="${tags.dir}" outputdir="${generated.dir}">
+ <fileset dir="." includes="Callback.ice"/>
+ </slice2java>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}"
+ source="1.4" classpath="${lib.dir}" debug="${debug}"/>
+ <javac srcdir="." destdir="${class.dir}" source="1.4"
+ classpath="${lib.dir}" excludes="generated/**" debug="${debug}"/>
+ </target>
+
+ <target name="all" depends="compile"/>
+
+ <target name="clean">
+ <delete dir="${tags.dir}"/>
+ <delete dir="${generated.dir}"/>
+ <delete dir="${class.dir}"/>
+ </target>
+
+</project>
diff --git a/java/test/Glacier/starter/run.py b/java/test/Glacier/starter/run.py
new file mode 100755
index 00000000000..579ef18ca60
--- /dev/null
+++ b/java/test/Glacier/starter/run.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2001
+# MutableRealms, Inc.
+# Huntsville, AL, USA
+#
+# All Rights Reserved
+#
+# **********************************************************************
+
+import os, sys
+
+for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
+ toplevel = os.path.normpath(toplevel)
+ if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")):
+ break
+else:
+ raise "can't find toplevel directory!"
+
+sys.path.append(os.path.join(toplevel, "config"))
+import TestUtil
+
+#
+# SSL isn't supported in Java
+#
+#if TestUtil.protocol != "ssl":
+# print "This test may only be run using the SSL protocol."
+# sys.exit(0)
+
+if not os.environ.has_key('ICE_HOME'):
+ print "ICE_HOME is not defined."
+ sys.exit(0)
+
+ice_home = os.environ['ICE_HOME']
+
+starter = os.path.join(ice_home, "bin", "glacierstarter")
+router = os.path.join(ice_home, "bin", "glacier")
+
+updatedServerOptions = TestUtil.serverOptions.replace("TOPLEVELDIR", toplevel)
+updatedClientOptions = TestUtil.clientOptions.replace("TOPLEVELDIR", toplevel)
+updatedClientServerOptions = TestUtil.clientServerOptions.replace("TOPLEVELDIR", toplevel)
+
+command = starter + updatedClientServerOptions + \
+ r' --Ice.PrintProcessId' \
+ r' --Glacier.Starter.RouterPath=' + router + \
+ r' --Glacier.Starter.Endpoints="default -p 12346 -t 5000"' + \
+ r' --Glacier.Router.Endpoints="default"' + \
+ r' --Glacier.Client.Endpoints="default"' + \
+ r' --Glacier.Server.Endpoints="tcp"' + \
+ r' --Glacier.Starter.Certificate.Country=US' + \
+ r' --Glacier.Starter.Certificate.StateProvince=Alabama' + \
+ r' --Glacier.Starter.Certificate.Locality=Huntsville' + \
+ r' --Glacier.Starter.Certificate.Organization="Mutable Realms"' + \
+ r' --Glacier.Starter.Certificate.OrganizationalUnit="Ice Age Game"' + \
+ r' --Glacier.Starter.Certificate.CommonName="Ice Age Certificate"' + \
+ r' --Glacier.Starter.Certificate.BitStrength=1024' + \
+ r' --Glacier.Starter.Certificate.SecondsValid=31536000'
+
+print "starting glacier starter...",
+starterPipe = os.popen(command)
+TestUtil.getServerPid(starterPipe)
+TestUtil.getAdapterReady(starterPipe)
+print "ok"
+
+name = os.path.join("Glacier", "starter")
+TestUtil.clientServerHybridTest(toplevel, name)
+
+print "shutting down glacier starter...",
+TestUtil.killServers() # TODO: Graceful shutdown
+print "ok"
+
+sys.exit(0)
diff --git a/java/test/build.xml b/java/test/build.xml
index 2b0be8194a1..34c03f644c7 100644
--- a/java/test/build.xml
+++ b/java/test/build.xml
@@ -4,12 +4,14 @@
<ant dir="Ice"/>
<ant dir="IceXML"/>
<ant dir="Freeze"/>
+ <ant dir="Glacier"/>
</target>
<target name="clean">
<ant dir="Ice" target="clean"/>
<ant dir="IceXML" target="clean"/>
<ant dir="Freeze" target="clean"/>
+ <ant dir="Glacier" target="clean"/>
</target>
</project>