private void TestInterceptorExceptions(IMyObjectPrx prx) { var exceptions = new List <(string operation, string kind)> { ("raiseBeforeDispatch", "invalidInput"), ("raiseBeforeDispatch", "notExist"), ("raiseAfterDispatch", "invalidInput"), ("raiseAfterDispatch", "notExist") }; foreach ((string operation, string kind) in exceptions) { var ctx = new Dictionary <string, string> { { operation, kind } }; try { prx.IcePing(ctx); Assert(false); } catch (InvalidInputException) when(kind.Equals("invalidInput")) { } catch (ObjectNotExistException) when(kind.Equals("notExist")) { } } }
private void runTest(IMyObjectPrx prx, Interceptor interceptor) { System.IO.TextWriter output = GetWriter(); output.Write("testing simple interceptor... "); output.Flush(); Assert(interceptor.getLastOperation() == null); Assert(!interceptor.AsyncCompletion); prx.IcePing(); Assert(interceptor.getLastOperation() !.Equals("ice_ping")); Assert(!interceptor.AsyncCompletion); string typeId = prx.IceId(); Assert(interceptor.getLastOperation() !.Equals("ice_id")); Assert(!interceptor.AsyncCompletion); Assert(prx.IceIsA(typeId)); Assert(interceptor.getLastOperation() !.Equals("ice_isA")); Assert(!interceptor.AsyncCompletion); Assert(prx.add(33, 12) == 45); Assert(interceptor.getLastOperation() !.Equals("add")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing retry... "); output.Flush(); Assert(prx.addWithRetry(33, 12) == 45); Assert(interceptor.getLastOperation() !.Equals("addWithRetry")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing remote exception... "); output.Flush(); try { prx.badAdd(33, 12); Assert(false); } catch (InvalidInputException) { // expected } Assert(interceptor.getLastOperation() !.Equals("badAdd")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing ONE... "); output.Flush(); interceptor.clear(); try { prx.notExistAdd(33, 12); Assert(false); } catch (ObjectNotExistException) { // expected } Assert(interceptor.getLastOperation() !.Equals("notExistAdd")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing exceptions raised by the interceptor... "); output.Flush(); TestInterceptorExceptions(prx); output.WriteLine("ok"); }
allTests(global::Test.TestHelper helper) { var output = helper.getWriter(); Communicator communicator = helper.communicator(); ObjectAdapter oa = communicator.CreateObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.Activate(); var servantI = new MyObject(); Disp servantD = (servantI as IObject).Dispatch; // // Register default servant with category "foo" // oa.AddDefaultServant(servantD, "foo"); // // Start test // output.Write("testing single category... "); output.Flush(); Disp r = oa.FindDefaultServant("foo"); test(r == servantD); r = oa.FindDefaultServant("bar"); test(r == null); Identity identity = new Identity("", "foo"); string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; IMyObjectPrx prx = null; for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.getName() == names[idx]); } identity = new Identity("ObjectNotExist", identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (ObjectNotExistException) { // Expected } identity = new Identity("FacetNotExist", identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (FacetNotExistException) { // Expected } try { prx.getName(); test(false); } catch (FacetNotExistException) { // Expected } identity = new Identity(identity.Name, "bar"); for (int idx = 0; idx < 5; idx++) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, Test.IMyObjectPrx.Factory); try { prx.IcePing(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } oa.RemoveDefaultServant("foo"); identity = new Identity(identity.Name, "foo"); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); try { prx.IcePing(); } catch (ObjectNotExistException) { // Expected } output.WriteLine("ok"); output.Write("testing default category... "); output.Flush(); oa.AddDefaultServant(servantD, ""); r = oa.FindDefaultServant("bar"); test(r == null); r = oa.FindDefaultServant(""); test(r == servantD); for (int idx = 0; idx < 5; ++idx) { identity = new Identity(names[idx], identity.Category); prx = oa.CreateProxy(identity, IMyObjectPrx.Factory); prx.IcePing(); test(prx.getName() == names[idx]); } output.WriteLine("ok"); }
allTests(global::Test.TestHelper helper) { var output = helper.getWriter(); Communicator communicator = helper.communicator(); ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.Activate(); var servantI = new MyObjectI(); var servantT = default(MyObjectTraits); Disp servantD = (incoming, current) => servantT.Dispatch(servantI, incoming, current); // // Register default servant with category "foo" // oa.AddDefaultServant(servantD, "foo"); // // Start test // output.Write("testing single category... "); output.Flush(); Disp r = oa.FindDefaultServant("foo"); test(r == servantD); r = oa.FindDefaultServant("bar"); test(r == null); Ice.Identity identity = new Ice.Identity(); identity.category = "foo"; string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; IMyObjectPrx prx = null; for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); prx.IcePing(); test(prx.getName() == names[idx]); } identity.name = "ObjectNotExist"; prx = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); try { prx.IcePing(); test(false); } catch (ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (ObjectNotExistException) { // Expected } identity.name = "FacetNotExist"; prx = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); try { prx.IcePing(); test(false); } catch (FacetNotExistException) { // Expected } try { prx.getName(); test(false); } catch (FacetNotExistException) { // Expected } identity.category = "bar"; for (int idx = 0; idx < 5; idx++) { identity.name = names[idx]; prx = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); try { prx.IcePing(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } oa.RemoveDefaultServant("foo"); identity.category = "foo"; prx = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); try { prx.IcePing(); } catch (Ice.ObjectNotExistException) { // Expected } output.WriteLine("ok"); output.Write("testing default category... "); output.Flush(); oa.AddDefaultServant(servantD, ""); r = oa.FindDefaultServant("bar"); test(r == null); r = oa.FindDefaultServant(""); test(r == servantD); for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity)); prx.IcePing(); test(prx.getName() == names[idx]); } output.WriteLine("ok"); }
private void Run(IMyObjectPrx prx, Interceptor interceptor) { System.IO.TextWriter output = GetWriter(); output.Write("testing simple interceptor... "); output.Flush(); Assert(interceptor.GetLastOperation() == null); Assert(!interceptor.AsyncCompletion); prx.IcePing(); Assert(interceptor.GetLastOperation() !.Equals("ice_ping")); Assert(!interceptor.AsyncCompletion); string typeId = prx.IceId(); Assert(interceptor.GetLastOperation() !.Equals("ice_id")); Assert(!interceptor.AsyncCompletion); Assert(prx.IceIsA(typeId)); Assert(interceptor.GetLastOperation() !.Equals("ice_isA")); Assert(!interceptor.AsyncCompletion); Assert(prx.Add(33, 12) == 45); Assert(interceptor.GetLastOperation() !.Equals("add")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing retry... "); output.Flush(); Assert(prx.AddWithRetry(33, 12) == 45); Assert(interceptor.GetLastOperation() !.Equals("addWithRetry")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing remote exception... "); output.Flush(); try { prx.BadAdd(33, 12); Assert(false); } catch (InvalidInputException) { // expected } Assert(interceptor.GetLastOperation() !.Equals("badAdd")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing ONE... "); output.Flush(); interceptor.Clear(); try { prx.NotExistAdd(33, 12); Assert(false); } catch (ObjectNotExistException) { // expected } Assert(interceptor.GetLastOperation() !.Equals("notExistAdd")); Assert(!interceptor.AsyncCompletion); output.WriteLine("ok"); output.Write("testing exceptions raised by the interceptor... "); output.Flush(); TestInterceptorExceptions(prx); output.WriteLine("ok"); output.Write("testing binary context... "); output.Flush(); bool ice2 = Communicator() !.DefaultProtocol != Protocol.Ice1; if (ice2) { for (int size = 128; size < 4096; size *= 2) { var token = new Token(1, "mytoken", Enumerable.Range(0, size).Select(i => (byte)2).ToArray()); var request = OutgoingRequestFrame.WithParamList(prx, "opWithBinaryContext", idempotent: false, compress: false, format: default,