public static void Run(TestHelper helper, List <int> ports) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); // Build a multi-endpoint proxy by hand. // TODO: should the TestHelper help with that? string refString = helper.GetTestProxy("test", 0); if (ports.Count > 1) { var sb = new StringBuilder(refString); if (helper.Protocol == Protocol.Ice1) { string transport = helper.Transport; for (int i = 1; i < ports.Count; ++i) { sb.Append($": {transport} -h "); sb.Append(helper.Host); sb.Append(" -p "); sb.Append(helper.BasePort + ports[i]); } } else { sb.Append("?alt-endpoint="); for (int i = 1; i < ports.Count; ++i) { if (i > 1) { sb.Append(','); } sb.Append(helper.Host); sb.Append(':'); sb.Append(helper.BasePort + ports[i]); } } refString = sb.ToString(); } var obj = ITestIntfPrx.Parse(refString, communicator); output.WriteLine("ok"); int oldPid = 0; bool ami = false; for (int i = 1, j = 0; i <= ports.Count; ++i, ++j) { if (j > 3) { j = 0; ami = !ami; } if (!ami) { output.Write("testing server #" + i + "... "); output.Flush(); int pid = obj.Pid(); TestHelper.Assert(pid != oldPid); output.WriteLine("ok"); oldPid = pid; } else { output.Write("testing server #" + i + " with AMI... "); output.Flush(); int pid = obj.PidAsync().Result; TestHelper.Assert(pid != oldPid); output.WriteLine("ok"); oldPid = pid; } if (j == 0) { if (!ami) { output.Write("shutting down server #" + i + "... "); output.Flush(); obj.Shutdown(); output.WriteLine("ok"); } else { output.Write("shutting down server #" + i + " with AMI... "); obj.ShutdownAsync().Wait(); output.WriteLine("ok"); } } else if (j == 1 || i + 1 > ports.Count) { if (!ami) { output.Write("aborting server #" + i + "... "); output.Flush(); try { obj.Abort(); TestHelper.Assert(false); } catch (ConnectionLostException) { output.WriteLine("ok"); } catch (ConnectFailedException) { output.WriteLine("ok"); } catch (TransportException) { output.WriteLine("ok"); } } else { output.Write($"aborting server #{i} with AMI... "); output.Flush(); try { obj.AbortAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ex) { TestHelper.Assert(ex.InnerException != null); ExceptAbortI(ex.InnerException, output); } output.WriteLine("ok"); } } else if (j == 2 || j == 3) { if (!ami) { output.Write($"aborting server #{i} and #{i + 1} with idempotent call... "); output.Flush(); try { obj.IdempotentAbort(); TestHelper.Assert(false); } catch (ConnectionLostException) { output.WriteLine("ok"); } catch (ConnectFailedException) { output.WriteLine("ok"); } catch (TransportException) { output.WriteLine("ok"); } } else { output.Write($"aborting server #{i} and #{i + 1} with idempotent AMI call... "); output.Flush(); try { obj.IdempotentAbortAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ex) { TestHelper.Assert(ex.InnerException != null); ExceptAbortI(ex.InnerException, output); } output.WriteLine("ok"); } ++i; } else { TestHelper.Assert(false); } } output.Write("testing whether all servers are gone... "); output.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } }
allTestsWithDeploy(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); var obj = ITestIntfPrx.Parse("test @ TestAdapter", communicator); var obj2 = ITestIntfPrx.Parse("test", communicator); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.IcePing(); obj2.IcePing(); Console.Out.WriteLine("ok"); Console.Out.Write("testing encoding versioning... "); Console.Out.Flush(); Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown identity... "); Console.Out.Flush(); try { IObjectPrx.Parse("unknown/unknown", communicator).IcePing(); TestHelper.Assert(false); } catch (ObjectNotFoundException) { // expected } Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown adapter... "); Console.Out.Flush(); try { IObjectPrx.Parse("test @ TestAdapterUnknown", communicator).IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { // expected } Console.Out.WriteLine("ok"); IRegistryPrx registry = IRegistryPrx.Parse( communicator.DefaultLocator !.Identity.Category + "/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); session.GetConnection() !.SetACM(registry.GetACMTimeout(), null, ACMHeartbeat.HeartbeatAlways); IAdminPrx?admin = session.GetAdmin(); TestHelper.Assert(admin != null); admin.EnableServer("server", false); admin.StopServer("server"); Console.Out.Write("testing whether server is still reachable... "); Console.Out.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { obj2.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { admin.EnableServer("server", true); } catch (ServerNotExistException) { TestHelper.Assert(false); } catch (NodeUnreachableException) { TestHelper.Assert(false); } try { obj.IcePing(); } catch (NoEndpointException) { TestHelper.Assert(false); } try { obj2.IcePing(); } catch (NoEndpointException) { TestHelper.Assert(false); } Console.Out.WriteLine("ok"); try { admin.StopServer("server"); } catch (ServerNotExistException) { TestHelper.Assert(false); } catch (ServerStopException) { TestHelper.Assert(false); } catch (NodeUnreachableException) { TestHelper.Assert(false); } session.Destroy(); }
public static ITestIntfPrx Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); var proxy = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); System.IO.TextWriter output = helper.Output; output.Write("testing enum values... "); output.Flush(); TestHelper.Assert((int)ByteEnum.benum1 == 0); TestHelper.Assert((int)ByteEnum.benum2 == 1); TestHelper.Assert((int)ByteEnum.benum3 == Constants.ByteConst1); TestHelper.Assert((int)ByteEnum.benum4 == Constants.ByteConst1 + 1); TestHelper.Assert((int)ByteEnum.benum5 == Constants.ShortConst1); TestHelper.Assert((int)ByteEnum.benum6 == Constants.ShortConst1 + 1); TestHelper.Assert((int)ByteEnum.benum7 == Constants.IntConst1); TestHelper.Assert((int)ByteEnum.benum8 == Constants.IntConst1 + 1); TestHelper.Assert((int)ByteEnum.benum9 == Constants.LongConst1); TestHelper.Assert((int)ByteEnum.benum10 == Constants.LongConst1 + 1); TestHelper.Assert((int)ByteEnum.benum11 == Constants.ByteConst2); TestHelper.Assert((int)ShortEnum.senum1 == 3); TestHelper.Assert((int)ShortEnum.senum2 == 4); TestHelper.Assert((int)ShortEnum.senum3 == Constants.ByteConst1); TestHelper.Assert((int)ShortEnum.senum4 == Constants.ByteConst1 + 1); TestHelper.Assert((int)ShortEnum.senum5 == Constants.ShortConst1); TestHelper.Assert((int)ShortEnum.senum6 == Constants.ShortConst1 + 1); TestHelper.Assert((int)ShortEnum.senum7 == Constants.IntConst1); TestHelper.Assert((int)ShortEnum.senum8 == Constants.IntConst1 + 1); TestHelper.Assert((int)ShortEnum.senum9 == Constants.LongConst1); TestHelper.Assert((int)ShortEnum.senum10 == Constants.LongConst1 + 1); TestHelper.Assert((int)ShortEnum.senum11 == Constants.ShortConst2); TestHelper.Assert((int)IntEnum.ienum1 == 0); TestHelper.Assert((int)IntEnum.ienum2 == 1); TestHelper.Assert((int)IntEnum.ienum3 == Constants.ByteConst1); TestHelper.Assert((int)IntEnum.ienum4 == Constants.ByteConst1 + 1); TestHelper.Assert((int)IntEnum.ienum5 == Constants.ShortConst1); TestHelper.Assert((int)IntEnum.ienum6 == Constants.ShortConst1 + 1); TestHelper.Assert((int)IntEnum.ienum7 == Constants.IntConst1); TestHelper.Assert((int)IntEnum.ienum8 == Constants.IntConst1 + 1); TestHelper.Assert((int)IntEnum.ienum9 == Constants.LongConst1); TestHelper.Assert((int)IntEnum.ienum10 == Constants.LongConst1 + 1); TestHelper.Assert((int)IntEnum.ienum11 == Constants.IntConst2); TestHelper.Assert((int)IntEnum.ienum12 == Constants.LongConst2); TestHelper.Assert((int)SimpleEnum.red == 0); TestHelper.Assert((int)SimpleEnum.green == 1); TestHelper.Assert((int)SimpleEnum.blue == 2); output.WriteLine("ok"); output.Write("testing enum operations... "); output.Flush(); { (ByteEnum r, ByteEnum o) = proxy.OpByte(ByteEnum.benum1); TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1); (r, o) = proxy.OpByte(ByteEnum.benum11); TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11); } { // 42 does not correspond to a ByteEnum enumerator, so we expect failure since ByteEnum is checked. try { _ = proxy.OpByte((ByteEnum)42); TestHelper.Assert(false); } catch (UnhandledException) // unhandled dispatch exception { // expected } } { (ByteEnum? r, ByteEnum? o) = proxy.OpTaggedByte(ByteEnum.benum1); TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1); (r, o) = proxy.OpTaggedByte(ByteEnum.benum11); TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11); (r, o) = proxy.OpTaggedByte(null); TestHelper.Assert(r == null && o == null); } { try { _ = proxy.OpTaggedByte((ByteEnum)42); TestHelper.Assert(false); } catch (UnhandledException) // unhandled dispatch exception { // expected } } { (ShortEnum r, ShortEnum o) = proxy.OpShort(ShortEnum.senum1); TestHelper.Assert(r == ShortEnum.senum1 && o == ShortEnum.senum1); (r, o) = proxy.OpShort(ShortEnum.senum11); TestHelper.Assert(r == ShortEnum.senum11 && o == ShortEnum.senum11); } { (IntEnum r, IntEnum o) = proxy.OpInt(IntEnum.ienum1); TestHelper.Assert(r == IntEnum.ienum1 && o == IntEnum.ienum1); (r, o) = proxy.OpInt(IntEnum.ienum11); TestHelper.Assert(r == IntEnum.ienum11 && o == IntEnum.ienum11); (r, o) = proxy.OpInt(IntEnum.ienum12); TestHelper.Assert(r == IntEnum.ienum12 && o == IntEnum.ienum12); } { (SimpleEnum r, SimpleEnum o) = proxy.OpSimple(SimpleEnum.green); TestHelper.Assert(r == SimpleEnum.green && o == SimpleEnum.green); } { (FLByteEnum r, FLByteEnum o) = proxy.OpFLByte(FLByteEnum.benum1); TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1); (r, o) = proxy.OpFLByte(FLByteEnum.benum11); TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11); } { (FLByteEnum? r, FLByteEnum? o) = proxy.OpTaggedFLByte(FLByteEnum.benum1); TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1); (r, o) = proxy.OpTaggedFLByte(FLByteEnum.benum11); TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11); (r, o) = proxy.OpTaggedFLByte(null); TestHelper.Assert(r == null && o == null); } { (FLShortEnum r, FLShortEnum o) = proxy.OpFLShort(FLShortEnum.senum1); TestHelper.Assert(r == FLShortEnum.senum1 && o == FLShortEnum.senum1); (r, o) = proxy.OpFLShort(FLShortEnum.senum11); TestHelper.Assert(r == FLShortEnum.senum11 && o == FLShortEnum.senum11); } { (FLUShortEnum r, FLUShortEnum o) = proxy.OpFLUShort(FLUShortEnum.senum1); TestHelper.Assert(r == FLUShortEnum.senum1 && o == FLUShortEnum.senum1); (r, o) = proxy.OpFLUShort(FLUShortEnum.senum11); TestHelper.Assert(r == FLUShortEnum.senum11 && o == FLUShortEnum.senum11); } { (FLIntEnum r, FLIntEnum o) = proxy.OpFLInt(FLIntEnum.ienum1); TestHelper.Assert(r == FLIntEnum.ienum1 && o == FLIntEnum.ienum1); (r, o) = proxy.OpFLInt(FLIntEnum.ienum11); TestHelper.Assert(r == FLIntEnum.ienum11 && o == FLIntEnum.ienum11); (r, o) = proxy.OpFLInt(FLIntEnum.ienum12); TestHelper.Assert(r == FLIntEnum.ienum12 && o == FLIntEnum.ienum12); } { (FLUIntEnum r, FLUIntEnum o) = proxy.OpFLUInt(FLUIntEnum.ienum1); TestHelper.Assert(r == FLUIntEnum.ienum1 && o == FLUIntEnum.ienum1); (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum11); TestHelper.Assert(r == FLUIntEnum.ienum11 && o == FLUIntEnum.ienum11); (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum12); TestHelper.Assert(r == FLUIntEnum.ienum12 && o == FLUIntEnum.ienum12); } { (FLSimpleEnum r, FLSimpleEnum o) = proxy.OpFLSimple(FLSimpleEnum.green); TestHelper.Assert(r == FLSimpleEnum.green && o == FLSimpleEnum.green); } output.WriteLine("ok"); output.Write("testing enum sequences operations... "); output.Flush(); { var b1 = new ByteEnum[11] { ByteEnum.benum1, ByteEnum.benum2, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5, ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, ByteEnum.benum9, ByteEnum.benum10, ByteEnum.benum11 }; (ByteEnum[] b3, ByteEnum[] b2) = proxy.OpByteSeq(b1); TestHelper.Assert(b1.SequenceEqual(b2)); TestHelper.Assert(b1.SequenceEqual(b3)); } { var b1 = new ByteEnum[12] { ByteEnum.benum1, ByteEnum.benum2, (ByteEnum)42, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5, ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, ByteEnum.benum9, ByteEnum.benum10, ByteEnum.benum11 }; try { _ = proxy.OpByteSeq(b1); TestHelper.Assert(false); } catch (UnhandledException) { // expected } } { var s1 = new ShortEnum[11] { ShortEnum.senum1, ShortEnum.senum2, ShortEnum.senum3, ShortEnum.senum4, ShortEnum.senum5, ShortEnum.senum6, ShortEnum.senum7, ShortEnum.senum8, ShortEnum.senum9, ShortEnum.senum10, ShortEnum.senum11 }; (ShortEnum[] s3, ShortEnum[] s2) = proxy.OpShortSeq(s1); TestHelper.Assert(s1.SequenceEqual(s2)); TestHelper.Assert(s1.SequenceEqual(s3)); } { var i1 = new IntEnum[11] { IntEnum.ienum1, IntEnum.ienum2, IntEnum.ienum3, IntEnum.ienum4, IntEnum.ienum5, IntEnum.ienum6, IntEnum.ienum7, IntEnum.ienum8, IntEnum.ienum9, IntEnum.ienum10, IntEnum.ienum11 }; (IntEnum[] i3, IntEnum[] i2) = proxy.OpIntSeq(i1); TestHelper.Assert(i1.SequenceEqual(i2)); TestHelper.Assert(i1.SequenceEqual(i3)); } { var s1 = new SimpleEnum[3] { SimpleEnum.red, SimpleEnum.green, SimpleEnum.blue }; (SimpleEnum[] s3, SimpleEnum[] s2) = proxy.OpSimpleSeq(s1); TestHelper.Assert(s1.SequenceEqual(s2)); TestHelper.Assert(s1.SequenceEqual(s3)); } { var b1 = new FLByteEnum[11] { FLByteEnum.benum1, FLByteEnum.benum2, FLByteEnum.benum3, FLByteEnum.benum4, FLByteEnum.benum5, FLByteEnum.benum6, FLByteEnum.benum7, FLByteEnum.benum8, FLByteEnum.benum9, FLByteEnum.benum10, FLByteEnum.benum11 }; (FLByteEnum[] b3, FLByteEnum[] b2) = proxy.OpFLByteSeq(b1); TestHelper.Assert(b1.SequenceEqual(b2)); TestHelper.Assert(b1.SequenceEqual(b3)); } { var s1 = new FLShortEnum[11] { FLShortEnum.senum1, FLShortEnum.senum2, FLShortEnum.senum3, FLShortEnum.senum4, FLShortEnum.senum5, FLShortEnum.senum6, FLShortEnum.senum7, FLShortEnum.senum8, FLShortEnum.senum9, FLShortEnum.senum10, FLShortEnum.senum11 }; (FLShortEnum[] s3, FLShortEnum[] s2) = proxy.OpFLShortSeq(s1); TestHelper.Assert(s1.SequenceEqual(s2)); TestHelper.Assert(s1.SequenceEqual(s3)); } { var s1 = new FLUShortEnum[11] { FLUShortEnum.senum1, FLUShortEnum.senum2, FLUShortEnum.senum3, FLUShortEnum.senum4, FLUShortEnum.senum5, FLUShortEnum.senum6, FLUShortEnum.senum7, FLUShortEnum.senum8, FLUShortEnum.senum9, FLUShortEnum.senum10, FLUShortEnum.senum11 }; (FLUShortEnum[] s3, FLUShortEnum[] s2) = proxy.OpFLUShortSeq(s1); TestHelper.Assert(s1.SequenceEqual(s2)); TestHelper.Assert(s1.SequenceEqual(s3)); } { var i1 = new FLIntEnum[11] { FLIntEnum.ienum1, FLIntEnum.ienum2, FLIntEnum.ienum3, FLIntEnum.ienum4, FLIntEnum.ienum5, FLIntEnum.ienum6, FLIntEnum.ienum7, FLIntEnum.ienum8, FLIntEnum.ienum9, FLIntEnum.ienum10, FLIntEnum.ienum11 }; (FLIntEnum[] i3, FLIntEnum[] i2) = proxy.OpFLIntSeq(i1); TestHelper.Assert(i1.SequenceEqual(i2)); TestHelper.Assert(i1.SequenceEqual(i3)); } { var i1 = new FLUIntEnum[11] { FLUIntEnum.ienum1, FLUIntEnum.ienum2, FLUIntEnum.ienum3, FLUIntEnum.ienum4, FLUIntEnum.ienum5, FLUIntEnum.ienum6, FLUIntEnum.ienum7, FLUIntEnum.ienum8, FLUIntEnum.ienum9, FLUIntEnum.ienum10, FLUIntEnum.ienum11 }; (FLUIntEnum[] i3, FLUIntEnum[] i2) = proxy.OpFLUIntSeq(i1); TestHelper.Assert(i1.SequenceEqual(i2)); TestHelper.Assert(i1.SequenceEqual(i3)); } { var s1 = new FLSimpleEnum[3] { FLSimpleEnum.red, FLSimpleEnum.green, FLSimpleEnum.blue }; (FLSimpleEnum[] s3, FLSimpleEnum[] s2) = proxy.OpFLSimpleSeq(s1); TestHelper.Assert(s1.SequenceEqual(s2)); TestHelper.Assert(s1.SequenceEqual(s3)); } { var b1 = new ByteEnum[11] { ByteEnum.benum1, ByteEnum.benum2, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5, ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, ByteEnum.benum9, ByteEnum.benum10, ByteEnum.benum11 }; (ByteEnum[]? b3, ByteEnum[]? b2) = proxy.OpTaggedByteSeq(b1); TestHelper.Assert(b2 != null && b3 != null); TestHelper.Assert(b1.SequenceEqual(b2)); TestHelper.Assert(b1.SequenceEqual(b3)); (b3, b2) = proxy.OpTaggedByteSeq(null); TestHelper.Assert(b2 == null && b3 == null); } { var b1 = new ByteEnum[12] { ByteEnum.benum1, ByteEnum.benum2, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5, ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, (ByteEnum)42, ByteEnum.benum9, ByteEnum.benum10, ByteEnum.benum11 }; try { _ = proxy.OpTaggedByteSeq(b1); TestHelper.Assert(false); } catch (UnhandledException) { // expected } } { var b1 = new FLByteEnum[11] { FLByteEnum.benum1, FLByteEnum.benum2, FLByteEnum.benum3, FLByteEnum.benum4, FLByteEnum.benum5, FLByteEnum.benum6, FLByteEnum.benum7, FLByteEnum.benum8, FLByteEnum.benum9, FLByteEnum.benum10, FLByteEnum.benum11 }; (FLByteEnum[]? b3, FLByteEnum[]? b2) = proxy.OpTaggedFLByteSeq(b1); TestHelper.Assert(b2 != null && b3 != null); TestHelper.Assert(b1.SequenceEqual(b2)); TestHelper.Assert(b1.SequenceEqual(b3)); (b3, b2) = proxy.OpTaggedFLByteSeq(null); TestHelper.Assert(b2 == null && b3 == null); } { var i1 = new FLIntEnum[11] { FLIntEnum.ienum1, FLIntEnum.ienum2, FLIntEnum.ienum3, FLIntEnum.ienum4, FLIntEnum.ienum5, FLIntEnum.ienum6, FLIntEnum.ienum7, FLIntEnum.ienum8, FLIntEnum.ienum9, FLIntEnum.ienum10, FLIntEnum.ienum11 }; (FLIntEnum[]? i3, FLIntEnum[]? i2) = proxy.OpTaggedFLIntSeq(i1); TestHelper.Assert(i2 != null && i3 != null); TestHelper.Assert(i1.SequenceEqual(i2)); TestHelper.Assert(i1.SequenceEqual(i3)); (i3, i2) = proxy.OpTaggedFLIntSeq(null); TestHelper.Assert(i2 == null && i3 == null); } output.WriteLine("ok"); output.Write("testing unchecked enums... "); output.Flush(); { (MyFlags r, MyFlags f2) = proxy.OpMyFlags(MyFlags.E31); TestHelper.Assert(r == MyFlags.E31 && f2 == r); (r, f2) = proxy.OpMyFlags(MyFlags.E10 | MyFlags.E11); TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r); } output.Flush(); { (MyFlags? r, MyFlags? f2) = proxy.OpTaggedMyFlags(null); TestHelper.Assert(r == null && f2 == r); (r, f2) = proxy.OpTaggedMyFlags(MyFlags.E10 | MyFlags.E11); TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r); } output.Flush(); { var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 }; (MyFlags[] r, MyFlags[] f2) = proxy.OpMyFlagsSeq(myFlagsSeq); TestHelper.Assert(r.SequenceEqual(myFlagsSeq) && f2.SequenceEqual(myFlagsSeq)); } output.Flush(); { var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 }; (MyFlags[]? r, MyFlags[]? f2) = proxy.OpTaggedMyFlagsSeq(myFlagsSeq); TestHelper.Assert(r !.SequenceEqual(myFlagsSeq) && f2 !.SequenceEqual(myFlagsSeq)); } output.WriteLine("ok"); return(proxy); }
public static void allTests(Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var service1 = ITestIntfPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var service2 = ITestIntfPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator); var service3 = ITestIntfPrx.Parse($"test:{helper.getTestEndpoint(2)}", communicator); var service4 = ITestIntfPrx.Parse($"test:{helper.getTestEndpoint(3)}", communicator); if (service1.getProperty("IceBox.InheritProperties") == "") { Console.Out.Write("testing service properties... "); Console.Out.Flush(); test(service1.getProperty("Ice.ProgramName") == "IceBox-Service1"); test(service1.getProperty("Service") == "1"); test(service1.getProperty("Service1.Ovrd") == "2"); test(service1.getProperty("Service1.Unset") == ""); test(service1.getProperty("Arg") == "1"); string[] args1 = { "-a", "--Arg=2" }; test(Ice.Collections.Equals(service1.getArgs(), args1)); test(service2.getProperty("Ice.ProgramName") == "Test"); test(service2.getProperty("Service") == "2"); test(service2.getProperty("Service1.ArgProp") == ""); test(service2.getProperty("IceBox.InheritProperties") == "1"); string[] args2 = { "--Service1.ArgProp=1" }; test(Ice.Collections.Equals(service2.getArgs(), args2)); Console.Out.WriteLine("ok"); Console.Out.Write("testing with shared communicator... "); Console.Out.Flush(); test(service3.getProperty("Ice.ProgramName") == "IceBox-SharedCommunicator"); test(service3.getProperty("Service") == "4"); test(service3.getProperty("Prop") == ""); test(service3.getProperty("Service3.Prop") == "1"); test(service3.getProperty("Ice.Trace.Slicing") == "3"); test(service4.getProperty("Ice.ProgramName") == "IceBox-SharedCommunicator"); test(service4.getProperty("Service") == "4"); test(service4.getProperty("Prop") == ""); test(service4.getProperty("Service3.Prop") == "1"); test(service4.getProperty("Ice.Trace.Slicing") == "3"); string[] args4 = { "--Service3.Prop=2" }; test(Ice.Collections.Equals(service4.getArgs(), args4)); Console.Out.WriteLine("ok"); } else { Console.Out.Write("testing property inheritance... "); Console.Out.Flush(); Console.WriteLine(service1.getProperty("Ice.ProgramName")); test(service1.getProperty("Ice.ProgramName") == "IceBox2-Service1"); test(service1.getProperty("ServerProp") == "1"); test(service1.getProperty("OverrideMe") == "2"); test(service1.getProperty("UnsetMe") == ""); test(service1.getProperty("Service1.Prop") == "1"); test(service1.getProperty("Service1.ArgProp") == "2"); test(service2.getProperty("Ice.ProgramName") == "IceBox2-SharedCommunicator"); test(service2.getProperty("ServerProp") == "1"); test(service2.getProperty("OverrideMe") == "3"); test(service2.getProperty("UnsetMe") == ""); test(service2.getProperty("Service2.Prop") == "1"); Console.Out.WriteLine("ok"); } }
allTests(Test.TestHelper helper, int num) { var output = helper.getWriter(); Ice.Communicator communicator = helper.communicator(); List <IControllerPrx> proxies = new List <IControllerPrx>(); List <IControllerPrx> indirectProxies = new List <IControllerPrx>(); for (int i = 0; i < num; ++i) { string id = "controller" + i; proxies.Add(IControllerPrx.Parse(id, communicator)); indirectProxies.Add(IControllerPrx.Parse($"{id}@control{i}", communicator)); } output.Write("testing indirect proxies... "); output.Flush(); { foreach (IControllerPrx prx in indirectProxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing well-known proxies... "); output.Flush(); { foreach (IControllerPrx prx in proxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing object adapter registration... "); output.Flush(); { try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (NoEndpointException) { } proxies[0].activateObjectAdapter("oa", "oa1", ""); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (NoEndpointException) { } } output.WriteLine("ok"); output.Write("testing object adapter migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[0].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); proxies[0].removeObject("oa", "object"); proxies[0].deactivateObjectAdapter("oa"); proxies[1].activateObjectAdapter("oa", "oa1", ""); proxies[1].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); proxies[1].removeObject("oa", "object"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing object migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[1].activateObjectAdapter("oa", "oa2", ""); proxies[0].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[0].removeObject("oa", "object"); proxies[1].addObject("oa", "object"); IObjectPrx.Parse("object @ oa2", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[1].removeObject("oa", "object"); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); } catch (ObjectNotExistException) { } try { IObjectPrx.Parse("object @ oa2", communicator).IcePing(); } catch (ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing replica groups..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[1].activateObjectAdapter("oa", "oa2", "rg"); proxies[2].activateObjectAdapter("oa", "oa3", "rg"); proxies[0].addObject("oa", "object"); proxies[1].addObject("oa", "object"); proxies[2].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); IObjectPrx.Parse("object @ oa2", communicator).IcePing(); IObjectPrx.Parse("object @ oa3", communicator).IcePing(); IObjectPrx.Parse("object @ rg", communicator).IcePing(); List <string> adapterIds = new List <string>(); adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); ITestIntfPrx intf = ITestIntfPrx.Parse("object", communicator).Clone( connectionCached: false, locatorCacheTimeout: 0); while (adapterIds.Count > 0) { adapterIds.Remove(intf.getAdapterId()); } while (true) { adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); intf = ITestIntfPrx.Parse("object @ rg", communicator).Clone(connectionCached: false); int nRetry = 100; while (adapterIds.Count > 0 && --nRetry > 0) { adapterIds.Remove(intf.getAdapterId()); } if (nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. IObjectPrx.Parse("object @ rg", communicator).Clone(locatorCacheTimeout: 0).IcePing(); } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); test(ITestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa3")); proxies[2].deactivateObjectAdapter("oa"); proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[0].addObject("oa", "object"); test(ITestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa1")); proxies[0].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing invalid lookup endpoints... "); output.Flush(); { string multicast; if (communicator.GetProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { var properties = communicator.GetProperties(); properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; Communicator comm = new Communicator(properties); test(comm.GetDefaultLocator() != null); try { IObjectPrx.Parse("controller0@control0", comm).IcePing(); test(false); } catch (System.Exception) { } comm.Destroy(); } { var properties = communicator.GetProperties(); string intf = communicator.GetProperty("IceDiscovery.Interface") ?? ""; if (intf != "") { intf = $" --interface \"{intf}\""; } string port = communicator.GetProperty("IceDiscovery.Port") ?? ""; properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}"; Communicator comm = new Communicator(properties); test(comm.GetDefaultLocator() != null); IObjectPrx.Parse("controller0@control0", comm).IcePing(); comm.Destroy(); } } output.WriteLine("ok"); output.Write("shutting down... "); output.Flush(); foreach (IControllerPrx prx in proxies) { prx.shutdown(); } output.WriteLine("ok"); }
public static void Run(TestHelper helper, List <int> ports) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); // Build a multi-endpoint proxy by hand. // TODO: should the TestHelper help with that? string refString = helper.GetTestProxy("test", 0); if (ports.Count > 1) { var sb = new StringBuilder(refString); if (helper.Protocol == Protocol.Ice1) { string transport = helper.Transport; for (int i = 0; i < ports.Count; ++i) { sb.Append($": {transport} -h "); sb.Append(helper.Host.Contains(":") ? $"\"{helper.Host}\"" : helper.Host); sb.Append(" -p "); sb.Append(helper.BasePort + ports[i]); } } else { sb.Append("?alt-endpoint="); for (int i = 0; i < ports.Count; ++i) { if (i > 0) { sb.Append(','); } sb.Append(helper.Host.Contains(":") ? $"[{helper.Host}]" : helper.Host); sb.Append(':'); sb.Append(helper.BasePort + ports[i]); } } refString = sb.ToString(); } var obj = ITestIntfPrx.Parse(refString, communicator); output.WriteLine("ok"); int oldPid = 0; for (int i = 1, j = 0; i <= ports.Count; ++i, ++j) { output.Write($"testing server #{i}... "); output.Flush(); int pid = obj.Pid(); TestHelper.Assert(pid != oldPid); output.WriteLine("ok"); oldPid = pid; using var cancel = new CancellationTokenSource(100); if (i % 2 == 0) { output.Write($"shutting down server #{i}... "); output.Flush(); obj.Shutdown(cancel: cancel.Token); output.WriteLine("ok"); } else { output.Write($"aborting server #{i}... "); output.Flush(); try { obj.Abort(cancel: cancel.Token); TestHelper.Assert(false); } catch (ConnectionLostException) { output.WriteLine("ok"); } catch (ConnectFailedException) { output.WriteLine("ok"); } catch (TransportException) { output.WriteLine("ok"); } } } output.Write("testing whether all servers are gone... "); output.Flush(); try { using var cancel = new CancellationTokenSource(100); obj.IcePing(cancel: cancel.Token); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); var service1 = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); var service2 = ITestIntfPrx.Parse(helper.GetTestProxy("test", 1), communicator); var service3 = ITestIntfPrx.Parse(helper.GetTestProxy("test", 2), communicator); var service4 = ITestIntfPrx.Parse(helper.GetTestProxy("test", 3), communicator); if (service1.GetProperty("IceBox.InheritProperties").Length == 0) { Console.Out.Write("testing service properties... "); Console.Out.Flush(); TestHelper.Assert(service1.GetProperty("Ice.ProgramName") == "IceBox-Service1"); TestHelper.Assert(service1.GetProperty("Service") == "1"); TestHelper.Assert(service1.GetProperty("Service1.Ovrd") == "2"); TestHelper.Assert(service1.GetProperty("Service1.Unset").Length == 0); TestHelper.Assert(service1.GetProperty("Arg") == "1"); string[] args1 = { "-a", "--Arg=2" }; TestHelper.Assert(service1.GetArgs().SequenceEqual(args1)); TestHelper.Assert(service2.GetProperty("Ice.ProgramName") == "Test"); TestHelper.Assert(service2.GetProperty("Service") == "2"); TestHelper.Assert(service2.GetProperty("Service1.ArgProp").Length == 0); TestHelper.Assert(service2.GetProperty("IceBox.InheritProperties") == "1"); string[] args2 = { "--Service1.ArgProp=1" }; TestHelper.Assert(service2.GetArgs().SequenceEqual(args2)); Console.Out.WriteLine("ok"); Console.Out.Write("testing with shared communicator... "); Console.Out.Flush(); TestHelper.Assert(service3.GetProperty("Ice.ProgramName") == "IceBox-SharedCommunicator"); TestHelper.Assert(service3.GetProperty("Service") == "4"); TestHelper.Assert(service3.GetProperty("Prop").Length == 0); TestHelper.Assert(service3.GetProperty("Service3.Prop") == "1"); TestHelper.Assert(service3.GetProperty("Ice.Trace.Slicing") == "3"); TestHelper.Assert(service4.GetProperty("Ice.ProgramName") == "IceBox-SharedCommunicator"); TestHelper.Assert(service4.GetProperty("Service") == "4"); TestHelper.Assert(service4.GetProperty("Prop").Length == 0); TestHelper.Assert(service4.GetProperty("Service3.Prop") == "1"); TestHelper.Assert(service4.GetProperty("Ice.Trace.Slicing") == "3"); string[] args4 = { "--Service3.Prop=2" }; TestHelper.Assert(service4.GetArgs().SequenceEqual(args4)); Console.Out.WriteLine("ok"); } else { Console.Out.Write("testing property inheritance... "); Console.Out.Flush(); TestHelper.Assert(service1.GetProperty("Ice.ProgramName") == "IceBox2-Service1"); TestHelper.Assert(service1.GetProperty("ServerProp") == "1"); TestHelper.Assert(service1.GetProperty("OverrideMe") == "2"); TestHelper.Assert(service1.GetProperty("UnsetMe").Length == 0); TestHelper.Assert(service1.GetProperty("Service1.Prop") == "1"); TestHelper.Assert(service1.GetProperty("Service1.ArgProp") == "2"); TestHelper.Assert(service2.GetProperty("Ice.ProgramName") == "IceBox2-SharedCommunicator"); TestHelper.Assert(service2.GetProperty("ServerProp") == "1"); TestHelper.Assert(service2.GetProperty("OverrideMe") == "3"); TestHelper.Assert(service2.GetProperty("UnsetMe").Length == 0); TestHelper.Assert(service2.GetProperty("Service2.Prop") == "1"); Console.Out.WriteLine("ok"); } }
public static void Run(TestHelper helper, int num) { TextWriter output = helper.Output; Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); var proxies = new List <IControllerPrx>(); var indirectProxies = new List <IControllerPrx>(); bool ice1 = helper.Protocol == Protocol.Ice1; for (int i = 0; i < num; ++i) { proxies.Add(IControllerPrx.Parse(ice1 ? $"controller{i}" : $"ice:controller{i}", communicator)); indirectProxies.Add( IControllerPrx.Parse(ice1 ? $"controller{i} @ control{i}" : $"ice:control{i}//controller{i}", communicator)); } output.Write("testing indirect proxies... "); output.Flush(); { foreach (IControllerPrx prx in indirectProxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing well-known proxies... "); output.Flush(); { foreach (IControllerPrx prx in proxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing object adapter registration... "); output.Flush(); { try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } proxies[0].ActivateObjectAdapter("oa", "oa1", ""); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { } proxies[0].DeactivateObjectAdapter("oa"); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } output.WriteLine("ok"); output.Write("testing object adapter migration..."); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", ""); proxies[0].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); proxies[0].RemoveObject("oa", "object"); proxies[0].DeactivateObjectAdapter("oa"); proxies[1].ActivateObjectAdapter("oa", "oa1", ""); proxies[1].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); proxies[1].RemoveObject("oa", "object"); proxies[1].DeactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing object migration..."); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", ""); proxies[1].ActivateObjectAdapter("oa", "oa2", ""); proxies[0].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[0].RemoveObject("oa", "object"); proxies[1].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[1].RemoveObject("oa", "object"); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); } catch (ObjectNotExistException) { } try { IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); } catch (ObjectNotExistException) { } proxies[0].DeactivateObjectAdapter("oa"); proxies[1].DeactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing replica groups..."); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", "rg"); proxies[1].ActivateObjectAdapter("oa", "oa2", "rg"); proxies[2].ActivateObjectAdapter("oa", "oa3", "rg"); proxies[0].AddObject("oa", "object"); proxies[1].AddObject("oa", "object"); proxies[2].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa3" : "ice:oa3//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ rg" : "ice:rg//object", communicator).IcePing(); var adapterIds = new List <string> { "oa1", "oa2", "oa3" }; ITestIntfPrx intf = ITestIntfPrx.Parse(ice1 ? "object" : "ice:object", communicator).Clone( cacheConnection: false, locatorCacheTimeout: TimeSpan.Zero); while (adapterIds.Count > 0) { adapterIds.Remove(intf.GetAdapterId()); } while (true) { adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); intf = ITestIntfPrx.Parse(ice1 ? "object @ rg" : "ice:rg//object", communicator).Clone( cacheConnection: false); int nRetry = 100; while (adapterIds.Count > 0 && --nRetry > 0) { adapterIds.Remove(intf.GetAdapterId()); } if (nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. IObjectPrx.Parse("object @ rg", communicator).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); } proxies[0].DeactivateObjectAdapter("oa"); proxies[1].DeactivateObjectAdapter("oa"); TestHelper.Assert( ITestIntfPrx.Parse( ice1 ? "object @ rg" : "ice:rg//object", communicator).GetAdapterId().Equals("oa3")); proxies[2].DeactivateObjectAdapter("oa"); proxies[0].ActivateObjectAdapter("oa", "oa1", "rg"); proxies[0].AddObject("oa", "object"); TestHelper.Assert( ITestIntfPrx.Parse( ice1 ? "object @ rg" : "ice:rg//object", communicator).GetAdapterId().Equals("oa1")); proxies[0].DeactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing invalid lookup endpoints... "); output.Flush(); { string multicast; if (communicator.GetProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { Dictionary <string, string> properties = communicator.GetProperties(); properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; using var comm = new Communicator(properties); TestHelper.Assert(comm.DefaultLocator != null); try { IObjectPrx.Parse("controller0@control0", comm).IcePing(); TestHelper.Assert(false); } catch { } } { Dictionary <string, string> properties = communicator.GetProperties(); string intf = communicator.GetProperty("IceDiscovery.Interface") ?? ""; if (intf.Length > 0) { intf = $" --interface \"{intf}\""; } string port = communicator.GetProperty("IceDiscovery.Port") ?? ""; properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}"; using var comm = new Communicator(properties); TestHelper.Assert(comm.DefaultLocator != null); IObjectPrx.Parse("controller0@control0", comm).IcePing(); } } output.WriteLine("ok"); output.Write("shutting down... "); output.Flush(); foreach (IControllerPrx prx in proxies) { prx.Shutdown(); } output.WriteLine("ok"); }
public static async Task RunAsync(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); string rf = "test @ TestAdapter"; var obj = ITestIntfPrx.Parse(rf, communicator); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.IcePing(); Console.Out.WriteLine("ok"); Console.Out.Write("testing locator finder... "); var finderId = new Identity("LocatorFinder", "Ice"); ILocatorFinderPrx finder = communicator.DefaultLocator !.Clone(ILocatorFinderPrx.Factory, identity: finderId); TestHelper.Assert(finder != null && finder.GetLocator() != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing discovery... "); Console.Out.Flush(); { // Add test well-known object var registry = IRegistryPrx.Parse( communicator.DefaultLocator !.Identity.Category + "/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); session.GetAdmin() !.AddObjectWithType(obj, "::Test"); session.Destroy(); // Ensure locator discovery can discover the registries and make sure locator requests are forwarded. Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.Default.Locator"] = "LocatorDiscovery"; properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter"; properties["AdapterForDiscoveryTest.Endpoints"] = $"{helper.Transport} -h 127.0.0.1"; { await using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); IObjectPrx.Parse("test", com).IcePing(); Ice.ILocatorPrx defaultLocator = com.DefaultLocator !; TestHelper.Assert(defaultLocator.Protocol == Protocol.Ice2); TestHelper.Assert(defaultLocator.Encoding == Encoding.V20); // This works fine because the LocatorDiscovery Locator performs transcoding for Ice::Locator // operations. TestHelper.Assert(defaultLocator.GetRegistry() != null); // CheckedCast on the _IceGrid_ Locator proxy fails because ice_isA is not forwarded (due to the // encoding mismatch) but is instead implemented by the plain Locator of LocatorDiscovery. TestHelper.Assert(defaultLocator.CheckedCast(ILocatorPrx.Factory) == null); // Change the encoding to make it work: defaultLocator = defaultLocator.Clone(encoding: Encoding.V11); var iceGridLocator = defaultLocator.CheckedCast(ILocatorPrx.Factory); TestHelper.Assert(iceGridLocator != null); TestHelper.Assert(iceGridLocator.GetLocalRegistry() != null); TestHelper.Assert(iceGridLocator.GetLocalQuery() != null); ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); await adapter.ActivateAsync(); } // Now, ensure that locator discovery correctly handles failure to find a locator. { properties["Ice.LocatorDiscovery.InstanceName"] = "unknown"; properties["Ice.LocatorDiscovery.RetryCount"] = "1"; properties["Ice.LocatorDiscovery.Timeout"] = "100ms"; await using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { IObjectPrx.Parse("test", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } Ice.ILocatorPrx defaultLocator = com.DefaultLocator !.Clone(encoding: Encoding.V11); try { defaultLocator.Clone(ILocatorPrx.Factory).GetLocalRegistry(); TestHelper.Assert(false); } catch (OperationNotExistException) { } await using ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); await adapter.ActivateAsync(); } string multicast; if (helper.Host.Contains(":")) { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } // Test invalid lookup endpoints { properties = communicator.GetProperties(); properties["Ice.Default.Locator"] = "locatordiscovery"; properties["Ice.LocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; await using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } { properties = communicator.GetProperties(); properties["Ice.Default.Locator"] = "locatordiscovery"; properties["Ice.LocatorDiscovery.RetryCount"] = "0"; properties["Ice.LocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; await using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } { properties = communicator.GetProperties(); properties["Ice.Default.Locator"] = "locatordiscovery"; properties["Ice.LocatorDiscovery.RetryCount"] = "1"; { string intf = helper.Host.Contains(":") ? $"\"{helper.Host}\"" : helper.Host; string port = $"{helper.BasePort + 99}"; properties["Ice.LocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port} --interface {intf}"; } await using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); } } Console.Out.WriteLine("ok"); Console.Out.Write("shutting down server... "); Console.Out.Flush(); obj.Shutdown(); Console.Out.WriteLine("ok"); }
public static async Task RunWithDeployAsync(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); var obj = ITestIntfPrx.Parse("test @ TestAdapter", communicator); var obj2 = ITestIntfPrx.Parse("test", communicator); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.IcePing(); obj2.IcePing(); Console.Out.WriteLine("ok"); Console.Out.Write("testing encoding versioning... "); Console.Out.Flush(); Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown identity... "); Console.Out.Flush(); try { IObjectPrx.Parse("unknown/unknown", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { // expected } Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown adapter... "); Console.Out.Flush(); try { IObjectPrx.Parse("test @ TestAdapterUnknown", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { // expected } Console.Out.WriteLine("ok"); var registry = IRegistryPrx.Parse( $"{communicator.DefaultLocator!.Identity.Category}/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); Connection connection = await session.GetConnectionAsync(); connection.KeepAlive = true; IAdminPrx?admin = session.GetAdmin(); TestHelper.Assert(admin != null); admin.EnableServer("server", false); admin.StopServer("server"); Console.Out.Write("testing whether server is still reachable... "); Console.Out.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { obj2.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } admin.EnableServer("server", true); obj.IcePing(); obj2.IcePing(); Console.Out.WriteLine("ok"); admin.StopServer("server"); session.Destroy(); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); communicator.SetProperty("ReplyAdapter.Endpoints", "udp"); ObjectAdapter adapter = communicator.CreateObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); IPingReplyPrx reply = adapter.AddWithUUID(replyI, IPingReplyPrx.Factory) .Clone(invocationMode: InvocationMode.Datagram); adapter.Activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); var obj = ITestIntfPrx.Parse("test:" + helper.getTestEndpoint(0, "udp"), communicator).Clone(invocationMode: InvocationMode.Datagram); int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } test(ret == true); if ((communicator.GetPropertyAsInt("Ice.Override.Compress") ?? 0) == 0) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = new byte[1024];; try { while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // test(seq.Length > 16384); } obj.GetConnection().Close(Ice.ConnectionClose.GracefullyWithWait); communicator.SetProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // test(!b); } catch (DatagramLimitException) { } catch (LocalException ex) { Console.Out.WriteLine(ex); test(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); StringBuilder endpoint = new StringBuilder(); // // Use loopback to prevent other machines to answer. // if (communicator.GetProperty("Ice.IPv6") == "1") { endpoint.Append("udp -h \"ff15::1:1\""); if (IceInternal.AssemblyUtil.IsWindows || IceInternal.AssemblyUtil.IsMacOS) { endpoint.Append(" --interface \"::1\""); } } else { endpoint.Append("udp -h 239.255.1.1"); if (IceInternal.AssemblyUtil.IsWindows || IceInternal.AssemblyUtil.IsMacOS) { endpoint.Append(" --interface 127.0.0.1"); } } endpoint.Append(" -p "); endpoint.Append(helper.getTestPort(10)); var objMcast = ITestIntfPrx.Parse($"test -d:{endpoint}", communicator); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); objMcast.ping(reply); ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } if (!ret) { Console.Out.WriteLine("failed(is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.GetConnection().SetAdapter(adapter); objMcast.GetConnection().SetAdapter(adapter); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } test(ret); Console.Out.WriteLine("ok"); // // Sending the replies back on the multicast UDP connection doesn't work for most // platform(it works for macOS Leopard but not Snow Leopard, doesn't work on SLES, // Windows...). For Windows, see UdpTransceiver constructor for the details. So // we don't run this test. // // Console.Out.Write("testing udp bi-dir connection... "); // nRetry = 5; // while(nRetry-- > 0) // { // replyI.reset(); // objMcast.pingBiDir(reply.Identity); // ret = replyI.waitReply(5, 2000); // if(ret) // { // break; // Success // } // replyI = new PingReplyI(); // reply =(PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); // } // if(!ret) // { // Console.Out.WriteLine("failed(is a firewall enabled?)"); // } // else // { // Console.Out.WriteLine("ok"); // } }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = helper.Protocol == Protocol.Ice1; string transport = helper.Transport; TextWriter output = helper.Output; output.Write("testing proxy endpoint information... "); output.Flush(); { string ice1Prx = @"test -t:tcp -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10: udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:opaque -e 1.8 -t 100 -v ABCD"; string ice2Prx = "ice+tcp://tcphost:10000/test?source-address=10.10.10.10" + "&alt-endpoint=ice+universal://unihost:10000?transport=100$option=ABCD"; var p1 = IObjectPrx.Parse(ice1 ? ice1Prx : ice2Prx, communicator); IReadOnlyList <Endpoint> endps = p1.Endpoints; Endpoint tcpEndpoint = endps[0]; TestHelper.Assert(tcpEndpoint.Transport == Transport.TCP && !tcpEndpoint.IsSecure); TestHelper.Assert(tcpEndpoint.Host == "tcphost"); TestHelper.Assert(tcpEndpoint.Port == 10000); TestHelper.Assert(tcpEndpoint["source-address"] == "10.10.10.10"); if (ice1) { TestHelper.Assert(tcpEndpoint["timeout"] == "1200"); TestHelper.Assert(tcpEndpoint["compress"] == "true"); } TestHelper.Assert(!tcpEndpoint.IsDatagram); if (ice1) { Endpoint udpEndpoint = endps[1]; TestHelper.Assert(udpEndpoint.Host == "udphost"); TestHelper.Assert(udpEndpoint.Port == 10001); TestHelper.Assert(udpEndpoint["interface"] == "eth0"); TestHelper.Assert(udpEndpoint["ttl"] == "5"); TestHelper.Assert(udpEndpoint["source-address"] == "10.10.10.10"); TestHelper.Assert(udpEndpoint["timeout"] == null); TestHelper.Assert(udpEndpoint["compress"] == null); TestHelper.Assert(!udpEndpoint.IsSecure); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Transport == Transport.UDP); Endpoint opaqueEndpoint = endps[2]; TestHelper.Assert(opaqueEndpoint["value"] == "ABCD"); TestHelper.Assert(opaqueEndpoint["value-encoding"] == "1.8"); } else { Endpoint universalEndpoint = endps[1]; TestHelper.Assert(universalEndpoint.Transport == (Transport)100); TestHelper.Assert(universalEndpoint["option"] == "ABCD"); } } output.WriteLine("ok"); ObjectAdapter adapter; output.Write("test object adapter endpoint information... "); output.Flush(); { string host = (communicator.GetPropertyAsBool("Ice.IPv6") ?? false) ? "::1" : "127.0.0.1"; communicator.SetProperty("TestAdapter.Endpoints", "tcp -h \"" + host + "\" -t 15000:udp -h \"" + host + "\""); adapter = communicator.CreateObjectAdapter("TestAdapter"); IReadOnlyList <Endpoint> endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count == 2); IReadOnlyList <Endpoint> publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); Endpoint tcpEndpoint = endpoints[0]; TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Transport == Transport.TCP || tcpEndpoint.Transport == Transport.SSL || tcpEndpoint.Transport == Transport.WS || tcpEndpoint.Transport == Transport.WSS); TestHelper.Assert(tcpEndpoint.Host == host); TestHelper.Assert(tcpEndpoint.Port > 0); TestHelper.Assert(tcpEndpoint["timeout"] is string value && int.Parse(value) == 15000); Endpoint udpEndpoint = endpoints[1]; TestHelper.Assert(udpEndpoint.Host == host); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Port > 0); endpoints = new List <Endpoint> { endpoints[0] }; adapter.SetPublishedEndpoints(endpoints); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); adapter.Dispose(); int port = helper.BasePort + 1; communicator.SetProperty("TestAdapter.Endpoints", ice1 ? $"{transport} -h 0.0.0.0 -p {port}" : $"ice+{transport}://0.0.0.0:{port}"); communicator.SetProperty("TestAdapter.PublishedEndpoints", helper.GetTestEndpoint(1)); adapter = communicator.CreateObjectAdapter("TestAdapter"); endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count >= 1); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(publishedEndpoints.Count == 1); foreach (Endpoint endpoint in endpoints) { TestHelper.Assert(endpoint.Port == port); } tcpEndpoint = publishedEndpoints[0]; TestHelper.Assert(tcpEndpoint.Host == "127.0.0.1"); TestHelper.Assert(tcpEndpoint.Port == port); adapter.Dispose(); } output.WriteLine("ok"); int endpointPort = helper.BasePort + 0; ITestIntfPrx testIntf; if (ice1) { testIntf = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0) + ":" + helper.GetTestEndpoint(0, "udp"), communicator); } else { testIntf = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); } string defaultHost = helper.Host; output.Write("test connection endpoint information... "); output.Flush(); { Endpoint tcpEndpoint = testIntf.GetConnection() !.Endpoint; TestHelper.Assert(tcpEndpoint.Port == endpointPort); TestHelper.Assert(tcpEndpoint["compress"] == null); TestHelper.Assert(tcpEndpoint.Host == defaultHost); Dictionary <string, string> ctx = testIntf.GetEndpointInfoAsContext(); TestHelper.Assert(ctx["host"] == tcpEndpoint.Host); TestHelper.Assert(ctx["compress"] == "false"); int port = int.Parse(ctx["port"]); TestHelper.Assert(port > 0); if (ice1) { Endpoint udpEndpoint = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection() !.Endpoint; TestHelper.Assert(udpEndpoint.Port == endpointPort); TestHelper.Assert(udpEndpoint.Host == defaultHost); } } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { var connection = (IPConnection)testIntf.GetConnection() !; TestHelper.Assert(!connection.IsIncoming); TestHelper.Assert(connection.Adapter == null); TestHelper.Assert(connection.RemoteEndpoint !.Port == endpointPort); TestHelper.Assert(connection.LocalEndpoint !.Port > 0); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(connection.LocalEndpoint !.Address.ToString() == defaultHost); TestHelper.Assert(connection.RemoteEndpoint !.Address.ToString() == defaultHost); } if (connection.Endpoint.IsSecure) { TestHelper.Assert(((TcpConnection)connection).IsEncrypted); // WSS tests run client authentication disabled for compatibility with web browser testing. if (connection.Endpoint.Transport == Transport.SSL) { TestHelper.Assert(((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(((TcpConnection)connection).LocalCertificate != null); } else { TestHelper.Assert(!((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(((TcpConnection)connection).LocalCertificate == null); } TestHelper.Assert(((TcpConnection)connection).IsSigned); TestHelper.Assert(((TcpConnection)connection).RemoteCertificate != null); TestHelper.Assert(((TcpConnection)connection).NegotiatedApplicationProtocol != null); TestHelper.Assert(((TcpConnection)connection).NegotiatedCipherSuite != null); TestHelper.Assert(((TcpConnection)connection).SslProtocol == SslProtocols.Tls12 || ((TcpConnection)connection).SslProtocol == SslProtocols.Tls13); } else { TestHelper.Assert(!((TcpConnection)connection).IsEncrypted); TestHelper.Assert(!((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(!((TcpConnection)connection).IsSigned); TestHelper.Assert(((TcpConnection)connection).LocalCertificate == null); TestHelper.Assert(((TcpConnection)connection).RemoteCertificate == null); TestHelper.Assert(((TcpConnection)connection).NegotiatedApplicationProtocol == null); TestHelper.Assert(((TcpConnection)connection).NegotiatedCipherSuite == null); TestHelper.Assert(((TcpConnection)connection).SslProtocol == null); } Dictionary <string, string> ctx = testIntf.GetConnectionInfoAsContext(); TestHelper.Assert(ctx["incoming"].Equals("true")); TestHelper.Assert(ctx["adapterName"].Equals("TestAdapter")); TestHelper.Assert(ctx["remoteAddress"].Equals(connection.LocalEndpoint !.Address.ToString())); TestHelper.Assert(ctx["localAddress"].Equals(connection.RemoteEndpoint !.Address.ToString())); TestHelper.Assert(ctx["remotePort"].Equals(connection.LocalEndpoint !.Port.ToString())); TestHelper.Assert(ctx["localPort"].Equals(connection.RemoteEndpoint !.Port.ToString())); if ((connection as WSConnection)?.Headers is IReadOnlyDictionary <string, string> headers) { TestHelper.Assert(headers["Upgrade"].Equals("websocket")); TestHelper.Assert(headers["Connection"].Equals("Upgrade")); TestHelper.Assert(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(headers["Sec-WebSocket-Accept"] != null); TestHelper.Assert(ctx["ws.Upgrade"].Equals("websocket")); TestHelper.Assert(ctx["ws.Connection"].Equals("Upgrade")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Version"].Equals("13")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Key"] != null); } if (ice1) { connection = (IPConnection)testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection() !; var udpConnection = connection as UdpConnection; TestHelper.Assert(udpConnection != null); TestHelper.Assert(!udpConnection.IsIncoming); TestHelper.Assert(udpConnection.Adapter == null); TestHelper.Assert(udpConnection.LocalEndpoint?.Port > 0); TestHelper.Assert(udpConnection.RemoteEndpoint?.Port == endpointPort); if (defaultHost == "127.0.0.1") { TestHelper.Assert(udpConnection.RemoteEndpoint.Address.ToString().Equals(defaultHost)); TestHelper.Assert(udpConnection.LocalEndpoint.Address.ToString().Equals(defaultHost)); } } } output.WriteLine("ok"); testIntf.Shutdown(); communicator.ShutdownAsync(); communicator.WaitForShutdownAsync(); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); communicator.SetProperty("ReplyAdapter.Endpoints", "udp -h localhost"); ObjectAdapter adapter = communicator.CreateObjectAdapter("ReplyAdapter"); var replyI = new PingReplyI(); IPingReplyPrx reply = adapter.AddWithUUID(replyI, IPingReplyPrx.Factory) .Clone(invocationMode: InvocationMode.Datagram); adapter.Activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); ITestIntfPrx obj = ITestIntfPrx.Parse( helper.GetTestProxy("test", 0, "udp"), communicator).Clone(invocationMode: InvocationMode.Datagram); try { int val = obj.GetValue(); TestHelper.Assert(false); } catch (InvalidOperationException) { // expected } int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.Reset(); obj.Ping(reply); obj.Ping(reply); obj.Ping(reply); ret = replyI.WaitReply(3, TimeSpan.FromSeconds(2)); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } TestHelper.Assert(ret == true); byte[] seq = new byte[1024]; try { while (true) { seq = new byte[(seq.Length * 2) + 10]; replyI.Reset(); obj.SendByteSeq(seq, reply); replyI.WaitReply(1, TimeSpan.FromSeconds(10)); } } catch (DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // TestHelper.Assert(seq.Length > 16384); } obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); communicator.SetProperty("Ice.UDP.SndSize", "64K"); seq = new byte[50000]; try { replyI.Reset(); obj.SendByteSeq(seq, reply); bool b = replyI.WaitReply(1, TimeSpan.FromMilliseconds(500)); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // TestHelper.Assert(!b); } catch (DatagramLimitException) { } catch (Exception ex) { Console.Out.WriteLine(ex); TestHelper.Assert(false); } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); var sb = new StringBuilder("test -d:udp -h "); // Use loopback to prevent other machines to answer. if (communicator.GetPropertyAsBool("Ice.IPv6") ?? false) { sb.Append("\"ff15::1:1\""); } else { sb.Append("239.255.1.1"); } sb.Append(" -p "); sb.Append(helper.GetTestPort(10)); if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS) { if (communicator.GetPropertyAsBool("Ice.IPv6") ?? false) { sb.Append(" --interface \"::1\""); } else { sb.Append(" --interface 127.0.0.1"); } } var objMcast = ITestIntfPrx.Parse(sb.ToString(), communicator); nRetry = 5; while (nRetry-- > 0) { replyI.Reset(); objMcast.Ping(reply); ret = replyI.WaitReply(5, TimeSpan.FromSeconds(5)); if (ret) { break; } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } if (!ret) { Console.Out.WriteLine("failed(is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.GetConnection() !.Adapter = adapter; objMcast.GetConnection() !.Adapter = adapter; nRetry = 5; while (nRetry-- > 0) { replyI.Reset(); obj.PingBiDir(reply.Identity); obj.PingBiDir(reply.Identity); obj.PingBiDir(reply.Identity); ret = replyI.WaitReply(3, TimeSpan.FromSeconds(2)); if (ret) { break; // Success } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } TestHelper.Assert(ret); Console.Out.WriteLine("ok"); }
public static async Task RunAsync(TestHelper helper) { Communicator communicator = helper.Communicator; bool ice1 = TestHelper.GetTestProtocol(communicator.GetProperties()) == Protocol.Ice1; TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); var obj = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); { await using var adapter = communicator.CreateObjectAdapterWithEndpoints( "TransientTestAdapter", helper.GetTestEndpoint(1)); try { communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); TestHelper.Assert(false); } catch (ArgumentException) { } } // Use a different port than the first adapter to avoid an "address already in use" error. { var adapter = communicator.CreateObjectAdapterWithEndpoints( "TransientTestAdapter", helper.GetTestEndpoint(2)); TestHelper.Assert(!adapter.ShutdownComplete.IsCompleted); await adapter.DisposeAsync(); TestHelper.Assert(adapter.ShutdownComplete.IsCompletedSuccessfully); } output.WriteLine("ok"); } output.Write("creating/activating/disposing object adapter in one operation... "); output.Flush(); obj.Transient(); obj.TransientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { await using var comm = new Communicator(communicator.GetProperties()); _ = IObjectPrx.Parse(helper.GetTestProxy("test", 0), communicator).IcePingAsync(); } output.WriteLine("ok"); } { output.Write("testing invalid object adapter endpoints... "); output.Flush(); try { communicator.CreateObjectAdapterWithEndpoints( "BadAdapter1", ice1 ? "tcp -h localhost -p 0" : "ice+tcp://localhost:0"); TestHelper.Assert(false); } catch (InvalidConfigurationException) { // expected } try { communicator.CreateObjectAdapterWithEndpoints( "BadAdapter2", ice1 ? "tcp -h 127.0.0.1 -p 0:tcp -h \"::1\" -p 10000" : "ice+tcp://127.0.0.1:0?alt-endpoint=[::1]:10000"); TestHelper.Assert(false); } catch (InvalidConfigurationException) { // expected } output.WriteLine("ok"); } { output.Write("testing object adapter default published endpoints... "); string testHost = "testhost"; communicator.SetProperty("DAdapter.ServerName", testHost); if (ice1) { communicator.SetProperty("DAdapter.AcceptNonSecure", "Always"); } { communicator.SetProperty( "DAdapter.Endpoints", ice1 ? "tcp -h \"::0\" -p 0" : "ice+tcp://[::0]:0"); await using var adapter = communicator.CreateObjectAdapter("DAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); Endpoint publishedEndpoint = adapter.PublishedEndpoints[0]; TestHelper.Assert(publishedEndpoint.Host == testHost); } { communicator.SetProperty( "DAdapter.Endpoints", ice1 ? $"{helper.GetTestEndpoint(1)}:{helper.GetTestEndpoint(2)}" : $"{helper.GetTestEndpoint(1)}?alt-endpoint={helper.GetTestEndpoint(2)}"); await using var adapter = communicator.CreateObjectAdapter("DAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 2); Endpoint publishedEndpoint0 = adapter.PublishedEndpoints[0]; TestHelper.Assert(publishedEndpoint0.Host == testHost); TestHelper.Assert(publishedEndpoint0.Port == helper.BasePort + 1); Endpoint publishedEndpoint1 = adapter.PublishedEndpoints[1]; TestHelper.Assert(publishedEndpoint1.Host == testHost); TestHelper.Assert(publishedEndpoint1.Port == helper.BasePort + 2); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 30000" : "ice+tcp://localhost:12345"); await using var adapter = communicator.CreateObjectAdapter("PAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); Endpoint?endpt = adapter.PublishedEndpoints[0]; TestHelper.Assert(endpt != null); if (ice1) { TestHelper.Assert(endpt.ToString() == "tcp -h localhost -p 12345 -t 30000"); } else { TestHelper.Assert(endpt.ToString() == "ice+tcp://localhost:12345"); } } output.WriteLine("ok"); Connection connection = await obj.GetConnectionAsync(); { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapter(); connection.Adapter = adapter; connection.Adapter = null; await adapter.DisposeAsync(); // Setting a deactivated adapter on a connection no longer raise ObjectAdapterDeactivatedException connection.Adapter = adapter; output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); if (ice1) { var routerId = new Identity("router", ""); IRouterPrx router = obj.Clone(IRouterPrx.Factory, label: "rc", identity: routerId); { await using var adapter = communicator.CreateObjectAdapterWithRouter(router); await adapter.ActivateAsync(); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); string endpointsStr = adapter.PublishedEndpoints[0].ToString(); TestHelper.Assert(endpointsStr == "tcp -h localhost -p 23456 -t 60000"); } try { routerId = new Identity("test", ""); router = obj.Clone(IRouterPrx.Factory, identity: routerId); await using var adapter = communicator.CreateObjectAdapterWithRouter(router); await adapter.ActivateAsync(); TestHelper.Assert(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse(helper.GetTestProxy("test", 1), communicator); await using var adapter = communicator.CreateObjectAdapterWithRouter(router); await adapter.ActivateAsync(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } else { try { await using var adapter = communicator.CreateObjectAdapterWithRouter( obj.Clone(IRouterPrx.Factory, label: "rc", identity: new Identity("router", ""))); TestHelper.Assert(false); } catch (ArgumentException) { // expected. } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { await using var adapter1 = communicator.CreateObjectAdapterWithEndpoints("Adpt1", helper.GetTestEndpoint(10)); try { communicator.CreateObjectAdapterWithEndpoints("Adpt2", helper.GetTestEndpoint(10)); TestHelper.Assert(false); } catch { // Expected can't re-use the same endpoint. } } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.Deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } }
public static void Run(TestHelper helper, int num) { TextWriter output = helper.Output; Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); var proxies = new List <IControllerPrx>(); var facetedProxies = new List <IControllerPrx>(); var indirectProxies = new List <IControllerPrx>(); bool ice1 = helper.Protocol == Protocol.Ice1; for (int i = 0; i < num; ++i) { proxies.Add(IControllerPrx.Parse(ice1 ? $"controller{i}" : $"ice:controller{i}", communicator)); facetedProxies.Add(IControllerPrx.Parse( ice1 ? $"faceted-controller{i} -f abc" : $"ice:faceted-controller{i}#abc", communicator)); indirectProxies.Add( IControllerPrx.Parse(ice1 ? $"controller{i} @ control{i}" : $"ice:control{i}//controller{i}", communicator)); } output.Write("testing indirect proxies... "); output.Flush(); { foreach (IControllerPrx prx in indirectProxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing well-known proxies... "); output.Flush(); { foreach (IControllerPrx prx in proxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing faceted well-known proxies... "); output.Flush(); { foreach (IControllerPrx prx in facetedProxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing object adapter registration... "); output.Flush(); { try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } proxies[0].ActivateObjectAdapter("oa", "oa1", ""); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { } proxies[0].DeactivateObjectAdapter("oa"); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } output.WriteLine("ok"); output.Write("testing object adapter migration... "); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", ""); proxies[0].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); proxies[0].RemoveObject("oa", "object"); proxies[0].DeactivateObjectAdapter("oa"); proxies[1].ActivateObjectAdapter("oa", "oa1", ""); proxies[1].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); proxies[1].RemoveObject("oa", "object"); proxies[1].DeactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", ""); proxies[1].ActivateObjectAdapter("oa", "oa2", ""); proxies[0].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object" : "ice:object", communicator).IcePing(); proxies[0].RemoveObject("oa", "object"); proxies[1].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); if (ice1) { // TODO: this currently does not work with ice2 because the previous object (in oa1) is still in // the cache and we don't retry on ONE. IObjectPrx.Parse("object", communicator).IcePing(); } proxies[1].RemoveObject("oa", "object"); try { IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); } catch (ObjectNotExistException) { } try { IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); } catch (ObjectNotExistException) { } proxies[0].DeactivateObjectAdapter("oa"); proxies[1].DeactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing replica groups... "); output.Flush(); { proxies[0].ActivateObjectAdapter("oa", "oa1", "rg"); proxies[1].ActivateObjectAdapter("oa", "oa2", "rg"); proxies[2].ActivateObjectAdapter("oa", "oa3", "rg"); proxies[0].AddObject("oa", "object"); proxies[1].AddObject("oa", "object"); proxies[2].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa3" : "ice:oa3//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ rg" : "ice:rg//object", communicator).IcePing(); var adapterIds = new List <string> { "oa1", "oa2", "oa3" }; // Check that the well known object is reachable with all replica group members ITestIntfPrx intf = ITestIntfPrx.Parse(ice1 ? "object" : "ice:object", communicator).Clone( cacheConnection: false, preferExistingConnection: false, locatorCacheTimeout: TimeSpan.Zero); while (adapterIds.Count > 0) { string id = intf.GetAdapterId(); adapterIds.Remove(id); switch (id) { case "oa1": { proxies[0].DeactivateObjectAdapter("oa"); break; } case "oa2": { proxies[1].DeactivateObjectAdapter("oa"); break; } case "oa3": { proxies[2].DeactivateObjectAdapter("oa"); break; } } } proxies[0].ActivateObjectAdapter("oa", "oa1", "rg"); proxies[1].ActivateObjectAdapter("oa", "oa2", "rg"); proxies[2].ActivateObjectAdapter("oa", "oa3", "rg"); proxies[0].AddObject("oa", "object"); proxies[1].AddObject("oa", "object"); proxies[2].AddObject("oa", "object"); IObjectPrx.Parse(ice1 ? "object @ oa1" : "ice:oa1//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa2" : "ice:oa2//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ oa3" : "ice:oa3//object", communicator).IcePing(); IObjectPrx.Parse(ice1 ? "object @ rg" : "ice:rg//object", communicator).IcePing(); adapterIds = new List <string> { "oa1", "oa2", "oa3" }; // Check that the indirect reference is reachable with all replica group members intf = ITestIntfPrx.Parse(ice1 ? "object @ rg" : "ice:rg//object", communicator).Clone( cacheConnection: false, preferExistingConnection: false, locatorCacheTimeout: TimeSpan.Zero); while (adapterIds.Count > 0) { var id = intf.GetAdapterId(); adapterIds.Remove(id); switch (id) { case "oa1": { proxies[0].DeactivateObjectAdapter("oa"); break; } case "oa2": { proxies[1].DeactivateObjectAdapter("oa"); break; } case "oa3": { proxies[2].DeactivateObjectAdapter("oa"); break; } } } } output.WriteLine("ok"); output.Write("testing invalid lookup endpoints... "); output.Flush(); { string multicast; if (helper.Host.Contains(":")) { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.Discovery.Lookup"] = $"udp -h {multicast} --interface unknown"; using var comm = new Communicator(properties); TestHelper.Assert(comm.DefaultLocator != null); try { IObjectPrx.Parse(ice1 ? "controller0@control0" : "ice:control0//controller0", comm).IcePing(); TestHelper.Assert(false); } catch { } } { Dictionary <string, string> properties = communicator.GetProperties(); string port = $"{helper.BasePort + 10}"; string intf = helper.Host.Contains(":") ? $"\"{helper.Host}\"" : helper.Host; string lookup = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}"; if (!OperatingSystem.IsLinux()) { lookup += " --interface {intf}"; } using var comm = new Communicator(properties); TestHelper.Assert(comm.DefaultLocator != null); IObjectPrx.Parse(ice1 ? "controller0@control0" : "ice:control0//controller0", comm).IcePing(); } } output.WriteLine("ok"); output.Write("shutting down... "); output.Flush(); foreach (IControllerPrx prx in proxies) { prx.Shutdown(); } output.WriteLine("ok"); }
public static async ValueTask allTestsWithServer(TestHelper helper, bool collocated, int server) { System.IO.TextWriter output = helper.GetWriter(); var scheduler = TaskScheduler.Current; var proxy = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(server), helper.Communicator() !); if (collocated) { // With collocation, synchronous calls dispatched on an object adapter which doesn't set a task // scheduler are dispatched from the client invocation task scheduler. var context = new Dictionary <string, string>() { { "scheduler", scheduler.Id.ToString() } }; proxy.pingSync(context); proxy.ping(context); } else { proxy.pingSync(); proxy.ping(); } // Ensure the continuation is ran on the current task scheduler await proxy.pingSyncAsync(); TestHelper.Assert(TaskScheduler.Current == scheduler); await proxy.pingAsync(); TestHelper.Assert(TaskScheduler.Current == scheduler); // The continuation set with ContinueWith are expected to be ran on the Current task // scheduler if no task scheduler is provided to ContinueWith. Func <string, Action <Task> > checkScheduler = (op) => { return(t => { if (TaskScheduler.Current != scheduler) { throw new TestFailedException( $"unexpected scheduler for {op} ContinueWith {TaskScheduler.Current}"); } }); }; await proxy.pingSyncAsync().ContinueWith(checkScheduler("pingSyncAsync")); TestHelper.Assert(TaskScheduler.Current == scheduler); await proxy.pingAsync().ContinueWith(checkScheduler("pingAsyncAsync")); TestHelper.Assert(TaskScheduler.Current == scheduler); // The progress Report callback is always called from the default task scheduler right now. Progress progress; progress = new Progress(); await proxy.pingSyncAsync(progress : progress); TestHelper.Assert(progress.Scheduler == TaskScheduler.Default); progress = new Progress(); await proxy.pingAsync(progress : progress); TestHelper.Assert(progress.Scheduler == TaskScheduler.Default); // The continuation of an awaitable setup with ConfigureAwait(false) is ran with the default // scheduler. await proxy.pingSyncAsync().ConfigureAwait(false); TestHelper.Assert(TaskScheduler.Current == TaskScheduler.Default); await proxy.pingAsync().ConfigureAwait(false); TestHelper.Assert(TaskScheduler.Current == TaskScheduler.Default); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); string rf = "test @ TestAdapter"; var obj = ITestIntfPrx.Parse(rf, communicator); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.IcePing(); Console.Out.WriteLine("ok"); Console.Out.Write("testing locator finder... "); var finderId = new Identity("LocatorFinder", "Ice"); ILocatorFinderPrx finder = communicator.DefaultLocator !.Clone(ILocatorFinderPrx.Factory, identity: finderId); TestHelper.Assert(finder != null && finder.GetLocator() != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing discovery... "); Console.Out.Flush(); { // Add test well-known object var registry = IRegistryPrx.Parse( communicator.DefaultLocator !.Identity.Category + "/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); session.GetAdmin() !.AddObjectWithType(obj, "::Test"); session.Destroy(); // Ensure the IceGrid discovery locator can discover the registries and make sure locator requests are // forwarded. Dictionary <string, string>?properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Port"] = $"{helper.BasePort + 99}"; properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter"; properties["AdapterForDiscoveryTest.Endpoints"] = $"{helper.Transport} -h 127.0.0.1"; { using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); IObjectPrx.Parse("test", com).IcePing(); // TODO: currently, com.DefaultLocator is a regular ice2/2.0 proxy and we don't want to forward // 2.0-encoded requests to IceGrid until IceGrid supports such requests. ILocatorPrx defaultLocator = com.DefaultLocator !.Clone(ILocatorPrx.Factory, encoding: Encoding.V11); TestHelper.Assert(defaultLocator.GetRegistry() != null); TestHelper.Assert(defaultLocator.GetLocalRegistry() != null); TestHelper.Assert(defaultLocator.GetLocalQuery() != null); ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); adapter.Activate(); } // Now, ensure that the IceGrid discovery locator correctly handles failure to find a locator. { properties["IceLocatorDiscovery.InstanceName"] = "unknown"; properties["IceLocatorDiscovery.RetryCount"] = "1"; properties["IceLocatorDiscovery.Timeout"] = "100ms"; using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); } catch (NoEndpointException) { } try { IObjectPrx.Parse("test", com).IcePing(); } catch (NoEndpointException) { } Ice.ILocatorPrx defaultLocator = com.DefaultLocator !.Clone(encoding: Encoding.V11); TestHelper.Assert(defaultLocator.GetRegistry() == null); TestHelper.Assert(defaultLocator.CheckedCast(ILocatorPrx.Factory) == null); try { com.DefaultLocator !.Clone(ILocatorPrx.Factory).GetLocalRegistry(); } catch (OperationNotExistException) { } using ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); adapter.Activate(); } string multicast; if (communicator.GetProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } // Test invalid lookup endpoints { properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } { properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["IceLocatorDiscovery.RetryCount"] = "0"; properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } } { properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["IceLocatorDiscovery.RetryCount"] = "1"; properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; { string intf = communicator.GetProperty("IceLocatorDiscovery.Interface") ?? ""; if (intf.Length > 0) { intf = $" --interface \"{intf}\""; } string port = $"{helper.BasePort + 99}"; properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}"; } using var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); } catch (NoEndpointException) { TestHelper.Assert(false); } } } Console.Out.WriteLine("ok"); Console.Out.Write("shutting down server... "); Console.Out.Flush(); obj.Shutdown(); Console.Out.WriteLine("ok"); }
public static async Task <ITestIntfPrx> RunAsync(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); TextWriter?output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); var testPrx = ITestIntfPrx.Parse(helper.GetTestProxy("Test", 0), communicator); output.WriteLine("ok"); output.Write("base... "); output.Flush(); { try { testPrx.BaseAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.B.Equals("Base.b")); TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("base (AMI)... "); output.Flush(); { try { testPrx.BaseAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.B.Equals("Base.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown derived... "); output.Flush(); { try { testPrx.UnknownDerivedAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownDerived.b")); TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown derived (AMI)... "); output.Flush(); { try { testPrx.UnknownDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownDerived.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base... "); output.Flush(); { try { testPrx.KnownDerivedAsBase(); TestHelper.Assert(false); } catch (KnownDerived k) { TestHelper.Assert(k.B.Equals("KnownDerived.b")); TestHelper.Assert(k.Kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownDerived")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base (AMI)... "); output.Flush(); { try { testPrx.KnownDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownDerived k) { TestHelper.Assert(k.B.Equals("KnownDerived.b")); TestHelper.Assert(k.Kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().Name.Equals("KnownDerived")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived... "); output.Flush(); { try { testPrx.KnownDerivedAsKnownDerived(); TestHelper.Assert(false); } catch (KnownDerived k) { TestHelper.Assert(k.B.Equals("KnownDerived.b")); TestHelper.Assert(k.Kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownDerived")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived (AMI)... "); output.Flush(); { try { testPrx.KnownDerivedAsKnownDerivedAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownDerived k) { TestHelper.Assert(k.B.Equals("KnownDerived.b")); TestHelper.Assert(k.Kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().Name.Equals("KnownDerived")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base... "); output.Flush(); { try { testPrx.UnknownIntermediateAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownIntermediate.b")); TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base (AMI)... "); output.Flush(); { try { testPrx.UnknownIntermediateAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownIntermediate.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base... "); output.Flush(); { try { testPrx.KnownIntermediateAsBase(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.Ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals( "ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.KnownIntermediateAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.Ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of known most derived as base... "); output.Flush(); { try { testPrx.KnownMostDerivedAsBase(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of known most derived as base (AMI)... "); output.Flush(); { try { testPrx.KnownMostDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate... "); output.Flush(); { try { testPrx.KnownIntermediateAsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.Ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.KnownIntermediateAsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.Ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate... "); output.Flush(); { try { testPrx.KnownMostDerivedAsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate (AMI)... "); output.Flush(); { try { testPrx.KnownMostDerivedAsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived... "); output.Flush(); { try { testPrx.KnownMostDerivedAsKnownMostDerived(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived (AMI)... "); output.Flush(); { try { testPrx.KnownMostDerivedAsKnownMostDerivedAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.B.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.Ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.Kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base... "); output.Flush(); { try { testPrx.UnknownMostDerived1AsBase(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.Ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.UnknownMostDerived1AsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.Ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate... "); output.Flush(); { try { testPrx.UnknownMostDerived1AsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.Ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.UnknownMostDerived1AsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.B.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.Ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base... "); output.Flush(); { try { testPrx.UnknownMostDerived2AsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownMostDerived2.b")); TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base")); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); output.Flush(); { try { testPrx.UnknownMostDerived2AsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.B.Equals("UnknownMostDerived2.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("unknown most derived in compact format... "); output.Flush(); { try { testPrx.UnknownMostDerived2AsBaseCompact(); TestHelper.Assert(false); } catch (Base) { // Exceptions are always marshaled in sliced format; format:compact applies only to in-parameters and // return values. } catch (OperationNotExistException) { } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("completely unknown server-private exception... "); output.Flush(); { try { testPrx.ServerPrivateException(); TestHelper.Assert(false); } catch (RemoteException ex) { SlicedData slicedData = ex.GetSlicedData() !.Value; TestHelper.Assert(slicedData.Slices.Count == 1); TestHelper.Assert(slicedData.Slices[0].TypeId ! == "::ZeroC::Ice::Test::Slicing::Exceptions::ServerPrivateException"); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("preserved exceptions... "); output.Flush(); { try { testPrx.UnknownPreservedAsBase(); TestHelper.Assert(false); } catch (Base ex) { IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices; TestHelper.Assert(slices.Count == 2); TestHelper.Assert(slices[1].TypeId !.Equals("::ZeroC::Ice::Test::Slicing::Exceptions::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::ZeroC::Ice::Test::Slicing::Exceptions::SPreserved2")); } try { testPrx.UnknownPreservedAsKnownPreserved(); TestHelper.Assert(false); } catch (KnownPreserved ex) { TestHelper.Assert(ex.Kp.Equals("preserved")); IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices; TestHelper.Assert(slices.Count == 2); TestHelper.Assert(slices[1].TypeId !.Equals("::ZeroC::Ice::Test::Slicing::Exceptions::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::ZeroC::Ice::Test::Slicing::Exceptions::SPreserved2")); } await using var adapter = communicator.CreateObjectAdapter(protocol: helper.Protocol); IRelayPrx relay = adapter.AddWithUUID(new Relay(), IRelayPrx.Factory); await adapter.ActivateAsync(); testPrx.GetConnection().Adapter = adapter; try { testPrx.RelayKnownPreservedAsBase(relay); TestHelper.Assert(false); } catch (KnownPreservedDerived ex) { TestHelper.Assert(ex.B.Equals("base")); TestHelper.Assert(ex.Kp.Equals("preserved")); TestHelper.Assert(ex.Kpd.Equals("derived")); } catch (OperationNotExistException) { } catch { TestHelper.Assert(false); } try { testPrx.RelayKnownPreservedAsKnownPreserved(relay); TestHelper.Assert(false); } catch (KnownPreservedDerived ex) { TestHelper.Assert(ex.B.Equals("base")); TestHelper.Assert(ex.Kp.Equals("preserved")); TestHelper.Assert(ex.Kpd.Equals("derived")); } catch (OperationNotExistException) { } catch { TestHelper.Assert(false); } try { testPrx.RelayUnknownPreservedAsBase(relay); TestHelper.Assert(false); } catch (Preserved2 ex) { TestHelper.Assert(ex.B.Equals("base")); TestHelper.Assert(ex.Kp.Equals("preserved")); TestHelper.Assert(ex.Kpd.Equals("derived")); TestHelper.Assert(ex.P1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId())); var pc = ex.P1 as PreservedClass; TestHelper.Assert(pc !.Bc.Equals("bc")); TestHelper.Assert(pc !.Pc.Equals("pc")); TestHelper.Assert(ex.P2 == ex.P1); } catch (OperationNotExistException) { } catch { TestHelper.Assert(false); } try { testPrx.RelayUnknownPreservedAsKnownPreserved(relay); TestHelper.Assert(false); } catch (Preserved2 ex) { TestHelper.Assert(ex.B.Equals("base")); TestHelper.Assert(ex.Kp.Equals("preserved")); TestHelper.Assert(ex.Kpd.Equals("derived")); TestHelper.Assert(ex.P1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId())); var pc = ex.P1 as PreservedClass; TestHelper.Assert(pc !.Bc.Equals("bc")); TestHelper.Assert(pc !.Pc.Equals("pc")); TestHelper.Assert(ex.P2 == ex.P1); } catch (OperationNotExistException) { } catch { TestHelper.Assert(false); } try { testPrx.RelayClientPrivateException(relay); TestHelper.Assert(false); } catch (ClientPrivateException ex) { TestHelper.Assert(ex.Cpe == "ClientPrivate"); } catch { TestHelper.Assert(false); } } output.WriteLine("ok"); return(testPrx); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var output = helper.GetWriter(); output.Write("testing proxy endpoint information... "); output.Flush(); { var p1 = IObjectPrx.Parse( "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" + "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" + "opaque -e 1.8 -t 100 -v ABCD", communicator); var endps = p1.Endpoints; Endpoint endpoint = endps[0]; TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Host.Equals("tcphost")); TestHelper.Assert(tcpEndpoint.Port == 10000); TestHelper.Assert(tcpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(tcpEndpoint.Timeout == 1200); TestHelper.Assert(tcpEndpoint.HasCompressionFlag); TestHelper.Assert(!tcpEndpoint.IsDatagram); TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && !tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.SSL && tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.WS && !tcpEndpoint.IsSecure || tcpEndpoint.Type == EndpointType.WSS && tcpEndpoint.IsSecure); TestHelper.Assert(tcpEndpoint.Type == EndpointType.TCP && endpoint is TcpEndpoint || tcpEndpoint.Type == EndpointType.SSL && endpoint is SslEndpoint || tcpEndpoint.Type == EndpointType.WS && endpoint is WSEndpoint || tcpEndpoint.Type == EndpointType.WSS && endpoint is WSEndpoint); UdpEndpoint udpEndpoint = (UdpEndpoint)endps[1]; TestHelper.Assert(udpEndpoint.Host.Equals("udphost")); TestHelper.Assert(udpEndpoint.Port == 10001); TestHelper.Assert(udpEndpoint.McastInterface.Equals("eth0")); TestHelper.Assert(udpEndpoint.McastTtl == 5); TestHelper.Assert(udpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(udpEndpoint.Timeout == -1); TestHelper.Assert(!udpEndpoint.HasCompressionFlag); TestHelper.Assert(!udpEndpoint.IsSecure); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Type == EndpointType.UDP); OpaqueEndpoint opaqueEndpoint = (OpaqueEndpoint)endps[2]; TestHelper.Assert(opaqueEndpoint.Bytes.Length > 0); TestHelper.Assert(opaqueEndpoint.Encoding.Equals(new Encoding(1, 8))); } output.WriteLine("ok"); ObjectAdapter adapter; output.Write("test object adapter endpoint information... "); output.Flush(); { string host = (communicator.GetPropertyAsBool("Ice.IPv6") ?? false) ? "::1" : "127.0.0.1"; communicator.SetProperty("TestAdapter.Endpoints", "tcp -h \"" + host + "\" -t 15000:udp -h \"" + host + "\""); adapter = communicator.CreateObjectAdapter("TestAdapter"); var endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count == 2); var publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoints[0]); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert( tcpEndpoint.Type == EndpointType.TCP || tcpEndpoint.Type == EndpointType.SSL || tcpEndpoint.Type == EndpointType.WS || tcpEndpoint.Type == EndpointType.WSS); TestHelper.Assert(tcpEndpoint.Host.Equals(host)); TestHelper.Assert(tcpEndpoint.Port > 0); TestHelper.Assert(tcpEndpoint.Timeout == 15000); UdpEndpoint udpEndpoint = (UdpEndpoint)endpoints[1]; TestHelper.Assert(udpEndpoint.Host.Equals(host)); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Port > 0); endpoints = new List <Endpoint> { endpoints[0] }; TestHelper.Assert(endpoints.Count == 1); adapter.SetPublishedEndpoints(endpoints); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); adapter.Destroy(); int port = helper.GetTestPort(1); communicator.SetProperty("TestAdapter.Endpoints", $"default -h * -p {port}"); communicator.SetProperty("TestAdapter.PublishedEndpoints", helper.GetTestEndpoint(1)); adapter = communicator.CreateObjectAdapter("TestAdapter"); endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count >= 1); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(publishedEndpoints.Count == 1); foreach (var endpoint in endpoints) { tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint !.Port == port); } tcpEndpoint = getTCPEndpoint(publishedEndpoints[0]); TestHelper.Assert(tcpEndpoint !.Host == "127.0.0.1"); TestHelper.Assert(tcpEndpoint !.Port == port); adapter.Destroy(); } output.WriteLine("ok"); int endpointPort = helper.GetTestPort(0); var testIntf = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0) + ":" + helper.GetTestEndpoint(0, "udp"), communicator); string defaultHost = communicator.GetProperty("Ice.Default.Host") ?? ""; output.Write("test connection endpoint information... "); output.Flush(); { Endpoint endpoint = testIntf.GetConnection().Endpoint; TcpEndpoint?tcpEndpoint = getTCPEndpoint(endpoint); TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Port == endpointPort); TestHelper.Assert(!tcpEndpoint.HasCompressionFlag); TestHelper.Assert(tcpEndpoint.Host.Equals(defaultHost)); Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext(); TestHelper.Assert(ctx["host"].Equals(tcpEndpoint.Host)); TestHelper.Assert(ctx["compress"].Equals("false")); int port = int.Parse(ctx["port"]); TestHelper.Assert(port > 0); endpoint = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection().Endpoint; UdpEndpoint udp = (UdpEndpoint)endpoint; TestHelper.Assert(udp.Port == endpointPort); TestHelper.Assert(udp.Host.Equals(defaultHost)); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { Connection connection = testIntf.GetConnection(); connection.SetBufferSize(1024, 2048); ConnectionInfo info = connection.GetConnectionInfo(); TCPConnectionInfo ipInfo = getTCPConnectionInfo(info) !; TestHelper.Assert(!info.Incoming); TestHelper.Assert(info.AdapterName !.Length == 0); TestHelper.Assert(ipInfo.RemotePort == endpointPort); TestHelper.Assert(ipInfo.LocalPort > 0); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(ipInfo.LocalAddress.Equals(defaultHost)); TestHelper.Assert(ipInfo.RemoteAddress.Equals(defaultHost)); } TestHelper.Assert(ipInfo.RcvSize >= 1024); TestHelper.Assert(ipInfo.SndSize >= 2048); Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext(); TestHelper.Assert(ctx["incoming"].Equals("true")); TestHelper.Assert(ctx["adapterName"].Equals("TestAdapter")); TestHelper.Assert(ctx["remoteAddress"].Equals(ipInfo.LocalAddress)); TestHelper.Assert(ctx["localAddress"].Equals(ipInfo.RemoteAddress)); TestHelper.Assert(ctx["remotePort"].Equals(ipInfo.LocalPort.ToString())); TestHelper.Assert(ctx["localPort"].Equals(ipInfo.RemotePort.ToString())); if (testIntf.GetConnection().Type().Equals("ws") || testIntf.GetConnection().Type().Equals("wss")) { Dictionary <string, string> headers = ((WSConnectionInfo)info).Headers !; TestHelper.Assert(headers["Upgrade"].Equals("websocket")); TestHelper.Assert(headers["Connection"].Equals("Upgrade")); TestHelper.Assert(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(headers["Sec-WebSocket-Accept"] != null); TestHelper.Assert(ctx["ws.Upgrade"].Equals("websocket")); TestHelper.Assert(ctx["ws.Connection"].Equals("Upgrade")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Version"].Equals("13")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Key"] != null); } connection = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection(); connection.SetBufferSize(2048, 1024); UDPConnectionInfo udpInfo = (UDPConnectionInfo)connection.GetConnectionInfo(); TestHelper.Assert(!udpInfo.Incoming); TestHelper.Assert(udpInfo.AdapterName !.Length == 0); TestHelper.Assert(udpInfo.LocalPort > 0); TestHelper.Assert(udpInfo.RemotePort == endpointPort); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(udpInfo.RemoteAddress.Equals(defaultHost)); TestHelper.Assert(udpInfo.LocalAddress.Equals(defaultHost)); } TestHelper.Assert(udpInfo.RcvSize >= 2048); TestHelper.Assert(udpInfo.SndSize >= 1024); } output.WriteLine("ok"); testIntf.shutdown(); communicator.Shutdown(); communicator.WaitForShutdown(); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var output = helper.GetWriter(); output.Write("testing proxy endpoint information... "); output.Flush(); { var p1 = IObjectPrx.Parse( "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" + "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" + "opaque -e 1.8 -t 100 -v ABCD", communicator); var endps = p1.Endpoints; Endpoint endpoint = endps[0]; var tcpEndpoint = endpoint as TcpEndpoint; TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Host.Equals("tcphost")); TestHelper.Assert(tcpEndpoint.Port == 10000); TestHelper.Assert(tcpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(tcpEndpoint.Timeout == 1200); TestHelper.Assert(tcpEndpoint.HasCompressionFlag); TestHelper.Assert(!tcpEndpoint.IsDatagram); TestHelper.Assert((tcpEndpoint.Transport == Transport.TCP && !endpoint.IsSecure) || (tcpEndpoint.Transport == Transport.SSL && endpoint.IsSecure) || (tcpEndpoint.Transport == Transport.WS && !endpoint.IsSecure) || (tcpEndpoint.Transport == Transport.WSS && endpoint.IsSecure)); UdpEndpoint udpEndpoint = (UdpEndpoint)endps[1]; TestHelper.Assert(udpEndpoint.Host.Equals("udphost")); TestHelper.Assert(udpEndpoint.Port == 10001); TestHelper.Assert(udpEndpoint.McastInterface.Equals("eth0")); TestHelper.Assert(udpEndpoint.McastTtl == 5); TestHelper.Assert(udpEndpoint.SourceAddress !.ToString().Equals("10.10.10.10")); TestHelper.Assert(udpEndpoint.Timeout == -1); TestHelper.Assert(!udpEndpoint.HasCompressionFlag); TestHelper.Assert(!udpEndpoint.IsSecure); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Transport == Transport.UDP); OpaqueEndpoint opaqueEndpoint = (OpaqueEndpoint)endps[2]; TestHelper.Assert(opaqueEndpoint.Bytes.Length > 0); TestHelper.Assert(opaqueEndpoint.Encoding.Equals(new Encoding(1, 8))); } output.WriteLine("ok"); ObjectAdapter adapter; output.Write("test object adapter endpoint information... "); output.Flush(); { string host = (communicator.GetPropertyAsBool("Ice.IPv6") ?? false) ? "::1" : "127.0.0.1"; communicator.SetProperty("TestAdapter.Endpoints", "tcp -h \"" + host + "\" -t 15000:udp -h \"" + host + "\""); adapter = communicator.CreateObjectAdapter("TestAdapter"); var endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count == 2); var publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); var tcpEndpoint = endpoints[0] as TcpEndpoint; TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Transport == Transport.TCP || tcpEndpoint.Transport == Transport.SSL || tcpEndpoint.Transport == Transport.WS || tcpEndpoint.Transport == Transport.WSS); TestHelper.Assert(tcpEndpoint.Host.Equals(host)); TestHelper.Assert(tcpEndpoint.Port > 0); TestHelper.Assert(tcpEndpoint.Timeout == 15000); UdpEndpoint udpEndpoint = (UdpEndpoint)endpoints[1]; TestHelper.Assert(udpEndpoint.Host.Equals(host)); TestHelper.Assert(udpEndpoint.IsDatagram); TestHelper.Assert(udpEndpoint.Port > 0); endpoints = new List <Endpoint> { endpoints[0] }; TestHelper.Assert(endpoints.Count == 1); adapter.SetPublishedEndpoints(endpoints); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(endpoints.SequenceEqual(publishedEndpoints)); adapter.Destroy(); int port = helper.GetTestPort(1); communicator.SetProperty("TestAdapter.Endpoints", $"default -h * -p {port}"); communicator.SetProperty("TestAdapter.PublishedEndpoints", helper.GetTestEndpoint(1)); adapter = communicator.CreateObjectAdapter("TestAdapter"); endpoints = adapter.GetEndpoints(); TestHelper.Assert(endpoints.Count >= 1); publishedEndpoints = adapter.GetPublishedEndpoints(); TestHelper.Assert(publishedEndpoints.Count == 1); foreach (var endpoint in endpoints) { tcpEndpoint = endpoint as TcpEndpoint; TestHelper.Assert(tcpEndpoint !.Port == port); } tcpEndpoint = publishedEndpoints[0] as TcpEndpoint; TestHelper.Assert(tcpEndpoint !.Host == "127.0.0.1"); TestHelper.Assert(tcpEndpoint !.Port == port); adapter.Destroy(); } output.WriteLine("ok"); int endpointPort = helper.GetTestPort(0); var testIntf = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0) + ":" + helper.GetTestEndpoint(0, "udp"), communicator); string defaultHost = communicator.GetProperty("Ice.Default.Host") ?? ""; output.Write("test connection endpoint information... "); output.Flush(); { Endpoint endpoint = testIntf.GetConnection() !.Endpoint; var tcpEndpoint = endpoint as TcpEndpoint; TestHelper.Assert(tcpEndpoint != null); TestHelper.Assert(tcpEndpoint.Port == endpointPort); TestHelper.Assert(!tcpEndpoint.HasCompressionFlag); TestHelper.Assert(tcpEndpoint.Host.Equals(defaultHost)); Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext(); TestHelper.Assert(ctx["host"].Equals(tcpEndpoint.Host)); TestHelper.Assert(ctx["compress"].Equals("false")); int port = int.Parse(ctx["port"]); TestHelper.Assert(port > 0); endpoint = testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection() !.Endpoint; UdpEndpoint udp = (UdpEndpoint)endpoint; TestHelper.Assert(udp.Port == endpointPort); TestHelper.Assert(udp.Host.Equals(defaultHost)); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { IPConnection connection = (IPConnection)testIntf.GetConnection() !; TestHelper.Assert(!connection.IsIncoming); TestHelper.Assert(connection.Adapter == null); TestHelper.Assert(connection.RemoteEndpoint !.Port == endpointPort); TestHelper.Assert(connection.LocalEndpoint !.Port > 0); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(connection.LocalEndpoint !.Address.ToString().Equals(defaultHost)); TestHelper.Assert(connection.RemoteEndpoint !.Address.ToString().Equals(defaultHost)); } if (connection.Endpoint.IsSecure) { TestHelper.Assert(((TcpConnection)connection).IsEncrypted); // WSS tests run with IceSSL.VerifyPeer set to 0 so the connection is no mutually // authenticated for compatibility with web browser testing. if (connection.Endpoint.Transport == Transport.SSL) { TestHelper.Assert(((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(((TcpConnection)connection).LocalCertificate != null); } else { TestHelper.Assert(!((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(((TcpConnection)connection).LocalCertificate == null); } TestHelper.Assert(((TcpConnection)connection).IsSigned); TestHelper.Assert(((TcpConnection)connection).RemoteCertificate != null); TestHelper.Assert(((TcpConnection)connection).NegotiatedApplicationProtocol != null); TestHelper.Assert(((TcpConnection)connection).NegotiatedCipherSuite != null); TestHelper.Assert(((TcpConnection)connection).SslProtocol == SslProtocols.Tls12 || ((TcpConnection)connection).SslProtocol == SslProtocols.Tls13); } else { TestHelper.Assert(!((TcpConnection)connection).IsEncrypted); TestHelper.Assert(!((TcpConnection)connection).IsMutuallyAuthenticated); TestHelper.Assert(!((TcpConnection)connection).IsSigned); TestHelper.Assert(((TcpConnection)connection).LocalCertificate == null); TestHelper.Assert(((TcpConnection)connection).RemoteCertificate == null); TestHelper.Assert(((TcpConnection)connection).NegotiatedApplicationProtocol == null); TestHelper.Assert(((TcpConnection)connection).NegotiatedCipherSuite == null); TestHelper.Assert(((TcpConnection)connection).SslProtocol == null); } Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext(); TestHelper.Assert(ctx["incoming"].Equals("true")); TestHelper.Assert(ctx["adapterName"].Equals("TestAdapter")); TestHelper.Assert(ctx["remoteAddress"].Equals(connection.LocalEndpoint !.Address.ToString())); TestHelper.Assert(ctx["localAddress"].Equals(connection.RemoteEndpoint !.Address.ToString())); TestHelper.Assert(ctx["remotePort"].Equals(connection.LocalEndpoint !.Port.ToString())); TestHelper.Assert(ctx["localPort"].Equals(connection.RemoteEndpoint !.Port.ToString())); if ((connection as WSConnection)?.Headers is IReadOnlyDictionary <string, string> headers) { TestHelper.Assert(headers["Upgrade"].Equals("websocket")); TestHelper.Assert(headers["Connection"].Equals("Upgrade")); TestHelper.Assert(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(headers["Sec-WebSocket-Accept"] != null); TestHelper.Assert(ctx["ws.Upgrade"].Equals("websocket")); TestHelper.Assert(ctx["ws.Connection"].Equals("Upgrade")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Version"].Equals("13")); TestHelper.Assert(ctx["ws.Sec-WebSocket-Key"] != null); } connection = (IPConnection)testIntf.Clone(invocationMode: InvocationMode.Datagram).GetConnection() !; var udpConnection = connection as UdpConnection; TestHelper.Assert(udpConnection != null); TestHelper.Assert(!udpConnection.IsIncoming); TestHelper.Assert(udpConnection.Adapter == null); TestHelper.Assert(udpConnection.LocalEndpoint?.Port > 0); TestHelper.Assert(udpConnection.RemoteEndpoint?.Port == endpointPort); if (defaultHost.Equals("127.0.0.1")) { TestHelper.Assert(udpConnection.RemoteEndpoint.Address.ToString().Equals(defaultHost)); TestHelper.Assert(udpConnection.LocalEndpoint.Address.ToString().Equals(defaultHost)); } } output.WriteLine("ok"); testIntf.shutdown(); communicator.Shutdown(); communicator.WaitForShutdown(); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = helper.Protocol == Protocol.Ice1; var manager = IServerManagerPrx.Parse(helper.GetTestProxy("ServerManager", 0), communicator); var locator = communicator.DefaultLocator !.Clone(ITestLocatorPrx.Factory); Console.WriteLine("registry checkedcast"); var registry = locator.GetRegistry() !.Clone(ITestLocatorRegistryPrx.Factory); TestHelper.Assert(registry != null); System.IO.TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); IObjectPrx base1, base2, base3, base4, base5, base6; if (ice1) { base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); base3 = IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator); base4 = IObjectPrx.Parse("ServerManager", communicator); base5 = IObjectPrx.Parse("test2", communicator); base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); } else { base1 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base2 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base3 = IObjectPrx.Parse("ice:test", communicator); base4 = IObjectPrx.Parse("ice:ServerManager", communicator); base5 = IObjectPrx.Parse("ice:test2", communicator); base6 = IObjectPrx.Parse("ice:ReplicatedAdapter//test", communicator); } output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); var anotherLocator = ILocatorPrx.Parse(ice1 ? "anotherLocator" : "ice:anotherLocator", communicator); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Locator == null); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = locator; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); // TODO: We also test ice_router/ice_getRouter(perhaps we should add a test/Ice/router test?) TestHelper.Assert(base1.Router == null); var anotherRouter = IRouterPrx.Parse(ice1 ? "anotherRouter" : "ice:anotherRouter", communicator); base1 = base1.Clone(router: anotherRouter); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter)); var router = IRouterPrx.Parse(ice1 ? "dummyrouter" : "ice:dummyrouter", communicator); communicator.DefaultRouter = router; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !)); communicator.DefaultRouter = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.StartServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj1 = base1.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj1 != null); var obj2 = base2.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj2 != null); var obj3 = base3.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj3 != null); var obj4 = base4.CheckedCast(IServerManagerPrx.Factory); TestHelper.Assert(obj4 != null); var obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); var obj6 = base6.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj6 != null); output.WriteLine("ok"); output.Write("testing AdapterId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing ReplicaGroupId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj6.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); obj5.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { base1 = IObjectPrx.Parse(ice1 ? "unknown/unknown" : "ice:unknown/unknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (ObjectNotFoundException) { } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { base1 = IObjectPrx.Parse( ice1 ? "test @ TestAdapterUnknown" : "ice:TestAdapterUnknown//test", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); IObjectPrx basencc = IObjectPrx.Parse( ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(cacheConnection: false); int count = locator.GetRequestCount(); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. TestHelper.Assert(++count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout TestHelper.Assert(count == locator.GetRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator) .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); TestHelper.Assert(IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj1 = ITestIntfPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator); IHelloPrx?hello = obj1.GetHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "TestAdapter"); hello.SayHello(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "ReplicatedAdapter"); hello.SayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj1.GetReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false); TestHelper.Assert(hello != null); count = locator.GetRequestCount(); hello.IcePing(); TestHelper.Assert(++count == locator.GetRequestCount()); var results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 999); count = locator.GetRequestCount(); hello = hello.Clone(location: ImmutableArray.Create("unknown")); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync().ContinueWith( t => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is AdapterNotFoundException) { } }, TaskScheduler.Default)); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 1999); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); registry.SetAdapterDirectProxy( "TestAdapter3", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestUnknown" : "ice:TestUnknown//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter4" : "ice:TestAdapter4//test3", communicator)); // Update registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.AddObject(IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator)); try { IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; using Communicator ic = helper.Initialize(properties); registry.SetAdapterDirectProxy("TestAdapter5", locator.FindAdapterById("TestAdapter")); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 3; TestHelper.Assert(count == locator.GetRequestCount()); registry.SetAdapterDirectProxy("TestAdapter5", null); registry.AddObject(IObjectPrx.Parse(helper.GetTestProxy("test3", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); obj1.Shutdown(); manager.StartServer(); hello.SayHello(); output.WriteLine("ok"); // TODO: this does not work with ice2 because we currently don't retry on any remote exception, including // ONE. if (ice1) { output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); obj1.MigrateHello(); hello.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); output.WriteLine("ok"); } output.Write("testing locator encoding resolution... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone( encoding: Encoding.V11).IcePing(); // TODO: the count is apparently tied to whether or not we skip the if (ice1) block above. Would be nice to // add a comment. if (ice1) { TestHelper.Assert(count == locator.GetRequestCount()); } else { TestHelper.Assert(count + 1 == locator.GetRequestCount()); } output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj1.Shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { obj3.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { TestHelper.Assert(obj5 != null); obj5.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints( "Hello", ice1 ? "tcp -h localhost" : "ice+tcp://localhost:0"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(id, new Hello()); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx; if (ice1) { helloPrx = IHelloPrx.Parse($"{id}", communicator); } else { helloPrx = IHelloPrx.Parse($"ice:{id}", communicator); } TestHelper.Assert(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = adapter.CreateIndirectProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = adapter.CreateDirectProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.Shutdown(); output.WriteLine("ok"); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = IServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = ITestLocatorPrx.UncheckedCast(communicator.GetDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = ITestLocatorRegistryPrx.CheckedCast(locator.GetRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = IObjectPrx.Parse("test @ TestAdapter", communicator); var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); var base3 = IObjectPrx.Parse("test", communicator); var base4 = IObjectPrx.Parse("ServerManager", communicator); var base5 = IObjectPrx.Parse("test2", communicator); var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(default(ProxyIdentityComparer).Equals(@base.Locator, communicator.GetDefaultLocator())); var anotherLocator = ILocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Equals(@base.Locator, anotherLocator)); communicator.SetDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Equals(@base.Locator, anotherLocator)); communicator.SetDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Equals(@base.Locator, communicator.GetDefaultLocator())); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Equals(@base.Router, anotherRouter)); var router = IRouterPrx.Parse("dummyrouter", communicator); communicator.SetDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Equals(@base.Router, communicator.GetDefaultRouter())); communicator.SetDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.ITestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.ITestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.ITestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.IServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.ITestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.ITestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.ITestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject.Equals("object")); test(ex.Id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject.Equals("object adapter")); test(ex.Id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = ITestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = hello.Clone(adapterId: "unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync().ContinueWith((Task t) => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject == "object adapter"); test(ex.Id.Equals("TestAdapter3")); } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); registry.SetAdapterDirectProxy("TestAdapter3", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.KindOfObject == "object adapter"); test(ex.Id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; Communicator ic = helper.initialize(properties); registry.SetAdapterDirectProxy("TestAdapter5", locator.FindAdapterById("TestAdapter")); registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.SetAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.Destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.GetConnection().Close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = IHelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("Hello", "default"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(id, new Hello()); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx = IHelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateIndirectProxy(id, IObjectPrx.Factory)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateDirectProxy(id, IObjectPrx.Factory)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
public static ITestIntfPrx Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = TestHelper.GetTestProtocol(communicator.GetProperties()) == Protocol.Ice1; TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); var obj = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(1)); try { communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); TestHelper.Assert(false); } catch (ArgumentException) { } adapter.Dispose(); // Use a different port than the first adapter to avoid an "address already in use" error. adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); adapter.Dispose(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.Transient(); obj.TransientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { using var comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse(helper.GetTestProxy("test", 0), communicator).IcePingAsync(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 30000" : "ice+tcp://localhost:12345"); ObjectAdapter adapter = communicator.CreateObjectAdapter("PAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); Endpoint?endpt = adapter.PublishedEndpoints[0]; TestHelper.Assert(endpt != null); if (ice1) { TestHelper.Assert(endpt.ToString() !.Equals("tcp -h localhost -p 12345 -t 30000")); } else { TestHelper.Assert(endpt.ToString() !.Equals("ice+tcp://localhost:12345")); } var prx = IObjectPrx.Parse(ice1 ? "dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000" : "ice+tcp://localhost:12346/dummy?alt-endpoint=localhost:12347", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); TestHelper.Assert(adapter.PublishedEndpoints.Count == 2); TestHelper.Assert(adapter.CreateProxy(new Identity("dummy", ""), IObjectPrx.Factory).Endpoints. SequenceEqual(prx.Endpoints)); TestHelper.Assert(adapter.PublishedEndpoints.SequenceEqual(prx.Endpoints)); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); TestHelper.Assert(adapter.PublishedEndpoints[0].Equals(endpt)); communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 20000" : "ice+tcp://localhost:12345"); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); if (ice1) { TestHelper.Assert( adapter.PublishedEndpoints[0].ToString() == "tcp -h localhost -p 12345 -t 20000"); } else { TestHelper.Assert(adapter.PublishedEndpoints[0].ToString() == "ice+tcp://localhost:12345"); } adapter.Dispose(); } output.WriteLine("ok"); Connection?connection = obj.GetConnection(); if (connection != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapter(); connection.Adapter = adapter; connection.Adapter = null; adapter.Dispose(); // Setting a deactivated adapter on a connection no longer raise ObjectAdapterDeactivatedException connection.Adapter = adapter; output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity("router", ""); IRouterPrx router = obj.Clone(IRouterPrx.Factory, connectionId: "rc", identity: routerId); ObjectAdapter adapter = communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); string endpointsStr = adapter.PublishedEndpoints[0].ToString(); if (ice1) { TestHelper.Assert(endpointsStr == "tcp -h localhost -p 23456 -t 60000"); } else { TestHelper.Assert(endpointsStr == "ice+tcp://localhost:23456"); } adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); if (ice1) { TestHelper.Assert( adapter.PublishedEndpoints[0].ToString() == "tcp -h localhost -p 23457 -t 60000"); } else { TestHelper.Assert(adapter.PublishedEndpoints[0].ToString() == "ice+tcp://localhost:23457"); } try { adapter.SetPublishedEndpoints(router.Endpoints); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected. } adapter.Dispose(); try { routerId = new Identity("test", ""); router = obj.Clone(IRouterPrx.Factory, identity: routerId); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse(helper.GetTestProxy("test", 1), communicator); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { ObjectAdapter adapter1 = communicator.CreateObjectAdapterWithEndpoints("Adpt1", helper.GetTestEndpoint(10)); try { communicator.CreateObjectAdapterWithEndpoints("Adpt2", helper.GetTestEndpoint(10)); TestHelper.Assert(false); } catch { // Expected can't re-use the same endpoint. } adapter1.Dispose(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.Deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } return(obj); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); communicator.SetProperty("ReplyAdapter.Endpoints", "udp"); ObjectAdapter adapter = communicator.CreateObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); IPingReplyPrx reply = adapter.AddWithUUID(replyI, IPingReplyPrx.Factory) .Clone(invocationMode: InvocationMode.Datagram); adapter.Activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); var obj = ITestIntfPrx.Parse("test:" + helper.GetTestEndpoint(0, "udp"), communicator).Clone(invocationMode: InvocationMode.Datagram); try { int val = obj.getValue(); TestHelper.Assert(false); } catch (System.InvalidOperationException) { // expected } int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } TestHelper.Assert(ret == true); if (!(communicator.GetPropertyAsBool("Ice.Override.Compress") ?? false)) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = new byte[1024];; try { while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // TestHelper.Assert(seq.Length > 16384); } obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); communicator.SetProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // TestHelper.Assert(!b); } catch (DatagramLimitException) { } catch (Exception ex) { Console.Out.WriteLine(ex); TestHelper.Assert(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); StringBuilder endpoint = new StringBuilder(); // // Use loopback to prevent other machines to answer. // if (communicator.GetProperty("Ice.IPv6") == "1") { endpoint.Append("udp -h \"ff15::1:1\""); if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS) { endpoint.Append(" --interface \"::1\""); } } else { endpoint.Append("udp -h 239.255.1.1"); if (AssemblyUtil.IsWindows || AssemblyUtil.IsMacOS) { endpoint.Append(" --interface 127.0.0.1"); } } endpoint.Append(" -p "); endpoint.Append(helper.GetTestPort(10)); var objMcast = ITestIntfPrx.Parse($"test -d:{endpoint}", communicator); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); objMcast.ping(reply); ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } if (!ret) { Console.Out.WriteLine("failed(is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.GetConnection().Adapter = adapter; objMcast.GetConnection().Adapter = adapter; nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = adapter.AddWithUUID( replyI, IPingReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); } TestHelper.Assert(ret); Console.Out.WriteLine("ok"); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); string rf = "test @ TestAdapter"; var obj = ITestIntfPrx.Parse(rf, communicator); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.IcePing(); Console.Out.WriteLine("ok"); Console.Out.Write("testing locator finder... "); Identity finderId = new Identity("LocatorFinder", "Ice"); ILocatorFinderPrx?finder = ILocatorFinderPrx.CheckedCast(communicator.DefaultLocator !.Clone(finderId, IObjectPrx.Factory)); TestHelper.Assert(finder != null && finder.GetLocator() != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing discovery... "); { // Add test well-known object IRegistryPrx?registry = IRegistryPrx.Parse( communicator.DefaultLocator !.Identity.Category + "/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); session.GetAdmin() !.AddObjectWithType(obj, "::Test"); session.Destroy(); // // Ensure the IceGrid discovery locator can discover the // registries and make sure locator requests are forwarded. // var properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Port"] = helper.GetTestPort(99).ToString(); properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter"; properties["AdapterForDiscoveryTest.Endpoints"] = "default"; var com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); IObjectPrx.Parse("test", com).IcePing(); TestHelper.Assert(com.DefaultLocator !.GetRegistry() != null); TestHelper.Assert(ZeroC.IceGrid.ILocatorPrx.UncheckedCast(com.DefaultLocator !).GetLocalRegistry() != null); TestHelper.Assert(ZeroC.IceGrid.ILocatorPrx.UncheckedCast(com.DefaultLocator !).GetLocalQuery() != null); ObjectAdapter adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); adapter.Activate(); adapter.Deactivate(); com.Destroy(); // // Now, ensure that the IceGrid discovery locator correctly // handles failure to find a locator. // properties["IceLocatorDiscovery.InstanceName"] = "unknown"; properties["IceLocatorDiscovery.RetryCount"] = "1"; properties["IceLocatorDiscovery.Timeout"] = "100"; com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); } catch (NoEndpointException) { } try { IObjectPrx.Parse("test", com).IcePing(); } catch (NoEndpointException) { } TestHelper.Assert(com.DefaultLocator !.GetRegistry() == null); TestHelper.Assert(ZeroC.IceGrid.ILocatorPrx.CheckedCast(com.DefaultLocator !) == null); try { ZeroC.IceGrid.ILocatorPrx.UncheckedCast(com.DefaultLocator !).GetLocalRegistry(); } catch (OperationNotExistException) { } adapter = com.CreateObjectAdapter("AdapterForDiscoveryTest"); adapter.Activate(); adapter.Deactivate(); com.Destroy(); string multicast; if (communicator.GetProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } // // Test invalid lookup endpoints // properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } com.Destroy(); properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["IceLocatorDiscovery.RetryCount"] = "0"; properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } com.Destroy(); properties = communicator.GetProperties(); properties.Remove("Ice.Default.Locator"); properties["IceLocatorDiscovery.RetryCount"] = "1"; properties["Ice.Plugin.IceLocatorDiscovery"] = "Ice:ZeroC.IceLocatorDiscovery.PluginFactory"; { string intf = communicator.GetProperty("IceLocatorDiscovery.Interface") ?? ""; if (intf != "") { intf = $" --interface \"{intf}\""; } string port = helper.GetTestPort(99).ToString(); properties["IceLocatorDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}"; } com = new Communicator(properties); TestHelper.Assert(com.DefaultLocator != null); try { IObjectPrx.Parse("test @ TestAdapter", com).IcePing(); } catch (NoEndpointException) { TestHelper.Assert(false); } com.Destroy(); } Console.Out.WriteLine("ok"); Console.Out.Write("shutting down server... "); Console.Out.Flush(); obj.shutdown(); Console.Out.WriteLine("ok"); }
public static ITestIntfPrx allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var output = helper.GetWriter(); output.Write("testing stringToProxy... "); output.Flush(); ITestIntfPrx testPrx = ITestIntfPrx.Parse($"Test:{helper.GetTestEndpoint(0)} -t 2000", communicator); output.WriteLine("ok"); output.Write("base... "); output.Flush(); { try { testPrx.baseAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.b.Equals("Base.b")); TestHelper.Assert(b.GetType().FullName !.Equals("Test.Base")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("base (AMI)... "); output.Flush(); { try { testPrx.baseAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.b.Equals("Base.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown derived... "); output.Flush(); { try { testPrx.unknownDerivedAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownDerived.b")); TestHelper.Assert(b.GetType().FullName !.Equals("Test.Base")); } catch (System.Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown derived (AMI)... "); output.Flush(); { try { testPrx.unknownDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownDerived.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base... "); output.Flush(); { try { testPrx.knownDerivedAsBase(); TestHelper.Assert(false); } catch (KnownDerived k) { TestHelper.Assert(k.b.Equals("KnownDerived.b")); TestHelper.Assert(k.kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().FullName !.Equals("Test.KnownDerived")); } catch (System.Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownDerived k) { TestHelper.Assert(k.b.Equals("KnownDerived.b")); TestHelper.Assert(k.kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerived(); TestHelper.Assert(false); } catch (KnownDerived k) { TestHelper.Assert(k.b.Equals("KnownDerived.b")); TestHelper.Assert(k.kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().FullName !.Equals("Test.KnownDerived")); } catch (System.Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerivedAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownDerived k) { TestHelper.Assert(k.b.Equals("KnownDerived.b")); TestHelper.Assert(k.kd.Equals("KnownDerived.kd")); TestHelper.Assert(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base... "); output.Flush(); { try { testPrx.unknownIntermediateAsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownIntermediate.b")); TestHelper.Assert(b.GetType().FullName !.Equals("Test.Base")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownIntermediateAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownIntermediate.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base... "); output.Flush(); { try { testPrx.knownIntermediateAsBase(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("Test.KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of known most derived as base... "); output.Flush(); { try { testPrx.knownMostDerivedAsBase(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("Test.KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of known most derived as base (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("Test.KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("KnownIntermediate.b")); TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("Test.KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); TestHelper.Assert(false); } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().FullName !.Equals("Test.KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownMostDerived kmd) { TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b")); TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki")); TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd")); TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBase(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("Test.KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); TestHelper.Assert(false); } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().FullName !.Equals("Test.KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (KnownIntermediate ki) { TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b")); TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki")); TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBase(); TestHelper.Assert(false); } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownMostDerived2.b")); TestHelper.Assert(b.GetType().FullName !.Equals("Test.Base")); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseAsync().Wait(); TestHelper.Assert(false); } catch (AggregateException ae) { try { TestHelper.Assert(ae.InnerException != null); throw ae.InnerException; } catch (Base b) { TestHelper.Assert(b.b.Equals("UnknownMostDerived2.b")); TestHelper.Assert(b.GetType().Name.Equals("Base")); } catch (Exception) { TestHelper.Assert(false); } } } output.WriteLine("ok"); output.Write("unknown most derived in compact format... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); TestHelper.Assert(false); } catch (Base) { // Exceptions are always marshaled in sliced format; format:compact applies only to in-parameters and // return values. } catch (OperationNotExistException) { } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("completely unknown server-private exception... "); output.Flush(); { try { testPrx.serverPrivateException(); TestHelper.Assert(false); } catch (RemoteException ex) { SlicedData slicedData = ex.GetSlicedData() !.Value; TestHelper.Assert(slicedData.Slices.Count == 1); TestHelper.Assert(slicedData.Slices[0].TypeId ! == "::Test::ServerPrivateException"); } catch (Exception) { TestHelper.Assert(false); } } output.WriteLine("ok"); output.Write("preserved exceptions... "); output.Flush(); { try { testPrx.unknownPreservedAsBase(); TestHelper.Assert(false); } catch (Base ex) { IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices; TestHelper.Assert(slices.Count == 2); TestHelper.Assert(slices[1].TypeId !.Equals("::Test::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::Test::SPreserved2")); } try { testPrx.unknownPreservedAsKnownPreserved(); TestHelper.Assert(false); } catch (KnownPreserved ex) { TestHelper.Assert(ex.kp.Equals("preserved")); IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices; TestHelper.Assert(slices.Count == 2); TestHelper.Assert(slices[1].TypeId !.Equals("::Test::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::Test::SPreserved2")); } ObjectAdapter adapter = communicator.CreateObjectAdapter(); IRelayPrx relay = adapter.AddWithUUID(new Relay(), IRelayPrx.Factory); adapter.Activate(); testPrx.GetConnection().SetAdapter(adapter); try { testPrx.relayKnownPreservedAsBase(relay); TestHelper.Assert(false); } catch (KnownPreservedDerived ex) { TestHelper.Assert(ex.b.Equals("base")); TestHelper.Assert(ex.kp.Equals("preserved")); TestHelper.Assert(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { TestHelper.Assert(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); TestHelper.Assert(false); } catch (KnownPreservedDerived ex) { TestHelper.Assert(ex.b.Equals("base")); TestHelper.Assert(ex.kp.Equals("preserved")); TestHelper.Assert(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { TestHelper.Assert(false); } try { testPrx.relayUnknownPreservedAsBase(relay); TestHelper.Assert(false); } catch (Preserved2 ex) { TestHelper.Assert(ex.b.Equals("base")); TestHelper.Assert(ex.kp.Equals("preserved")); TestHelper.Assert(ex.kpd.Equals("derived")); TestHelper.Assert(ex.p1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId())); var pc = ex.p1 as PreservedClass; TestHelper.Assert(pc !.bc.Equals("bc")); TestHelper.Assert(pc !.pc.Equals("pc")); TestHelper.Assert(ex.p2 == ex.p1); } catch (OperationNotExistException) { } catch (Exception) { TestHelper.Assert(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); TestHelper.Assert(false); } catch (Preserved2 ex) { TestHelper.Assert(ex.b.Equals("base")); TestHelper.Assert(ex.kp.Equals("preserved")); TestHelper.Assert(ex.kpd.Equals("derived")); TestHelper.Assert(ex.p1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId())); var pc = ex.p1 as PreservedClass; TestHelper.Assert(pc !.bc.Equals("bc")); TestHelper.Assert(pc !.pc.Equals("pc")); TestHelper.Assert(ex.p2 == ex.p1); } catch (OperationNotExistException) { } catch (Exception) { TestHelper.Assert(false); } try { testPrx.relayClientPrivateException(relay); TestHelper.Assert(false); } catch (ClientPrivateException ex) { TestHelper.Assert(ex.cpe == "ClientPrivate"); } catch (System.Exception) { TestHelper.Assert(false); } adapter.Destroy(); } output.WriteLine("ok"); return(testPrx); }
public static void allTests(global::Test.TestHelper helper, bool collocated) { Communicator communicator = helper.communicator(); var p = ITestIntfPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var testController = ITestIntfControllerPrx.Parse($"testController:{helper.getTestEndpoint(1)}", communicator); var output = helper.getWriter(); output.Write("testing async invocation..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(p.IceIsAAsync("::Test::TestIntf").Result); test(p.IceIsAAsync("::Test::TestIntf", ctx).Result); p.IcePingAsync().Wait(); p.IcePingAsync(ctx).Wait(); test(p.IceIdAsync().Result.Equals("::Test::TestIntf")); test(p.IceIdAsync(ctx).Result.Equals("::Test::TestIntf")); test(p.IceIdsAsync().Result.Length == 2); test(p.IceIdsAsync(ctx).Result.Length == 2); if (!collocated) { test(p.GetConnectionAsync().Result != null); } p.opAsync().Wait(); p.opAsync(ctx).Wait(); test(p.opWithResultAsync().Result == 15); test(p.opWithResultAsync(ctx).Result == 15); try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } try { p.opWithUEAsync(ctx).Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } } output.WriteLine("ok"); output.Write("testing async/await..."); output.Flush(); { Task.Run(async() => { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(await p.IceIsAAsync("::Test::TestIntf")); test(await p.IceIsAAsync("::Test::TestIntf", ctx)); await p.IcePingAsync(); await p.IcePingAsync(ctx); var id = await p.IceIdAsync(); test(id.Equals("::Test::TestIntf")); id = await p.IceIdAsync(ctx); test(id.Equals("::Test::TestIntf")); var ids = await p.IceIdsAsync(); test(ids.Length == 2); ids = await p.IceIdsAsync(ctx); test(ids.Length == 2); if (!collocated) { var conn = await p.GetConnectionAsync(); test(conn != null); } await p.opAsync(); await p.opAsync(ctx); var result = await p.opWithResultAsync(); test(result == 15); result = await p.opWithResultAsync(ctx); test(result == 15); try { await p.opWithUEAsync(); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } try { await p.opWithUEAsync(ctx); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing async continuations..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); p.IceIsAAsync("::Test::TestIntf").ContinueWith(previous => { test(previous.Result); }).Wait(); p.IceIsAAsync("::Test::TestIntf", ctx).ContinueWith(previous => { test(previous.Result); }).Wait(); p.IcePingAsync().ContinueWith(previous => { previous.Wait(); }).Wait(); p.IcePingAsync(ctx).ContinueWith(previous => { previous.Wait(); }).Wait(); p.IceIdAsync().ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.IceIdAsync(ctx).ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.IceIdsAsync().ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); p.IceIdsAsync(ctx).ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); if (!collocated) { p.GetConnectionAsync().ContinueWith(previous => { test(previous.Result != null); }).Wait(); } p.opAsync().ContinueWith(previous => previous.Wait()).Wait(); p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait(); p.opWithResultAsync().ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithResultAsync(ctx).ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithUEAsync().ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); p.opWithUEAsync(ctx).ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing local exceptions with async tasks... "); output.Flush(); { ITestIntfPrx indirect = p.Clone(adapterId: "dummy"); try { indirect.opAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is NoEndpointException); }); } try { p.Clone(oneway: true).opWithResultAsync(); test(false); } catch (TwowayOnlyException) { } // // Check that CommunicatorDestroyedException is raised directly. // if (p.GetConnection() != null) { Communicator ic = helper.initialize(communicator.GetProperties()); IObjectPrx o = IObjectPrx.Parse(p.ToString(), ic); ITestIntfPrx p2 = ITestIntfPrx.CheckedCast(o); ic.destroy(); try { p2.opAsync(); test(false); } catch (CommunicatorDestroyedException) { // Expected. } } } output.WriteLine("ok"); output.Write("testing exception with async task... "); output.Flush(); { ITestIntfPrx i = p.Clone(adapterId: "dummy"); try { i.IceIsAAsync("::Test::TestIntf").Wait(); test(false); } catch (AggregateException) { } try { i.opAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithResultAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithUEAsync().Wait(); test(false); } catch (AggregateException) { } // Ensures no exception is called when response is received test(p.IceIsAAsync("::Test::TestIntf").Result); p.opAsync().Wait(); p.opWithResultAsync().Wait(); // If response is a user exception, it should be received. try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is Test.TestIntfException); }); } } output.WriteLine("ok"); output.Write("testing progress callback... "); output.Flush(); { { SentCallback cb = new SentCallback(); Task t = p.IceIsAAsync("", progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IcePingAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IceIdAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IceIdsAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.opAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); } List <Task> tasks = new List <Task>(); byte[] seq = new byte[10024]; (new Random()).NextBytes(seq); testController.holdAdapter(); try { Task t = null; ProgresCallback cb; do { cb = new ProgresCallback(); t = p.opWithPayloadAsync(seq, progress: cb); tasks.Add(t); }while (cb.SentSynchronously); } finally { testController.resumeAdapter(); } foreach (Task t in tasks) { t.Wait(); } } output.WriteLine("ok"); output.Write("testing async/await... "); output.Flush(); Func <Task> task = async() => { try { await p.opAsync(); var r = await p.opWithResultAsync(); test(r == 15); try { await p.opWithUEAsync(); } catch (Test.TestIntfException) { } // Operations implemented with amd and async. await p.opAsyncDispatchAsync(); r = await p.opWithResultAsyncDispatchAsync(); test(r == 15); try { await p.opWithUEAsyncDispatchAsync(); test(false); } catch (Test.TestIntfException) { } } catch (OperationNotExistException) { // Expected with cross testing, this opXxxAsyncDispatch methods are C# only. } }; task().Wait(); output.WriteLine("ok"); if (p.GetConnection() != null) { output.Write("testing async Task cancellation... "); output.Flush(); { var cs1 = new CancellationTokenSource(); var cs2 = new CancellationTokenSource(); var cs3 = new CancellationTokenSource(); Task t1; Task t2; Task t3; try { testController.holdAdapter(); ProgresCallback cb = null; byte[] seq = new byte[10024]; for (int i = 0; i < 200; ++i) // 2MB { cb = new ProgresCallback(); p.opWithPayloadAsync(seq, progress: cb); } test(!cb.Sent); t1 = p.IcePingAsync(cancel: cs1.Token); t2 = p.IcePingAsync(cancel: cs2.Token); cs3.Cancel(); t3 = p.IcePingAsync(cancel: cs3.Token); cs1.Cancel(); cs2.Cancel(); try { t1.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t2.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t3.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } } finally { testController.resumeAdapter(); p.IcePing(); } } output.WriteLine("ok"); } if (p.GetConnection() != null && p.supportsAMD()) { output.Write("testing graceful close connection with wait... "); output.Flush(); { // // Local case: begin a request, close the connection gracefully, and make sure it waits // for the request to complete. // Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); Task t = p.sleepAsync(100); con.close(ConnectionClose.GracefullyWithWait); t.Wait(); // Should complete successfully. cb.check(); } { // // Remote case. // byte[] seq = new byte[1024 * 10]; // // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // int maxQueue = 2; bool done = false; while (!done && maxQueue < 50) { done = true; p.IcePing(); List <Task> results = new List <Task>(); for (int i = 0; i < maxQueue; ++i) { results.Add(p.opWithPayloadAsync(seq)); } ProgresCallback cb = new ProgresCallback(); p.closeAsync(Test.CloseMode.GracefullyWithWait, progress: cb); if (!cb.SentSynchronously) { for (int i = 0; i < maxQueue; i++) { cb = new ProgresCallback(); Task t = p.opWithPayloadAsync(seq, progress: cb); results.Add(t); if (cb.SentSynchronously) { done = false; maxQueue *= 2; break; } } } else { maxQueue *= 2; done = false; } foreach (Task q in results) { q.Wait(); } } } output.WriteLine("ok"); output.Write("testing graceful close connection without wait... "); output.Flush(); { // // Local case: start an operation and then close the connection gracefully on the client side // without waiting for the pending invocation to complete. There will be no retry and we expect the // invocation to fail with ConnectionManuallyClosedException. // p = p.Clone(connectionId: "CloseGracefully"); // Start with a new connection. Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Gracefully); try { t.Wait(); test(false); } catch (System.AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test((ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection gracefully, which means the connection // will not be closed until all pending dispatched requests have completed. // con = p.GetConnection(); cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); t = p.sleepAsync(100); p.close(Test.CloseMode.Gracefully); // Close is delayed until sleep completes. cb.check(); t.Wait(); } output.WriteLine("ok"); output.Write("testing forceful close connection... "); output.Flush(); { // // Local case: start an operation and then close the connection forcefully on the client side. // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException. // p.IcePing(); Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Forcefully); try { t.Wait(); test(false); } catch (AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test(!(ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection forcefully. This causes the request to fail // with a ConnectionLostException. Since the close() operation is not idempotent, the client // will not retry. // try { p.close(Test.CloseMode.Forcefully); test(false); } catch (ConnectionLostException) { // Expected. } } output.WriteLine("ok"); } output.Write("testing ice_scheduler... "); output.Flush(); { p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }).Wait(); p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, p.Scheduler).Wait(); { TaskCompletionSource <int> s1 = new TaskCompletionSource <int>(); TaskCompletionSource <int> s2 = new TaskCompletionSource <int>(); Task t1 = s1.Task; Task t2 = s2.Task; Task t3 = null; Task t4 = null; p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); // // t1 Continuation run in the thread that completes it. // var id = Thread.CurrentThread.ManagedThreadId; t3 = t1.ContinueWith(prev => { test(id == Thread.CurrentThread.ManagedThreadId); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.Scheduler); s1.SetResult(1); // // t2 completed from the main thread // t4 = t2.ContinueWith(prev => { test(id != Thread.CurrentThread.ManagedThreadId); test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.Scheduler); }, p.Scheduler).Wait(); s2.SetResult(1); Task.WaitAll(t1, t2, t3, t4); } if (!collocated) { ObjectAdapter adapter = communicator.createObjectAdapter(""); PingReplyI replyI = new PingReplyI(); var reply = adapter.Add(replyI); adapter.Activate(); p.GetConnection().setAdapter(adapter); p.pingBiDir(reply); test(replyI.checkReceived()); adapter.Destroy(); } } output.WriteLine("ok"); output.Write("testing result struct... "); output.Flush(); { var q = Test.Outer.Inner.ITestIntfPrx.Parse($"test2:{helper.getTestEndpoint(0)}", communicator); q.opAsync(1).ContinueWith(t => { var r = t.Result; test(r.returnValue == 1); test(r.j == 1); }).Wait(); } output.WriteLine("ok"); p.shutdown(); }