Search in sources :

Example 1 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBatchExecutor method testGet.

@Test
public void testGet() throws Exception {
    when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).thenReturn(mockFuture);
    final byte[] key = randomBytes(8);
    Result response = Result.create(ImmutableList.<Cell>of(new RowCell(key, Bytes.toBytes("family"), Bytes.toBytes(""), 1000L, Bytes.toBytes("value"))));
    setFuture(response);
    Result[] results = batch(ImmutableList.<Row>of(new Get(key)));
    assertTrue(matchesRow(response).matches(results[0]));
}
Also used : ByteString(com.google.protobuf.ByteString) Get(org.apache.hadoop.hbase.client.Get) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 2 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBatchExecutor method testBatchBulkGets.

@Test
public void testBatchBulkGets() throws Exception {
    final List<Get> gets = new ArrayList<>(10);
    final List<ApiFuture<Result>> expected = new ArrayList<>(10);
    gets.add(new Get(Bytes.toBytes("key0")));
    expected.add(ApiFutures.<Result>immediateFuture(null));
    for (int i = 1; i < 10; i++) {
        byte[] row_key = randomBytes(8);
        gets.add(new Get(row_key));
        ByteString key = ByteStringer.wrap(row_key);
        ByteString cellValue = ByteString.copyFrom(randomBytes(8));
        expected.add(ApiFutures.immediateFuture(Result.create(ImmutableList.<Cell>of(new RowCell(key.toByteArray(), Bytes.toBytes("family"), Bytes.toBytes(""), System.nanoTime() / 1000, cellValue.toByteArray())))));
    }
    // Test 10 gets, but return only 9 to test the row not found case.
    when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).then(new Answer<ApiFuture<Result>>() {

        final AtomicInteger counter = new AtomicInteger();

        @Override
        public ApiFuture<Result> answer(InvocationOnMock invocation) throws Throwable {
            return expected.get(counter.getAndIncrement());
        }
    });
    ByteString key = ByteStringer.wrap(randomBytes(8));
    ByteString cellValue = ByteString.copyFrom(randomBytes(8));
    Result row = Result.create(ImmutableList.<Cell>of(new RowCell(key.toByteArray(), Bytes.toBytes("family"), Bytes.toBytes(""), 1000L, cellValue.toByteArray())));
    when(mockFuture.get()).thenReturn(row);
    Result[] results = createExecutor().batch(gets);
    verify(mockBulkRead, times(10)).add(any(ByteString.class), any(Filters.Filter.class));
    verify(mockBulkRead, times(1)).sendOutstanding();
    assertTrue(matchesRow(Result.EMPTY_RESULT).matches(results[0]));
    for (int i = 1; i < results.length; i++) {
        assertTrue("Expected " + Bytes.toString(gets.get(i).getRow()) + " but was " + Bytes.toString(results[i].getRow()), Bytes.equals(results[i].getRow(), gets.get(i).getRow()));
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) ApiFuture(com.google.api.core.ApiFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Get(org.apache.hadoop.hbase.client.Get) Test(org.junit.Test)

Example 3 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBatchExecutor method testGetCallback.

@Test
public void testGetCallback() throws Exception {
    when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).thenReturn(mockFuture);
    byte[] key = randomBytes(8);
    Result response = Result.create(ImmutableList.<Cell>of(new RowCell(key, Bytes.toBytes("family"), Bytes.toBytes(""), 1000L, Bytes.toBytes("value"))));
    setFuture(response);
    final Callback<Result> callback = Mockito.mock(Callback.class);
    createExecutor().batchCallback(ImmutableList.<Row>of(new Get(key)), new Object[1], callback);
    verify(callback, times(1)).update(same(BatchExecutor.NO_REGION), same(key), argThat(matchesRow(response)));
}
Also used : ByteString(com.google.protobuf.ByteString) Get(org.apache.hadoop.hbase.client.Get) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 4 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestRowResultAdapter method testWithSingleCellRow.

@Test
public void testWithSingleCellRow() {
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 10000L, Collections.<String>emptyList(), VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    rowBuilder.startCell(COL_FAMILY, QUAL_TWO, 20000L, LABELS, -1);
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 10L, VALUE.toByteArray()), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_TWO.toByteArray(), 20L, VALUE.toByteArray(), LABELS)));
    assertResult(expected, rowBuilder.finishRow());
    assertEquals(ROW_KEY, underTest.getKey(expected));
}
Also used : RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 5 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestRowResultAdapter method testOnlyValueIsDifferent.

@Test
public void testOnlyValueIsDifferent() {
    ByteString valuePart1 = ByteString.copyFromUtf8("part-1");
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    // started cell with same qualifier but different value
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, valuePart1.size());
    rowBuilder.cellValue(valuePart1);
    rowBuilder.finishCell();
    Result actual = rowBuilder.finishRow();
    assertEquals(2, actual.size());
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), LABELS), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, valuePart1.toByteArray(), LABELS)));
    assertResult(expected, actual);
}
Also used : ByteString(com.google.protobuf.ByteString) RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)16 Result (org.apache.hadoop.hbase.client.Result)15 Test (org.junit.Test)15 ByteString (com.google.protobuf.ByteString)9 Get (org.apache.hadoop.hbase.client.Get)5 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)5 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 Cell (org.apache.hadoop.hbase.Cell)3 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 Query (com.google.cloud.bigtable.data.v2.models.Query)2 Scan (org.apache.hadoop.hbase.client.Scan)2 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)2 WhileMatchFilter (org.apache.hadoop.hbase.filter.WhileMatchFilter)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ApiFuture (com.google.api.core.ApiFuture)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)1