Search in sources :

Example 21 with Row

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

the class EnhancedBigtableStubTest method testUserAgent.

@Test
public void testUserAgent() throws InterruptedException {
    ServerStreamingCallable<Query, Row> streamingCallable = enhancedBigtableStub.createReadRowsCallable(new DefaultRowAdapter());
    Query request = Query.create("table-id").rowKey("row-key");
    streamingCallable.call(request).iterator().next();
    assertThat(metadataInterceptor.headers).hasSize(1);
    Metadata metadata = metadataInterceptor.headers.take();
    assertThat(metadata.get(Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER))).containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Metadata(io.grpc.Metadata) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 22 with Row

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

the class EnhancedBigtableStubTest method testCreateReadRowsRawCallable.

@Test
public void testCreateReadRowsRawCallable() throws InterruptedException {
    ServerStreamingCallable<ReadRowsRequest, Row> callable = enhancedBigtableStub.createReadRowsRawCallable(new DefaultRowAdapter());
    ReadRowsRequest expectedRequest = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-1").setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("test-row-key"))).build();
    callable.call(expectedRequest).iterator().next();
    assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest);
    ReadRowsRequest expectedRequest2 = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-2").build();
    callable.call(expectedRequest2).iterator().next();
    assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest2);
}
Also used : ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 23 with Row

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

the class ReadModifyWriteRowCallableTest method responseSortsFamilies.

@Test
public void responseSortsFamilies() throws Exception {
    ByteString col = ByteString.copyFromUtf8("col1");
    ByteString value1 = ByteString.copyFromUtf8("value1");
    ByteString value2 = ByteString.copyFromUtf8("value2");
    ApiFuture<Row> result = callable.futureCall(ReadModifyWriteRow.create("my-table", "my-key").append("my-family", "col", "suffix"));
    inner.response.set(ReadModifyWriteRowResponse.newBuilder().setRow(com.google.bigtable.v2.Row.newBuilder().setKey(ByteString.copyFromUtf8("my-key")).addFamilies(Family.newBuilder().setName("family2").addColumns(Column.newBuilder().setQualifier(col).addCells(Cell.newBuilder().setTimestampMicros(1_000).setValue(value2)))).addFamilies(Family.newBuilder().setName("family1").addColumns(Column.newBuilder().setQualifier(col).addCells(Cell.newBuilder().setTimestampMicros(1_000).setValue(value1))).build())).build());
    assertThat(result.get(1, TimeUnit.SECONDS)).isEqualTo(Row.create(ByteString.copyFromUtf8("my-key"), ImmutableList.of(RowCell.create("family1", col, 1_000, ImmutableList.<String>of(), value1), RowCell.create("family2", col, 1_000, ImmutableList.<String>of(), value2))));
}
Also used : ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 24 with Row

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

the class MetricsTracerTest method testReadRowsFirstRow.

@Test
public void testReadRowsFirstRow() throws InterruptedException {
    final long beforeSleep = 50;
    final long afterSleep = 50;
    SettableFuture<Void> gotFirstRow = SettableFuture.create();
    ExecutorService executor = Executors.newCachedThreadPool();
    doAnswer(invocation -> {
        StreamObserver<ReadRowsResponse> observer = invocation.getArgument(1);
        executor.submit(() -> {
            Thread.sleep(beforeSleep);
            observer.onNext(DEFAULT_READ_ROWS_RESPONSES);
            // wait until the first row is consumed before padding the operation span
            gotFirstRow.get();
            Thread.sleep(afterSleep);
            observer.onCompleted();
            return null;
        });
        return null;
    }).when(mockService).readRows(any(ReadRowsRequest.class), any());
    Stopwatch stopwatch = Stopwatch.createStarted();
    // Get the first row and notify the mock that it can start padding the operation span
    Iterator<Row> it = stub.readRowsCallable().call(Query.create(TABLE_ID)).iterator();
    it.next();
    gotFirstRow.set(null);
    // finish the stream
    while (it.hasNext()) {
        it.next();
    }
    long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    // Give OpenCensus a chance to update the views asynchronously.
    Thread.sleep(100);
    executor.shutdown();
    long firstRowLatency = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY_VIEW, ImmutableMap.<TagKey, TagValue>of(), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
    assertThat(firstRowLatency).isIn(Range.closed(beforeSleep, elapsed - afterSleep));
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ExecutorService(java.util.concurrent.ExecutorService) Stopwatch(com.google.common.base.Stopwatch) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 25 with Row

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

the class SampleRowsIT method test.

@Test
public void test() throws InterruptedException, ExecutionException, TimeoutException {
    BigtableDataClient client = testEnvRule.env().getDataClient();
    String rowPrefix = UUID.randomUUID().toString();
    // Create some data so that sample row keys has something to show
    List<ApiFuture<?>> futures = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        ApiFuture<Void> future = client.mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowPrefix + "-" + i).setCell(testEnvRule.env().getFamilyId(), "", "value"));
        futures.add(future);
    }
    ApiFutures.allAsList(futures).get(1, TimeUnit.MINUTES);
    ApiFuture<List<KeyOffset>> future = client.sampleRowKeysAsync(testEnvRule.env().getTableId());
    List<KeyOffset> results = future.get(1, TimeUnit.MINUTES);
    assertThat(results).isNotEmpty();
    assertThat(results.get(results.size() - 1).getOffsetBytes()).isGreaterThan(0L);
}
Also used : ApiFuture(com.google.api.core.ApiFuture) KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) List(java.util.List) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) Test(org.junit.Test)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4