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 2021/06/04 13:46:40 UTC
[qpid-protonj2] branch main updated: PROTON-2393 Populate the
delivery tag of scripted remote transfers
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 0aa4976 PROTON-2393 Populate the delivery tag of scripted remote transfers
0aa4976 is described below
commit 0aa4976e6df4f8d4571e812a5c11b017cb538b44
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Thu Jun 3 18:15:27 2021 -0400
PROTON-2393 Populate the delivery tag of scripted remote transfers
When a remote transfer is scripted auto-fill the delivery tag unless
told otherwise by the test script. Add a few additional APIs for
scripting expectations as well.
---
.../protonj2/client/impl/StreamReceiverTest.java | 2 +-
.../test/driver/actions/TransferInjectAction.java | 38 +++++++++++++++++
.../driver/expectations/TransferExpectation.java | 8 ++++
.../protonj2/test/driver/SenderHandlingTest.java | 47 ++++++++++++++++++++++
4 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
index aabfc12..1c1560f 100644
--- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
+++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
@@ -634,7 +634,7 @@ class StreamReceiverTest extends ImperativeClientTestCase {
peer.remoteTransfer().withHandle(0)
.withDeliveryId(0)
- .withDeliveryTag(new byte[] { 1 })
+ .withNullDeliveryTag()
.withMore(false)
.withMessageFormat(0)
.withPayload(payload).now();
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
index 4024d81..644975c 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
@@ -18,6 +18,7 @@ package org.apache.qpid.protonj2.test.driver.actions;
import java.util.Date;
import java.util.List;
+import java.util.UUID;
import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
import org.apache.qpid.protonj2.test.driver.SessionTracker;
@@ -68,6 +69,8 @@ public class TransferInjectAction extends AbstractPerformativeInjectAction<Trans
private DescribedType body;
private Footer footer;
+ private boolean explicitlyNullDeliveryTag;
+
public TransferInjectAction(AMQPTestDriver driver) {
super(driver);
}
@@ -101,6 +104,10 @@ public class TransferInjectAction extends AbstractPerformativeInjectAction<Trans
final SessionTracker session = driver.sessions().getSessionFromLocalChannel(UnsignedShort.valueOf(onChannel()));
+ if (transfer.getDeliveryTag() == null && !explicitlyNullDeliveryTag) {
+ transfer.setDeliveryTag(new Binary(generateUniqueDeliveryTag()));
+ }
+
// A test might be trying to send Transfer outside of session scope to check for error handling
// of unexpected performatives so we just allow no session cases and send what we are told.
if (session != null) {
@@ -128,15 +135,23 @@ public class TransferInjectAction extends AbstractPerformativeInjectAction<Trans
}
public TransferInjectAction withDeliveryTag(byte[] deliveryTag) {
+ explicitlyNullDeliveryTag = deliveryTag == null;
transfer.setDeliveryTag(new Binary(deliveryTag));
return this;
}
public TransferInjectAction withDeliveryTag(Binary deliveryTag) {
+ explicitlyNullDeliveryTag = deliveryTag == null;
transfer.setDeliveryTag(deliveryTag);
return this;
}
+ public TransferInjectAction withNullDeliveryTag() {
+ explicitlyNullDeliveryTag = true;
+ transfer.setDeliveryTag(null);
+ return this;
+ }
+
public TransferInjectAction withMessageFormat(int messageFormat) {
transfer.setMessageFormat(UnsignedInteger.valueOf(messageFormat));
return this;
@@ -612,4 +627,27 @@ public class TransferInjectAction extends AbstractPerformativeInjectAction<Trans
return this;
}
}
+
+ private static byte[] generateUniqueDeliveryTag() {
+ final byte[] tag = new byte[Long.BYTES + Long.BYTES];
+ final UUID uuid = UUID.randomUUID();
+
+ writeLong(uuid.getMostSignificantBits(), tag, 0);
+ writeLong(uuid.getLeastSignificantBits(), tag, Long.BYTES);
+
+ return tag;
+ }
+
+ private static byte[] writeLong(long value, byte[] destination, int offset) {
+ destination[offset++] = (byte) (value >>> 56);
+ destination[offset++] = (byte) (value >>> 48);
+ destination[offset++] = (byte) (value >>> 40);
+ destination[offset++] = (byte) (value >>> 32);
+ destination[offset++] = (byte) (value >>> 24);
+ destination[offset++] = (byte) (value >>> 16);
+ destination[offset++] = (byte) (value >>> 8);
+ destination[offset++] = (byte) (value >>> 0);
+
+ return destination;
+ }
}
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/TransferExpectation.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/TransferExpectation.java
index 2e95937..7f8c729 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/TransferExpectation.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/TransferExpectation.java
@@ -197,6 +197,14 @@ public class TransferExpectation extends AbstractExpectation<Transfer> {
return withDeliveryTag(equalTo(deliveryTag));
}
+ public TransferExpectation withNonNullDeliveryTag() {
+ return withDeliveryTag(notNullValue());
+ }
+
+ public TransferExpectation withNullDeliveryTag() {
+ return withDeliveryTag(nullValue());
+ }
+
public TransferExpectation withMessageFormat(int messageFormat) {
return withMessageFormat(equalTo(UnsignedInteger.valueOf(messageFormat)));
}
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 32b1a16..f28cd8e 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
@@ -341,4 +341,51 @@ class SenderHandlingTest extends TestPeerTestsBase {
assertThrows(AssertionError.class, () -> peer.waitForScriptToComplete(5, TimeUnit.SECONDS));
}
}
+
+ @Test
+ public void testTransferAutoPopulatesDeliveryTagAndHandleFromLastOpenedLink() throws Exception {
+ try (ProtonTestServer peer = new ProtonTestServer();
+ ProtonTestClient client = new ProtonTestClient()) {
+
+ peer.expectAMQPHeader().respondWithAMQPHeader();
+ peer.expectOpen().respond();
+ peer.expectBegin().respond();
+ peer.expectAttach().ofSender().respond().withHandle(42);
+ peer.remoteFlow().withLinkCredit(1).queue();
+ peer.expectTransfer().withHandle(2)
+ .withDeliveryId(0)
+ .withNonNullDeliveryTag()
+ .withNonNullPayload();
+ peer.expectDetach().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().ofReceiver().withHandle(42);
+ client.expectFlow().withLinkCredit(1).withHandle(42);
+ client.remoteTransfer().withDeliveryId(0).withPayload(new byte[] {0}).queue();
+ // Now start and then await the remote grant of credit and out send of a transfer
+ client.remoteHeader(AMQPHeader.getAMQPHeader()).now();
+ client.remoteOpen().now();
+ client.remoteBegin().now();
+ client.remoteAttach().ofSender().withHandle(2).now();
+
+ client.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ client.expectDetach().withHandle(42);
+ client.expectEnd();
+
+ client.remoteDetach().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