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/04/12 22:53:17 UTC
[qpid-protonj2] branch main updated: PROTON-2711 Allow for single property values to be set on performatives
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 e2453e38 PROTON-2711 Allow for single property values to be set on performatives
e2453e38 is described below
commit e2453e3886a6661dfed4cbb9afa2458788d34909
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Wed Apr 12 18:45:24 2023 -0400
PROTON-2711 Allow for single property values to be set on performatives
For those performatives that have properties allow for a simpler
withProperty(k,v) syntax as opposed to requiring user to supply a Map
instance that is already populated.
---
.../test/driver/actions/AttachInjectAction.java | 13 ++++++++
.../test/driver/actions/BeginInjectAction.java | 14 +++++++++
.../test/driver/actions/FlowInjectAction.java | 14 +++++++++
.../test/driver/actions/OpenInjectAction.java | 14 +++++++++
.../protonj2/test/driver/SenderHandlingTest.java | 35 +++++++++++++++++++++-
5 files changed, 89 insertions(+), 1 deletion(-)
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 6609a599..081fa8c6 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
@@ -272,6 +272,19 @@ public class AttachInjectAction extends AbstractPerformativeInjectAction<Attach>
return this;
}
+ public AttachInjectAction withProperty(Symbol key, Object value) {
+ if (attach.getProperties() == null) {
+ attach.setProperties(new LinkedHashMap<>());
+ }
+
+ attach.getProperties().put(key, value);
+ return this;
+ }
+
+ public AttachInjectAction withProperty(String key, Object value) {
+ return withProperty(Symbol.valueOf(key), value);
+ }
+
@Override
protected void beforeActionPerformed(AMQPTestDriver driver) {
// A test that is trying to send an unsolicited attach must provide a channel as we
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/BeginInjectAction.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/BeginInjectAction.java
index 5ef8c848..2e80d69c 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/BeginInjectAction.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/BeginInjectAction.java
@@ -16,6 +16,7 @@
*/
package org.apache.qpid.protonj2.test.driver.actions;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
@@ -155,6 +156,19 @@ public class BeginInjectAction extends AbstractPerformativeInjectAction<Begin> {
return this;
}
+ public BeginInjectAction withProperty(Symbol key, Object value) {
+ if (begin.getProperties() == null) {
+ begin.setProperties(new LinkedHashMap<>());
+ }
+
+ begin.getProperties().put(key, value);
+ return this;
+ }
+
+ public BeginInjectAction withProperty(String key, Object value) {
+ return withProperty(Symbol.valueOf(key), value);
+ }
+
@Override
protected void beforeActionPerformed(AMQPTestDriver driver) {
// We fill in a channel using the next available channel id if one isn't set, then
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/FlowInjectAction.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/FlowInjectAction.java
index 7e3bc95f..01bace8c 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/FlowInjectAction.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/FlowInjectAction.java
@@ -16,6 +16,7 @@
*/
package org.apache.qpid.protonj2.test.driver.actions;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
@@ -146,6 +147,19 @@ public class FlowInjectAction extends AbstractPerformativeInjectAction<Flow> {
return this;
}
+ public FlowInjectAction withProperty(Symbol key, Object value) {
+ if (flow.getProperties() == null) {
+ flow.setProperties(new LinkedHashMap<>());
+ }
+
+ flow.getProperties().put(key, value);
+ return this;
+ }
+
+ public FlowInjectAction withProperty(String key, Object value) {
+ return withProperty(Symbol.valueOf(key), value);
+ }
+
@Override
protected void beforeActionPerformed(AMQPTestDriver driver) {
final SessionTracker session = driver.sessions().getLastLocallyOpenedSession();
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/OpenInjectAction.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/OpenInjectAction.java
index 5d46e8cf..24b562ed 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/OpenInjectAction.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/OpenInjectAction.java
@@ -16,6 +16,7 @@
*/
package org.apache.qpid.protonj2.test.driver.actions;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
@@ -157,4 +158,17 @@ public class OpenInjectAction extends AbstractPerformativeInjectAction<Open> {
open.setProperties(properties);
return this;
}
+
+ public OpenInjectAction withProperty(Symbol key, Object value) {
+ if (open.getProperties() == null) {
+ open.setProperties(new LinkedHashMap<>());
+ }
+
+ open.getProperties().put(key, value);
+ return this;
+ }
+
+ public OpenInjectAction withProperty(String key, Object value) {
+ return withProperty(Symbol.valueOf(key), value);
+ }
}
diff --git a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
index 5f59a6f8..5d0fbe6f 100644
--- a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
+++ b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
@@ -20,6 +20,8 @@ package org.apache.qpid.protonj2.test.driver;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.qpid.protonj2.test.driver.codec.transport.AMQPHeader;
@@ -401,7 +403,7 @@ class SenderHandlingTest extends TestPeerTestsBase {
client.connect(remoteURI.getHost(), remoteURI.getPort());
// These should not be sent until a non-deferred action is triggered.
- client.remoteHeader(AMQPHeader.getAMQPHeader()).deferred().now();
+ client.remoteAMQPHeader().deferred().now();
client.remoteOpen().deferred().now();
client.remoteBegin().deferred().now();
client.remoteAttach().ofSender().deferred().now();
@@ -430,4 +432,35 @@ class SenderHandlingTest extends TestPeerTestsBase {
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
+
+ @Test
+ public void testSendRemoteCommandsWithSingularPropertyAPIs() throws Exception {
+ try (ProtonTestServer peer = new ProtonTestServer();
+ ProtonTestClient client = new ProtonTestClient()) {
+
+ final Map<String, Object> expecetedProperties = new HashMap<>();
+ expecetedProperties.put("test", "entry");
+
+ peer.expectAMQPHeader().respondWithAMQPHeader();
+ peer.expectOpen().withProperties(expecetedProperties);
+ peer.expectBegin().withProperties(expecetedProperties);
+ peer.expectAttach().ofSender().withProperties(expecetedProperties);
+ peer.start();
+
+ URI remoteURI = peer.getServerURI();
+
+ LOG.info("Test started, peer listening on: {}", remoteURI);
+
+ client.connect(remoteURI.getHost(), remoteURI.getPort());
+ client.expectAMQPHeader();
+ client.remoteAMQPHeader().now();
+ client.remoteOpen().withProperty("test", "entry").now();
+ client.remoteBegin().withProperty("test", "entry").now();
+ client.remoteAttach().ofSender().withProperty("test", "entry").now();
+
+ // Wait for the above and then script next steps
+ 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