You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2023/06/22 16:49:02 UTC
[qpid-protonj2] branch main updated: PROTON-2739 Add simple API for JMS selectors to test peer Attach
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 e3cf5b44 PROTON-2739 Add simple API for JMS selectors to test peer Attach
e3cf5b44 is described below
commit e3cf5b44eba2ddceab05e7a61b2bc138750345f1
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Thu Jun 22 12:42:26 2023 -0400
PROTON-2739 Add simple API for JMS selectors to test peer Attach
Allow attach inject and expect to script JMS selectors with simple
syntax.
---
.../test/driver/actions/AttachInjectAction.java | 11 +++++
.../driver/expectations/AttachExpectation.java | 12 ++++++
.../matchers/JmsSelectorByIdDescribedType.java | 48 ++++++++++++++++++++++
.../protonj2/test/driver/ReceiverHandlingTest.java | 33 +++++++++++++++
4 files changed, 104 insertions(+)
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 3914edd9..97efc1c9 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
@@ -16,6 +16,7 @@
*/
package org.apache.qpid.protonj2.test.driver.actions;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -46,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.JmsSelectorByIdDescribedType;
/**
* AMQP Attach injection action which can be added to a driver for write at a specific time or
@@ -496,6 +498,15 @@ public class AttachInjectAction extends AbstractPerformativeInjectAction<Attach>
return this;
}
+ public SourceBuilder withJMSSelector(String selector) {
+ final JmsSelectorByIdDescribedType jmsSelector = new JmsSelectorByIdDescribedType(selector);
+ final Map<String, Object> filters = new HashMap<>();
+
+ filters.put(JmsSelectorByIdDescribedType.JMS_SELECTOR_KEY, jmsSelector);
+
+ 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/expectations/AttachExpectation.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/AttachExpectation.java
index 3b66894e..1efc4bdb 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
@@ -24,6 +24,7 @@ import static org.hamcrest.collection.ArrayMatching.hasItemInArray;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
@@ -53,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.JmsSelectorByIdDescribedType;
import org.apache.qpid.protonj2.test.driver.matchers.messaging.SourceMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.messaging.TargetMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.transactions.CoordinatorMatcher;
@@ -623,6 +625,16 @@ public class AttachExpectation extends AbstractExpectation<Attach> {
return this;
}
+ public AttachSourceMatcher withJMSSelector(String selector) {
+ final JmsSelectorByIdDescribedType filterType = new JmsSelectorByIdDescribedType(selector);
+ final Map<String, Object> filtersMap = new HashMap<>();
+
+ filtersMap.put(JmsSelectorByIdDescribedType.JMS_SELECTOR_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/JmsSelectorByIdDescribedType.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/JmsSelectorByIdDescribedType.java
new file mode 100644
index 00000000..15c7a789
--- /dev/null
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/JmsSelectorByIdDescribedType.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 Selector described type that uses an unsigned long ID for the descriptor
+ */
+public class JmsSelectorByIdDescribedType extends UnknownDescribedType {
+
+ /**
+ * Key name used when add the selector type to the filters map.
+ */
+ public static final String JMS_SELECTOR_KEY = "jms-selector";
+
+ public static final UnsignedLong JMS_SELECTOR_ULONG_DESCRIPTOR = UnsignedLong.valueOf(0x0000468C00000004L);
+
+ public JmsSelectorByIdDescribedType(String selector) {
+ super(JMS_SELECTOR_ULONG_DESCRIPTOR, selector);
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return super.equals(o);
+ }
+
+ @Override
+ public String toString() {
+ return "JmsSelectorByIdDescribedType{ " + 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 ae1b9432..4f4e0da8 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
@@ -410,4 +410,37 @@ class ReceiverHandlingTest extends TestPeerTestsBase {
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
+
+ @Test
+ public void testReceiverAttachWithJMSSelectorMatchingAPI() throws Exception {
+ try (ProtonTestServer peer = new ProtonTestServer();
+ ProtonTestClient client = new ProtonTestClient()) {
+
+ peer.expectAMQPHeader().respondWithAMQPHeader();
+ peer.expectOpen().respond();
+ peer.expectBegin().respond();
+ peer.expectAttach().ofReceiver().withSource().withJMSSelector("property=1").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().withJMSSelector("property=1").and().now();
+ client.remoteEnd().now();
+
+ client.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org