Search in sources :

Example 1 with DefaultRowAdapter

use of com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter 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 2 with DefaultRowAdapter

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

the class EnhancedBigtableStubTest method testCreateReadRowsCallable.

@Test
public void testCreateReadRowsCallable() throws InterruptedException {
    ServerStreamingCallable<Query, Row> streamingCallable = enhancedBigtableStub.createReadRowsCallable(new DefaultRowAdapter());
    Query request = Query.create("table-id").rowKey("row-key");
    streamingCallable.call(request).iterator().next();
    ReadRowsRequest expected = request.toProto(RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID));
    assertThat(fakeDataService.popLastRequest()).isEqualTo(expected);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) 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 3 with DefaultRowAdapter

use of com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter 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 4 with DefaultRowAdapter

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

the class ReadRowsMergingAcceptanceTest method test.

@Test
public void test() throws Exception {
    List<ReadRowsResponse> responses = Lists.newArrayList();
    // Convert the chunks into a single ReadRowsResponse
    for (CellChunk chunk : testCase.getChunksList()) {
        ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
        responseBuilder.addChunks(chunk);
        responses.add(responseBuilder.build());
    }
    // Wrap the responses in a callable
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
    RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
    // Invoke the callable to get the merged rows
    ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
    // Read all of the rows and transform them into logical cells
    List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
    Exception error = null;
    try {
        for (Row row : stream) {
            for (RowCell cell : row.getCells()) {
                actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
            }
        }
    } catch (Exception e) {
        error = e;
    }
    // Verify the results
    if (expectsError(testCase)) {
        assertThat(error).isNotNull();
    } else {
        if (error != null) {
            throw error;
        }
    }
    assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
Also used : CellChunk(com.google.bigtable.v2.ReadRowsResponse.CellChunk) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) IOException(java.io.IOException) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadRowsTest(com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest) Test(org.junit.Test)

Example 5 with DefaultRowAdapter

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

the class RowMergingCallableTest method scanMarker.

@Test
public void scanMarker() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) 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)

Aggregations

DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)7 Row (com.google.cloud.bigtable.data.v2.models.Row)7 Test (org.junit.Test)6 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)5 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)3 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)3 Query (com.google.cloud.bigtable.data.v2.models.Query)2 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)2 FakeStreamingApi (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi)2 ApiFuture (com.google.api.core.ApiFuture)1 CellChunk (com.google.bigtable.v2.ReadRowsResponse.CellChunk)1 ReadRowsTest (com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest)1 ByteString (com.google.protobuf.ByteString)1 Metadata (io.grpc.Metadata)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1