HBASE-19847 Fix findbugs and error-prone warnings in hbase-thrift (branch-2)

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Peter Somogyi 2018-01-23 15:54:26 +01:00 committed by tedyu
parent 970636c5af
commit d589b72382
9 changed files with 161 additions and 139 deletions

View File

@ -158,6 +158,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean {
namePrefix = "ICV-" + poolNumber.getAndIncrement() + "-thread-";
}
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
@ -348,49 +349,72 @@ public class IncrementCoalescer implements IncrementCoalescerMBean {
}
// MBean get/set methods
@Override
public int getQueueSize() {
return pool.getQueue().size();
}
@Override
public int getMaxQueueSize() {
return this.maxQueueSize;
}
@Override
public void setMaxQueueSize(int newSize) {
this.maxQueueSize = newSize;
}
@Override
public long getPoolCompletedTaskCount() {
return pool.getCompletedTaskCount();
}
@Override
public long getPoolTaskCount() {
return pool.getTaskCount();
}
@Override
public int getPoolLargestPoolSize() {
return pool.getLargestPoolSize();
}
@Override
public int getCorePoolSize() {
return pool.getCorePoolSize();
}
@Override
public void setCorePoolSize(int newCoreSize) {
pool.setCorePoolSize(newCoreSize);
}
@Override
public int getMaxPoolSize() {
return pool.getMaximumPoolSize();
}
@Override
public void setMaxPoolSize(int newMaxSize) {
pool.setMaximumPoolSize(newMaxSize);
}
@Override
public long getFailedIncrements() {
return failedIncrements.sum();
}
@Override
public long getSuccessfulCoalescings() {
return successfulCoalescings.sum();
}
@Override
public long getTotalIncrements() {
return totalIncrements.sum();
}
@Override
public long getCountersMapSize() {
return countersMap.size();
}

View File

