From c907dcf3d552e0ee812ec192a4b2a5924380d93a Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:20:48 -0500 Subject: [PATCH 1/8] Bigtable 12. Implement SampleRowKeys Implements the SampleRowKeys api method: - convert table ids into SampleRowKeyRequests - converts streaming SampleRowKeyResponses into a spooled List of KeyOffsets --- .../data/v2/stub/EnhancedBigtableStub.java | 41 +++++- .../data/v2/stub/SampleRowKeysCallable.java | 81 ++++++++++++ .../v2/stub/SampleRowKeysCallableTest.java | 125 ++++++++++++++++++ 3 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java create mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 398a4ab9e146..415ea4c4e39f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -17,11 +17,15 @@ import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; +import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.Callables; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter; import com.google.cloud.bigtable.data.v2.models.KeyOffset; @@ -31,6 +35,7 @@ import com.google.cloud.bigtable.data.v2.models.RowMutation; import java.io.IOException; import java.util.List; +import org.threeten.bp.Duration; /** * The core client that converts method calls to RPCs. @@ -46,6 +51,18 @@ */ @InternalApi public class EnhancedBigtableStub implements AutoCloseable { + private static final RetrySettings DISABLED_RETRY_SETTINGS = + RetrySettings.newBuilder() + .setMaxAttempts(1) + .setTotalTimeout(Duration.ofHours(2)) + .setInitialRetryDelay(Duration.ZERO) + .setRetryDelayMultiplier(1) + .setMaxRetryDelay(Duration.ZERO) + .setInitialRpcTimeout(Duration.ofHours(2)) + .setRpcTimeoutMultiplier(1) + .setMaxRpcTimeout(Duration.ofHours(2)) + .build(); + private final EnhancedBigtableStubSettings settings; private final GrpcBigtableStub stub; private final ClientContext clientContext; @@ -64,6 +81,14 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) .setEndpoint(settings.getEndpoint()) .setCredentialsProvider(settings.getCredentialsProvider()); + // SampleRowKeys retries are handled in the overlay: disable retries in the base layer + baseSettingsBuilder + .sampleRowKeysSettings() + .setRetryableCodes(settings.sampleRowKeysSettings().getRetryableCodes()) + .setRetrySettings(DISABLED_RETRY_SETTINGS) + .setTimeoutCheckInterval(Duration.ZERO) + .setIdleTimeout(Duration.ZERO); + BigtableStubSettings baseSettings = baseSettingsBuilder.build(); ClientContext clientContext = ClientContext.create(baseSettings); GrpcBigtableStub stub = new GrpcBigtableStub(baseSettings, clientContext); @@ -109,12 +134,16 @@ public void call( * */ private UnaryCallable> createSampleRowKeysCallable() { - return new UnaryCallable>() { - @Override - public ApiFuture> futureCall(String request, ApiCallContext context) { - throw new UnsupportedOperationException("todo"); - } - }; + UnaryCallable> + spooling = stub.sampleRowKeysCallable().all(); + + UnaryCallable> retrying = + Callables.retrying(spooling, settings.sampleRowKeysSettings(), clientContext); + + UnaryCallable> withContext = + retrying.withDefaultCallContext(clientContext.getDefaultCallContext()); + + return new SampleRowKeysCallable(withContext, requestContext); } private UnaryCallable createMutateRowCallable() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java new file mode 100644 index 000000000000..36c71173d232 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -0,0 +1,81 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.data.v2.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.wrappers.KeyOffset; +import com.google.common.collect.ImmutableList; +import java.util.List; + +/** Simple wrapper for SampleRowKeys to wrap the request and response protobufs. */ +class SampleRowKeysCallable extends UnaryCallable> { + private final RequestContext requestContext; + private final UnaryCallable< + com.google.bigtable.v2.SampleRowKeysRequest, List> + inner; + + SampleRowKeysCallable( + UnaryCallable> inner, + RequestContext requestContext) { + + this.requestContext = requestContext; + this.inner = inner; + } + + @Override + public ApiFuture> futureCall(String tableId, ApiCallContext context) { + TableName tableName = + TableName.of( + requestContext.getInstanceName().getProject(), + requestContext.getInstanceName().getInstance(), + tableId); + + SampleRowKeysRequest request = + SampleRowKeysRequest.newBuilder() + .setTableName(tableName.toString()) + .setAppProfileId(requestContext.getAppProfileId()) + .build(); + + ApiFuture> rawResponse = inner.futureCall(request, context); + + return ApiFutures.transform( + rawResponse, + new ApiFunction, List>() { + @Override + public List apply(List responses) { + return convert(responses); + } + }); + } + + private List convert(List response) { + ImmutableList.Builder results = ImmutableList.builder(); + + for (SampleRowKeysResponse element : response) { + results.add(KeyOffset.create(element.getRowKey(), element.getOffsetBytes())); + } + + return results.build(); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java new file mode 100644 index 000000000000..e1cb7c13df89 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -0,0 +1,125 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.data.v2.stub; + +import com.google.api.core.ApiFuture; +import com.google.api.core.SettableApiFuture; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.NotFoundException; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.wrappers.KeyOffset; +import com.google.common.collect.ImmutableList; +import com.google.common.truth.Truth; +import com.google.protobuf.ByteString; +import io.grpc.Status.Code; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class SampleRowKeysCallableTest { + private RequestContext requestContext = + RequestContext.create(InstanceName.of("my-project", "my-instance"), "my-app-profile"); + private FakeCallable inner; + private SampleRowKeysCallable callable; + + @Before + public void setUp() { + inner = new FakeCallable(); + callable = new SampleRowKeysCallable(inner, requestContext); + } + + @Test + public void requestIsCorrect() { + callable.futureCall("my-table"); + + Truth.assertThat(inner.request) + .isEqualTo( + SampleRowKeysRequest.newBuilder() + .setTableName(requestContext.getInstanceName() + "/tables/my-table") + .setAppProfileId(requestContext.getAppProfileId()) + .build()); + } + + @Test + public void responseCorrectlyTransformed() + throws ExecutionException, InterruptedException, TimeoutException { + ApiFuture> result = callable.futureCall("my-table"); + + inner.response.set( + ImmutableList.of( + SampleRowKeysResponse.newBuilder() + .setRowKey(ByteString.copyFromUtf8("key1")) + .setOffsetBytes(100) + .build(), + SampleRowKeysResponse.newBuilder() + .setRowKey(ByteString.copyFromUtf8("")) + .setOffsetBytes(1000) + .build())); + + Truth.assertThat(result.get(1, TimeUnit.SECONDS)) + .isEqualTo( + ImmutableList.of( + KeyOffset.create(ByteString.copyFromUtf8("key1"), 100), + KeyOffset.create(ByteString.EMPTY, 1000))); + } + + @Test + public void errorIsPropagated() { + ApiFuture> result = callable.futureCall("my-table"); + + Throwable expectedError = + new NotFoundException("fake error", null, GrpcStatusCode.of(Code.NOT_FOUND), false); + inner.response.setException(expectedError); + + Throwable actualError = null; + try { + result.get(1, TimeUnit.SECONDS); + } catch (ExecutionException e) { + actualError = e.getCause(); + } catch (Throwable t) { + actualError = t; + } + + Truth.assertThat(actualError).isEqualTo(expectedError); + } + + static class FakeCallable + extends UnaryCallable> { + SampleRowKeysRequest request; + ApiCallContext callContext; + SettableApiFuture> response = SettableApiFuture.create(); + + @Override + public ApiFuture> futureCall( + SampleRowKeysRequest request, ApiCallContext context) { + this.request = request; + this.callContext = context; + + return response; + } + } +} From 98ed0e54f717dca483fb14685c23a5a6f0958c20 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:38:36 -0500 Subject: [PATCH 2/8] codacy fixes --- .../cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java | 5 ++--- .../cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java | 2 +- .../bigtable/data/v2/stub/SampleRowKeysCallableTest.java | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 415ea4c4e39f..ecce45fda6a4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.stub; -import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -134,8 +133,8 @@ public void call( * */ private UnaryCallable> createSampleRowKeysCallable() { - UnaryCallable> - spooling = stub.sampleRowKeysCallable().all(); + UnaryCallable> spooling = + stub.sampleRowKeysCallable().all(); UnaryCallable> retrying = Callables.retrying(spooling, settings.sampleRowKeysSettings(), clientContext); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java index 36c71173d232..2b8d42cec491 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -36,7 +36,7 @@ class SampleRowKeysCallable extends UnaryCallable> { inner; SampleRowKeysCallable( - UnaryCallable> inner, + UnaryCallable> inner, RequestContext requestContext) { this.requestContext = requestContext; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java index e1cb7c13df89..6492e8a8ec97 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -41,7 +41,7 @@ @RunWith(JUnit4.class) public class SampleRowKeysCallableTest { - private RequestContext requestContext = + private final RequestContext requestContext = RequestContext.create(InstanceName.of("my-project", "my-instance"), "my-app-profile"); private FakeCallable inner; private SampleRowKeysCallable callable; From 1d47bfd2083db181acef290dd2598b5c5d4b91bc Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:41:32 -0500 Subject: [PATCH 3/8] static import truth --- .../bigtable/data/v2/stub/SampleRowKeysCallableTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java index 6492e8a8ec97..84dce0568629 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -15,6 +15,8 @@ */ package com.google.cloud.bigtable.data.v2.stub; +import static com.google.common.truth.Truth.assertThat; + import com.google.api.core.ApiFuture; import com.google.api.core.SettableApiFuture; import com.google.api.gax.grpc.GrpcStatusCode; @@ -27,7 +29,6 @@ import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.wrappers.KeyOffset; import com.google.common.collect.ImmutableList; -import com.google.common.truth.Truth; import com.google.protobuf.ByteString; import io.grpc.Status.Code; import java.util.List; @@ -56,7 +57,7 @@ public void setUp() { public void requestIsCorrect() { callable.futureCall("my-table"); - Truth.assertThat(inner.request) + assertThat(inner.request) .isEqualTo( SampleRowKeysRequest.newBuilder() .setTableName(requestContext.getInstanceName() + "/tables/my-table") @@ -80,7 +81,7 @@ public void responseCorrectlyTransformed() .setOffsetBytes(1000) .build())); - Truth.assertThat(result.get(1, TimeUnit.SECONDS)) + assertThat(result.get(1, TimeUnit.SECONDS)) .isEqualTo( ImmutableList.of( KeyOffset.create(ByteString.copyFromUtf8("key1"), 100), @@ -104,7 +105,7 @@ public void errorIsPropagated() { actualError = t; } - Truth.assertThat(actualError).isEqualTo(expectedError); + assertThat(actualError).isEqualTo(expectedError); } static class FakeCallable From 3aa19513b91916e768b01a6293b4483b06a710ae Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:42:18 -0500 Subject: [PATCH 4/8] one more codacy fix --- .../cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java index 2b8d42cec491..c5111edecd77 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -31,8 +31,7 @@ /** Simple wrapper for SampleRowKeys to wrap the request and response protobufs. */ class SampleRowKeysCallable extends UnaryCallable> { private final RequestContext requestContext; - private final UnaryCallable< - com.google.bigtable.v2.SampleRowKeysRequest, List> + private final UnaryCallable> inner; SampleRowKeysCallable( From 6047a3a6ed6b7b4eb29c2ba772cfd23d62e66f22 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:51:18 -0500 Subject: [PATCH 5/8] improve disable retries code --- .../data/v2/stub/EnhancedBigtableStub.java | 22 +++++-------------- .../data/v2/stub/SampleRowKeysCallable.java | 3 +-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index ecce45fda6a4..6efed2591415 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -50,18 +50,6 @@ */ @InternalApi public class EnhancedBigtableStub implements AutoCloseable { - private static final RetrySettings DISABLED_RETRY_SETTINGS = - RetrySettings.newBuilder() - .setMaxAttempts(1) - .setTotalTimeout(Duration.ofHours(2)) - .setInitialRetryDelay(Duration.ZERO) - .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ZERO) - .setInitialRpcTimeout(Duration.ofHours(2)) - .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofHours(2)) - .build(); - private final EnhancedBigtableStubSettings settings; private final GrpcBigtableStub stub; private final ClientContext clientContext; @@ -80,13 +68,13 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) .setEndpoint(settings.getEndpoint()) .setCredentialsProvider(settings.getCredentialsProvider()); - // SampleRowKeys retries are handled in the overlay: disable retries in the base layer + // SampleRowKeys retries are handled in the overlay: disable retries in the base layer (but make + // sure to preserve the exception callable settings. baseSettingsBuilder .sampleRowKeysSettings() - .setRetryableCodes(settings.sampleRowKeysSettings().getRetryableCodes()) - .setRetrySettings(DISABLED_RETRY_SETTINGS) - .setTimeoutCheckInterval(Duration.ZERO) - .setIdleTimeout(Duration.ZERO); + .setSimpleTimeoutNoRetries( + baseSettingsBuilder.sampleRowKeysSettings().getRetrySettings().getTotalTimeout()) + .setRetryableCodes(settings.sampleRowKeysSettings().getRetryableCodes()); BigtableStubSettings baseSettings = baseSettingsBuilder.build(); ClientContext clientContext = ClientContext.create(baseSettings); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java index c5111edecd77..64f75b27060e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -31,8 +31,7 @@ /** Simple wrapper for SampleRowKeys to wrap the request and response protobufs. */ class SampleRowKeysCallable extends UnaryCallable> { private final RequestContext requestContext; - private final UnaryCallable> - inner; + private final UnaryCallable> inner; SampleRowKeysCallable( UnaryCallable> inner, From 7199a84acca6c997584ed5c8fbd3481320d54926 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 15 Feb 2018 16:51:50 -0500 Subject: [PATCH 6/8] fix imports --- .../cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 6efed2591415..590f783e0be5 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -16,7 +16,6 @@ package com.google.cloud.bigtable.data.v2.stub; import com.google.api.core.InternalApi; -import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.Callables; import com.google.api.gax.rpc.ClientContext; @@ -34,7 +33,6 @@ import com.google.cloud.bigtable.data.v2.models.RowMutation; import java.io.IOException; import java.util.List; -import org.threeten.bp.Duration; /** * The core client that converts method calls to RPCs. From df708539f1b2a75b45812cae09ec10235d38c3b5 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Fri, 16 Feb 2018 08:53:09 -0500 Subject: [PATCH 7/8] address feedback --- .../bigtable/data/v2/stub/EnhancedBigtableStub.java | 10 +++++----- .../bigtable/data/v2/stub/SampleRowKeysCallable.java | 8 ++++---- .../data/v2/stub/SampleRowKeysCallableTest.java | 8 ++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 590f783e0be5..cfe63b329299 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -71,7 +71,7 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) baseSettingsBuilder .sampleRowKeysSettings() .setSimpleTimeoutNoRetries( - baseSettingsBuilder.sampleRowKeysSettings().getRetrySettings().getTotalTimeout()) + settings.sampleRowKeysSettings().getRetrySettings().getTotalTimeout()) .setRetryableCodes(settings.sampleRowKeysSettings().getRetryableCodes()); BigtableStubSettings baseSettings = baseSettingsBuilder.build(); @@ -119,14 +119,14 @@ public void call( * */ private UnaryCallable> createSampleRowKeysCallable() { - UnaryCallable> spooling = + UnaryCallable> spoolable = stub.sampleRowKeysCallable().all(); - UnaryCallable> retrying = - Callables.retrying(spooling, settings.sampleRowKeysSettings(), clientContext); + UnaryCallable> retryable = + Callables.retrying(spoolable, settings.sampleRowKeysSettings(), clientContext); UnaryCallable> withContext = - retrying.withDefaultCallContext(clientContext.getDefaultCallContext()); + retryable.withDefaultCallContext(clientContext.getDefaultCallContext()); return new SampleRowKeysCallable(withContext, requestContext); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java index 64f75b27060e..4ad0e22a05a7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -61,16 +61,16 @@ public ApiFuture> futureCall(String tableId, ApiCallContext cont rawResponse, new ApiFunction, List>() { @Override - public List apply(List responses) { - return convert(responses); + public List apply(List rawResponse) { + return convert(rawResponse); } }); } - private List convert(List response) { + private static List convert(List rawResponse) { ImmutableList.Builder results = ImmutableList.builder(); - for (SampleRowKeysResponse element : response) { + for (SampleRowKeysResponse element : rawResponse) { results.add(KeyOffset.create(element.getRowKey(), element.getOffsetBytes())); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java index 84dce0568629..ea80ffa55bed 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -66,8 +65,7 @@ public void requestIsCorrect() { } @Test - public void responseCorrectlyTransformed() - throws ExecutionException, InterruptedException, TimeoutException { + public void responseCorrectlyTransformed() throws Exception { ApiFuture> result = callable.futureCall("my-table"); inner.response.set( @@ -89,7 +87,7 @@ public void responseCorrectlyTransformed() } @Test - public void errorIsPropagated() { + public void errorIsPropagated() throws Exception { ApiFuture> result = callable.futureCall("my-table"); Throwable expectedError = @@ -101,8 +99,6 @@ public void errorIsPropagated() { result.get(1, TimeUnit.SECONDS); } catch (ExecutionException e) { actualError = e.getCause(); - } catch (Throwable t) { - actualError = t; } assertThat(actualError).isEqualTo(expectedError); From c5b06fb0feb97e4818e9c628cb9b959141d6fe0b Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Wed, 21 Feb 2018 18:20:18 -0500 Subject: [PATCH 8/8] rename wrappers package --- .../cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java | 1 + .../cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java | 2 +- .../cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index cfe63b329299..68db38e24fcf 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -15,6 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.stub; +import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.Callables; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java index 4ad0e22a05a7..b3442668c115 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java @@ -24,7 +24,7 @@ import com.google.bigtable.v2.SampleRowKeysResponse; import com.google.bigtable.v2.TableName; import com.google.cloud.bigtable.data.v2.internal.RequestContext; -import com.google.cloud.bigtable.data.v2.wrappers.KeyOffset; +import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.common.collect.ImmutableList; import java.util.List; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java index ea80ffa55bed..aa0ec3debbd3 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -27,7 +27,7 @@ import com.google.bigtable.v2.SampleRowKeysRequest; import com.google.bigtable.v2.SampleRowKeysResponse; import com.google.cloud.bigtable.data.v2.internal.RequestContext; -import com.google.cloud.bigtable.data.v2.wrappers.KeyOffset; +import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.common.collect.ImmutableList; import com.google.protobuf.ByteString; import io.grpc.Status.Code;