Search in sources :

Example 6 with DefaultRowAdapter

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

the class RowMergingCallableTest method invalidMarkerInCell.

@Test
public void invalidMarkerInCell() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setRowKey(ByteString.copyFromUtf8("key1")).setFamilyName(StringValue.newBuilder().setValue("family")).setQualifier(BytesValue.newBuilder().setValue(ByteString.EMPTY)).setTimestampMicros(1_000).setValue(ByteString.copyFromUtf8("a")).setValueSize(2)).build(), // send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build(), // finish the cell & row
    ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setValue(ByteString.copyFromUtf8("b")).setValueSize(0).setCommitRow(true)).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    Throwable actualError = null;
    try {
        rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    } catch (Throwable t) {
        actualError = t;
    }
    Truth.assertThat(actualError).isInstanceOf(IllegalStateException.class);
}
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) 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 7 with DefaultRowAdapter

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

the class BigtableChannelPrimer method sendPrimeRequests.

private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException {
    // Wrap the channel in a temporary stub
    EnhancedBigtableStubSettings primingSettings = settingsTemplate.toBuilder().setTransportChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(managedChannel))).build();
    try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(primingSettings)) {
        Map<String, ApiFuture<?>> primeFutures = new HashMap<>();
        // Prime all of the table ids in parallel
        for (String tableId : tableIds) {
            ApiFuture<Row> f = stub.createReadRowsRawCallable(new DefaultRowAdapter()).first().futureCall(ReadRowsRequest.newBuilder().setTableName(TableName.format(primingSettings.getProjectId(), primingSettings.getInstanceId(), tableId)).setAppProfileId(primingSettings.getAppProfileId()).setRows(RowSet.newBuilder().addRowKeys(PRIMING_ROW_KEY).build()).setFilter(RowFilter.newBuilder().setBlockAllFilter(true).build()).setRowsLimit(1).build());
            primeFutures.put(tableId, f);
        }
        // Wait for all of the prime requests to complete.
        for (Map.Entry<String, ApiFuture<?>> entry : primeFutures.entrySet()) {
            try {
                entry.getValue().get();
            } catch (Throwable e) {
                if (e instanceof ExecutionException) {
                    e = e.getCause();
                }
                LOG.warning(String.format("Failed to prime channel for table: %s: %s", entry.getKey(), e.getMessage()));
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ApiFuture(com.google.api.core.ApiFuture) Row(com.google.cloud.bigtable.data.v2.models.Row) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map)

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