@ -161,6 +161,7 @@ public class TBoundedThreadPoolServer extends TServer {
serverOptions = options;
}
@Override
public void serve() {
try {
serverTransport_.listen();
@ -274,6 +275,7 @@ public class TBoundedThreadPoolServer extends TServer {
/**
* Loops on processing a client forever
*/
@Override
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;

View File

@ -1996,7 +1996,7 @@ public class ThriftServerRunner implements Runnable {
}
@Override
public Throwable getCause() {
public synchronized Throwable getCause() {
return cause;
}

View File

@ -143,7 +143,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
}
@Override
public Throwable getCause() {
public synchronized Throwable getCause() {
return cause;
}

View File

@ -58,8 +58,7 @@ public class TestCallQueue {
Collection<Object[]> parameters = new ArrayList<>();
for (int elementsAdded : new int[] {100, 200, 300}) {
for (int elementsRemoved : new int[] {0, 20, 100}) {
parameters.add(new Object[]{new Integer(elementsAdded),
new Integer(elementsRemoved)});
parameters.add(new Object[]{ elementsAdded, elementsRemoved });
}
}
return parameters;

View File

@ -235,13 +235,13 @@ public class TestThriftServer {
public static void createTestTables(Hbase.Iface handler) throws Exception {
// Create/enable/disable/delete tables, ensure methods act correctly
assertEquals(handler.getTableNames().size(), 0);
assertEquals(0, handler.getTableNames().size());
handler.createTable(tableAname, getColumnDescriptors());
assertEquals(handler.getTableNames().size(), 1);
assertEquals(handler.getColumnDescriptors(tableAname).size(), 2);
assertEquals(1, handler.getTableNames().size());
assertEquals(2, handler.getColumnDescriptors(tableAname).size());
assertTrue(handler.isTableEnabled(tableAname));
handler.createTable(tableBname, getColumnDescriptors());
assertEquals(handler.getTableNames().size(), 2);
assertEquals(2, handler.getTableNames().size());
}
public static void checkTableList(Hbase.Iface handler) throws Exception {
@ -252,7 +252,7 @@ public class TestThriftServer {
handler.disableTable(tableBname);
assertFalse(handler.isTableEnabled(tableBname));
handler.deleteTable(tableBname);
assertEquals(handler.getTableNames().size(), 1);
assertEquals(1, handler.getTableNames().size());
handler.disableTable(tableAname);
assertFalse(handler.isTableEnabled(tableAname));
/* TODO Reenable.
@ -261,7 +261,7 @@ public class TestThriftServer {
assertTrue(handler.isTableEnabled(tableAname));
handler.disableTable(tableAname);*/
handler.deleteTable(tableAname);
assertEquals(handler.getTableNames().size(), 0);
assertEquals(0, handler.getTableNames().size());
}
public void doTestIncrements() throws Exception {
@ -494,12 +494,12 @@ public class TestThriftServer {
// This used to be '1'. I don't know why when we are asking for two columns
// and when the mutations above would seem to add two columns to the row.
// -- St.Ack 05/12/2009
assertEquals(rowResult1a.columns.size(), 1);
assertEquals(1, rowResult1a.columns.size());
assertEquals(rowResult1a.columns.get(columnBname).value, valueCname);
TRowResult rowResult1b = handler.scannerGet(scanner1).get(0);
assertEquals(rowResult1b.row, rowBname);
assertEquals(rowResult1b.columns.size(), 2);
assertEquals(2, rowResult1b.columns.size());
assertEquals(rowResult1b.columns.get(columnAname).value, valueCname);
assertEquals(rowResult1b.columns.get(columnBname).value, valueDname);
closeScanner(scanner1, handler);
@ -508,7 +508,7 @@ public class TestThriftServer {
int scanner2 = handler.scannerOpenTs(tableAname, rowAname, getColumnList(true, true), time1,
null);
TRowResult rowResult2a = handler.scannerGet(scanner2).get(0);
assertEquals(rowResult2a.columns.size(), 1);
assertEquals(1, rowResult2a.columns.size());
// column A deleted, does not exist.
//assertTrue(Bytes.equals(rowResult2a.columns.get(columnAname).value, valueAname));
assertEquals(rowResult2a.columns.get(columnBname).value, valueBname);
@ -523,7 +523,7 @@ public class TestThriftServer {
int scanner4 = handler.scannerOpenWithStopTs(tableAname, rowAname, rowBname,
getColumnList(false, true), time1, null);
TRowResult rowResult4a = handler.scannerGet(scanner4).get(0);
assertEquals(rowResult4a.columns.size(), 1);
assertEquals(1, rowResult4a.columns.size());
assertEquals(rowResult4a.columns.get(columnBname).value, valueBname);
// Test scanner using a TScan object once with sortColumns False and once with sortColumns true
@ -533,7 +533,7 @@ public class TestThriftServer {
int scanner5 = handler.scannerOpenWithScan(tableAname , scanNoSortColumns, null);
TRowResult rowResult5 = handler.scannerGet(scanner5).get(0);
assertEquals(rowResult5.columns.size(), 1);
assertEquals(1, rowResult5.columns.size());
assertEquals(rowResult5.columns.get(columnBname).value, valueCname);
TScan scanSortColumns = new TScan();
@ -543,7 +543,7 @@ public class TestThriftServer {
int scanner6 = handler.scannerOpenWithScan(tableAname ,scanSortColumns, null);
TRowResult rowResult6 = handler.scannerGet(scanner6).get(0);
assertEquals(rowResult6.sortedColumns.size(), 1);
assertEquals(1, rowResult6.sortedColumns.size());
assertEquals(rowResult6.sortedColumns.get(0).getCell().value, valueCname);
List<Mutation> rowBmutations = new ArrayList<>(20);
@ -574,7 +574,7 @@ public class TestThriftServer {
int scanner8 = handler.scannerOpenWithScan(tableAname , reversedScan, null);
List<TRowResult> results = handler.scannerGet(scanner8);
handler.scannerClose(scanner8);
assertEquals(results.size(), 1);
assertEquals(1, results.size());
assertEquals(ByteBuffer.wrap(results.get(0).getRow()), rowBname);
// Teardown
@ -595,19 +595,19 @@ public class TestThriftServer {
public static void doTestGetTableRegions(Hbase.Iface handler)
throws Exception {
assertEquals(handler.getTableNames().size(), 0);
assertEquals(0, handler.getTableNames().size());
handler.createTable(tableAname, getColumnDescriptors());
assertEquals(handler.getTableNames().size(), 1);
assertEquals(1, handler.getTableNames().size());
List<TRegionInfo> regions = handler.getTableRegions(tableAname);
int regionCount = regions.size();
assertEquals("empty table should have only 1 region, " +
"but found " + regionCount, regionCount, 1);
"but found " + regionCount, 1, regionCount);
LOG.info("Region found:" + regions.get(0));
handler.disableTable(tableAname);
handler.deleteTable(tableAname);
regionCount = handler.getTableRegions(tableAname).size();
assertEquals("non-existing table should have 0 region, " +
"but found " + regionCount, regionCount, 0);
"but found " + regionCount, 0, regionCount);
}
public void doTestFilterRegistration() throws Exception {

View File

@ -199,7 +199,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testExists() throws TIOError, TException {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testExists".getBytes();
byte[] rowName = Bytes.toBytes("testExists");
ByteBuffer table = wrap(tableAname);
TGet get = new TGet(wrap(rowName));
@ -219,8 +219,8 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testExistsAll() throws TIOError, TException {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName1 = "testExistsAll1".getBytes();
byte[] rowName2 = "testExistsAll2".getBytes();
byte[] rowName1 = Bytes.toBytes("testExistsAll1");
byte[] rowName2 = Bytes.toBytes("testExistsAll2");
ByteBuffer table = wrap(tableAname);
List<TGet> gets = new ArrayList<>();
@ -247,7 +247,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testPutGet() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testPutGet".getBytes();
byte[] rowName = Bytes.toBytes("testPutGet");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(2);
@ -271,8 +271,8 @@ public class TestThriftHBaseServiceHandler {
public void testPutGetMultiple() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = "testPutGetMultiple1".getBytes();
byte[] rowName2 = "testPutGetMultiple2".getBytes();
byte[] rowName1 = Bytes.toBytes("testPutGetMultiple1");
byte[] rowName2 = Bytes.toBytes("testPutGetMultiple2");
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
@ -301,8 +301,8 @@ public class TestThriftHBaseServiceHandler {
public void testDeleteMultiple() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = "testDeleteMultiple1".getBytes();
byte[] rowName2 = "testDeleteMultiple2".getBytes();
byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
@ -328,7 +328,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testDelete() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDelete".getBytes();
byte[] rowName = Bytes.toBytes("testDelete");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(2);
@ -365,7 +365,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testDeleteAllTimestamps() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteAllTimestamps".getBytes();
byte[] rowName = Bytes.toBytes("testDeleteAllTimestamps");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
@ -405,7 +405,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testDeleteSingleTimestamp() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteSingleTimestamp".getBytes();
byte[] rowName = Bytes.toBytes("testDeleteSingleTimestamp");
ByteBuffer table = wrap(tableAname);
long timestamp1 = System.currentTimeMillis() - 10;
@ -450,13 +450,13 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testDeleteFamily() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteFamily".getBytes();
byte[] rowName = Bytes.toBytes("testDeleteFamily");
ByteBuffer table = wrap(tableAname);
long timestamp1 = System.currentTimeMillis() - 10;
long timestamp2 = System.currentTimeMillis();
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
List<TColumnValue> columnValues = new ArrayList<>();
TColumnValue columnValueA =
new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValueA.setTimestamp(timestamp1);
@ -475,7 +475,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(2, result.getColumnValuesSize());
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<TColumn>();
List<TColumn> deleteColumns = new ArrayList<>();
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
@ -492,13 +492,13 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testDeleteFamilyVersion() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteFamilyVersion".getBytes();
byte[] rowName = Bytes.toBytes("testDeleteFamilyVersion");
ByteBuffer table = wrap(tableAname);
long timestamp1 = System.currentTimeMillis() - 10;
long timestamp2 = System.currentTimeMillis();
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
List<TColumnValue> columnValues = new ArrayList<>();
TColumnValue columnValueA =
new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValueA.setTimestamp(timestamp1);
@ -517,7 +517,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(2, result.getColumnValuesSize());
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<TColumn>();
List<TColumn> deleteColumns = new ArrayList<>();
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setTimestamp(timestamp1);
deleteColumns.add(deleteColumn);
@ -536,7 +536,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testIncrement() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrement".getBytes();
byte[] rowName = Bytes.toBytes("testIncrement");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
@ -563,7 +563,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testAppend() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testAppend".getBytes();
byte[] rowName = Bytes.toBytes("testAppend");
ByteBuffer table = wrap(tableAname);
byte[] v1 = Bytes.toBytes("42");
byte[] v2 = Bytes.toBytes("23");
@ -594,7 +594,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testCheckAndPut() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testCheckAndPut".getBytes();
byte[] rowName = Bytes.toBytes("testCheckAndPut");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);
@ -639,7 +639,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testCheckAndDelete() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testCheckAndDelete".getBytes();
byte[] rowName = Bytes.toBytes("testCheckAndDelete");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);
@ -690,7 +690,7 @@ public class TestThriftHBaseServiceHandler {
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testScan" + i)), columnValues);
handler.put(table, put);
}
@ -702,8 +702,8 @@ public class TestThriftHBaseServiceHandler {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScan".getBytes());
scan.setStopRow("testScan\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testScan"));
scan.setStopRow(Bytes.toBytes("testScan\uffff"));
// get scanner and rows
int scanId = handler.openScanner(table, scan);
@ -711,7 +711,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
assertArrayEquals(Bytes.toBytes("testScan" + i), results.get(i).getRow());
}
// check that we are at the end of the scan
@ -750,7 +750,7 @@ public class TestThriftHBaseServiceHandler {
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < numTrials; i++) {
TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testScan" + i)), columnValues);
handler.put(table, put);
}
@ -762,8 +762,8 @@ public class TestThriftHBaseServiceHandler {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScan".getBytes());
scan.setStopRow("testScan\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testScan"));
scan.setStopRow(Bytes.toBytes("testScan\uffff"));
// Prevent the scanner from caching results
scan.setCaching(1);
@ -772,7 +772,7 @@ public class TestThriftHBaseServiceHandler {
for (int i = 0; i < numTrials; i++) {
// Make sure that the Scanner doesn't throw an exception after the ConnectionCache timeout
List<TResult> results = handler.getScannerRows(scanId, 1);
assertArrayEquals(("testScan" + i).getBytes(), results.get(0).getRow());
assertArrayEquals(Bytes.toBytes("testScan" + i), results.get(0).getRow());
Thread.sleep(trialPause);
}
}
@ -788,7 +788,7 @@ public class TestThriftHBaseServiceHandler {
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testReverseScan" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testReverseScan" + i)), columnValues);
handler.put(table, put);
}
@ -801,8 +801,8 @@ public class TestThriftHBaseServiceHandler {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testReverseScan\uffff".getBytes());
scan.setStopRow("testReverseScan".getBytes());
scan.setStartRow(Bytes.toBytes("testReverseScan\uffff"));
scan.setStopRow(Bytes.toBytes("testReverseScan"));
// get scanner and rows
int scanId = handler.openScanner(table, scan);
@ -810,7 +810,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testReverseScan" + (9 - i)).getBytes(), results.get(i).getRow());
assertArrayEquals(Bytes.toBytes("testReverseScan" + (9 - i)), results.get(i).getRow());
}
// check that we are at the end of the scan
@ -837,7 +837,7 @@ public class TestThriftHBaseServiceHandler {
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testScanWithFilter" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testScanWithFilter" + i)), columnValues);
handler.put(table, put);
}
@ -849,10 +849,10 @@ public class TestThriftHBaseServiceHandler {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScanWithFilter".getBytes());
scan.setStopRow("testScanWithFilter\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testScanWithFilter"));
scan.setStopRow(Bytes.toBytes("testScanWithFilter\uffff"));
// only get the key part
scan.setFilterString(wrap(("KeyOnlyFilter()").getBytes()));
scan.setFilterString(wrap(Bytes.toBytes("KeyOnlyFilter()")));
// get scanner and rows
int scanId = handler.openScanner(table, scan);
@ -860,7 +860,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testScanWithFilter" + i).getBytes(), results.get(i).getRow());
assertArrayEquals(Bytes.toBytes("testScanWithFilter" + i), results.get(i).getRow());
// check that the value is indeed stripped by the filter
assertEquals(0, results.get(i).getColumnValues().get(0).getValue().length);
}
@ -895,7 +895,7 @@ public class TestThriftHBaseServiceHandler {
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(familyAColumnValue);
columnValues.add(familyBColumnValue);
TPut put = new TPut(wrap(("testScanWithColumnFamilyTimeRange" + i).getBytes()),
TPut put = new TPut(wrap(Bytes.toBytes("testScanWithColumnFamilyTimeRange" + i)),
columnValues);
handler.put(table, put);
}
@ -947,17 +947,17 @@ public class TestThriftHBaseServiceHandler {
// insert data
TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname),
wrap(valueAname));
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
List<TColumnValue> columnValues = new ArrayList<>();
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testSmallScan" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testSmallScan" + i)), columnValues);
handler.put(table, put);
}
// small scan instance
TScan scan = new TScan();
scan.setStartRow("testSmallScan".getBytes());
scan.setStopRow("testSmallScan\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testSmallScan"));
scan.setStopRow(Bytes.toBytes("testSmallScan\uffff"));
scan.setReadType(TReadType.PREAD);
scan.setCaching(2);
@ -967,7 +967,7 @@ public class TestThriftHBaseServiceHandler {
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testSmallScan" + i).getBytes(), results.get(i).getRow());
assertArrayEquals(Bytes.toBytes("testSmallScan" + i), results.get(i).getRow());
}
// check that we are at the end of the scan
@ -986,7 +986,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testPutTTL() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testPutTTL".getBytes();
byte[] rowName = Bytes.toBytes("testPutTTL");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
@ -1060,10 +1060,10 @@ public class TestThriftHBaseServiceHandler {
for (int i = 0; i < 100; i++) {
String colNum = pad(i, (byte) 3);
TColumnValue columnValue = new TColumnValue(wrap(familyAname),
wrap(("col" + colNum).getBytes()), wrap(("val" + colNum).getBytes()));
wrap(Bytes.toBytes("col" + colNum)), wrap(Bytes.toBytes("val" + colNum)));
columnValues.add(columnValue);
}
TPut put = new TPut(wrap(("testScanWithBatchSize").getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testScanWithBatchSize")), columnValues);
handler.put(table, put);
// create scan instance
@ -1073,8 +1073,8 @@ public class TestThriftHBaseServiceHandler {
column.setFamily(familyAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScanWithBatchSize".getBytes());
scan.setStopRow("testScanWithBatchSize\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testScanWithBatchSize"));
scan.setStopRow(Bytes.toBytes("testScanWithBatchSize\uffff"));
// set batch size to 10 columns per call
scan.setBatchSize(10);
@ -1092,7 +1092,7 @@ public class TestThriftHBaseServiceHandler {
for (int y = 0; y < 10; y++) {
int colNum = y + (10 * i);
String colNumPad = pad(colNum, (byte) 3);
assertArrayEquals(("col" + colNumPad).getBytes(), cols.get(y).getQualifier());
assertArrayEquals(Bytes.toBytes("col" + colNumPad), cols.get(y).getQualifier());
}
}
@ -1121,7 +1121,7 @@ public class TestThriftHBaseServiceHandler {
columnValues.add(columnValue);
for (int i = 0; i < 20; i++) {
TPut put =
new TPut(wrap(("testGetScannerResults" + pad(i, (byte) 2)).getBytes()), columnValues);
new TPut(wrap(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2))), columnValues);
handler.put(table, put);
}
@ -1133,35 +1133,35 @@ public class TestThriftHBaseServiceHandler {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testGetScannerResults".getBytes());
scan.setStartRow(Bytes.toBytes("testGetScannerResults"));
// get 5 rows and check the returned results
scan.setStopRow("testGetScannerResults05".getBytes());
scan.setStopRow(Bytes.toBytes("testGetScannerResults05"));
List<TResult> results = handler.getScannerResults(table, scan, 5);
assertEquals(5, results.size());
for (int i = 0; i < 5; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i)
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2)), results.get(i)
.getRow());
}
// get 10 rows and check the returned results
scan.setStopRow("testGetScannerResults10".getBytes());
scan.setStopRow(Bytes.toBytes("testGetScannerResults10"));
results = handler.getScannerResults(table, scan, 10);
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i)
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2)), results.get(i)
.getRow());
}
// get 20 rows and check the returned results
scan.setStopRow("testGetScannerResults20".getBytes());
scan.setStopRow(Bytes.toBytes("testGetScannerResults20"));
results = handler.getScannerResults(table, scan, 20);
assertEquals(20, results.size());
for (int i = 0; i < 20; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i)
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2)), results.get(i)
.getRow());
}
@ -1169,14 +1169,14 @@ public class TestThriftHBaseServiceHandler {
scan = new TScan();
scan.setColumns(columns);
scan.setReversed(true);
scan.setStartRow("testGetScannerResults20".getBytes());
scan.setStopRow("testGetScannerResults".getBytes());
scan.setStartRow(Bytes.toBytes("testGetScannerResults20"));
scan.setStopRow(Bytes.toBytes("testGetScannerResults"));
results = handler.getScannerResults(table, scan, 20);
assertEquals(20, results.size());
for (int i = 0; i < 20; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testGetScannerResults" + pad(19 - i, (byte) 2)).getBytes(), results.get(i)
.getRow());
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(19 - i, (byte) 2)),
results.get(i).getRow());
}
}
@ -1196,7 +1196,7 @@ public class TestThriftHBaseServiceHandler {
ThriftHBaseServiceHandler hbaseHandler = createHandler();
THBaseService.Iface handler =
ThriftHBaseServiceHandler.newInstance(hbaseHandler, metrics);
byte[] rowName = "testMetrics".getBytes();
byte[] rowName = Bytes.toBytes("testMetrics");
ByteBuffer table = wrap(tableAname);
TGet get = new TGet(wrap(rowName));
@ -1341,9 +1341,9 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testAttribute() throws Exception {
byte[] rowName = "testAttribute".getBytes();
byte[] attributeKey = "attribute1".getBytes();
byte[] attributeValue = "value1".getBytes();
byte[] rowName = Bytes.toBytes("testAttribute");
byte[] attributeKey = Bytes.toBytes("attribute1");
byte[] attributeValue = Bytes.toBytes("value1");
Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>();
attributes.put(wrap(attributeKey), wrap(attributeValue));
@ -1384,7 +1384,7 @@ public class TestThriftHBaseServiceHandler {
@Test
public void testMutateRow() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testMutateRow".getBytes();
byte[] rowName = Bytes.toBytes("testMutateRow");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);
@ -1445,7 +1445,7 @@ public class TestThriftHBaseServiceHandler {
*/
@Test
public void testDurability() throws Exception {
byte[] rowName = "testDurability".getBytes();
byte[] rowName = Bytes.toBytes("testDurability");
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
@ -1455,61 +1455,61 @@ public class TestThriftHBaseServiceHandler {
TDelete tDelete = new TDelete(wrap(rowName));
tDelete.setDurability(TDurability.SKIP_WAL);
Delete delete = deleteFromThrift(tDelete);
assertEquals(delete.getDurability(), Durability.SKIP_WAL);
assertEquals(Durability.SKIP_WAL, delete.getDurability());
tDelete.setDurability(TDurability.ASYNC_WAL);
delete = deleteFromThrift(tDelete);
assertEquals(delete.getDurability(), Durability.ASYNC_WAL);
assertEquals(Durability.ASYNC_WAL, delete.getDurability());
tDelete.setDurability(TDurability.SYNC_WAL);
delete = deleteFromThrift(tDelete);
assertEquals(delete.getDurability(), Durability.SYNC_WAL);
assertEquals(Durability.SYNC_WAL, delete.getDurability());
tDelete.setDurability(TDurability.FSYNC_WAL);
delete = deleteFromThrift(tDelete);
assertEquals(delete.getDurability(), Durability.FSYNC_WAL);
assertEquals(Durability.FSYNC_WAL, delete.getDurability());
TPut tPut = new TPut(wrap(rowName), columnValues);
tPut.setDurability(TDurability.SKIP_WAL);
Put put = putFromThrift(tPut);
assertEquals(put.getDurability(), Durability.SKIP_WAL);
assertEquals(Durability.SKIP_WAL, put.getDurability());
tPut.setDurability(TDurability.ASYNC_WAL);
put = putFromThrift(tPut);
assertEquals(put.getDurability(), Durability.ASYNC_WAL);
assertEquals(Durability.ASYNC_WAL, put.getDurability());
tPut.setDurability(TDurability.SYNC_WAL);
put = putFromThrift(tPut);
assertEquals(put.getDurability(), Durability.SYNC_WAL);
assertEquals(Durability.SYNC_WAL, put.getDurability());
tPut.setDurability(TDurability.FSYNC_WAL);
put = putFromThrift(tPut);
assertEquals(put.getDurability(), Durability.FSYNC_WAL);
assertEquals(Durability.FSYNC_WAL, put.getDurability());
TIncrement tIncrement = new TIncrement(wrap(rowName), incrementColumns);
tIncrement.setDurability(TDurability.SKIP_WAL);
Increment increment = incrementFromThrift(tIncrement);
assertEquals(increment.getDurability(), Durability.SKIP_WAL);
assertEquals(Durability.SKIP_WAL, increment.getDurability());
tIncrement.setDurability(TDurability.ASYNC_WAL);
increment = incrementFromThrift(tIncrement);
assertEquals(increment.getDurability(), Durability.ASYNC_WAL);
assertEquals(Durability.ASYNC_WAL, increment.getDurability());
tIncrement.setDurability(TDurability.SYNC_WAL);
increment = incrementFromThrift(tIncrement);
assertEquals(increment.getDurability(), Durability.SYNC_WAL);
assertEquals(Durability.SYNC_WAL, increment.getDurability());
tIncrement.setDurability(TDurability.FSYNC_WAL);
increment = incrementFromThrift(tIncrement);
assertEquals(increment.getDurability(), Durability.FSYNC_WAL);
assertEquals(Durability.FSYNC_WAL, increment.getDurability());
}
@Test
public void testCheckAndMutate() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
ByteBuffer row = wrap("row".getBytes());
ByteBuffer row = wrap(Bytes.toBytes("row"));
ByteBuffer family = wrap(familyAname);
ByteBuffer qualifier = wrap(qualifierAname);
ByteBuffer value = wrap(valueAname);

View File

@ -150,6 +150,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
private static void createLabels() throws IOException, InterruptedException {
PrivilegedExceptionAction<VisibilityLabelsResponse> action =
new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
@Override
public VisibilityLabelsResponse run() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
@ -197,7 +198,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
TPut put = new TPut(wrap(Bytes.toBytes("testScan" + i)), columnValues);
if (i == 5) {
put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
} else {
@ -215,8 +216,8 @@ public class TestThriftHBaseServiceHandlerWithLabels {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScan".getBytes());
scan.setStopRow("testScan\uffff".getBytes());
scan.setStartRow(Bytes.toBytes("testScan"));
scan.setStopRow(Bytes.toBytes("testScan\uffff"));
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(2);
@ -228,15 +229,14 @@ public class TestThriftHBaseServiceHandlerWithLabels {
int scanId = handler.openScanner(table, scan);
List<TResult> results = handler.getScannerRows(scanId, 10);
assertEquals(9, results.size());
Assert.assertFalse(Bytes.equals(results.get(5).getRow(),
("testScan" + 5).getBytes()));
Assert.assertFalse(Bytes.equals(results.get(5).getRow(), Bytes.toBytes("testScan" + 5)));
for (int i = 0; i < 9; i++) {
if (i < 5) {
assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
assertArrayEquals(Bytes.toBytes("testScan" + i), results.get(i).getRow());
} else if (i == 5) {
continue;
} else {
assertArrayEquals(("testScan" + (i + 1)).getBytes(), results.get(i)
assertArrayEquals(Bytes.toBytes("testScan" + (i + 1)), results.get(i)
.getRow());
}
}
@ -266,8 +266,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
columnValues.add(columnValue);
for (int i = 0; i < 20; i++) {
TPut put = new TPut(
wrap(("testGetScannerResults" + pad(i, (byte) 2)).getBytes()),
columnValues);
wrap(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2))), columnValues);
if (i == 3) {
put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
} else {
@ -285,10 +284,10 @@ public class TestThriftHBaseServiceHandlerWithLabels {
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testGetScannerResults".getBytes());
scan.setStartRow(Bytes.toBytes("testGetScannerResults"));
// get 5 rows and check the returned results
scan.setStopRow("testGetScannerResults05".getBytes());
scan.setStopRow(Bytes.toBytes("testGetScannerResults05"));
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(2);
labels.add(SECRET);
@ -300,14 +299,12 @@ public class TestThriftHBaseServiceHandlerWithLabels {
for (int i = 0; i < 4; i++) {
if (i < 3) {
assertArrayEquals(
("testGetScannerResults" + pad(i, (byte) 2)).getBytes(),
results.get(i).getRow());
Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2)), results.get(i).getRow());
} else if (i == 3) {
continue;
} else {
assertArrayEquals(
("testGetScannerResults" + pad(i + 1, (byte) 2)).getBytes(), results
.get(i).getRow());
Bytes.toBytes("testGetScannerResults" + pad(i + 1, (byte) 2)), results.get(i).getRow());
}
}
}
@ -315,7 +312,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
@Test
public void testGetsWithLabels() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testPutGet".getBytes();
byte[] rowName = Bytes.toBytes("testPutGet");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(2);
@ -345,7 +342,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
@Test
public void testIncrementWithTags() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrementWithTags".getBytes();
byte[] rowName = Bytes.toBytes("testIncrementWithTags");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
@ -380,7 +377,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
@Test
public void testIncrementWithTagsWithNotMatchLabels() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrementWithTagsWithNotMatchLabels".getBytes();
byte[] rowName = Bytes.toBytes("testIncrementWithTagsWithNotMatchLabels");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
@ -411,7 +408,7 @@ public class TestThriftHBaseServiceHandlerWithLabels {
@Test
public void testAppend() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testAppend".getBytes();
byte[] rowName = Bytes.toBytes("testAppend");
ByteBuffer table = wrap(tableAname);
byte[] v1 = Bytes.toBytes(1L);
byte[] v2 = Bytes.toBytes(5L);

View File

@ -114,7 +114,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testExistsWithReadOnly() throws TException {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testExists".getBytes();
byte[] rowName = Bytes.toBytes("testExists");
ByteBuffer table = wrap(tableAname);
TGet get = new TGet(wrap(rowName));
@ -131,8 +131,8 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testExistsAllWithReadOnly() throws TException {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName1 = "testExistsAll1".getBytes();
byte[] rowName2 = "testExistsAll2".getBytes();
byte[] rowName1 = Bytes.toBytes("testExistsAll1");
byte[] rowName2 = Bytes.toBytes("testExistsAll2");
ByteBuffer table = wrap(tableAname);
List<TGet> gets = new ArrayList<>();
@ -152,7 +152,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testGetWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testGet".getBytes();
byte[] rowName = Bytes.toBytes("testGet");
ByteBuffer table = wrap(tableAname);
TGet get = new TGet(wrap(rowName));
@ -171,8 +171,8 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testGetMultipleWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = "testGetMultiple1".getBytes();
byte[] rowName2 = "testGetMultiple2".getBytes();
byte[] rowName1 = Bytes.toBytes("testGetMultiple1");
byte[] rowName2 = Bytes.toBytes("testGetMultiple2");
List<TGet> gets = new ArrayList<>(2);
gets.add(new TGet(wrap(rowName1)));
@ -192,7 +192,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testPutWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName = "testPut".getBytes();
byte[] rowName = Bytes.toBytes("testPut");
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
@ -214,7 +214,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testCheckAndPutWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testCheckAndPut".getBytes();
byte[] rowName = Bytes.toBytes("testCheckAndPut");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);
@ -248,8 +248,8 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testPutMultipleWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = "testPutMultiple1".getBytes();
byte[] rowName2 = "testPutMultiple2".getBytes();
byte[] rowName1 = Bytes.toBytes("testPutMultiple1");
byte[] rowName2 = Bytes.toBytes("testPutMultiple2");
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
@ -273,7 +273,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testDeleteWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDelete".getBytes();
byte[] rowName = Bytes.toBytes("testDelete");
ByteBuffer table = wrap(tableAname);
TDelete delete = new TDelete(wrap(rowName));
@ -294,8 +294,8 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testDeleteMultipleWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = "testDeleteMultiple1".getBytes();
byte[] rowName2 = "testDeleteMultiple2".getBytes();
byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
List<TDelete> deletes = new ArrayList<>(2);
deletes.add(new TDelete(wrap(rowName1)));
@ -317,7 +317,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
public void testCheckAndMutateWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
ByteBuffer row = wrap("row".getBytes());
ByteBuffer row = wrap(Bytes.toBytes("row"));
ByteBuffer family = wrap(familyAname);
ByteBuffer qualifier = wrap(qualifierAname);
ByteBuffer value = wrap(valueAname);
@ -347,7 +347,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testCheckAndDeleteWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testCheckAndDelete".getBytes();
byte[] rowName = Bytes.toBytes("testCheckAndDelete");
ByteBuffer table = wrap(tableAname);
TDelete delete = new TDelete(wrap(rowName));
@ -368,7 +368,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testIncrementWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrement".getBytes();
byte[] rowName = Bytes.toBytes("testIncrement");
ByteBuffer table = wrap(tableAname);
List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
@ -390,7 +390,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testAppendWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testAppend".getBytes();
byte[] rowName = Bytes.toBytes("testAppend");
ByteBuffer table = wrap(tableAname);
byte[] v1 = Bytes.toBytes("42");
@ -413,7 +413,7 @@ public class TestThriftHBaseServiceHandlerWithReadOnly {
@Test
public void testMutateRowWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testMutateRow".getBytes();
byte[] rowName = Bytes.toBytes("testMutateRow");
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);