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 2018/07/09 15:59:07 UTC

qpid-proton-j git commit: PROTON-1889: ensure array indexing is updated if needed when appending new content to the composite

Repository: qpid-proton-j
Updated Branches:
  refs/heads/master e91fa5f18 -> c5e2f7990


PROTON-1889: ensure array indexing is updated if needed when appending new content to the composite


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/c5e2f799
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/c5e2f799
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/c5e2f799

Branch: refs/heads/master
Commit: c5e2f7990ca82cdf682c8ee3e27ad611447e542e
Parents: e91fa5f
Author: Robbie Gemmell <ro...@apache.org>
Authored: Mon Jul 9 16:57:42 2018 +0100
Committer: Robbie Gemmell <ro...@apache.org>
Committed: Mon Jul 9 16:57:42 2018 +0100

----------------------------------------------------------------------
 .../proton/codec/CompositeReadableBuffer.java   |  4 ++
 .../codec/CompositeReadableBufferTest.java      | 72 ++++++++++++++++++++
 2 files changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/c5e2f799/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
index 5a030f0..f5f2e2a 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
@@ -666,8 +666,12 @@ public class CompositeReadableBuffer implements ReadableBuffer {
             contents.add(currentArray);
             contents.add(array);
             currentArrayIndex = 0;
+            // If we exhausted the array previously then it should move to the new one now.
+            maybeMoveToNextArray();
         } else {
             contents.add(array);
+            // If we exhausted the list previously then it didn't move onward at the time, so it should now.
+            maybeMoveToNextArray();
         }
 
         capacity += array.length;

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/c5e2f799/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
index 09dc427..136f655 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
@@ -1108,6 +1108,78 @@ public class CompositeReadableBufferTest {
     //----- Test appending data to the buffer --------------------------------//
 
     @Test
+    public void testAppendToBufferAtEndOfContentArray() {
+        CompositeReadableBuffer buffer = new CompositeReadableBuffer();
+
+        byte[] source1 = new byte[] { 0, 1, 2, 3 };
+
+        buffer.append(source1);
+
+        assertTrue(buffer.hasArray());
+        assertEquals(0, buffer.getArrays().size());
+        assertEquals(-1, buffer.getCurrentIndex());
+
+        buffer.position(source1.length);
+
+        assertFalse(buffer.hasRemaining());
+        assertEquals(0, buffer.remaining());
+        assertEquals(-1, buffer.getCurrentIndex());
+
+        byte[] source2 = new byte[] { 4, 5, 6, 7 };
+        buffer.append(source2);
+
+        assertTrue(buffer.hasRemaining());
+        assertEquals(source2.length, buffer.remaining());
+        assertFalse(buffer.hasArray());
+        assertEquals(2, buffer.getArrays().size());
+        assertEquals(1, buffer.getCurrentIndex());
+        assertEquals(source1.length, buffer.position());
+
+        // Check each position in the array is read
+        for(int i = 0; i < source2.length; i++) {
+            assertEquals(1, buffer.getCurrentIndex());
+            assertEquals(source1.length + i, buffer.get());
+        }
+    }
+
+    @Test
+    public void testAppendToBufferAtEndOfContentList() {
+        CompositeReadableBuffer buffer = new CompositeReadableBuffer();
+
+        byte[] source1 = new byte[] { 0, 1, 2, 3 };
+        byte[] source2 = new byte[] { 4, 5, 6, 7 };
+
+        buffer.append(source1);
+        buffer.append(source2);
+
+        assertFalse(buffer.hasArray());
+        assertEquals(2, buffer.getArrays().size());
+        assertEquals(0, buffer.getCurrentIndex());
+
+        buffer.position(source1.length + source2.length);
+
+        assertFalse(buffer.hasRemaining());
+        assertEquals(0, buffer.remaining());
+        assertEquals(1, buffer.getCurrentIndex());
+
+        byte[] source3 = new byte[] { 8, 9, 10, 11 };
+        buffer.append(source3);
+
+        assertTrue(buffer.hasRemaining());
+        assertEquals(source3.length, buffer.remaining());
+        assertFalse(buffer.hasArray());
+        assertEquals(3, buffer.getArrays().size());
+        assertEquals(2, buffer.getCurrentIndex());
+        assertEquals(source1.length + source2.length, buffer.position());
+
+        // Check each position in the array is read
+        for(int i = 0; i < source3.length; i++) {
+            assertEquals(2, buffer.getCurrentIndex());
+            assertEquals(source1.length + source2.length + i, buffer.get());
+        }
+    }
+
+    @Test
     public void testAppendOne() {
         CompositeReadableBuffer buffer = new CompositeReadableBuffer();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org