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 2016/10/28 18:31:12 UTC

qpid-jms git commit: QPIDJMS-215 Writable Buffer does report true capacity

Repository: qpid-jms
Updated Branches:
  refs/heads/master 97970a3d9 -> 593b3e7f5


QPIDJMS-215 Writable Buffer does report true capacity

Fix the writable buffer to report the remaining and hasRemaining values
using the maxCapacity value of the ByteBuf, otherwise the the true value
is under reported.


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/593b3e7f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/593b3e7f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/593b3e7f

Branch: refs/heads/master
Commit: 593b3e7f5befbc73621273012f4877ee2ab5225d
Parents: 97970a3
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Oct 28 13:49:49 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Oct 28 14:31:01 2016 -0400

----------------------------------------------------------------------
 .../amqp/message/AmqpWritableBuffer.java        |  8 +-
 .../amqp/message/AmqpWritableBufferTest.java    | 83 ++++++++++++++++++++
 2 files changed, 88 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/593b3e7f/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBuffer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBuffer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBuffer.java
index 7088b5f..5e74cf6 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBuffer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBuffer.java
@@ -28,10 +28,12 @@ import io.netty.buffer.Unpooled;
  */
 public class AmqpWritableBuffer implements WritableBuffer {
 
+    public static final int INITIAL_CAPACITY = 1024;
+
     public ByteBuf nettyBuffer;
 
     public AmqpWritableBuffer() {
-        nettyBuffer = Unpooled.buffer(1024);
+        nettyBuffer = Unpooled.buffer(INITIAL_CAPACITY);
     }
 
     public AmqpWritableBuffer(ByteBuf buffer) {
@@ -88,12 +90,12 @@ public class AmqpWritableBuffer implements WritableBuffer {
 
     @Override
     public boolean hasRemaining() {
-        return nettyBuffer.writerIndex() < nettyBuffer.capacity();
+        return nettyBuffer.writerIndex() < nettyBuffer.maxCapacity();
     }
 
     @Override
     public int remaining() {
-        return nettyBuffer.capacity() - nettyBuffer.writerIndex();
+        return nettyBuffer.maxCapacity() - nettyBuffer.writerIndex();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/593b3e7f/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBufferTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBufferTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBufferTest.java
new file mode 100644
index 0000000..b583c27
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpWritableBufferTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.provider.amqp.message;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+/**
+ * Tests for behavior of AmqpWritableBuffer
+ */
+public class AmqpWritableBufferTest {
+
+    @Test
+    public void testGetBuffer() {
+        ByteBuf buffer = Unpooled.buffer(1024);
+        AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);
+
+        assertSame(buffer, writable.getBuffer());
+    }
+
+    @Test
+    public void testRemaining() {
+        ByteBuf buffer = Unpooled.buffer(1024);
+        AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);
+
+        assertEquals(buffer.maxCapacity(), writable.remaining());
+        writable.put((byte) 0);
+        assertEquals(buffer.maxCapacity() - 1, writable.remaining());
+    }
+
+    @Test
+    public void testHasRemaining() {
+        ByteBuf buffer = Unpooled.buffer(100, 100);
+        AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);
+
+        assertTrue(writable.hasRemaining());
+        writable.put((byte) 0);
+        assertTrue(writable.hasRemaining());
+        buffer.writerIndex(buffer.maxCapacity());
+        assertFalse(writable.hasRemaining());
+    }
+
+    @Test
+    public void testGetPosition() {
+        ByteBuf buffer = Unpooled.buffer(1024);
+        AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);
+
+        assertEquals(0, writable.position());
+        writable.put((byte) 0);
+        assertEquals(1, writable.position());
+    }
+
+    @Test
+    public void testSetPosition() {
+        ByteBuf buffer = Unpooled.buffer(1024);
+        AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);
+
+        assertEquals(0, writable.position());
+        writable.position(1);
+        assertEquals(1, writable.position());
+    }
+}


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