You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2017/03/06 18:36:55 UTC
qpid-proton-j git commit: PROTON-1409: expose the current available
byte count for a delivery to aid with sizing destination buffers
Repository: qpid-proton-j
Updated Branches:
refs/heads/master 5d364a79a -> 083833d30
PROTON-1409: expose the current available byte count for a delivery to aid with sizing destination buffers
This closes #7
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/083833d3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/083833d3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/083833d3
Branch: refs/heads/master
Commit: 083833d30e8bb4389148c9b82249053f95be7f99
Parents: 5d364a7
Author: Robert Gemmell <ro...@apache.org>
Authored: Mon Mar 6 18:36:12 2017 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Mon Mar 6 18:36:12 2017 +0000
----------------------------------------------------------------------
.../org/apache/qpid/proton/engine/Delivery.java | 16 ++++++++
.../qpid/proton/engine/impl/DeliveryImpl.java | 6 +++
.../engine/impl/DeferredSettlementTest.java | 9 +++--
.../proton/engine/impl/DeliveryImplTest.java | 39 ++++++++++++++++++++
4 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/083833d3/proton-j/src/main/java/org/apache/qpid/proton/engine/Delivery.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Delivery.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Delivery.java
index c5f6d73..58c62b6 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Delivery.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Delivery.java
@@ -143,4 +143,20 @@ public interface Delivery extends Extendable
*/
public int getMessageFormat();
+ /**
+ * Returns the number of bytes currently available for this delivery, which may not be complete yet, that are still
+ * to either be received by the application or sent by the transport.
+ *
+ * Note that this value will change as bytes are received/sent, and is in general not equal to the total length of
+ * a delivery, except the point where {@link #isPartial()} returns false and no content has yet been received by the
+ * application or sent by the transport.
+ *
+ * @return the number of bytes currently available for the delivery
+ *
+ * @see Receiver#recv(byte[], int, int)
+ * @see Receiver#recv(org.apache.qpid.proton.codec.WritableBuffer)
+ * @see Sender#send(byte[], int, int)
+ * @see Sender#send(org.apache.qpid.proton.codec.ReadableBuffer)
+ */
+ int available();
}
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/083833d3/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/DeliveryImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/DeliveryImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/DeliveryImpl.java
index 8b47231..61f8ec8 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/DeliveryImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/DeliveryImpl.java
@@ -387,6 +387,12 @@ public class DeliveryImpl implements Delivery
}
@Override
+ public int available()
+ {
+ return _dataSize;
+ }
+
+ @Override
public boolean isWritable()
{
return getLink() instanceof SenderImpl
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/083833d3/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeferredSettlementTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeferredSettlementTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeferredSettlementTest.java
index 34a26e6..10ff811 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeferredSettlementTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeferredSettlementTest.java
@@ -413,10 +413,13 @@ public class DeferredSettlementTest extends EngineTestBase
assertFalse(delivery.isPartial());
assertTrue(delivery.isReadable());
- byte[] received = new byte[BUFFER_SIZE];
- int len = clientReceiver.recv(received, 0, BUFFER_SIZE);
+ int size = delivery.available();
+ byte[] received = new byte[size];
- assertTrue("given array was too small", len < BUFFER_SIZE);
+ int len = clientReceiver.recv(received, 0, size);
+
+ assertEquals("Should have received " + size + " bytes", size, len);
+ assertEquals("Should be no bytes left", 0, delivery.available());
Message m = Proton.message();
m.decode(received, 0, len);
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/083833d3/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
index a063265..b754d5c 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
@@ -22,7 +22,11 @@ package org.apache.qpid.proton.engine.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.qpid.proton.engine.Delivery;
import org.apache.qpid.proton.engine.Record;
import org.junit.Test;
import org.mockito.Mockito;
@@ -74,4 +78,39 @@ public class DeliveryImplTest
Record attachments2 = delivery.attachments();
assertSame("Expected to get the same attachments", attachments, attachments2);
}
+
+ @Test
+ public void testAvailable() throws Exception
+ {
+ // Set up a delivery with some data
+ byte[] myData = "myData".getBytes(StandardCharsets.UTF_8);
+
+ DeliveryImpl deliveyImpl = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);
+ deliveyImpl.setData(myData);
+ deliveyImpl.setDataLength(myData.length);
+
+ Delivery delivery = deliveyImpl;
+
+ // Check the full data is available
+ assertNotNull("expected the delivery to be present", delivery);
+ assertEquals("unexpectd available count", myData.length, delivery.available());
+
+ // Extract some of the data as the receiver link will, check available gets reduced accordingly.
+ int partLength = 2;
+ int remainderLength = myData.length - partLength;
+ assertTrue(partLength < myData.length);
+
+ byte[] myRecievedData1 = new byte[partLength];
+
+ int received = deliveyImpl.recv(myRecievedData1, 0, myRecievedData1.length);
+ assertEquals("Unexpected data length received", partLength, received);
+ assertEquals("Unexpected data length available", remainderLength, delivery.available());
+
+ // Extract remainder of the data as the receiver link will, check available hits 0.
+ byte[] myRecievedData2 = new byte[remainderLength];
+
+ received = deliveyImpl.recv(myRecievedData2, 0, remainderLength);
+ assertEquals("Unexpected data length received", remainderLength, received);
+ assertEquals("Expected no data to remain available", 0, delivery.available());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org