You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ra...@apache.org on 2015/07/03 04:29:22 UTC
hbase git commit: HBASE-14011 - MultiByteBuffer position based reads
does not work correctly (Ram)
Repository: hbase
Updated Branches:
refs/heads/master 17703f036 -> 1b75fd2bd
HBASE-14011 - MultiByteBuffer position based reads does not work correctly
(Ram)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1b75fd2b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1b75fd2b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1b75fd2b
Branch: refs/heads/master
Commit: 1b75fd2bd6fdae2b6a8634ff24492ff0b96c1f32
Parents: 17703f0
Author: ramkrishna <ra...@gmail.com>
Authored: Fri Jul 3 07:58:48 2015 +0530
Committer: ramkrishna <ra...@gmail.com>
Committed: Fri Jul 3 07:58:48 2015 +0530
----------------------------------------------------------------------
.../hadoop/hbase/nio/MultiByteBuffer.java | 4 +--
.../hadoop/hbase/nio/TestMultiByteBuffer.java | 36 ++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/1b75fd2b/hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuffer.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuffer.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuffer.java
index 5fcc34d..1b4ad2a 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuffer.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuffer.java
@@ -151,7 +151,7 @@ public class MultiByteBuffer {
*/
private int getItemIndex(int elemIndex) {
int index = 1;
- while (elemIndex > this.itemBeginPos[index]) {
+ while (elemIndex >= this.itemBeginPos[index]) {
index++;
if (index == this.itemBeginPos.length) {
throw new IndexOutOfBoundsException();
@@ -166,7 +166,7 @@ public class MultiByteBuffer {
*/
private int getItemIndexFromCurItemIndex(int elemIndex) {
int index = this.curItemIndex;
- while (elemIndex < this.itemBeginPos[index]) {
+ while (elemIndex >= this.itemBeginPos[index]) {
index++;
if (index == this.itemBeginPos.length) {
throw new IndexOutOfBoundsException();
http://git-wip-us.apache.org/repos/asf/hbase/blob/1b75fd2b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuffer.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuffer.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuffer.java
index 27f3484..ddab391 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuffer.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuffer.java
@@ -277,4 +277,40 @@ public class TestMultiByteBuffer {
assertEquals(l1, dup.getLong());
assertEquals(l2, dup.getLong());
}
+
+ @Test
+ public void testGetWithPosOnMultiBuffers() throws IOException {
+ byte[] b = new byte[4];
+ byte[] b1 = new byte[4];
+ ByteBuffer bb1 = ByteBuffer.wrap(b);
+ ByteBuffer bb2 = ByteBuffer.wrap(b1);
+ MultiByteBuffer mbb1 = new MultiByteBuffer(bb1, bb2);
+ mbb1.position(2);
+ mbb1.putInt(4);
+ int res = mbb1.getInt(2);
+ byte[] bres = new byte[4];
+ bres[0] = mbb1.get(2);
+ bres[1] = mbb1.get(3);
+ bres[2] = mbb1.get(4);
+ bres[3] = mbb1.get(5);
+ int expected = Bytes.toInt(bres);
+ assertEquals(res, expected);
+ }
+
+ @Test
+ public void testGetIntStrictlyForwardWithPosOnMultiBuffers() throws IOException {
+ byte[] b = new byte[4];
+ byte[] b1 = new byte[4];
+ ByteBuffer bb1 = ByteBuffer.wrap(b);
+ ByteBuffer bb2 = ByteBuffer.wrap(b1);
+ MultiByteBuffer mbb1 = new MultiByteBuffer(bb1, bb2);
+ mbb1.position(2);
+ mbb1.putInt(4);
+ mbb1.position(7);
+ mbb1.put((byte) 2);
+ mbb1.position(0);
+ mbb1.getIntStrictlyForward(4);
+ byte res = mbb1.get(7);
+ assertEquals((byte) 2, res);
+ }
}