This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton-dotnet.git
The following commit(s) were added to refs/heads/main by this push: new 19bb9a0 PROTON-2619 Relax generic types on filters API to string, object 19bb9a0 is described below commit 19bb9a0551c8380875dcbab07900378e95d9f9c5 Author: Timothy Bish <tabish...@gmail.com> AuthorDate: Thu Oct 6 17:37:03 2022 -0400 PROTON-2619 Relax generic types on filters API to string, object Allow for described types in the filters API of source options --- src/Proton.Client/Client/SourceOptions.cs | 3 +- .../Codec/Primitives/UnknwonDescribedType.cs | 2 +- .../Client/Implementation/ClientReceiverTest.cs | 109 ++++++++++++++++++++- .../Client/Implementation/ClientSenderTest.cs | 2 +- 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/src/Proton.Client/Client/SourceOptions.cs b/src/Proton.Client/Client/SourceOptions.cs index 29d89e7..7ae05b2 100644 --- a/src/Proton.Client/Client/SourceOptions.cs +++ b/src/Proton.Client/Client/SourceOptions.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Apache.Qpid.Proton.Client.Implementation; namespace Apache.Qpid.Proton.Client @@ -57,7 +56,7 @@ namespace Apache.Qpid.Proton.Client /// <summary> /// The filters that are assigned to the source configuration. /// </summary> - public IDictionary<string, string> Filters { get; set; } + public IDictionary<string, object> Filters { get; set; } /// <summary> /// The default outcome to assign to the source configuration. diff --git a/src/Proton.TestPeer/Codec/Primitives/UnknwonDescribedType.cs b/src/Proton.TestPeer/Codec/Primitives/UnknwonDescribedType.cs index e013969..0a855d8 100644 --- a/src/Proton.TestPeer/Codec/Primitives/UnknwonDescribedType.cs +++ b/src/Proton.TestPeer/Codec/Primitives/UnknwonDescribedType.cs @@ -37,7 +37,7 @@ namespace Apache.Qpid.Proton.Test.Driver.Codec.Primitives public override bool Equals(object obj) { - return obj is UnknownDescribedType type && + return obj is IDescribedType type && EqualityComparer<object>.Default.Equals(Descriptor, type.Descriptor) && EqualityComparer<object>.Default.Equals(Described, type.Described); } diff --git a/test/Proton.Client.Tests/Client/Implementation/ClientReceiverTest.cs b/test/Proton.Client.Tests/Client/Implementation/ClientReceiverTest.cs index f2e9106..995421c 100644 --- a/test/Proton.Client.Tests/Client/Implementation/ClientReceiverTest.cs +++ b/test/Proton.Client.Tests/Client/Implementation/ClientReceiverTest.cs @@ -29,6 +29,7 @@ using System.Threading.Tasks; using Apache.Qpid.Proton.Utilities; using Apache.Qpid.Proton.Types.Messaging; using System.IO; +using Apache.Qpid.Proton.Types; namespace Apache.Qpid.Proton.Client.Implementation { @@ -2881,10 +2882,10 @@ namespace Apache.Qpid.Proton.Client.Implementation [Test] public void TestCreateReceiverWithUserConfiguredSourceAndTargetOptions() { - IDictionary<string, Object> filtersToObject = new Dictionary<string, object>(); + IDictionary<string, object> filtersToObject = new Dictionary<string, object>(); filtersToObject.Add("x-opt-filter", "a = b"); - IDictionary<string, string> filters = new Dictionary<string, string>(); + IDictionary<string, object> filters = new Dictionary<string, object>(); filters.Add("x-opt-filter", "a = b"); using (ProtonTestServer peer = new ProtonTestServer(loggerFactory)) @@ -3135,5 +3136,109 @@ namespace Apache.Qpid.Proton.Client.Implementation peer.WaitForScriptToComplete(); } } + + private class AmqpJmsSelectorType : IDescribedType + { + private string selector; + + public object Descriptor => 0x0000468C00000004UL; + + public object Described => selector; + + public AmqpJmsSelectorType(string selector) + { + this.selector = selector; + } + + public override string ToString() + { + return "AmqpJmsSelectorType{" + selector + "}"; + } + } + + private class PeerJmsSelectorType : Apache.Qpid.Proton.Test.Driver.Codec.Primitives.UnknownDescribedType + { + public PeerJmsSelectorType(string selector) : base(0x0000468C00000004UL, selector) + { + } + } + + [Test] + public void TestCreateReceiverWithUserConfiguredSourceWithJMSStyleSelector() + { + IDescribedType clientJmsSelector = new AmqpJmsSelectorType("myProperty=42"); + IDictionary<string, object> filters = new Dictionary<string, object>(); + filters.Add("jms-selector", clientJmsSelector); + + PeerJmsSelectorType peerJmsSelector = new PeerJmsSelectorType("myProperty=42"); + IDictionary<string, object> filtersAtPeer = new Dictionary<string, object>(); + filtersAtPeer.Add("jms-selector", peerJmsSelector); + + using (ProtonTestServer peer = new ProtonTestServer(loggerFactory)) + { + peer.ExpectSASLAnonymousConnect(); + peer.ExpectOpen().Respond(); + peer.ExpectBegin().Respond(); + peer.ExpectAttach().OfReceiver() + .WithSource().WithAddress("test-queue") + .WithDistributionMode("copy") + .WithTimeout(128) + .WithDurable(Test.Driver.Codec.Messaging.TerminusDurability.UnsettledState) + .WithExpiryPolicy(Test.Driver.Codec.Messaging.TerminusExpiryPolicy.ConnectionClose) + .WithDefaultOutcome(new Test.Driver.Codec.Messaging.Released()) + .WithCapabilities("QUEUE") + .WithFilter(filtersAtPeer) + .WithOutcomes("amqp:accepted:list", "amqp:rejected:list") + .Also() + .WithTarget().WithAddress(Test.Driver.Matchers.Is.NotNullValue()) + .WithCapabilities("QUEUE") + .WithDurable(Test.Driver.Codec.Messaging.TerminusDurability.Configuration) + .WithExpiryPolicy(Test.Driver.Codec.Messaging.TerminusExpiryPolicy.SessionEnd) + .WithTimeout(42) + .WithDynamic(Test.Driver.Matchers.Matches.AnyOf( + Test.Driver.Matchers.Is.NullValue(), + Test.Driver.Matchers.Is.EqualTo(false))) + .WithDynamicNodeProperties(Test.Driver.Matchers.Is.NullValue()) + .And().Respond(); + peer.ExpectFlow().WithLinkCredit(10); + peer.ExpectDetach().Respond(); + peer.ExpectEnd().Respond(); + peer.ExpectClose().Respond(); + peer.Start(); + + string remoteAddress = peer.ServerAddress; + int remotePort = peer.ServerPort; + + logger.LogInformation("Test started, peer listening on: {0}:{1}", remoteAddress, remotePort); + + IClient container = IClient.Create(); + IConnection connection = container.Connect(remoteAddress, remotePort); + ISession session = connection.OpenSession(); + ReceiverOptions receiverOptions = new ReceiverOptions(); + + receiverOptions.SourceOptions.Capabilities = new string[] { "QUEUE" }; + receiverOptions.SourceOptions.DistributionMode = DistributionMode.Copy; + receiverOptions.SourceOptions.Timeout = 128; + receiverOptions.SourceOptions.DurabilityMode = DurabilityMode.UnsettledState; + receiverOptions.SourceOptions.ExpiryPolicy = ExpiryPolicy.ConnectionClose; + receiverOptions.SourceOptions.DefaultOutcome = ClientReleased.Instance; + receiverOptions.SourceOptions.Filters = filters; + receiverOptions.SourceOptions.Outcomes = + new DeliveryStateType[] { DeliveryStateType.Accepted, DeliveryStateType.Rejected }; + + receiverOptions.TargetOptions.Capabilities = new string[] { "QUEUE" }; + receiverOptions.TargetOptions.DurabilityMode = DurabilityMode.Configuration; + receiverOptions.TargetOptions.ExpiryPolicy = ExpiryPolicy.SessionClose; + receiverOptions.TargetOptions.Timeout = 42; + + IReceiver receiver = session.OpenReceiver("test-queue", receiverOptions).OpenTask.GetAwaiter().GetResult(); + + receiver.Close(); + session.Close(); + connection.Close(); + + peer.WaitForScriptToComplete(); + } + } } } \ No newline at end of file diff --git a/test/Proton.Client.Tests/Client/Implementation/ClientSenderTest.cs b/test/Proton.Client.Tests/Client/Implementation/ClientSenderTest.cs index 8a349ad..d519642 100644 --- a/test/Proton.Client.Tests/Client/Implementation/ClientSenderTest.cs +++ b/test/Proton.Client.Tests/Client/Implementation/ClientSenderTest.cs @@ -2768,7 +2768,7 @@ namespace Apache.Qpid.Proton.Client.Implementation IDictionary<string, object> filtersToObject = new Dictionary<string, object>(); filtersToObject.Add("x-opt-filter", "a = b"); - IDictionary<string, string> filters = new Dictionary<string, string>(); + IDictionary<string, object> filters = new Dictionary<string, object>(); filters.Add("x-opt-filter", "a = b"); using (ProtonTestServer peer = new ProtonTestServer(loggerFactory)) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org