Search in sources :

Example 6 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.

the class TestRowRangeAdapter method testSingleClosedRangeRowSet.

@Test
public void testSingleClosedRangeRowSet() {
    ByteString key1 = ByteString.copyFromUtf8("myKey");
    ByteString key2 = ByteString.copyFromUtf8("otherKey");
    RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(key1).setEndKeyClosed(key2)).build();
    RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.closed(new RowKeyWrapper(key1), new RowKeyWrapper(key2))).build();
    assertEquals(expected, out);
    adapter.rangeSetToByteStringRange(out, query);
    assertEquals(in, query.toProto(requestContext).getRows());
}
Also used : ByteString(com.google.protobuf.ByteString) RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 7 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.

the class TestRowRangeAdapter method testAllRowSet.

@Test
public void testAllRowSet() {
    RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder()).build();
    RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.<RowKeyWrapper>all()).build();
    assertEquals(expected, out);
    adapter.rangeSetToByteStringRange(out, query);
    assertEquals(in, query.toProto(requestContext).getRows());
}
Also used : RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 8 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.

the class TestRowRangeAdapter method testSingleOpenClosedRangeRowSet.

@Test
public void testSingleOpenClosedRangeRowSet() {
    ByteString key1 = ByteString.copyFromUtf8("myKey");
    ByteString key2 = ByteString.copyFromUtf8("otherKey");
    RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyOpen(key1).setEndKeyClosed(key2)).build();
    RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.openClosed(new RowKeyWrapper(key1), new RowKeyWrapper(key2))).build();
    assertEquals(expected, out);
    adapter.rangeSetToByteStringRange(out, query);
    assertEquals(in, query.toProto(requestContext).getRows());
}
Also used : ByteString(com.google.protobuf.ByteString) RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 9 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.

the class DefaultRowAdapter method createRowFromProto.

/**
 * Helper to convert a proto Row to a model Row.
 *
 * <p>For internal use only.
 */
@InternalApi
public Row createRowFromProto(com.google.bigtable.v2.Row row) {
    RowBuilder<Row> builder = createRowBuilder();
    builder.startRow(row.getKey());
    for (Family family : row.getFamiliesList()) {
        for (Column column : family.getColumnsList()) {
            for (Cell cell : column.getCellsList()) {
                builder.startCell(family.getName(), column.getQualifier(), cell.getTimestampMicros(), cell.getLabelsList(), cell.getValue().size());
                builder.cellValue(cell.getValue());
                builder.finishCell();
            }
        }
    }
    return builder.finishRow();
}
Also used : Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Cell(com.google.bigtable.v2.Cell) InternalApi(com.google.api.core.InternalApi)

Example 10 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.

the class BigtableDataClientFactoryTest method testCreateWithRefreshingChannel.

@Test
public void testCreateWithRefreshingChannel() throws Exception {
    String[] tableIds = { "fake-table1", "fake-table2" };
    int poolSize = 3;
    BigtableDataSettings.Builder builder = BigtableDataSettings.newBuilderForEmulator(port).setProjectId(DEFAULT_PROJECT_ID).setInstanceId(DEFAULT_INSTANCE_ID).setAppProfileId(DEFAULT_APP_PROFILE_ID).setPrimingTableIds(tableIds).setRefreshingChannel(true);
    builder.stubSettings().setCredentialsProvider(credentialsProvider).setStreamWatchdogProvider(watchdogProvider).setExecutorProvider(executorProvider);
    InstantiatingGrpcChannelProvider channelProvider = (InstantiatingGrpcChannelProvider) builder.stubSettings().getTransportChannelProvider();
    InstantiatingGrpcChannelProvider.Builder channelProviderBuilder = channelProvider.toBuilder();
    channelProviderBuilder.setPoolSize(poolSize);
    builder.stubSettings().setTransportChannelProvider(channelProviderBuilder.build());
    BigtableDataClientFactory factory = BigtableDataClientFactory.create(builder.build());
    factory.createDefault();
    factory.createForAppProfile("other-appprofile");
    factory.createForInstance("other-project", "other-instance");
    // Make sure that only 1 instance is created for all clients
    Mockito.verify(credentialsProvider, Mockito.times(1)).getCredentials();
    Mockito.verify(executorProvider, Mockito.times(1)).getExecutor();
    Mockito.verify(watchdogProvider, Mockito.times(1)).getWatchdog();
    // Make sure that the clients are sharing the same ChannelPool
    assertThat(setUpAttributes).hasSize(poolSize);
    // Make sure that prime requests were sent only once per table per connection
    assertThat(service.readRowsRequests).hasSize(poolSize * tableIds.length);
    List<ReadRowsRequest> expectedRequests = new LinkedList<>();
    for (String tableId : tableIds) {
        for (int i = 0; i < poolSize; i++) {
            expectedRequests.add(ReadRowsRequest.newBuilder().setTableName(String.format("projects/%s/instances/%s/tables/%s", DEFAULT_PROJECT_ID, DEFAULT_INSTANCE_ID, tableId)).setAppProfileId(DEFAULT_APP_PROFILE_ID).setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("nonexistent-priming-row"))).setFilter(RowFilter.newBuilder().setBlockAllFilter(true).build()).setRowsLimit(1).build());
        }
    }
    assertThat(service.readRowsRequests).containsExactly(expectedRequests.toArray());
    // Wait for all the connections to close asynchronously
    factory.close();
    long sleepTimeMs = 1000;
    Thread.sleep(sleepTimeMs);
    // Verify that all the channels are closed
    assertThat(terminateAttributes).hasSize(poolSize);
}
Also used : InstantiatingGrpcChannelProvider(com.google.api.gax.grpc.InstantiatingGrpcChannelProvider) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 RowSet (com.google.bigtable.v2.RowSet)14 RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)12 ByteString (com.google.protobuf.ByteString)12 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)6 Builder (com.google.bigtable.v2.ReadRowsRequest.Builder)4 Column (com.google.bigtable.v2.Column)3 Family (com.google.bigtable.v2.Family)3 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 DeleteFromRow (com.google.bigtable.v2.Mutation.DeleteFromRow)2 Row (com.google.bigtable.v2.Row)2 RowFilter (com.google.bigtable.v2.RowFilter)2 Builder (com.google.bigtable.v2.RowFilter.Chain.Builder)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ExecutionException (java.util.concurrent.ExecutionException)2 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)2 InternalApi (com.google.api.core.InternalApi)1 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)1