public override void Run(string[] args) { using var communicator = Initialize(ref args); ITestIntfPrx test = AllTests.allTests(this, false); test.shutdown(); }
public override async Task RunAsync(string[] args) { await using Communicator communicator = Initialize(ref args); communicator.SetProperty("TestAdapterForwarder.Endpoints", GetTestEndpoint(0)); if (Protocol == Protocol.Ice1) { communicator.SetProperty("TestAdapterSame.Endpoints", $"{Transport} -h localhost"); communicator.SetProperty("TestAdapterOther.Endpoints", $"ice+{Transport}://localhost:0"); } else { communicator.SetProperty("TestAdapterSame.Endpoints", $"ice+{Transport}://localhost:0"); communicator.SetProperty("TestAdapterOther.Endpoints", $"{Transport} -h localhost"); } ObjectAdapter adapterForwarder = communicator.CreateObjectAdapter("TestAdapterForwarder"); ObjectAdapter adapterSame = communicator.CreateObjectAdapter("TestAdapterSame"); ObjectAdapter adapterOther = communicator.CreateObjectAdapter("TestAdapterOther"); ITestIntfPrx samePrx = adapterSame.Add("TestSame", new TestI(), ITestIntfPrx.Factory); ITestIntfPrx otherPrx = adapterOther.Add("TestOther", new TestI(), ITestIntfPrx.Factory); adapterForwarder.Add("ForwardSame", new Forwarder(samePrx)); adapterForwarder.Add("ForwardOther", new Forwarder(otherPrx)); await adapterForwarder.ActivateAsync(); await adapterSame.ActivateAsync(); await adapterOther.ActivateAsync(); ServerReady(); await communicator.WaitForShutdownAsync(); }
public override async Task RunAsync(string[] args) { await using Communicator communicator = Initialize(ref args); ITestIntfPrx test = await AllTests.RunAsync(this); await test.ShutdownAsync(); }
public override async Task RunAsync(string[] args) { Dictionary <string, string>?properties = CreateTestProperties(ref args); properties["Ice.Warn.Connections"] = "0"; properties["Ice.UDP.SndSize"] = "16K"; properties["Ice.Default.Protocol"] = "ice1"; // TODO: see comment in server await using Communicator communicator = Initialize(properties); AllTests.Run(this); int num; try { num = args.Length == 1 ? int.Parse(args[0]) : 1; } catch (FormatException) { num = 1; } for (int i = 0; i < num; ++i) { ITestIntfPrx.Parse(GetTestProxy("control", i, "tcp"), communicator).Shutdown(); } }
public override void Run(string[] args) { var properties = CreateTestProperties(ref args); properties["Ice.Warn.Connections"] = "0"; properties["Ice.UDP.SndSize"] = "16384"; using var communicator = Initialize(properties); AllTests.allTests(this); int num; try { num = args.Length == 1 ? int.Parse(args[0]) : 1; } catch (FormatException) { num = 1; } for (int i = 0; i < num; ++i) { ITestIntfPrx.Parse("control:" + GetTestEndpoint(i, "tcp"), communicator).shutdown(); } }
public override async Task RunAsync(string[] args) { await using Communicator communicator = Initialize(ref args); ITestIntfPrx test = AllTests.allTests(this); test.shutdown(); }
public static ITestIntfPrx Run(TestHelper helper, Communicator communicator) { var prx1 = ITestIntfPrx.Parse(helper.GetTestProxy("test-1", 0), communicator); var prx2 = ITestIntfPrx.Parse(helper.GetTestProxy("test-2", 0), communicator); for (int size = 1024; size <= 4096; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx1.OpCompressParams(size, p1); byte[] p2 = prx1.OpCompressParamsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx1.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); } for (int size = 2; size < 1024; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx2.OpCompressParams(size, p1); byte[] p2 = prx2.OpCompressParamsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx2.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); } return(prx1); }
public override void Run(string[] args) { using Communicator communicator = Initialize(ref args); ITestIntfPrx proxy = AllTests.allTests(this); proxy.shutdown(); }
public override Task RunAsync(string[] args) { using Communicator communicator = Initialize(ref args); ITestIntfPrx proxy = AllTests.allTests(this); proxy.Shutdown(); return(Task.CompletedTask); }
public override void RunTestCase(IRemoteObjectAdapterPrx adapter, ITestIntfPrx proxy) { proxy.Sleep(4); lock (Mutex) { TestHelper.Assert(Heartbeat >= 4); } }
public static async Task RunAsync(Communicator communicator, bool shutdown) { var prx1 = ITestIntfPrx.Parse(TestHelper.GetTestProxy("test-1", communicator.GetProperties()), communicator); var prx2 = ITestIntfPrx.Parse(TestHelper.GetTestProxy("test-2", communicator.GetProperties()), communicator); for (int size = 1024; size <= 4096; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx1.OpCompressArgs(size, p1); byte[] p2 = prx1.OpCompressArgsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx1.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); try { prx1.OpWithUserException(size); TestHelper.Assert(false); } catch (MyException ex) { TestHelper.Assert(ex.Bytes.SequenceEqual(p1)); } } for (int size = 2; size < 1024; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx2.OpCompressArgs(size, p1); byte[] p2 = prx2.OpCompressArgsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx2.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); try { prx1.OpWithUserException(size); TestHelper.Assert(false); } catch (MyException ex) { TestHelper.Assert(ex.Bytes.SequenceEqual(p1)); } } if (shutdown) { await prx1.ShutdownAsync(); } }
public override Task RunTestCaseAsync(IRemoteObjectAdapterPrx adapter, ITestIntfPrx proxy) { proxy.Sleep(4); lock (Mutex) { TestHelper.Assert(Heartbeat >= 2); TestHelper.Assert(!Closed); } return(Task.CompletedTask); }
public override void RunTestCase(IRemoteObjectAdapterPrx adapter, ITestIntfPrx proxy) { proxy.StartHeartbeatCount(); Connection con = proxy.GetConnection() !; con.Ping(); con.Ping(); con.Ping(); con.Ping(); con.Ping(); proxy.WaitForHeartbeatCount(5); }
public static ITestIntfPrx Run(TestHelper helper, Communicator communicator) { var prx1 = ITestIntfPrx.Parse(helper.GetTestProxy("test-1", 0), communicator); var prx2 = ITestIntfPrx.Parse(helper.GetTestProxy("test-2", 0), communicator); for (int size = 1024; size <= 4096; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx1.OpCompressArgs(size, p1); byte[] p2 = prx1.OpCompressArgsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx1.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); try { prx1.OpWithUserException(size); TestHelper.Assert(false); } catch (MyException ex) { TestHelper.Assert(ex.Bytes.SequenceEqual(p1)); } } for (int size = 2; size < 1024; size *= 2) { byte[] p1 = Enumerable.Range(0, size).Select(i => (byte)i).ToArray(); prx2.OpCompressArgs(size, p1); byte[] p2 = prx2.OpCompressArgsAndReturn(p1); TestHelper.Assert(p1.SequenceEqual(p2)); p2 = prx2.OpCompressReturn(size); TestHelper.Assert(p1.SequenceEqual(p2)); try { prx1.OpWithUserException(size); TestHelper.Assert(false); } catch (MyException ex) { TestHelper.Assert(ex.Bytes.SequenceEqual(p1)); } } return(prx1); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); string sref = helper.GetTestProxy("test", 0); var testPrx = ITestIntfPrx.Parse(sref, communicator); int proxyPort = communicator.GetPropertyAsInt("Ice.HTTPProxyPort") ?? communicator.GetPropertyAsInt("Ice.SOCKSProxyPort") ?? 0; TextWriter output = helper.GetWriter(); output.Write("testing connection... "); output.Flush(); { testPrx.IcePing(); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { var connection = (IPConnection)testPrx.GetConnection() !; TestHelper.Assert(connection.RemoteEndpoint !.Port == proxyPort); // make sure we are connected to the proxy port. } output.WriteLine("ok"); output.Write("shutting down server... "); output.Flush(); { testPrx.Shutdown(); } output.WriteLine("ok"); output.Write("testing connection failure... "); output.Flush(); { try { testPrx.IcePing(); TestHelper.Assert(false); } catch { } } output.WriteLine("ok"); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); string sref = "test:" + helper.GetTestEndpoint(0); var testPrx = ITestIntfPrx.Parse(sref, communicator); int proxyPort = communicator.GetPropertyAsInt("Ice.HTTPProxyPort") ?? communicator.GetPropertyAsInt("Ice.SOCKSProxyPort") ?? 0; var output = helper.GetWriter(); output.Write("testing connection... "); output.Flush(); { testPrx.IcePing(); } output.WriteLine("ok"); output.Write("testing connection information... "); output.Flush(); { IPConnectionInfo?info = getIPConnectionInfo(testPrx.GetConnection() !.GetConnectionInfo()); TestHelper.Assert(info !.RemotePort == proxyPort); // make sure we are connected to the proxy port. } output.WriteLine("ok"); output.Write("shutting down server... "); output.Flush(); { testPrx.shutdown(); } output.WriteLine("ok"); output.Write("testing connection failure... "); output.Flush(); { try { testPrx.IcePing(); TestHelper.Assert(false); } catch (System.Exception) { } } output.WriteLine("ok"); }
public override async Task RunAsync(string[] args) { await using Communicator communicator = Initialize(ref args); try { ITestIntfPrx server = await AllTests.Run(this, false); await server.ShutdownAsync(); } catch (TestFailedException ex) { Output.WriteLine($"test failed: {ex.Reason}"); Assert(false); throw; } }
public override void RunTestCase(IRemoteObjectAdapterPrx adapter, ITestIntfPrx proxy) { Connection?con = proxy.GetCachedConnection(); TestHelper.Assert(con != null); TestHelper.Assert(con.IdleTimeout == TimeSpan.FromSeconds(1)); TestHelper.Assert(con.KeepAlive == false); con.KeepAlive = true; TestHelper.Assert(con.KeepAlive == true); try { con.IdleTimeout = TimeSpan.FromSeconds(1); } catch { } proxy.StartHeartbeatCount(); proxy.WaitForHeartbeatCount(2); var t1 = new TaskCompletionSource <object?>(); var t2 = new TaskCompletionSource <object?>(); con.Closed += (sender, args) => t1.SetResult(null); con.Closed += (sender, args) => t2.SetResult(null); con.GoAwayAsync(); TestHelper.Assert(t1.Task.Result == null); TestHelper.Assert(t2.Task.Result == null); TestHelper.Assert(!con.IsActive); var t3 = new TaskCompletionSource <object?>(); con.Closed += (sender, args) => t3.SetResult(null); TestHelper.Assert(t3.Task.Result == null); con.PingReceived += (sender, args) => TestHelper.Assert(false); foreach ((int idleTimeout, string keepAlive) in new (int, string)[]
public static async Task RunAsync(TestHelper helper) { Communicator communicator = helper.Communicator !; var forwardSamePrx = ITestIntfPrx.Parse(helper.GetTestProxy("ForwardSame", 0), communicator); var forwardOtherPrx = ITestIntfPrx.Parse(helper.GetTestProxy("ForwardOther", 0), communicator); // The proxies have the same protocol and encoding; the difference is what they forward to. TestHelper.Assert(forwardSamePrx.Protocol == forwardOtherPrx.Protocol); TestHelper.Assert(forwardSamePrx.Encoding == forwardOtherPrx.Encoding); ITestIntfPrx newPrx; System.IO.TextWriter output = helper.Output; output.Write("testing forwarding with same protocol... "); output.Flush(); newPrx = TestProxy(forwardSamePrx); TestHelper.Assert(newPrx.Protocol == forwardSamePrx.Protocol); TestHelper.Assert(newPrx.Encoding == forwardSamePrx.Encoding); _ = TestProxy(newPrx); output.WriteLine("ok"); output.Write("testing forwarding with other protocol... "); output.Flush(); newPrx = TestProxy(forwardOtherPrx); TestHelper.Assert(newPrx.Protocol != forwardOtherPrx.Protocol); TestHelper.Assert(newPrx.Encoding == forwardOtherPrx.Encoding); // encoding must remain the same _ = TestProxy(newPrx); output.WriteLine("ok"); output.Write("testing forwarding with other protocol and other encoding... "); output.Flush(); Encoding encoding = forwardOtherPrx.Encoding == Encoding.V11 ? Encoding.V20 : Encoding.V11; newPrx = TestProxy(forwardOtherPrx.Clone(encoding: encoding)); TestHelper.Assert(newPrx.Protocol != forwardOtherPrx.Protocol); TestHelper.Assert(newPrx.Encoding == encoding); _ = TestProxy(newPrx); output.WriteLine("ok"); await forwardSamePrx.ShutdownAsync(); }
public override async Task RunAsync(string[] args) { await AllTests.RunAsync(this); int num; try { num = args.Length == 1 ? int.Parse(args[0]) : 1; } catch (FormatException) { num = 1; } for (int i = 0; i < num; ++i) { ITestIntfPrx.Parse(GetTestProxy("control", i, Transport), Communicator).Shutdown(); } }
private static ITestIntfPrx TestProxy(ITestIntfPrx prx) { var ctx = new Dictionary <string, string>(prx.Context); ctx.Add("MyCtx", "hello"); TestHelper.Assert(prx.Op(13, ctx) == 13); prx.OpVoid(ctx); (int v, string s) = prx.OpReturnOut(34); TestHelper.Assert(v == 34 && s == "value=34"); prx.OpOneway(42); try { prx.OpMyError(); TestHelper.Assert(false); } catch (MyError ex) { TestHelper.Assert(ex.Number == 42); } try { prx.OpObjectNotExistException(); TestHelper.Assert(false); } catch (ObjectNotExistException) { } return(prx.OpNewProxy().Clone(context: new Dictionary <string, string> { { "Direct", "1" } })); }
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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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("ZeroC.Ice.Test.Slicing.Exceptions.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 ! == "::Slicing::Exceptions::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("::Slicing::Exceptions::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::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("::Slicing::Exceptions::SPreserved1")); TestHelper.Assert(slices[0].TypeId !.Equals("::Slicing::Exceptions::SPreserved2")); } ObjectAdapter adapter = communicator.CreateObjectAdapter(); IRelayPrx relay = adapter.AddWithUUID(new Relay(), IRelayPrx.Factory); adapter.Activate(); 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 (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 (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(Test.TestHelper helper, List <int> ports) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string refString = "test"; for (int i = 0; i < ports.Count; i++) { refString += ":" + helper.getTestEndpoint(ports[i]); } Ice.IObjectPrx basePrx = Ice.IObjectPrx.Parse(refString, communicator); test(basePrx != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); ITestIntfPrx obj = ITestIntfPrx.CheckedCast(basePrx); test(obj != null); test(obj.Equals(basePrx)); 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(); test(pid != oldPid); output.WriteLine("ok"); oldPid = pid; } else { output.Write("testing server #" + i + " with AMI... "); output.Flush(); var pid = obj.pidAsync().Result; test(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(); test(false); } catch (Ice.ConnectionLostException) { output.WriteLine("ok"); } catch (Ice.ConnectFailedException) { output.WriteLine("ok"); } catch (Ice.TransportException) { output.WriteLine("ok"); } } else { output.Write("aborting server #" + i + " with AMI... "); output.Flush(); try { obj.abortAsync().Wait(); test(false); } catch (AggregateException ex) { 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(); test(false); } catch (Ice.ConnectionLostException) { output.WriteLine("ok"); } catch (Ice.ConnectFailedException) { output.WriteLine("ok"); } catch (Ice.TransportException) { output.WriteLine("ok"); } } else { output.Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent AMI call... "); output.Flush(); try { obj.idempotentAbortAsync().Wait(); test(false); } catch (AggregateException ex) { exceptAbortI(ex.InnerException, output); } output.WriteLine("ok"); } ++i; } else { Debug.Assert(false); } } output.Write("testing whether all servers are gone... "); output.Flush(); try { obj.IcePing(); test(false); } catch (System.Exception) { output.WriteLine("ok"); } }
public static ITestIntfPrx allTests(Test.TestHelper helper, bool collocated) { Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string @ref = "Test:" + helper.getTestEndpoint(0) + " -t 2000"; var @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); ITestIntfPrx testPrx = ITestIntfPrx.CheckedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); output.WriteLine("ok"); output.Write("base... "); output.Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("base (AMI)... "); output.Flush(); { try { testPrx.baseAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown derived... "); output.Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown derived (AMI)... "); output.Flush(); { try { testPrx.unknownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base... "); output.Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base... "); output.Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base... "); output.Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of known most derived as base... "); output.Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of known most derived as base (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (System.Exception) { test(false); } } } output.WriteLine("ok"); output.Write("unknown most derived in compact format... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { test(false); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // } catch (Ice.OperationNotExistException) { } catch (System.Exception) { test(false); } } output.WriteLine("ok"); output.Write("preserved exceptions... "); output.Flush(); { try { testPrx.unknownPreservedAsBase(); test(false); } catch (Base ex) { IReadOnlyList <Ice.SliceInfo> slices = ex.GetSlicedData().Value.Slices; test(slices.Count == 2); test(slices[1].TypeId.Equals("::Test::SPreserved1")); test(slices[0].TypeId.Equals("::Test::SPreserved2")); } try { testPrx.unknownPreservedAsKnownPreserved(); test(false); } catch (KnownPreserved ex) { test(ex.kp.Equals("preserved")); IReadOnlyList <Ice.SliceInfo> slices = ex.GetSlicedData().Value.Slices; test(slices.Count == 2); test(slices[1].TypeId.Equals("::Test::SPreserved1")); test(slices[0].TypeId.Equals("::Test::SPreserved2")); } ObjectAdapter adapter = communicator.CreateObjectAdapter(""); IRelayPrx relay = adapter.Add(new Relay(), IRelayPrx.Factory); adapter.Activate(); testPrx.GetConnection().SetAdapter(adapter); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.GetType().GetIceTypeId().Equals(typeof(PreservedClass).GetIceTypeId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.GetType().GetIceTypeId().Equals(typeof(PreservedClass).GetIceTypeId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (Ice.OperationNotExistException) { } catch (System.Exception) { test(false); } adapter.Destroy(); } output.WriteLine("ok"); return(testPrx); }
public abstract void RunTestCase(IRemoteObjectAdapterPrx adapter, ITestIntfPrx proxy);
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); communicator.SetProperty("ReplyAdapter.Endpoints", "udp"); 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 ValueTask AllTestsWithServer(TestHelper helper, bool collocated, int server) { System.IO.TextWriter output = helper.Output; TaskScheduler?scheduler = TaskScheduler.Current; var proxy = ITestIntfPrx.Parse(helper.GetTestProxy("test", 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"), TaskScheduler.Current); TestHelper.Assert(TaskScheduler.Current == scheduler); await proxy.PingAsync().ContinueWith(checkScheduler("pingAsyncAsync"), TaskScheduler.Current); 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 unless it completes synchronously in which cause it will run on the current // scheduler. await proxy.PingSyncAsync().ConfigureAwait(false); TestHelper.Assert(TaskScheduler.Current == TaskScheduler.Default); await proxy.PingAsync().ConfigureAwait(false); TestHelper.Assert(TaskScheduler.Current == TaskScheduler.Default); }
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 (LocalException) { } 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) { 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 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); } 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 RunWithDeploy(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"); var registry = IRegistryPrx.Parse( $"{communicator.DefaultLocator!.Identity.Category}/Registry", communicator); IAdminSessionPrx?session = registry.CreateAdminSession("foo", "bar"); TestHelper.Assert(session != null); Connection?connection = session.GetConnection() !; connection.Acm = new Acm(TimeSpan.FromSeconds(registry.GetACMTimeout()), connection.Acm.Close, AcmHeartbeat.Always); 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(); }