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 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 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 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 void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; bool ice1 = helper.Protocol == Protocol.Ice1; TestHelper.Assert(communicator != null); var com = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator); string testTransport = helper.Transport; var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); System.IO.TextWriter output = helper.Output; output.Write("testing binding with single endpoint... "); output.Flush(); { // Use "default" with ice1 + tcp here to ensure that it still works IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", (ice1 && testTransport == "tcp") ? "default" : testTransport); TestHelper.Assert(adapter != null); ITestIntfPrx?test1 = adapter.GetTestIntf(); ITestIntfPrx?test2 = adapter.GetTestIntf(); TestHelper.Assert(test1 != null && test2 != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); TestHelper.Assert(test3.GetCachedConnection() == test1.GetCachedConnection()); TestHelper.Assert(test3.GetCachedConnection() == test2.GetCachedConnection()); try { test3.IcePing(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter31", testTransport) !, com.CreateObjectAdapter("Adapter32", testTransport) !, com.CreateObjectAdapter("Adapter33", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter31"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter32"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter33"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } adapters.Clear(); } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport); TestHelper.Assert(adapter != null); ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false); ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false); TestHelper.Assert(!test1.CacheConnection); TestHelper.Assert(!test2.CacheConnection); TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); try { TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter61", testTransport) !, com.CreateObjectAdapter("Adapter62", testTransport) !, com.CreateObjectAdapter("Adapter63", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.CacheConnection); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing connection reuse with multiple endpoints... "); output.Flush(); { var adapters1 = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter81", testTransport) !, com.CreateObjectAdapter("Adapter82", testTransport) !, com.CreateObjectAdapter("Adapter83", testTransport) ! }; var adapters2 = new List <IRemoteObjectAdapterPrx> { adapters1[0], com.CreateObjectAdapter("Adapter84", testTransport) !, com.CreateObjectAdapter("Adapter85", testTransport) ! }; ITestIntfPrx obj1 = CreateTestIntfPrx(adapters1); ITestIntfPrx obj2 = CreateTestIntfPrx(adapters2); com.DeactivateObjectAdapter(adapters1[0]); Task <string> t1 = obj1.GetAdapterNameAsync(); Task <string> t2 = obj2.GetAdapterNameAsync(); TestHelper.Assert(t1.Result == "Adapter82"); TestHelper.Assert(t2.Result == "Adapter84"); Deactivate(com, adapters1); Deactivate(com, adapters2); } { var adapters1 = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter91", testTransport) !, com.CreateObjectAdapter("Adapter92", testTransport) !, com.CreateObjectAdapter("Adapter93", testTransport) ! }; var adapters2 = new List <IRemoteObjectAdapterPrx> { adapters1[0], com.CreateObjectAdapter("Adapter94", testTransport) !, com.CreateObjectAdapter("Adapter95", testTransport) ! }; ITestIntfPrx obj1 = CreateTestIntfPrx(adapters1); ITestIntfPrx obj2 = CreateTestIntfPrx(adapters2); Task <string> t1 = obj1.GetAdapterNameAsync(); Task <string> t2 = obj2.GetAdapterNameAsync(); TestHelper.Assert(t1.Result == "Adapter91"); TestHelper.Assert(t2.Result == "Adapter91"); Deactivate(com, adapters1); Deactivate(com, adapters2); } output.WriteLine("ok"); if (helper.Protocol == Protocol.Ice1) { output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter71", testTransport), com.CreateObjectAdapter("Adapter72", "udp") }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71")); // test that datagram proxies fail if PreferNonSecure is false ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram, preferNonSecure: false); try { testUDP.GetConnection(); TestHelper.Assert(false); } catch (NoEndpointException) { // expected } testUDP = obj.Clone(invocationMode: InvocationMode.Datagram, preferNonSecure: true); TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.GetAdapterName(); TestHelper.Assert(false); } catch (InvalidOperationException) { // expected } } output.WriteLine("ok"); } if (communicator.GetProperty("Ice.Plugin.IceSSL") != null) { output.Write("testing secure and non-secure endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter81", "ssl") !, com.CreateObjectAdapter("Adapter82", "tcp") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82")); obj.GetConnection().GoAwayAsync(); } ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true); // TODO: update when PreferNonSecure default is updated ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false); TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection()); TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection()); com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81")); obj.GetConnection().GoAwayAsync(); } // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA. for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83")); obj.GetConnection().GoAwayAsync(); } } com.DeactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // expected } Deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); Func <string, string> getEndpoint = host => TestHelper.GetTestEndpoint( new Dictionary <string, string>(communicator.GetProperties()) { ["Test.Host"] = host }, 2, "tcp"); Func <string, string, string> getProxy = (identity, host) => TestHelper.GetTestProxy( identity, new Dictionary <string, string>(communicator.GetProperties()) { ["Test.Host"] = host }, 2, "tcp"); var anyipv4 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("0.0.0.0"), ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1") }; var anyipv6 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::0"), ["Adapter.PublishedEndpoints"] = getEndpoint("::1") }; var anyipv46 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::0"), ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1") }; var anylocalhost = new Dictionary <string, string>() { { "Adapter.Endpoints", getEndpoint("::0") }, { "Adapter.PublishedEndpoints", getEndpoint("localhost") } }; var localipv4 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("127.0.0.1"), ["Adapter.ServerName"] = "127.0.0.1" }; var localipv6 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::1"), ["Adapter.ServerName"] = "::1" }; var localhost = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("localhost"), ["Adapter.ServerName"] = "localhost" }; var serverProps = new Dictionary <string, string>[] { anyipv4, anyipv6, anyipv46, anylocalhost, localipv4, localipv6, localhost }; foreach (Dictionary <string, string> p in serverProps) { using var serverCommunicator = new Communicator(p); ObjectAdapter oa = serverCommunicator.CreateObjectAdapter("Adapter"); oa.Activate(); IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); try { using var clientCommunicator = new Communicator(); prx = IObjectPrx.Parse(prx.ToString() !, clientCommunicator); prx.IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { // Expected. OA is reachable but there's no "dummy" object } } // Test IPv6 dual mode socket { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::0"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); try { using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(getEndpoint("0.0.0.0")); ipv4OA.Activate(); TestHelper.Assert(false); } catch (TransportException) { // Expected. ::0 is a dual-mode socket so binding 0.0.0.0 will fail } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); } catch (ObjectNotExistException) { // Expected, no object registered. } } // Test IPv6 only endpoints { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::0") + (ice1 ? " --ipv6Only" : "?ipv6-only=true"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); // 0.0.0.0 can still be bound if ::0 is IPv6 only { string ipv4Endpoint = getEndpoint("0.0.0.0"); using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint); ipv4OA.Activate(); } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // Expected, server socket is IPv6 only. } } // Listen on IPv4 loopback with IPv6 dual mode socket { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::ffff:127.0.0.1"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); try { string ipv4Endpoint = getEndpoint("127.0.0.1"); using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint); ipv4OA.Activate(); TestHelper.Assert(false); } catch (TransportException) { // Expected. 127.0.0.1 is already in use } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); } catch (ObjectNotExistException) { // Expected, no object registered. } } output.WriteLine("ok"); } com.Shutdown(); } } }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var com = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator); var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); System.IO.TextWriter output = helper.GetWriter(); output.Write("testing binding with single endpoint... "); output.Flush(); { IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default"); TestHelper.Assert(adapter != null); ITestIntfPrx?test1 = adapter.GetTestIntf(); ITestIntfPrx?test2 = adapter.GetTestIntf(); TestHelper.Assert(test1 != null && test2 != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = ITestIntfPrx.UncheckedCast(test1); TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(test3.GetConnection() == test2.GetConnection()); try { test3.IcePing(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter11", "default") !, com.CreateObjectAdapter("Adapter12", "default") !, com.CreateObjectAdapter("Adapter13", "default") ! }; // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are // eventually tried. var names = new List <string> { "Adapter11", "Adapter12", "Adapter13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection(we always send the request over the same // connection.) { foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = t.GetAdapterName(); for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++) { TestHelper.Assert(t.GetAdapterName() == name); } foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapters. com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new IRemoteObjectAdapterPrx[5] { com.CreateObjectAdapter("AdapterRandom11", "default") !, com.CreateObjectAdapter("AdapterRandom12", "default") !, com.CreateObjectAdapter("AdapterRandom13", "default") !, com.CreateObjectAdapter("AdapterRandom14", "default") !, com.CreateObjectAdapter("AdapterRandom15", "default") ! }; int count = 20; int adapterCount = adapters.Length; while (--count > 0) { ITestIntfPrx[] proxies; if (count == 1) { com.DeactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new ITestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new IRemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new IRemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = CreateTestIntfPrx(new List <IRemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].GetAdapterNameAsync(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].IcePing(); } catch { } } var connections = new List <Connection>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].GetCachedConnection() is Connection connection) { if (!connections.Contains(connection)) { connections.Add(connection); } } } TestHelper.Assert(connections.Count <= adapterCount); foreach (IRemoteObjectAdapterPrx a in adapters) { try { a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } catch { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI11", "default") !, com.CreateObjectAdapter("AdapterAMI12", "default") !, com.CreateObjectAdapter("AdapterAMI13", "default") ! }; // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // var names = new List <string> { "AdapterAMI11", "AdapterAMI12", "AdapterAMI13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection (we always send the request over the // same connection.) { foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = GetAdapterNameWithAMI(t); for (int i = 0; i < 10; i++) { TestHelper.Assert(GetAdapterNameWithAMI(t) == name); } foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection // to the remaining adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter21", "default") !, com.CreateObjectAdapter("Adapter22", "default") !, com.CreateObjectAdapter("Adapter23", "default") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); var names = new List <string> { "Adapter21", "Adapter22", "Adapter23" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } obj = obj.Clone(endpointSelection: EndpointSelectionType.Random); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter31", "default") !, com.CreateObjectAdapter("Adapter32", "default") !, com.CreateObjectAdapter("Adapter33", "default") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter31"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter32"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter33"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (communicator.DefaultProtocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter36", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter36"); } obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter35", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter35"); } obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter34", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter34"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", "default"); TestHelper.Assert(adapter != null); ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false); ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false); TestHelper.Assert(!test1.IsConnectionCached); TestHelper.Assert(!test2.IsConnectionCached); TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = ITestIntfPrx.UncheckedCast(test1); try { TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter51", "default") !, com.CreateObjectAdapter("Adapter52", "default") !, com.CreateObjectAdapter("Adapter53", "default") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "Adapter51", "Adapter52", "Adapter53" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI51", "default") !, com.CreateObjectAdapter("AdapterAMI52", "default") !, com.CreateObjectAdapter("AdapterAMI53", "default") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "AdapterAMI51", "AdapterAMI52", "AdapterAMI53" }; while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter61", "default") !, com.CreateObjectAdapter("Adapter62", "default") !, com.CreateObjectAdapter("Adapter63", "default") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (communicator.DefaultProtocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI61", "default") !, com.CreateObjectAdapter("AdapterAMI62", "default") !, com.CreateObjectAdapter("AdapterAMI63", "default") ! }; ITestIntfPrx?obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (communicator.DefaultProtocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); if (communicator.DefaultProtocol == Protocol.Ice1) { output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter71", "default"), com.CreateObjectAdapter("Adapter72", "udp") }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71")); ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram); TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.GetAdapterName(); TestHelper.Assert(false); } catch (InvalidOperationException) { // expected } } output.WriteLine("ok"); } if (communicator.GetProperty("Ice.Plugin.IceSSL") != null) { output.Write("testing secure and non-secure endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter81", "ssl") !, com.CreateObjectAdapter("Adapter82", "tcp") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true); // TODO: update when PreferNonSecure default is updated ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false); TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection()); TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection()); com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (communicator.DefaultProtocol == Protocol.Ice1) { com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA. for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } com.DeactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // expected } Deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); var ipv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "0" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var ipv6 = new Dictionary <string, string>() { { "IPv4", "0" }, { "IPv6", "1" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var bothPreferIPv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "0" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var bothPreferIPv6 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "1" }, { "Adapter.Endpoints", "tcp -h localhost" } }; Dictionary <string, string>[] clientProps = { ipv4, ipv6, bothPreferIPv4, bothPreferIPv6 }; string endpoint = "tcp -p " + helper.GetTestPort(2).ToString(); var anyipv4 = new Dictionary <string, string>(ipv4) { ["Adapter.Endpoints"] = endpoint, ["Adapter.PublishedEndpoints"] = $"{endpoint} -h 127.0.0.1" }; var anyipv6 = new Dictionary <string, string>(ipv6) { ["Adapter.Endpoints"] = endpoint, ["Adapter.PublishedEndpoints"] = $"{endpoint} -h \".1\"" }; var anyboth = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "Adapter.Endpoints", endpoint }, { "Adapter.PublishedEndpoints", $"{endpoint} -h \"::1\":{endpoint} -h 127.0.0.1" } }; var localipv4 = new Dictionary <string, string>(ipv4) { ["Adapter.Endpoints"] = "tcp -h 127.0.0.1" }; var localipv6 = new Dictionary <string, string>(ipv6) { ["Adapter.Endpoints"] = "tcp -h \"::1\"" }; Dictionary <string, string>[] serverProps = { anyipv4, anyipv6, anyboth, localipv4, localipv6 }; bool ipv6NotSupported = false; foreach (Dictionary <string, string> p in serverProps) { var serverCommunicator = new Communicator(p); ObjectAdapter oa; try { oa = serverCommunicator.CreateObjectAdapter("Adapter"); oa.Activate(); } catch (DNSException) { serverCommunicator.Dispose(); continue; // IP version not supported. } catch (TransportException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.Dispose(); continue; // IP version not supported. } IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); try { prx.IcePing(); } catch (DNSException) // TODO: is this really an expected exception? { serverCommunicator.Dispose(); continue; } catch (ObjectNotExistException) // TODO: is this really an expected exception? { serverCommunicator.Dispose(); continue; } string strPrx = prx.ToString() !; foreach (Dictionary <string, string> q in clientProps) { var clientCommunicator = new Communicator(q); prx = IObjectPrx.Parse(strPrx, clientCommunicator); try { prx.IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { // Expected, no object registered. } catch (DNSException) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch (TransportException) { TestHelper.Assert((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) || (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) || (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) || (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) || (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) || (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) || (p == bothPreferIPv6 && q == ipv6)); } clientCommunicator.Dispose(); } serverCommunicator.Dispose(); } output.WriteLine("ok"); } com.Shutdown(); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; bool ice1 = helper.Protocol == Protocol.Ice1; TestHelper.Assert(communicator != null); var com = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator); string testTransport = helper.Transport; var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); System.IO.TextWriter output = helper.Output; output.Write("testing binding with single endpoint... "); output.Flush(); { // Use "default" here to ensure that it still works IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default"); TestHelper.Assert(adapter != null); ITestIntfPrx?test1 = adapter.GetTestIntf(); ITestIntfPrx?test2 = adapter.GetTestIntf(); TestHelper.Assert(test1 != null && test2 != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(test3.GetConnection() == test2.GetConnection()); try { test3.IcePing(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter11", testTransport) !, com.CreateObjectAdapter("Adapter12", testTransport) !, com.CreateObjectAdapter("Adapter13", testTransport) ! }; // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are // eventually tried. var names = new List <string> { "Adapter11", "Adapter12", "Adapter13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection(we always send the request over the same // connection.) { foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = t.GetAdapterName(); for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++) { TestHelper.Assert(t.GetAdapterName() == name); } foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapters. com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new IRemoteObjectAdapterPrx[5] { com.CreateObjectAdapter("AdapterRandom11", testTransport) !, com.CreateObjectAdapter("AdapterRandom12", testTransport) !, com.CreateObjectAdapter("AdapterRandom13", testTransport) !, com.CreateObjectAdapter("AdapterRandom14", testTransport) !, com.CreateObjectAdapter("AdapterRandom15", testTransport) ! }; int count = 20; int adapterCount = adapters.Length; while (--count > 0) { ITestIntfPrx[] proxies; if (count == 1) { com.DeactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new ITestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new IRemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new IRemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = CreateTestIntfPrx(new List <IRemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].GetAdapterNameAsync(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].IcePing(); } catch { } } var connections = new List <Connection>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].GetCachedConnection() is Connection connection) { if (!connections.Contains(connection)) { connections.Add(connection); } } } TestHelper.Assert(connections.Count <= adapterCount); foreach (IRemoteObjectAdapterPrx a in adapters) { try { a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } catch { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI11", testTransport) !, com.CreateObjectAdapter("AdapterAMI12", testTransport) !, com.CreateObjectAdapter("AdapterAMI13", testTransport) ! }; // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are // eventually tried. var names = new List <string> { "AdapterAMI11", "AdapterAMI12", "AdapterAMI13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection (we always send the request over the // same connection.) { foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = GetAdapterNameWithAMI(t); for (int i = 0; i < 10; i++) { TestHelper.Assert(GetAdapterNameWithAMI(t) == name); } foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapters. com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter21", testTransport) !, com.CreateObjectAdapter("Adapter22", testTransport) !, com.CreateObjectAdapter("Adapter23", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); var names = new List <string> { "Adapter21", "Adapter22", "Adapter23" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } obj = obj.Clone(endpointSelection: EndpointSelectionType.Random); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter31", testTransport) !, com.CreateObjectAdapter("Adapter32", testTransport) !, com.CreateObjectAdapter("Adapter33", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter31"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter32"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter33"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } adapters.Clear(); } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport); TestHelper.Assert(adapter != null); ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false); ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false); TestHelper.Assert(!test1.IsConnectionCached); TestHelper.Assert(!test2.IsConnectionCached); TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); try { TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter51", testTransport) !, com.CreateObjectAdapter("Adapter52", testTransport) !, com.CreateObjectAdapter("Adapter53", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "Adapter51", "Adapter52", "Adapter53" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI51", testTransport) !, com.CreateObjectAdapter("AdapterAMI52", testTransport) !, com.CreateObjectAdapter("AdapterAMI53", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "AdapterAMI51", "AdapterAMI52", "AdapterAMI53" }; while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter61", testTransport) !, com.CreateObjectAdapter("Adapter62", testTransport) !, com.CreateObjectAdapter("Adapter63", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI61", testTransport) !, com.CreateObjectAdapter("AdapterAMI62", testTransport) !, com.CreateObjectAdapter("AdapterAMI63", testTransport) ! }; ITestIntfPrx?obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); if (helper.Protocol == Protocol.Ice1) { output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter71", testTransport), com.CreateObjectAdapter("Adapter72", "udp") }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71")); ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram); TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.GetAdapterName(); TestHelper.Assert(false); } catch (InvalidOperationException) { // expected } } output.WriteLine("ok"); } if (communicator.GetProperty("Ice.Plugin.IceSSL") != null) { output.Write("testing secure and non-secure endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter81", "ssl") !, com.CreateObjectAdapter("Adapter82", "tcp") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true); // TODO: update when PreferNonSecure default is updated ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false); TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection()); TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection()); com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA. for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } com.DeactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // expected } Deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); Func <string, string> getEndpoint = host => TestHelper.GetTestEndpoint( new Dictionary <string, string>(communicator.GetProperties()) { ["Test.Host"] = host }, 2, "tcp"); Func <string, string, string> getProxy = (identity, host) => TestHelper.GetTestProxy( identity, new Dictionary <string, string>(communicator.GetProperties()) { ["Test.Host"] = host }, 2, "tcp"); var anyipv4 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("0.0.0.0"), ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1") }; var anyipv6 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::0"), ["Adapter.PublishedEndpoints"] = getEndpoint("::1") }; var anyipv46 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::0"), ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1") }; var anylocalhost = new Dictionary <string, string>() { { "Adapter.Endpoints", getEndpoint("::0") }, { "Adapter.PublishedEndpoints", getEndpoint("localhost") } }; var localipv4 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("127.0.0.1") }; var localipv6 = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("::1") }; var localhost = new Dictionary <string, string>() { ["Adapter.Endpoints"] = getEndpoint("localhost") }; var serverProps = new Dictionary <string, string>[] { anyipv4, anyipv6, anyipv46, anylocalhost, localipv4, localipv6, localhost }; foreach (Dictionary <string, string> p in serverProps) { using var serverCommunicator = new Communicator(p); ObjectAdapter oa = serverCommunicator.CreateObjectAdapter("Adapter"); oa.Activate(); IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); try { using var clientCommunicator = new Communicator(); prx = IObjectPrx.Parse(prx.ToString() !, clientCommunicator); prx.IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { // Expected. OA is reachable but there's no "dummy" object } } // Test IPv6 dual mode socket { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::0"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); try { using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(getEndpoint("0.0.0.0")); ipv4OA.Activate(); TestHelper.Assert(false); } catch (TransportException) { // Expected. ::0 is a dual-mode socket so binding 0.0.0.0 will fail } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); } catch (ObjectNotExistException) { // Expected, no object registered. } } // Test IPv6 only socket { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::0") + (ice1 ? " --ipv6Only" : "?ipv6-only=true"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); // Returned endpoints must be IPv6 { IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); TestHelper.Assert(prx.Endpoints.Count > 0); TestHelper.Assert(prx.Endpoints.All(e => e.Host.Contains(":"))); } // 0.0.0.0 can still be bound if ::0 is IPv6 only { string ipv4Endpoint = getEndpoint("0.0.0.0"); using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint); ipv4OA.Activate(); } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // Expected, server socket is IPv6 only. } } // Listen on IPv4 loopback with IPv6 dual mode socket { using Communicator serverCommunicator = new Communicator(); string endpoint = getEndpoint("::ffff:127.0.0.1"); ObjectAdapter oa = serverCommunicator.CreateObjectAdapterWithEndpoints(endpoint); oa.Activate(); try { string ipv4Endpoint = getEndpoint("127.0.0.1"); using ObjectAdapter ipv4OA = serverCommunicator.CreateObjectAdapterWithEndpoints(ipv4Endpoint); ipv4OA.Activate(); TestHelper.Assert(false); } catch (TransportException) { // Expected. 127.0.0.1 is already in use } // Returned endpoint must be IPv6 { IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); TestHelper.Assert(prx.Endpoints.Count == 1); TestHelper.Assert(prx.Endpoints.All(e => e.Host.Contains(":"))); } try { using Communicator clientCommunicator = new Communicator(); var prx = IObjectPrx.Parse(getProxy("dummy", "127.0.0.1"), clientCommunicator); prx.IcePing(); } catch (ObjectNotExistException) { // Expected, no object registered. } } output.WriteLine("ok"); } com.Shutdown(); }