Search in sources :

Example 11 with KeyOffset

use of com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class TestAbstractBigtableConnection method testRegionLocator.

@Test
public void testRegionLocator() throws IOException {
    assertEquals(1, connection.getAllRegionInfos(TABLE_NAME).size());
    assertEquals(regionInfo, connection.getAllRegionInfos(TABLE_NAME).get(0));
    List<HRegionLocation> expectedRegionLocations = ImmutableList.of(new HRegionLocation(regionInfo, ServerName.valueOf(HOST_NAME, server.getPort(), 0)));
    when(mockSampledAdapter.adaptResponse(Mockito.<List<KeyOffset>>any())).thenReturn(expectedRegionLocations);
    RegionLocator regionLocator = connection.getRegionLocator(TABLE_NAME);
    assertEquals(expectedRegionLocations, regionLocator.getAllRegionLocations());
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) Test(org.junit.Test)

Example 12 with KeyOffset

use of com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createSampleRowKeysCallable.

/**
 * Creates a callable chain to handle SampleRowKeys RPcs. The chain will:
 *
 * <ul>
 *   <li>Convert a table id to a {@link com.google.bigtable.v2.SampleRowKeysRequest}.
 *   <li>Dispatch the request to the GAPIC's {@link BigtableStub#sampleRowKeysCallable()}.
 *   <li>Spool responses into a list.
 *   <li>Retry on failure.
 *   <li>Convert the responses into {@link KeyOffset}s.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private UnaryCallable<String, List<KeyOffset>> createSampleRowKeysCallable() {
    String methodName = "SampleRowKeys";
    ServerStreamingCallable<SampleRowKeysRequest, SampleRowKeysResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<SampleRowKeysRequest, SampleRowKeysResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getSampleRowKeysMethod()).setParamsExtractor(new RequestParamsExtractor<SampleRowKeysRequest>() {

        @Override
        public Map<String, String> extract(SampleRowKeysRequest sampleRowKeysRequest) {
            return ImmutableMap.of("table_name", sampleRowKeysRequest.getTableName(), "app_profile_id", sampleRowKeysRequest.getAppProfileId());
        }
    }).build(), settings.sampleRowKeysSettings().getRetryableCodes());
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> spoolable = base.all();
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withStatsHeaders = new StatsHeadersUnaryCallable<>(spoolable);
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> retryable = Callables.retrying(withHeaderTracer, settings.sampleRowKeysSettings(), clientContext);
    return createUserFacingUnaryCallable(methodName, new SampleRowKeysCallable(retryable, requestContext));
}
Also used : SampleRowKeysResponse(com.google.bigtable.v2.SampleRowKeysResponse) HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) SampleRowKeysRequest(com.google.bigtable.v2.SampleRowKeysRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) StatsHeadersUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable) ByteString(com.google.protobuf.ByteString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Test (org.junit.Test)9 KeyOffset (com.google.cloud.bigtable.data.v2.models.KeyOffset)8 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)6 ArrayList (java.util.ArrayList)5 KeyOffset (com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset)3 BoundedSource (org.apache.beam.sdk.io.BoundedSource)3 SampleRowKeysRequest (com.google.bigtable.v2.SampleRowKeysRequest)2 List (java.util.List)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ApiFuture (com.google.api.core.ApiFuture)1 SampleRowKeysResponse (com.google.bigtable.v2.SampleRowKeysResponse)1 AbstractSource (com.google.cloud.bigtable.beam.CloudBigtableIO.AbstractSource)1 Source (com.google.cloud.bigtable.beam.CloudBigtableIO.Source)1 SourceWithKeys (com.google.cloud.bigtable.beam.CloudBigtableIO.SourceWithKeys)1 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)1 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)1 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)1