use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDeleteAllTimestamps.
@Test
public void testDeleteAllTimestamps() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteAllTimestamps".getBytes();
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValueA.setTimestamp(System.currentTimeMillis() - 10);
columnValues.add(columnValueA);
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
handler.put(table, put);
columnValueA.setTimestamp(System.currentTimeMillis());
handler.put(table, put);
TGet get = new TGet(wrap(rowName));
get.setMaxVersions(2);
TResult result = handler.get(table, get);
assertEquals(2, result.getColumnValuesSize());
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<>(1);
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setQualifier(qualifierAname);
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
// This is the default anyway.
delete.setDeleteType(TDeleteType.DELETE_COLUMNS);
handler.deleteSingle(table, delete);
get = new TGet(wrap(rowName));
result = handler.get(table, get);
assertNull(result.getRow());
assertEquals(0, result.getColumnValuesSize());
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.
the class TestThriftHBaseServiceHandler method testMutateRow.
/**
* Put valueA to a row, make sure put has happened, then create a mutation object to put valueB
* and delete ValueA, then check that the row value is only valueB.
*
* @throws Exception
*/
@Test
public void testMutateRow() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testMutateRow".getBytes();
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValuesA = new ArrayList<>(1);
TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValuesA.add(columnValueA);
TPut putA = new TPut(wrap(rowName), columnValuesA);
putA.setColumnValues(columnValuesA);
handler.put(table, putA);
TGet get = new TGet(wrap(rowName));
TResult result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
List<TColumnValue> returnedColumnValues = result.getColumnValues();
List<TColumnValue> expectedColumnValues = new ArrayList<>(1);
expectedColumnValues.add(columnValueA);
assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
List<TColumnValue> columnValuesB = new ArrayList<>(1);
TColumnValue columnValueB = new TColumnValue(wrap(familyAname), wrap(qualifierBname), wrap(valueBname));
columnValuesB.add(columnValueB);
TPut putB = new TPut(wrap(rowName), columnValuesB);
putB.setColumnValues(columnValuesB);
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<>(1);
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setQualifier(qualifierAname);
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
List<TMutation> mutations = new ArrayList<>(2);
TMutation mutationA = TMutation.put(putB);
mutations.add(mutationA);
TMutation mutationB = TMutation.deleteSingle(delete);
mutations.add(mutationB);
TRowMutations tRowMutations = new TRowMutations(wrap(rowName), mutations);
handler.mutateRow(table, tRowMutations);
result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
returnedColumnValues = result.getColumnValues();
expectedColumnValues = new ArrayList<>(1);
expectedColumnValues.add(columnValueB);
assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.
the class TestThriftHBaseServiceHandler method testExistsAll.
@Test
public void testExistsAll() throws TIOError, TException {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName1 = "testExistsAll1".getBytes();
byte[] rowName2 = "testExistsAll2".getBytes();
ByteBuffer table = wrap(tableAname);
List<TGet> gets = new ArrayList<>();
gets.add(new TGet(wrap(rowName2)));
gets.add(new TGet(wrap(rowName2)));
List<Boolean> existsResult1 = handler.existsAll(table, gets);
assertFalse(existsResult1.get(0));
assertFalse(existsResult1.get(1));
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
List<TPut> puts = new ArrayList<TPut>();
puts.add(new TPut(wrap(rowName1), columnValues));
puts.add(new TPut(wrap(rowName2), columnValues));
handler.putMultiple(table, puts);
List<Boolean> existsResult2 = handler.existsAll(table, gets);
assertTrue(existsResult2.get(0));
assertTrue(existsResult2.get(1));
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.
the class TestThriftHBaseServiceHandler method testGetScannerResults.
@Test
public void testGetScannerResults() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
// insert data
TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 20; i++) {
TPut put = new TPut(wrap(("testGetScannerResults" + pad(i, (byte) 2)).getBytes()), columnValues);
handler.put(table, put);
}
// create scan instance
TScan scan = new TScan();
List<TColumn> columns = new ArrayList<>(1);
TColumn column = new TColumn();
column.setFamily(familyAname);
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testGetScannerResults".getBytes());
// get 5 rows and check the returned results
scan.setStopRow("testGetScannerResults05".getBytes());
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).getRow());
}
// get 10 rows and check the returned results
scan.setStopRow("testGetScannerResults10".getBytes());
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).getRow());
}
// get 20 rows and check the returned results
scan.setStopRow("testGetScannerResults20".getBytes());
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).getRow());
}
// reverse scan
scan = new TScan();
scan.setColumns(columns);
scan.setReversed(true);
scan.setStartRow("testGetScannerResults20".getBytes());
scan.setStopRow("testGetScannerResults".getBytes());
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());
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.
the class TestThriftHBaseServiceHandler method testPutGet.
@Test
public void testPutGet() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testPutGet".getBytes();
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
handler.put(table, put);
TGet get = new TGet(wrap(rowName));
TResult result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
List<TColumnValue> returnedColumnValues = result.getColumnValues();
assertTColumnValuesEqual(columnValues, returnedColumnValues);
}
Aggregations