HBASE-16014 Get and Put constructor argument lists are divergent

Signed-off-by: CHIA-PING TSAI <chia7712@gmail.com>
This commit is contained in:
brandboat 2017-03-18 18:02:42 +08:00 committed by CHIA-PING TSAI
parent a41b1852da
commit 9c8f02e4ef
2 changed files with 34 additions and 0 deletions

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.client;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -130,6 +131,27 @@ public class Get extends Query
}
}
/**
* Create a Get operation for the specified row.
* @param row
* @param rowOffset
* @param rowLength
*/
public Get(byte[] row, int rowOffset, int rowLength) {
Mutation.checkRow(row, rowOffset, rowLength);
this.row = Bytes.copy(row, rowOffset, rowLength);
}
/**
* Create a Get operation for the specified row.
* @param row
*/
public Get(ByteBuffer row) {
Mutation.checkRow(row);
this.row = new byte[row.remaining()];
row.get(this.row);
}
public boolean isCheckExistenceOnly() {
return checkExistenceOnly;
}

View File

@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
@ -241,4 +242,15 @@ public class TestGet {
assertEquals("my.MockFilter", filters.get(1).getClass().getName());
assertTrue(filters.get(2) instanceof KeyOnlyFilter);
}
@Test
public void testGetRowConstructor() {
byte[] row1 = Bytes.toBytes("testRow");
byte[] row2 = Bytes.toBytes("testtestRow");
ByteBuffer rowBuffer = ByteBuffer.allocate(16);
rowBuffer = ByteBuffer.wrap(row1);
Get get1 = new Get(rowBuffer);
Get get2 = new Get(row2, 4, 7);
Assert.assertArrayEquals(get1.getRow(), get2.getRow());
}
}