qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject qpid-proton-j git commit: PROTON-1891: ensure the empty slice rejects appends like non-empty slices do
Date Tue, 10 Jul 2018 12:08:37 GMT
Repository: qpid-proton-j
Updated Branches:
  refs/heads/master c5e2f7990 -> e36cc1d4a


PROTON-1891: ensure the empty slice rejects appends like non-empty slices do


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

Branch: refs/heads/master
Commit: e36cc1d4a5858521c46ed82195dd5bccd87e706d
Parents: c5e2f79
Author: Robbie Gemmell <robbie@apache.org>
Authored: Tue Jul 10 12:43:43 2018 +0100
Committer: Robbie Gemmell <robbie@apache.org>
Committed: Tue Jul 10 13:07:16 2018 +0100

----------------------------------------------------------------------
 .../proton/codec/CompositeReadableBuffer.java   |  2 +-
 .../codec/CompositeReadableBufferTest.java      | 39 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/e36cc1d4/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 f5f2e2a..3780668 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
@@ -36,7 +36,7 @@ public class CompositeReadableBuffer implements ReadableBuffer {
 
     private static final List<byte[]> EMPTY_LIST = Collections.unmodifiableList(new
ArrayList<byte[]>());
     private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap(new byte[0]);
-    private static final CompositeReadableBuffer EMPTY_SLICE = new CompositeReadableBuffer(true);
+    private static final CompositeReadableBuffer EMPTY_SLICE = new CompositeReadableBuffer(false);
     private static int UNSET_MARK = -1;
 
     private static final int SHORT_BYTES = 2;

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/e36cc1d4/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 136f655..4daef3e 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
@@ -1940,7 +1940,42 @@ public class CompositeReadableBufferTest {
     }
 
     @Test
-    public void testSliceIgnoresAppends() {
+    public void testSliceWithNoRemainderRefusesAppends() {
+        CompositeReadableBuffer buffer = new CompositeReadableBuffer();
+        buffer.append(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+        // Empty slice at end of buffer
+        assertEquals(10, buffer.remaining());
+        buffer.position(10);
+        assertEquals(0, buffer.remaining());
+
+        CompositeReadableBuffer emptySlice = buffer.slice();
+        assertNotSame(buffer, emptySlice);
+        assertEquals(0, emptySlice.remaining());
+
+        try {
+            emptySlice.append(new byte[] { 10 });
+            fail("Should not be allowed to append to empty slice, must throw IllegalStateException");
+        } catch (IllegalStateException ise) {}
+
+        // Empty slice at start of buffer
+        buffer.position(0);
+        assertEquals(10, buffer.remaining());
+        buffer.limit(0);
+        assertEquals(0, buffer.remaining());
+
+        emptySlice = buffer.slice();
+        assertNotSame(buffer, emptySlice);
+        assertEquals(0, emptySlice.remaining());
+
+        try {
+            emptySlice.append(new byte[] { 10 });
+            fail("Should not be allowed to append to empty slice, must throw IllegalStateException");
+        } catch (IllegalStateException ise) {}
+    }
+
+    @Test
+    public void testSliceRefusesAppends() {
         CompositeReadableBuffer buffer = new CompositeReadableBuffer();
         buffer.append(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
 
@@ -1950,7 +1985,7 @@ public class CompositeReadableBufferTest {
 
         try {
             slice.append(new byte[] { 10 });
-            fail("Should not be allowed to append to a slice, must throw ReadOnlyBufferException");
+            fail("Should not be allowed to append to a slice, must throw IllegalStateException");
         } catch (IllegalStateException ise) {}
     }
 


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


Mime
View raw message