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/13 18:36:38 UTC
[7/8] qpid-proton-j git commit: PROTON-1891: ensure the empty slice
rejects appends like non-empty slices do
PROTON-1891: ensure the empty slice rejects appends like non-empty slices do
(cherry picked from commit e36cc1d4a5858521c46ed82195dd5bccd87e706d)
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/2dbadb41
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/2dbadb41
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/2dbadb41
Branch: refs/heads/0.27.x
Commit: 2dbadb4196455e21f70c72075828ec46de133a63
Parents: e740e8a
Author: Robbie Gemmell <ro...@apache.org>
Authored: Tue Jul 10 12:43:43 2018 +0100
Committer: Robbie Gemmell <ro...@apache.org>
Committed: Fri Jul 13 19:18:33 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/2dbadb41/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/2dbadb41/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