use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableWhileMatchResultScannerAdapter method adapt_oneRow_hasNoMatchingLabels.
@Test
public void adapt_oneRow_hasNoMatchingLabels() throws IOException {
Result expectedResult = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("key"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-out"))));
when(mockBigtableResultScanner.next()).thenReturn(expectedResult);
ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan);
assertNull(scanner.next());
verify(mockSpan, times(1)).end();
verify(mockBigtableResultScanner).next();
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBatchExecutor method testPartialResults.
@Test
public void testPartialResults() throws Exception {
when(mockBigtableApi.getDataClient()).thenReturn(mockDataClientWrapper);
when(mockDataClientWrapper.createBulkRead(isA(String.class))).thenReturn(mockBulkRead);
byte[] key1 = randomBytes(8);
byte[] key2 = randomBytes(8);
Result expected = Result.create(ImmutableList.<org.apache.hadoop.hbase.Cell>of(new RowCell(key1, Bytes.toBytes("cf"), Bytes.toBytes(""), 10, Bytes.toBytes("hi!"), ImmutableList.<String>of())));
RuntimeException exception = new RuntimeException("Something bad happened");
when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).thenReturn(ApiFutures.immediateFuture(expected)).thenReturn(ApiFutures.<Result>immediateFailedFuture(exception));
List<Get> gets = Arrays.asList(new Get(key1), new Get(key2));
Object[] results = new Object[2];
try {
createExecutor().batch(gets, results);
} catch (RetriesExhaustedWithDetailsException ignored) {
}
assertTrue("first result is a result", results[0] instanceof Result);
assertTrue(matchesRow(expected).matches(results[0]));
Assert.assertEquals(exception, results[1]);
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableTable method testExists.
@Test
public void testExists() throws IOException {
Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray())));
when(mockBigtableDataClient.readRowAsync(isA(String.class), isA(ByteString.class), isA(Filters.Filter.class))).thenReturn(ApiFutures.immediateFuture(Result.EMPTY_RESULT)).thenReturn(ApiFutures.immediateFuture(expected));
assertFalse(table.exists(new Get(Bytes.toBytes("empty_row"))));
// second call is suppose to be present
assertTrue(table.exists(new Get(Bytes.toBytes("row_key"))));
verify(mockBigtableDataClient, times(2)).readRowAsync(isA(String.class), isA(ByteString.class), isA(Filters.Filter.class));
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableTable method getScanner_withBigtableWhileMatchResultScannerAdapter.
@Test
public void getScanner_withBigtableWhileMatchResultScannerAdapter() throws IOException {
// A row with no matching label. In case of {@link BigtableWhileMatchResultScannerAdapter} the
// result is null.
Result row = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes(""), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray(), Collections.singletonList("label-in")), new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes(""), Bytes.toBytes("q_name"), 0, Bytes.toBytes("value"))));
when(mockResultScanner.next()).thenReturn(row);
QualifierFilter filter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("x")));
WhileMatchFilter whileMatchFilter = new WhileMatchFilter(filter);
Scan scan = new Scan();
scan.setFilter(whileMatchFilter);
org.apache.hadoop.hbase.client.ResultScanner resultScanner = table.getScanner(scan);
assertNull(resultScanner.next());
verify(mockBigtableDataClient).readRows(isA(Query.class));
verify(mockResultScanner).next();
}
use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.
the class TestRowResultAdapter method testDeduplicationLogic.
@Test
public void testDeduplicationLogic() {
List<String> EMPTY_LABEL = ImmutableList.of();
ByteString valueForNewQual = ByteString.copyFromUtf8("value for new qualifier");
ByteString valueForCellWithoutLabel = ByteString.copyFromUtf8("value for Cell without label");
ByteString valueForCellWithLabel = ByteString.copyFromUtf8("value for cell with labels");
RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
rowBuilder.startRow(ROW_KEY);
// new qualifier
rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, valueForNewQual.size());
rowBuilder.cellValue(valueForNewQual);
rowBuilder.finishCell();
// same qualifier, same timestamp, without label
rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, -1);
rowBuilder.cellValue(valueForCellWithoutLabel);
rowBuilder.finishCell();
// same qualifier, same timestamp, with label
rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, LABELS, -1);
rowBuilder.cellValue(valueForCellWithLabel);
rowBuilder.finishCell();
// same qualifier, different timestamp
rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, EMPTY_LABEL, VALUE.size());
rowBuilder.cellValue(VALUE);
rowBuilder.finishCell();
Result actual = rowBuilder.finishRow();
assertEquals(3, actual.size());
Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForNewQual.toByteArray(), EMPTY_LABEL), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForCellWithLabel.toByteArray(), LABELS), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), EMPTY_LABEL)));
assertResult(expected, actual);
}
Aggregations