diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-11-26 14:18:59 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-11-26 14:18:59 -0330 |
commit | eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c (patch) | |
tree | b0abd1a4d60e7842b1b74ac8c9bbb02797db8a8b /java/test/Ice/invoke | |
parent | Removed getCookie from C# AsyncResult (diff) | |
download | ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.tar.bz2 ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.tar.xz ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.zip |
Added invoke test
Cleaned up invoke demo
Fixed order of paramaters in end_ice_invoke in C++
Diffstat (limited to 'java/test/Ice/invoke')
-rw-r--r-- | java/test/Ice/invoke/AllTests.java | 355 | ||||
-rw-r--r-- | java/test/Ice/invoke/BlobjectAsyncI.java | 62 | ||||
-rw-r--r-- | java/test/Ice/invoke/BlobjectI.java | 65 | ||||
-rw-r--r-- | java/test/Ice/invoke/Client.java | 40 | ||||
-rw-r--r-- | java/test/Ice/invoke/ServantLocatorI.java | 43 | ||||
-rw-r--r-- | java/test/Ice/invoke/Server.java | 48 | ||||
-rw-r--r-- | java/test/Ice/invoke/Test.ice | 32 | ||||
-rwxr-xr-x | java/test/Ice/invoke/run.py | 28 |
8 files changed, 673 insertions, 0 deletions
diff --git a/java/test/Ice/invoke/AllTests.java b/java/test/Ice/invoke/AllTests.java new file mode 100644 index 00000000000..c5555231f0c --- /dev/null +++ b/java/test/Ice/invoke/AllTests.java @@ -0,0 +1,355 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.invoke; +import java.io.PrintWriter; + +import test.Ice.invoke.Test.MyClassPrx; +import test.Ice.invoke.Test.MyClassPrxHelper; +import test.Ice.invoke.Test.MyException; + +public class AllTests +{ + final static String testString = "This is a test string"; + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + private static class Callback + { + Callback() + { + _called = false; + } + + public synchronized void check() + { + while(!_called) + { + try + { + wait(); + } + catch(InterruptedException ex) + { + } + } + + _called = false; + } + + public synchronized void called() + { + assert(!_called); + _called = true; + notify(); + } + + private boolean _called; + } + + private static class opStringI extends Ice.AsyncCallback + { + public opStringI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void completed(Ice.AsyncResult result) + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(result.getProxy().end_ice_invoke(outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + callback.called(); + } + else + { + test(false); + } + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class opExceptionI extends Ice.AsyncCallback + { + public opExceptionI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void completed(Ice.AsyncResult result) + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(result.getProxy().end_ice_invoke(outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + callback.called(); + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class Callback_Object_opStringI extends Ice.Callback_Object_ice_invoke + { + public Callback_Object_opStringI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void response(boolean ok, byte[] outParams) + { + if(ok) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + callback.called(); + } + else + { + test(false); + } + } + + @Override + public void exception(Ice.LocalException ex) + { + test(false); + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class Callback_Object_opExceptionI extends Ice.Callback_Object_ice_invoke + { + public Callback_Object_opExceptionI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void response(boolean ok, byte[] outParams) + { + if(ok) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + callback.called(); + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + @Override + public void exception(Ice.LocalException ex) + { + test(false); + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + public static MyClassPrx + allTests(Ice.Communicator communicator, PrintWriter out) + { + String ref = "test:default -p 12010"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + MyClassPrx cl = MyClassPrxHelper.checkedCast(base); + + out.print("testing ice_invoke... "); + out.flush(); + + { + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + byte[] inParams = outS.finished(); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.ice_invoke("opString", Ice.OperationMode.Normal, inParams, outParams)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + } + else + { + test(false); + } + } + + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.ice_invoke("opException", Ice.OperationMode.Normal, null, outParams)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + out.println("ok"); + + out.print("testing asynchronous ice_invoke... "); + out.flush(); + + { + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + byte[] inParams = outS.finished(); + + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.end_ice_invoke(outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + } + else + { + test(false); + } + + // begin_ice_invoke with Callback + opStringI cb1 = new opStringI(communicator); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb1); + cb1.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + Callback_Object_opStringI cb2 = new Callback_Object_opStringI(communicator); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb2); + cb2.check(); + } + + { + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.end_ice_invoke(outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + } + catch(java.lang.Exception ex) + { + test(false); + } + } + + // begin_ice_invoke with Callback + opExceptionI cb1 = new opExceptionI(communicator); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb1); + cb1.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + Callback_Object_opExceptionI cb2 = new Callback_Object_opExceptionI(communicator); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb2); + cb2.check(); + } + + out.println("ok"); + + return cl; + } +} diff --git a/java/test/Ice/invoke/BlobjectAsyncI.java b/java/test/Ice/invoke/BlobjectAsyncI.java new file mode 100644 index 00000000000..07f00734d13 --- /dev/null +++ b/java/test/Ice/invoke/BlobjectAsyncI.java @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyException; + +public class BlobjectAsyncI extends Ice.BlobjectAsync +{ + public void + ice_invoke_async(Ice.AMD_Object_ice_invoke cb, byte[] inParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream in = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + if(current.operation.equals("opString")) + { + String s = in.readString(); + out.writeString(s); + out.writeString(s); + cb.ice_response(true, out.finished()); + } + else if(current.operation.equals("opException")) + { + MyException ex = new MyException(); + out.writeException(ex); + cb.ice_response(false, out.finished()); + } + else if(current.operation.equals("shutdown")) + { + communicator.shutdown(); + cb.ice_response(true, null); + } + else if(current.operation.equals("ice_isA")) + { + String s = in.readString(); + if(s.equals("::Test::MyClass")) + { + out.writeBool(true); + } + else + { + out.writeBool(false); + } + cb.ice_response(true, out.finished()); + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} diff --git a/java/test/Ice/invoke/BlobjectI.java b/java/test/Ice/invoke/BlobjectI.java new file mode 100644 index 00000000000..e667155af05 --- /dev/null +++ b/java/test/Ice/invoke/BlobjectI.java @@ -0,0 +1,65 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyException; + +public class BlobjectI extends Ice.Blobject +{ + public boolean + ice_invoke(byte[] inParams, Ice.ByteSeqHolder outParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream in = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + if(current.operation.equals("opString")) + { + String s = in.readString(); + out.writeString(s); + out.writeString(s); + outParams.value = out.finished(); + return true; + } + else if(current.operation.equals("opException")) + { + MyException ex = new MyException(); + out.writeException(ex); + outParams.value = out.finished(); + return false; + } + else if(current.operation.equals("shutdown")) + { + communicator.shutdown(); + return true; + } + else if(current.operation.equals("ice_isA")) + { + String s = in.readString(); + if(s.equals("::Test::MyClass")) + { + out.writeBool(true); + } + else + { + out.writeBool(false); + } + outParams.value = out.finished(); + return true; + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} diff --git a/java/test/Ice/invoke/Client.java b/java/test/Ice/invoke/Client.java new file mode 100644 index 00000000000..b987c4e3348 --- /dev/null +++ b/java/test/Ice/invoke/Client.java @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyClassPrx; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + MyClassPrx myClass = AllTests.allTests(communicator(), getWriter()); + myClass.shutdown(); + + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.invoke"); + return initData; + } + + public static void main(String[] args) + { + Client c = new Client(); + int status = c.main("Client", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/invoke/ServantLocatorI.java b/java/test/Ice/invoke/ServantLocatorI.java new file mode 100644 index 00000000000..1e8cd3a3325 --- /dev/null +++ b/java/test/Ice/invoke/ServantLocatorI.java @@ -0,0 +1,43 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +public class ServantLocatorI implements Ice.ServantLocator +{ + public ServantLocatorI( boolean async) + { + if(async) + { + _blobject = new BlobjectAsyncI(); + } + else + { + _blobject = new BlobjectI(); + } + } + + public Ice.Object + locate(Ice.Current current, Ice.LocalObjectHolder cookie) + { + return _blobject; + } + + public void + finished(Ice.Current current, Ice.Object servant, java.lang.Object cookie) + { + } + + public void + deactivate(String category) + { + } + + private Ice.Object _blobject; +} diff --git a/java/test/Ice/invoke/Server.java b/java/test/Ice/invoke/Server.java new file mode 100644 index 00000000000..2cf3bb7cdc2 --- /dev/null +++ b/java/test/Ice/invoke/Server.java @@ -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. +// +// ********************************************************************** + +package test.Ice.invoke; + +public class Server extends test.Util.Application +{ + public int run(String[] args) + { + boolean async = false; + for(int i = 0; i < args.length; ++i) + { + if(args[i].equals("--async")) + { + async = true; + } + } + + communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI(async), ""); + adapter.activate(); + return WAIT; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.invoke"); + return initData; + } + + public static void main(String[] args) + { + Server c = new Server(); + int status = c.main("Server", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/invoke/Test.ice b/java/test/Ice/invoke/Test.ice new file mode 100644 index 00000000000..77492c307db --- /dev/null +++ b/java/test/Ice/invoke/Test.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// 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 + +[["java:package:test.Ice.invoke"]] +module Test +{ + +exception MyException +{ +}; + +class MyClass +{ + string opString(string s1, out string s2); + + void opException() throws MyException; + + void shutdown(); +}; + +}; + +#endif diff --git a/java/test/Ice/invoke/run.py b/java/test/Ice/invoke/run.py new file mode 100755 index 00000000000..47f6323efaa --- /dev/null +++ b/java/test/Ice/invoke/run.py @@ -0,0 +1,28 @@ +#!/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 Blobject server." +TestUtil.clientServerTest() + +print "tests with BlobjectAsync server." +TestUtil.clientServerTest(additionalServerOptions = "--async") + |