diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-01-10 10:22:43 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-01-10 10:22:43 +0000 |
commit | 26c33e45e09f6c635f6a663f05e9edb51f5461ef (patch) | |
tree | 55caad6a4594a51899948b9451171098dbc7fb1e /cs | |
parent | Win32 fix (diff) | |
download | ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.tar.bz2 ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.tar.xz ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.zip |
Fixed bug 1650
Diffstat (limited to 'cs')
-rwxr-xr-x | cs/allTests.py | 1 | ||||
-rwxr-xr-x | cs/src/Ice/ConnectionI.cs | 59 | ||||
-rwxr-xr-x | cs/src/Ice/Incoming.cs | 316 | ||||
-rwxr-xr-x | cs/src/Ice/IncomingAsync.cs | 239 | ||||
-rw-r--r-- | cs/test/Ice/Makefile | 3 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/AllTests.cs | 187 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Client.cs | 33 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Collocated.cs | 41 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/CookieI.cs | 18 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/Makefile | 44 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/Makefile.mak | 39 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/ServantLocatorI.cs | 135 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Server.cs | 39 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Test.ice | 40 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/TestAMD.ice | 40 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/TestAMDI.cs | 54 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/TestI.cs | 46 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/generated/.dummy | 0 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/run.py | 32 |
19 files changed, 959 insertions, 407 deletions
diff --git a/cs/allTests.py b/cs/allTests.py index 7bc216e0de6..5505265a20a 100755 --- a/cs/allTests.py +++ b/cs/allTests.py @@ -63,6 +63,7 @@ tests = [ \ "Ice/stream", \ "Ice/retry", \ "Ice/timeout", \ + "Ice/servantLocator", \ # "IceSSL/configuration", \ # Commented out for the moment because it fails with Mono 1.2 "Glacier2/router", \ "Glacier2/attack", \ diff --git a/cs/src/Ice/ConnectionI.cs b/cs/src/Ice/ConnectionI.cs index d508b92f6f5..258ea94ebf4 100755 --- a/cs/src/Ice/ConnectionI.cs +++ b/cs/src/Ice/ConnectionI.cs @@ -1339,6 +1339,30 @@ namespace Ice } } + public void invokeException(LocalException ex, int invokeNum) + { + // + // Fatal exception while invoking a request. Since sendResponse/sendNoResponse isn't + // called in case of a fatal exception we decrement _dispatchCount here. + // + + lock(this) + { + setState(StateClosed, ex); + + if(invokeNum > 0) + { + Debug.Assert(_dispatchCount > 0); + _dispatchCount -= invokeNum; + Debug.Assert(_dispatchCount >= 0); + if(_dispatchCount == 0) + { + Monitor.PulseAll(this); + } + } + } + } + public string type() { return _type; // No mutex lock, _type is immutable. @@ -2030,19 +2054,7 @@ namespace Ice } catch(LocalException ex) { - lock(this) - { - setState(StateClosed, ex); - } - } - catch(System.Exception ex) - { - lock(this) - { - UnknownException uex = new UnknownException(); - uex.unknown = ex.ToString(); - setState(StateClosed, uex); - } + invokeException(ex, invokeNum); } finally { @@ -2050,26 +2062,7 @@ namespace Ice { reclaimIncoming(inc); } - } - - // - // If invoke() above raised an exception, and therefore - // neither sendResponse() nor sendNoResponse() has been - // called, then we must decrement _dispatchCount here. - // - if(invokeNum > 0) - { - lock(this) - { - Debug.Assert(_dispatchCount > 0); - _dispatchCount -= invokeNum; - Debug.Assert(_dispatchCount >= 0); - if(_dispatchCount == 0) - { - Monitor.PulseAll(this); - } - } - } + } } private void run() diff --git a/cs/src/Ice/Incoming.cs b/cs/src/Ice/Incoming.cs index 3094e45dacc..03b39760b6a 100755 --- a/cs/src/Ice/Incoming.cs +++ b/cs/src/Ice/Incoming.cs @@ -119,158 +119,16 @@ namespace IceInternal os_.instance().initializationData().logger.warning(sw.ToString()); } } - - protected internal Ice.Current current_; - protected internal Ice.Object servant_; - protected internal Ice.ServantLocator locator_; - protected internal Ice.LocalObject cookie_; - - protected internal bool response_; - protected internal byte compress_; - - protected internal BasicStream os_; - - protected Ice.ConnectionI connection_; - } - - sealed public class Incoming : IncomingBase - { - public Incoming(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, - bool response, byte compress, int requestId) - : base(instance, connection, adapter, response, compress, requestId) - { - _is = new BasicStream(instance); - } - - // - // These functions allow this object to be reused, rather than reallocated. - // - public override void reset(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, - bool response, byte compress, int requestId) - { - if(_is == null) - { - _is = new BasicStream(instance); - } - - base.reset(instance, connection, adapter, response, compress, requestId); - } - - public override void reclaim() - { - if(_is != null) - { - _is.reset(); - } - - base.reclaim(); - } - - public void invoke(ServantManager servantManager) - { - // - // Read the current. - // - current_.id.read__(_is); - - // - // For compatibility with the old FacetPath. - // - string[] facetPath = _is.readStringSeq(); - if(facetPath.Length > 0) - { - if(facetPath.Length > 1) - { - throw new Ice.MarshalException(); - } - current_.facet = facetPath[0]; - } - else - { - current_.facet = ""; - } - current_.operation = _is.readString(); - current_.mode = (Ice.OperationMode)(int)_is.readByte(); - int sz = _is.readSize(); - while(sz-- > 0) - { - string first = _is.readString(); - string second = _is.readString(); - if(current_.ctx == null) - { - current_.ctx = new Ice.Context(); - } - current_.ctx[first] = second; - } - - _is.startReadEncaps(); - - if(response_) - { - Debug.Assert(os_.size() == Protocol.headerSize + 4); // Dispatch status position. - os_.writeByte((byte)0); - os_.startWriteEncaps(); - } - - // Initialize status to some value, to keep the compiler happy. - DispatchStatus status = DispatchStatus.DispatchOK; - - // - // Don't put the code above into the try block below. Exceptions - // in the code above are considered fatal, and must propagate to - // the caller of this operation. - // - + protected internal void handleException__(System.Exception exc) + { try { - try - { - if(servantManager != null) - { - servant_ = servantManager.findServant(current_.id, current_.facet); - if(servant_ == null) - { - locator_ = servantManager.findServantLocator(current_.id.category); - if(locator_ == null && current_.id.category.Length > 0) - { - locator_ = servantManager.findServantLocator(""); - } - if(locator_ != null) - { - servant_ = locator_.locate(current_, out cookie_); - } - } - } - if(servant_ == null) - { - if(servantManager != null && servantManager.hasServant(current_.id)) - { - status = DispatchStatus.DispatchFacetNotExist; - } - else - { - status = DispatchStatus.DispatchObjectNotExist; - } - } - else - { - status = servant_.dispatch__(this, current_); - } - } - finally - { - if(locator_ != null && servant_ != null && status != DispatchStatus.DispatchAsync) - { - locator_.finished(current_, servant_, cookie_); - } - } + throw exc; } catch(Ice.RequestFailedException ex) { - _is.endReadEncaps(); - - if(ex.id.name == null) + if(ex.id == null) { ex.id = current_.id; } @@ -339,8 +197,6 @@ namespace IceInternal } catch(Ice.UnknownLocalException ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -364,8 +220,6 @@ namespace IceInternal } catch(Ice.UnknownUserException ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -389,8 +243,6 @@ namespace IceInternal } catch(Ice.UnknownException ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -414,8 +266,6 @@ namespace IceInternal } catch(Ice.LocalException ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -440,8 +290,6 @@ namespace IceInternal catch(Ice.UserException ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -466,8 +314,6 @@ namespace IceInternal catch(System.Exception ex) { - _is.endReadEncaps(); - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 0) { @@ -489,6 +335,160 @@ namespace IceInternal return; } + } + + protected internal Ice.Current current_; + protected internal Ice.Object servant_; + protected internal Ice.ServantLocator locator_; + protected internal Ice.LocalObject cookie_; + + protected internal bool response_; + protected internal byte compress_; + + protected internal BasicStream os_; + + protected Ice.ConnectionI connection_; + } + + sealed public class Incoming : IncomingBase + { + public Incoming(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, + bool response, byte compress, int requestId) + : base(instance, connection, adapter, response, compress, requestId) + { + _is = new BasicStream(instance); + } + + // + // These functions allow this object to be reused, rather than reallocated. + // + public override void reset(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, + bool response, byte compress, int requestId) + { + if(_is == null) + { + _is = new BasicStream(instance); + } + + base.reset(instance, connection, adapter, response, compress, requestId); + } + + public override void reclaim() + { + if(_is != null) + { + _is.reset(); + } + + base.reclaim(); + } + + public void invoke(ServantManager servantManager) + { + // + // Read the current. + // + current_.id.read__(_is); + + // + // For compatibility with the old FacetPath. + // + string[] facetPath = _is.readStringSeq(); + if(facetPath.Length > 0) + { + if(facetPath.Length > 1) + { + throw new Ice.MarshalException(); + } + current_.facet = facetPath[0]; + } + else + { + current_.facet = ""; + } + + current_.operation = _is.readString(); + current_.mode = (Ice.OperationMode)(int)_is.readByte(); + int sz = _is.readSize(); + while(sz-- > 0) + { + string first = _is.readString(); + string second = _is.readString(); + if(current_.ctx == null) + { + current_.ctx = new Ice.Context(); + } + current_.ctx[first] = second; + } + + _is.startReadEncaps(); + + if(response_) + { + Debug.Assert(os_.size() == Protocol.headerSize + 4); // Dispatch status position. + os_.writeByte((byte)0); + os_.startWriteEncaps(); + } + + // Initialize status to some value, to keep the compiler happy. + DispatchStatus status = DispatchStatus.DispatchOK; + + // + // Don't put the code above into the try block below. Exceptions + // in the code above are considered fatal, and must propagate to + // the caller of this operation. + // + + try + { + try + { + if(servantManager != null) + { + servant_ = servantManager.findServant(current_.id, current_.facet); + if(servant_ == null) + { + locator_ = servantManager.findServantLocator(current_.id.category); + if(locator_ == null && current_.id.category.Length > 0) + { + locator_ = servantManager.findServantLocator(""); + } + if(locator_ != null) + { + servant_ = locator_.locate(current_, out cookie_); + } + } + } + if(servant_ == null) + { + if(servantManager != null && servantManager.hasServant(current_.id)) + { + status = DispatchStatus.DispatchFacetNotExist; + } + else + { + status = DispatchStatus.DispatchObjectNotExist; + } + } + else + { + status = servant_.dispatch__(this, current_); + } + } + finally + { + if(locator_ != null && servant_ != null && status != DispatchStatus.DispatchAsync) + { + locator_.finished(current_, servant_, cookie_); + } + } + } + catch(System.Exception ex) + { + _is.endReadEncaps(); + handleException__(ex); + return; + } // // Don't put the code below into the try block above. Exceptions diff --git a/cs/src/Ice/IncomingAsync.cs b/cs/src/Ice/IncomingAsync.cs index 412729398d7..c77e4f4851e 100755 --- a/cs/src/Ice/IncomingAsync.cs +++ b/cs/src/Ice/IncomingAsync.cs @@ -23,9 +23,9 @@ namespace IceInternal { try { - if(locator_ != null && servant_ != null) + if(!servantLocatorFinished__()) { - locator_.finished(current_, servant_, cookie_); + return; } if(response_) @@ -55,13 +55,7 @@ namespace IceInternal } catch(Ice.LocalException ex) { - connection_.exception(ex); - } - catch(System.Exception ex) - { - Ice.UnknownException uex = new Ice.UnknownException(); - uex.unknown = ex.ToString(); - connection_.exception(uex); + connection_.invokeException(ex, 1); } } @@ -69,218 +63,16 @@ namespace IceInternal { try { - if(locator_ != null && servant_ != null) + if(!servantLocatorFinished__()) { - locator_.finished(current_, servant_, cookie_); + return; } - try - { - throw exc; - } - catch(Ice.RequestFailedException ex) - { - if(ex.id.name == null) - { - ex.id = current_.id; - } - - if(ex.facet == null) - { - ex.facet = current_.facet; - } - - if(ex.operation == null || ex.operation.Length == 0) - { - ex.operation = current_.operation; - } - - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 1) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - if(ex is Ice.ObjectNotExistException) - { - os_.writeByte((byte)DispatchStatus.DispatchObjectNotExist); - } - else if(ex is Ice.FacetNotExistException) - { - os_.writeByte((byte)DispatchStatus.DispatchFacetNotExist); - } - else if(ex is Ice.OperationNotExistException) - { - os_.writeByte((byte)DispatchStatus.DispatchOperationNotExist); - } - else - { - Debug.Assert(false); - } - ex.id.write__(os_); - - // - // For compatibility with the old FacetPath. - // - if(ex.facet == null || ex.facet.Length == 0) - { - os_.writeStringSeq(null); - } - else - { - string[] facetPath = { ex.facet }; - os_.writeStringSeq(facetPath); - } - - os_.writeString(ex.operation); - - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(Ice.UnknownLocalException ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); - os_.writeString(ex.unknown); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(Ice.UnknownUserException ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownUserException); - os_.writeString(ex.unknown); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(Ice.UnknownException ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownException); - os_.writeString(ex.unknown); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(Ice.LocalException ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); - os_.writeString(ex.ToString()); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(Ice.UserException ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownUserException); - os_.writeString(ex.ToString()); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } - catch(System.Exception ex) - { - if(os_.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - warning__(ex); - } - - if(response_) - { - os_.endWriteEncaps(); - os_.resize(Protocol.headerSize + 4, false); // Dispatch status position. - os_.writeByte((byte)DispatchStatus.DispatchUnknownException); - os_.writeString(ex.ToString()); - connection_.sendResponse(os_, compress_); - } - else - { - connection_.sendNoResponse(); - } - } + handleException__(exc); } catch(Ice.LocalException ex) { - connection_.exception(ex); - } - catch(System.Exception ex) - { - Ice.UnknownException uex = new Ice.UnknownException(); - uex.unknown = ex.ToString(); - connection_.exception(uex); + connection_.invokeException(ex, 1); } } @@ -288,6 +80,23 @@ namespace IceInternal { return os_; } + + private bool servantLocatorFinished__() + { + try + { + if(locator_ != null && servant_ != null) + { + locator_.finished(current_, servant_, cookie_); + } + return true; + } + catch(System.Exception ex) + { + handleException__(ex); + return false; + } + } } } diff --git a/cs/test/Ice/Makefile b/cs/test/Ice/Makefile index 1f16f817680..9c3a7db182d 100644 --- a/cs/test/Ice/Makefile +++ b/cs/test/Ice/Makefile @@ -26,7 +26,8 @@ SUBDIRS = application \ checksum \ stream \ retry \ - timeout + timeout \ + servantLocator $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cs/test/Ice/servantLocator/AllTests.cs b/cs/test/Ice/servantLocator/AllTests.cs new file mode 100755 index 00000000000..66754cd5c8b --- /dev/null +++ b/cs/test/Ice/servantLocator/AllTests.cs @@ -0,0 +1,187 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System; +using Test; +using Ice; + +public class AllTests +{ + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public static void testExceptions(TestIntfPrx obj, bool collocated) + { + try + { + obj.requestFailedException(); + test(false); + } + catch(ObjectNotExistException ex) + { + if(!collocated) + { + test(ex.id.Equals(obj.ice_getIdentity())); + test(ex.facet.Equals(obj.ice_getFacet())); + test(ex.operation.Equals("requestFailedException")); + } + } + + try + { + obj.unknownUserException(); + test(false); + } + catch(UnknownUserException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.unknownLocalException(); + test(false); + } + catch(UnknownLocalException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.unknownException(); + test(false); + } + catch(UnknownException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.userException(); + test(false); + } + catch(UnknownUserException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("Test.TestIntfUserException") >= 0); + } + catch(TestIntfUserException) + { + test(collocated); + } + + try + { + obj.localException(); + test(false); + } + catch(UnknownLocalException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("Ice.SocketException") >= 0); + } + catch(SocketException) + { + test(collocated); + } + + try + { + obj.csException(); + test(false); + } + catch(UnknownException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("System.Exception: message") >= 0); + } + catch(System.Exception) + { + test(collocated); + } + } + + public static TestIntfPrx allTests(Ice.Communicator communicator, bool collocated) + { + Console.Out.Write("testing stringToProxy... "); + Console.Out.Flush(); + string @ref = "asm:default -p 12010 -t 2000"; + Ice.ObjectPrx @base = communicator.stringToProxy(@ref); + test(@base != null); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing checked cast... "); + Console.Out.Flush(); + TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); + test(obj != null); + test(obj.Equals(@base)); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing servant locator..."); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing default servant locator..."); + Console.Out.Flush(); + @base = communicator.stringToProxy("anothercat/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + @base = communicator.stringToProxy("locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing locate exceptions... "); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + testExceptions(obj, collocated); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing finished exceptions... "); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/finished:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + testExceptions(obj, collocated); + Console.Out.WriteLine("ok"); + + return obj; + } +} diff --git a/cs/test/Ice/servantLocator/Client.cs b/cs/test/Ice/servantLocator/Client.cs new file mode 100755 index 00000000000..e926daaf993 --- /dev/null +++ b/cs/test/Ice/servantLocator/Client.cs @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using Test; + +public class Client +{ + internal class TestClient : Ice.Application + { + public override int run(string[] args) + { + TestIntfPrx obj = AllTests.allTests(communicator(), false); + obj.shutdown(); + return 0; + } + } + + public static void Main(string[] args) + { + TestClient app = new TestClient(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/Collocated.cs b/cs/test/Ice/servantLocator/Collocated.cs new file mode 100755 index 00000000000..fcb518de41f --- /dev/null +++ b/cs/test/Ice/servantLocator/Collocated.cs @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using Test; + +public class Collocated +{ + internal class TestClient : Ice.Application + { + public override int run(string[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + AllTests.allTests(communicator(), true); + + return 0; + } + } + + public static void Main(string[] args) + { + TestClient app = new TestClient(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/CookieI.cs b/cs/test/Ice/servantLocator/CookieI.cs new file mode 100755 index 00000000000..f225eac92bb --- /dev/null +++ b/cs/test/Ice/servantLocator/CookieI.cs @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using Test; + +public sealed class CookieI : Cookie +{ + public override string message() + { + return "blahblah"; + } +} diff --git a/cs/test/Ice/servantLocator/Makefile b/cs/test/Ice/servantLocator/Makefile new file mode 100644 index 00000000000..522ef811e98 --- /dev/null +++ b/cs/test/Ice/servantLocator/Makefile @@ -0,0 +1,44 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = client.exe server.exe serveramd.exe collocated.exe + +C_SRCS = Client.cs AllTests.cs +S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs +COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs +SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs + +SLICE_SRCS = $(SDIR)/Test.ice +SLICE_AMD_SRCS = $(SDIR)/TestAMD.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) -I. + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +collocated.exe: $(COL_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +serveramd.exe: $(SAMD_SRCS) $(GEN_AMD_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Ice/servantLocator/Makefile.mak b/cs/test/Ice/servantLocator/Makefile.mak new file mode 100644 index 00000000000..2f95cdcc1d0 --- /dev/null +++ b/cs/test/Ice/servantLocator/Makefile.mak @@ -0,0 +1,39 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +TARGETS = client.exe server.exe collocated.exe + +C_SRCS = Client.cs AllTests.cs +S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs +COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs + +GEN_SRCS = $(GDIR)\Test.cs + +SDIR = . + +GDIR = generated + +!include $(top_srcdir)\config\Make.rules.mak + +MCSFLAGS = $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS = $(SLICE2CSFLAGS) -I. + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(C_SRCS) $(GEN_SRCS) + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(S_SRCS) $(GEN_SRCS) + +collocated.exe: $(COL_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(COL_SRCS) $(GEN_SRCS) + +!include .depend diff --git a/cs/test/Ice/servantLocator/ServantLocatorI.cs b/cs/test/Ice/servantLocator/ServantLocatorI.cs new file mode 100755 index 00000000000..1ebb6ae20f6 --- /dev/null +++ b/cs/test/Ice/servantLocator/ServantLocatorI.cs @@ -0,0 +1,135 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System; +using Test; +using Ice; + +public sealed class ServantLocatorI : Ice.LocalObjectImpl, Ice.ServantLocator +{ + public ServantLocatorI(String category) + { + _category = category; + _deactivated = false; + } + + ~ServantLocatorI() + { + lock(this) + { + test(_deactivated); + } + } + + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public Ice.Object locate(Ice.Current current, out Ice.LocalObject cookie) + { + lock(this) + { + test(!_deactivated); + } + + test(current.id.category.Equals(_category) || _category.Length == 0); + + if(current.id.name.Equals("unknown")) + { + cookie = null; + return null; + } + + test(current.id.name.Equals("locate") || current.id.name.Equals("finished")); + if(current.id.name.Equals("locate")) + { + exception(current); + } + + cookie = new CookieI(); + + return new TestI(); + } + + public void finished(Ice.Current current, Ice.Object servant, Ice.LocalObject cookie) + { + lock(this) + { + test(!_deactivated); + } + + test(current.id.category.Equals(_category) || _category.Length == 0); + test(current.id.name.Equals("locate") || current.id.name.Equals("finished")); + + if(current.id.name.Equals("finished")) + { + exception(current); + } + + Cookie co = (Cookie) cookie; + test(co.message().Equals("blahblah")); + } + + public void deactivate(string category) + { + lock(this) + { + test(!_deactivated); + + _deactivated = true; + } + } + + private void exception(Ice.Current current) + { + if(current.operation.Equals("requestFailedException")) + { + throw new ObjectNotExistException(); + } + else if(current.operation.Equals("unknownUserException")) + { + UnknownUserException ex = new UnknownUserException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("unknownLocalException")) + { + UnknownLocalException ex = new UnknownLocalException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("unknownException")) + { + UnknownException ex = new UnknownException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("userException")) + { + throw new TestIntfUserException(); + } + else if(current.operation.Equals("localException")) + { + SocketException ex = new SocketException(); + ex.error = 0; + throw ex; + } + else if(current.operation.Equals("csException")) + { + throw new System.Exception("message"); + } + } + + private bool _deactivated; + private string _category; +} diff --git a/cs/test/Ice/servantLocator/Server.cs b/cs/test/Ice/servantLocator/Server.cs new file mode 100755 index 00000000000..6280e1373d4 --- /dev/null +++ b/cs/test/Ice/servantLocator/Server.cs @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + internal class TestServer : Ice.Application + { + public override int run(string[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 2000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + adapter.activate(); + adapter.waitForDeactivate(); + return 0; + } + } + + public static void Main(string[] args) + { + TestServer app = new TestServer(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/Test.ice b/cs/test/Ice/servantLocator/Test.ice new file mode 100755 index 00000000000..82f3679d75f --- /dev/null +++ b/cs/test/Ice/servantLocator/Test.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 +{ + +exception TestIntfUserException +{ +}; + +interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + void userException(); + void csException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/cs/test/Ice/servantLocator/TestAMD.ice b/cs/test/Ice/servantLocator/TestAMD.ice new file mode 100644 index 00000000000..fdd81edd0db --- /dev/null +++ b/cs/test/Ice/servantLocator/TestAMD.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 +{ + +exception TestIntfUserException +{ +}; + +["amd"] interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + void userException(); + void csException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/cs/test/Ice/servantLocator/TestAMDI.cs b/cs/test/Ice/servantLocator/TestAMDI.cs new file mode 100644 index 00000000000..555c6ada355 --- /dev/null +++ b/cs/test/Ice/servantLocator/TestAMDI.cs @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using Test; + +public sealed class TestI : TestIntfDisp_ +{ + public override void requestFailedException_async(AMD_TestIntf_requestFailedException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownUserException_async(AMD_TestIntf_unknownUserException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownLocalException_async(AMD_TestIntf_unknownLocalException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownException_async(AMD_TestIntf_unknownException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void localException_async(AMD_TestIntf_localException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void userException_async(AMD_TestIntf_userException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void csException_async(AMD_TestIntf_csException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void shutdown_async(AMD_TestIntf_shutdown cb, Ice.Current current) + { + current.adapter.deactivate(); + cb.ice_response(); + } +} diff --git a/cs/test/Ice/servantLocator/TestI.cs b/cs/test/Ice/servantLocator/TestI.cs new file mode 100755 index 00000000000..85f67a82bf7 --- /dev/null +++ b/cs/test/Ice/servantLocator/TestI.cs @@ -0,0 +1,46 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using Test; + +public sealed class TestI : TestIntfDisp_ +{ + public override void requestFailedException(Ice.Current current) + { + } + + public override void unknownUserException(Ice.Current current) + { + } + + public override void unknownLocalException(Ice.Current current) + { + } + + public override void unknownException(Ice.Current current) + { + } + + public override void localException(Ice.Current current) + { + } + + public override void userException(Ice.Current current) + { + } + + public override void csException(Ice.Current current) + { + } + + public override void shutdown(Ice.Current current) + { + current.adapter.deactivate(); + } +} diff --git a/cs/test/Ice/servantLocator/generated/.dummy b/cs/test/Ice/servantLocator/generated/.dummy new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cs/test/Ice/servantLocator/generated/.dummy diff --git a/cs/test/Ice/servantLocator/run.py b/cs/test/Ice/servantLocator/run.py new file mode 100755 index 00000000000..f5d55842c4b --- /dev/null +++ b/cs/test/Ice/servantLocator/run.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys, getopt + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Ice", "servantLocator") + +print "tests with regular server." +TestUtil.clientServerTest(name) +print "tests with AMD server." +TestUtil.clientServerTestWithOptionsAndNames(name, "", "", "serveramd", "client") +print "tests with collocated server." +TestUtil.collocatedTest(name) + +sys.exit(0) |