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-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new 9a04d4bf PROTON-2802 Add some utilities for scripting no-local filter
detection
9a04d4bf is described below
commit 9a04d4bf400958c6b60f3b4ae9716a2b5e27fa4c
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Mar 5 15:41:32 2024 -0500
PROTON-2802 Add some utilities for scripting no-local filter detection
Allows for some easier testing of the no-local filter on attach when
testing some JMS style AMQP endpoints.
---
.../qpid/protonj2/client/impl/ReceiverTest.java | 103 +++++++++++++++++++++
.../test/driver/actions/AttachInjectAction.java | 10 ++
.../codec/primitives/UnknownDescribedType.java | 6 +-
.../driver/expectations/AttachExpectation.java | 11 +++
.../matchers/JmsNoLocalByIdDescribedType.java | 48 ++++++++++
.../protonj2/test/driver/ReceiverHandlingTest.java | 33 +++++++
6 files changed, 208 insertions(+), 3 deletions(-)
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReceiverTest.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReceiverTest.java
index 0b72e7d9..d4085ffa 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReceiverTest.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReceiverTest.java
@@ -2622,6 +2622,25 @@ public class ReceiverTest extends
ImperativeClientTestCase {
}
}
+ public class AmqpJmsNoLocalType implements DescribedType {
+
+ private final String noLocal;
+
+ public AmqpJmsNoLocalType() {
+ this.noLocal = "NoLocalFilter{}";
+ }
+
+ @Override
+ public Object getDescriptor() {
+ return UnsignedLong.valueOf(0x0000468C00000003L);
+ }
+
+ @Override
+ public Object getDescribed() {
+ return this.noLocal;
+ }
+ }
+
private class PeerJmsSelectorType extends UnknownDescribedType {
public PeerJmsSelectorType(String selector) {
@@ -2629,6 +2648,13 @@ public class ReceiverTest extends
ImperativeClientTestCase {
}
}
+ private class PeerNoLocalFilterType extends UnknownDescribedType {
+
+ public PeerNoLocalFilterType() {
+
super(org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong.valueOf(0x0000468C00000003L),
"NoLocalFilter{}");
+ }
+ }
+
@Test
public void
testCreateReceiverWithUserConfiguredSourceWithJMSStyleSelector() throws
Exception {
final DescribedType clientJmsSelector = new
AmqpJmsSelectorType("myProperty=42");
@@ -2701,6 +2727,83 @@ public class ReceiverTest extends
ImperativeClientTestCase {
}
}
+ @Test
+ public void
testCreateReceiverWithUserConfiguredSourceWithJMSStyleSelectorAndNoLocalFilter()
throws Exception {
+ final DescribedType clientJmsSelector = new
AmqpJmsSelectorType("myProperty=42");
+ final DescribedType clientNoLocalFilter = new AmqpJmsNoLocalType();
+
+ final Map<String, Object> filters = new HashMap<>();
+ filters.put("no-local", clientNoLocalFilter);
+ filters.put("jms-selector", clientJmsSelector);
+
+ final PeerJmsSelectorType peerJmsSelector = new
PeerJmsSelectorType("myProperty=42");
+ final PeerNoLocalFilterType peerNoLocalFilter = new
PeerNoLocalFilterType();
+ final Map<String, Object> filtersAtPeer = new HashMap<>();
+ filtersAtPeer.put("jms-selector", peerJmsSelector);
+ filtersAtPeer.put("no-local", peerNoLocalFilter);
+
+ try (ProtonTestServer peer = new ProtonTestServer()) {
+ peer.expectSASLAnonymousConnect();
+ peer.expectOpen().respond();
+ peer.expectBegin().respond();
+ peer.expectAttach().ofReceiver()
+ .withSource().withAddress("test-queue")
+ .withDistributionMode("copy")
+ .withTimeout(128)
+
.withDurable(TerminusDurability.UNSETTLED_STATE)
+
.withExpiryPolicy(TerminusExpiryPolicy.CONNECTION_CLOSE)
+ .withDefaultOutcome(new Released())
+ .withCapabilities("QUEUE")
+ .withFilter(filtersAtPeer)
+
.withOutcomes("amqp:accepted:list", "amqp:rejected:list")
+ .also()
+ .withTarget().withAddress(notNullValue())
+ .withCapabilities("QUEUE")
+
.withDurable(TerminusDurability.CONFIGURATION)
+
.withExpiryPolicy(TerminusExpiryPolicy.SESSION_END)
+ .withTimeout(42)
+ .withDynamic(anyOf(nullValue(),
equalTo(false)))
+
.withDynamicNodeProperties(nullValue())
+ .and().respond();
+ peer.expectFlow().withLinkCredit(10);
+ peer.expectDetach().respond();
+ peer.expectEnd().respond();
+ peer.expectClose().respond();
+ peer.start();
+
+ URI remoteURI = peer.getServerURI();
+
+ LOG.info("Test started, peer listening on: {}", remoteURI);
+
+ Client container = Client.create();
+ Connection connection = container.connect(remoteURI.getHost(),
remoteURI.getPort());
+ Session session = connection.openSession();
+ ReceiverOptions receiverOptions = new ReceiverOptions();
+
+ receiverOptions.sourceOptions().capabilities("QUEUE");
+
receiverOptions.sourceOptions().distributionMode(DistributionMode.COPY);
+ receiverOptions.sourceOptions().timeout(128);
+
receiverOptions.sourceOptions().durabilityMode(DurabilityMode.UNSETTLED_STATE);
+
receiverOptions.sourceOptions().expiryPolicy(ExpiryPolicy.CONNECTION_CLOSE);
+
receiverOptions.sourceOptions().defaultOutcome(DeliveryState.released());
+ receiverOptions.sourceOptions().filters(filters);
+
receiverOptions.sourceOptions().outcomes(DeliveryState.Type.ACCEPTED,
DeliveryState.Type.REJECTED);
+
+ receiverOptions.targetOptions().capabilities("QUEUE");
+
receiverOptions.targetOptions().durabilityMode(DurabilityMode.CONFIGURATION);
+
receiverOptions.targetOptions().expiryPolicy(ExpiryPolicy.SESSION_CLOSE);
+ receiverOptions.targetOptions().timeout(42);
+
+ Receiver receiver = session.openReceiver("test-queue",
receiverOptions).openFuture().get();
+
+ receiver.close();
+ session.close();
+ connection.close();
+
+ peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ }
+ }
+
@Test
public void testOpenDurableReceiver() throws Exception {
final String address = "test-topic";
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/AttachInjectAction.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/AttachInjectAction.java
index 97efc1c9..e19f6e57 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/AttachInjectAction.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/AttachInjectAction.java
@@ -47,6 +47,7 @@ import
org.apache.qpid.protonj2.test.driver.codec.transport.ReceiverSettleMode;
import org.apache.qpid.protonj2.test.driver.codec.transport.Role;
import org.apache.qpid.protonj2.test.driver.codec.transport.SenderSettleMode;
import org.apache.qpid.protonj2.test.driver.codec.util.TypeMapper;
+import
org.apache.qpid.protonj2.test.driver.matchers.JmsNoLocalByIdDescribedType;
import
org.apache.qpid.protonj2.test.driver.matchers.JmsSelectorByIdDescribedType;
/**
@@ -507,6 +508,15 @@ public class AttachInjectAction extends
AbstractPerformativeInjectAction<Attach>
return withFilterMap(filters);
}
+ public SourceBuilder withNoLocal() {
+ final JmsNoLocalByIdDescribedType noLocal = new
JmsNoLocalByIdDescribedType();
+ final Map<String, Object> filters = new HashMap<>();
+
+ filters.put(JmsNoLocalByIdDescribedType.JMS_NO_LOCAL_KEY, noLocal);
+
+ return withFilterMap(filters);
+ }
+
public SourceBuilder withFilter(Map<Symbol, Object> filters) {
source.setFilter(filters);
return this;
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/codec/primitives/UnknownDescribedType.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/codec/primitives/UnknownDescribedType.java
index 30109bb9..b9f2dbe3 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/codec/primitives/UnknownDescribedType.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/codec/primitives/UnknownDescribedType.java
@@ -45,12 +45,12 @@ public class UnknownDescribedType implements DescribedType {
return false;
}
- final UnknownDescribedType that = (UnknownDescribedType) o;
+ final DescribedType that = (DescribedType) o;
- if (described != null ? !described.equals(that.described) :
that.described != null) {
+ if (described != null ? !described.equals(that.getDescribed()) :
that.getDescriptor() != null) {
return false;
}
- if (descriptor != null ? !descriptor.equals(that.descriptor) :
that.descriptor != null) {
+ if (descriptor != null ? !descriptor.equals(that.getDescriptor()) :
that.getDescriptor() != null) {
return false;
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/AttachExpectation.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/AttachExpectation.java
index 636d9a40..6a767d1f 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/AttachExpectation.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/AttachExpectation.java
@@ -54,6 +54,7 @@ import
org.apache.qpid.protonj2.test.driver.codec.transport.ReceiverSettleMode;
import org.apache.qpid.protonj2.test.driver.codec.transport.Role;
import org.apache.qpid.protonj2.test.driver.codec.transport.SenderSettleMode;
import org.apache.qpid.protonj2.test.driver.codec.util.TypeMapper;
+import
org.apache.qpid.protonj2.test.driver.matchers.JmsNoLocalByIdDescribedType;
import
org.apache.qpid.protonj2.test.driver.matchers.JmsSelectorByIdDescribedType;
import org.apache.qpid.protonj2.test.driver.matchers.messaging.SourceMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.messaging.TargetMatcher;
@@ -643,6 +644,16 @@ public class AttachExpectation extends
AbstractExpectation<Attach> {
return this;
}
+ public AttachSourceMatcher withNoLocal() {
+ final JmsNoLocalByIdDescribedType filterType = new
JmsNoLocalByIdDescribedType();
+ final Map<String, Object> filtersMap = new HashMap<>();
+
+ filtersMap.put(JmsNoLocalByIdDescribedType.JMS_NO_LOCAL_KEY,
filterType);
+
+ super.withFilter(filtersMap);
+ return this;
+ }
+
@Override
public AttachSourceMatcher withDefaultOutcome(DeliveryState
defaultOutcome) {
super.withDefaultOutcome(defaultOutcome);
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/JmsNoLocalByIdDescribedType.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/JmsNoLocalByIdDescribedType.java
new file mode 100644
index 00000000..cc9d73a7
--- /dev/null
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/JmsNoLocalByIdDescribedType.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.qpid.protonj2.test.driver.matchers;
+
+import
org.apache.qpid.protonj2.test.driver.codec.primitives.UnknownDescribedType;
+import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
+
+/**
+ * JMS No Local described type that uses an unsigned long ID for the descriptor
+ */
+public class JmsNoLocalByIdDescribedType extends UnknownDescribedType {
+
+ /**
+ * Key name used when add the selector type to the filters map.
+ */
+ public static final String JMS_NO_LOCAL_KEY = "no-local";
+
+ public static final UnsignedLong JMS_NO_LOCAL_ULONG_DESCRIPTOR =
UnsignedLong.valueOf(0x0000468C00000003L);
+
+ public JmsNoLocalByIdDescribedType() {
+ super(JMS_NO_LOCAL_ULONG_DESCRIPTOR, "NoLocalFilter{}");
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return super.equals(o);
+ }
+
+ @Override
+ public String toString() {
+ return "JmsNoLocalByIdDescribedType{ " + getDescribed() + " }";
+ }
+}
diff --git
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ReceiverHandlingTest.java
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ReceiverHandlingTest.java
index 4f4e0da8..408c2cac 100644
---
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ReceiverHandlingTest.java
+++
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ReceiverHandlingTest.java
@@ -443,4 +443,37 @@ class ReceiverHandlingTest extends TestPeerTestsBase {
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
+
+ @Test
+ public void testReceiverAttachWithNoLocalMatchingAPI() throws Exception {
+ try (ProtonTestServer peer = new ProtonTestServer();
+ ProtonTestClient client = new ProtonTestClient()) {
+
+ peer.expectAMQPHeader().respondWithAMQPHeader();
+ peer.expectOpen().respond();
+ peer.expectBegin().respond();
+
peer.expectAttach().ofReceiver().withSource().withNoLocal().also().respond();
+ peer.expectEnd().respond();
+ peer.start();
+
+ URI remoteURI = peer.getServerURI();
+
+ LOG.info("Test started, peer listening on: {}", remoteURI);
+
+ client.connect(remoteURI.getHost(), remoteURI.getPort());
+ client.expectAMQPHeader();
+ client.expectOpen();
+ client.expectBegin();
+
client.expectAttach().ofSender().withOfferedCapabilities(Matchers.nullValue());
+ client.expectEnd();
+ client.remoteAMQPHeader().now();
+ client.remoteOpen().now();
+ client.remoteBegin().now();
+
client.remoteAttach().ofReceiver().withSource().withNoLocal().and().now();
+ client.remoteEnd().now();
+
+ client.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]