diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index 47bdf1931a..8ce5eeecd8 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -427,7 +427,7 @@ -XDcompilePolicy=simple --should-stop=ifError=FLOW - -Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode -Xep:MissingSummary:OFF -Xep:InlineMeSuggester:OFF -Xep:AutoValueImmutableFields:OFF -Xep:ObjectEqualsForPrimitives:OFF + -Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode -Xep:MissingSummary:OFF -Xep:InlineMeSuggester:OFF -Xep:AutoValueImmutableFields:OFF -Xep:ObjectEqualsForPrimitives:OFF -Xep:JavaDurationGetSecondsToToSeconds:OFF -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index b936d72e90..3cd7fef840 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -1042,6 +1042,7 @@ public ApiFuture dropAllRowsAsync(String tableId) { * @throws com.google.api.gax.retrying.PollException when polling exceeds the total timeout */ @ObsoleteApi("Use getBaseClient() to access the auto-generated proto-based methods instead.") + @Deprecated public void awaitReplication(String tableId) { // TODO(igorbernstein2): remove usage of typesafe names com.google.bigtable.admin.v2.TableName tableName = @@ -1667,6 +1668,7 @@ public Backup apply(com.google.bigtable.admin.v2.Backup backupProto) { */ @SuppressWarnings("WeakerAccess") @ObsoleteApi("Use getBaseClient() to access the auto-generated proto-based methods instead.") + @Deprecated public ApiFuture awaitReplicationAsync(final String tableId) { // TODO(igorbernstein2): remove usage of typesafe names com.google.bigtable.admin.v2.TableName tableName = diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/SubsetView.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/SubsetView.java index 6ace603e46..dc0e599286 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/SubsetView.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/SubsetView.java @@ -105,6 +105,7 @@ public com.google.bigtable.admin.v2.AuthorizedView.SubsetView toProto() { } @Override + @SuppressWarnings("EqualsGetClass") public boolean equals(Object o) { if (this == o) { return true; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Type.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Type.java index c3fa2c6bf9..0505aa90b3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Type.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Type.java @@ -52,8 +52,9 @@ static Type fromProto(com.google.bigtable.admin.v2.Type source) { return Aggregate.fromProto(source.getAggregateType()); case KIND_NOT_SET: return Raw.create(); + default: + throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); } /** The raw type denotes the absence of a type. */ @@ -204,8 +205,9 @@ static Encoding fromProto(com.google.bigtable.admin.v2.Type.Int64.Encoding sourc return BigEndianBytes.create(); case ENCODING_NOT_SET: return BigEndianBytes.create(); + default: + throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); } @AutoValue diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index 395a77cdb3..b4e42e2354 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -21,9 +21,10 @@ import com.google.api.core.ApiFutures; import com.google.api.gax.retrying.ExponentialPollAlgorithm; import com.google.api.gax.retrying.NonCancellableFuture; -import com.google.api.gax.retrying.ResultRetryAlgorithm; +import com.google.api.gax.retrying.ResultRetryAlgorithmWithContext; import com.google.api.gax.retrying.RetryAlgorithm; import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.retrying.RetryingContext; import com.google.api.gax.retrying.RetryingExecutor; import com.google.api.gax.retrying.RetryingFuture; import com.google.api.gax.retrying.ScheduledRetryingExecutor; @@ -149,7 +150,7 @@ private static class AttemptCallable implements Callable externalFuture; - private volatile ApiCallContext callContext; + private final ApiCallContext callContext; AttemptCallable( UnaryCallable callable, RequestT request, ApiCallContext callContext) { @@ -186,7 +187,8 @@ public ResponseT call() { * handle this. */ private static class PollResultAlgorithm - implements ResultRetryAlgorithm { + implements ResultRetryAlgorithmWithContext { + @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, @@ -195,6 +197,22 @@ public TimedAttemptSettings createNextAttempt( return null; } + @Override + public TimedAttemptSettings createNextAttempt( + RetryingContext context, + Throwable previousThrowable, + CheckConsistencyResponse previousResponse, + TimedAttemptSettings previousSettings) { + return null; + } + + @Override + public boolean shouldRetry( + RetryingContext context, Throwable previousThrowable, CheckConsistencyResponse prevResponse) + throws CancellationException { + return prevResponse != null && !prevResponse.getConsistent(); + } + @Override public boolean shouldRetry(Throwable prevThrowable, CheckConsistencyResponse prevResponse) throws CancellationException { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index 2cb8549f5d..53b3be73e6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -28,7 +28,9 @@ *

This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a * token then poll until isConsistent is true. */ -/** @deprecated Please use {@link AwaitConsistencyCallable instead. */ +/** + * @deprecated Please use {@link AwaitConsistencyCallable} instead. + */ @Deprecated class AwaitReplicationCallable extends UnaryCallable { private final AwaitConsistencyCallable awaitConsistencyCallable; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 4373c041fe..e68cafca54 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -56,7 +56,7 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { private final TableAdminRequestContext requestContext; - private final AwaitReplicationCallable awaitReplicationCallable; + @Deprecated private final AwaitReplicationCallable awaitReplicationCallable; private final AwaitConsistencyCallable awaitConsistencyCallable; private final OperationCallable @@ -85,6 +85,7 @@ private EnhancedBigtableTableAdminStub( createOptimizeRestoredTableOperationBaseCallable(); } + @Deprecated private AwaitReplicationCallable createAwaitReplicationCallable() { return AwaitReplicationCallable.create(awaitConsistencyCallable); } @@ -207,6 +208,7 @@ public Empty apply(OperationSnapshot input) { unusedInitialCallSettings, operationCallSettings, clientContext, getOperationsStub()); } + @Deprecated public UnaryCallable awaitReplicationCallable() { return awaitReplicationCallable; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java index c3118825a8..8d283af11b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java @@ -306,6 +306,7 @@ public SqlType getType(java.lang.String fieldName) { } @Override + @SuppressWarnings("EqualsGetClass") public boolean equals(Object obj) { if (this == obj) { return true; @@ -457,12 +458,12 @@ public Code getCode() { } @Override - public java.lang.String toString() { + public final java.lang.String toString() { return getCode().name() + "{enum=" + getEnumName() + "}"; } @Override - public boolean equals(Object o) { + public final boolean equals(Object o) { if (this == o) { return true; } @@ -486,7 +487,7 @@ public boolean equals(Object o) { } @Override - public int hashCode() { + public final int hashCode() { T thisEnum = getForNumber().apply(0); if (thisEnum == null) { return getForNumber().hashCode(); @@ -561,6 +562,7 @@ public static SchemalessEnum create( return new AutoValue_Type_SchemalessEnum(enumName, schemaBundleId); } + @Override public abstract java.lang.String getEnumName(); public abstract java.lang.String schemaBundleId(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java index 208e059d23..85529de8d9 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java @@ -2697,8 +2697,8 @@ public void readChangeStreamAsync( * Executes a SQL Query and returns a ResultSet to iterate over the results. The returned * ResultSet instance is not threadsafe, it can only be used from single thread. * - *

The {@link BoundStatement} must be built from a {@link PreparedStatement} created using - * the same instance and app profile. + *

The {@link BoundStatement} must be built from a {@link PreparedStatement} created using the + * same instance and app profile. * *

Sample code: * @@ -2719,9 +2719,11 @@ public void readChangeStreamAsync( * } catch (RuntimeException e) { * e.printStackTrace(); * } + * } * } * - * @see {@link PreparedStatement} & {@link BoundStatement} for query options. + * @see PreparedStatement for query options. + * @see BoundStatement for query options. */ public ResultSet executeQuery(BoundStatement boundStatement) { boundStatement.assertUsingSameStub(stub); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java index 4329e98f63..535c9d9993 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java @@ -119,65 +119,65 @@ public static Builder newBuilderForEmulator(int port) { * port number. */ public static Builder newBuilderForEmulator(String hostname, int port) { - Builder builder = new Builder(); - - builder - .stubSettings() - .setCredentialsProvider(NoCredentialsProvider.create()) - .setEndpoint(hostname + ":" + port) - // disable channel refreshing when creating an emulator - .setRefreshingChannel(false) - .setMetricsProvider(NoopMetricsProvider.INSTANCE) // disable exporting metrics for emulator - .disableInternalMetrics() - .setTransportChannelProvider( - InstantiatingGrpcChannelProvider.newBuilder() - .setMaxInboundMessageSize(256 * 1024 * 1024) - .setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)) - .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) - .setKeepAliveTimeDuration( - java.time.Duration.ofSeconds(61)) // sends ping in this interval - .setKeepAliveTimeoutDuration( - java.time.Duration.ofSeconds( - 10)) // wait this long before considering the connection dead - .build()); + BigtableDataSettings.Builder builder = new BigtableDataSettings.Builder(); + + // TODO: remove the suppression once setRefreshingChannel is no longer necessary + @SuppressWarnings({"deprecation", "VariableUnused"}) + EnhancedBigtableStubSettings.Builder ignored = + builder + .stubSettings() + .setCredentialsProvider(NoCredentialsProvider.create()) + .setEndpoint(hostname + ":" + port) + // disable channel refreshing when creating an emulator + .setRefreshingChannel(false) + .setMetricsProvider( + NoopMetricsProvider.INSTANCE) // disable exporting metrics for emulator + .disableInternalMetrics() + .setTransportChannelProvider( + InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(256 * 1024 * 1024) + .setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)) + .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) + .setKeepAliveTimeDuration( + java.time.Duration.ofSeconds(61)) // sends ping in this interval + .setKeepAliveTimeoutDuration( + java.time.Duration.ofSeconds( + 10)) // wait this long before considering the connection dead + .build()); LOGGER.info("Connecting to the Bigtable emulator at " + hostname + ":" + port); return builder; } /** - * @deprecated OpenCensus support is deprecated and will be removed in a future version - * Enables OpenCensus metric aggregations. - * - *

This will register Bigtable client relevant {@link io.opencensus.stats.View}s. When coupled - * with an exporter, it allows users to monitor client behavior. - * - *

Please note that in addition to calling this method, the application must: - *

    - *
  • Include openensus-impl dependency on the classpath - *
  • Configure an exporter like opencensus-exporter-stats-stackdriver - *
- * - *

Example usage for maven: - *

{@code
-   *   
-   *     io.opencensus
-   *     opencensus-impl
-   *     ${opencensus.version}
-   *     runtime
-   *   
-   *
-   *   
-   *     io.opencensus
-   *     opencensus-exporter-stats-stackdriver
-   *     ${opencensus.version}
-   *   
-   * 
+ * @deprecated OpenCensus support is deprecated and will be removed in a future version Enables + * OpenCensus metric aggregations. + *

This will register Bigtable client relevant {@link io.opencensus.stats.View}s. When + * coupled with an exporter, it allows users to monitor client behavior. + *

Please note that in addition to calling this method, the application must: + *

    + *
  • Include openensus-impl dependency on the classpath + *
  • Configure an exporter like opencensus-exporter-stats-stackdriver + *
+ *

Example usage for maven: + *

{@code
+   * 
+   *   io.opencensus
+   *   opencensus-impl
+   *   ${opencensus.version}
+   *   runtime
+   * 
    *
-   * Java:
-   * 
{@code
-   *   StackdriverStatsExporter.createAndRegister();
-   *   BigtableDataSettings.enableOpenCensusStats();
+   * 
+   *   io.opencensus
+   *   opencensus-exporter-stats-stackdriver
+   *   ${opencensus.version}
+   * 
+   * }
+ * Java: + *
{@code
+   * StackdriverStatsExporter.createAndRegister();
+   * BigtableDataSettings.enableOpenCensusStats();
    * }
*/ @Deprecated diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java index b7ce1bb828..166da1b553 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java @@ -41,8 +41,10 @@ public abstract class AbstractProtoStructReader implements StructReader { abstract List values(); // Force subclasses to override equals and hashcode. We need this for tests. + @Override public abstract boolean equals(Object other); + @Override public abstract int hashCode(); /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImpl.java index 2e5c0d44cd..ea0de5bf8f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImpl.java @@ -20,7 +20,6 @@ import com.google.api.core.InternalApi; import com.google.auto.value.AutoValue; import com.google.cloud.bigtable.data.v2.models.sql.BoundStatement; -import com.google.cloud.bigtable.data.v2.models.sql.BoundStatement.Builder; import com.google.cloud.bigtable.data.v2.models.sql.PreparedStatement; import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub; @@ -76,7 +75,7 @@ public static PreparedStatement create( @Override public BoundStatement.Builder bind() { - return new Builder(this, paramTypes); + return new BoundStatement.Builder(this, paramTypes); } /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java index a838b4fb51..00cebcf462 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java @@ -33,7 +33,7 @@ */ @InternalApi public final class RegexUtil { - private static final byte[] NULL_BYTES = "\\x00".getBytes(); + private static final byte[] NULL_BYTES = {0}; private RegexUtil() {} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java index 921d0329ad..b430cb8119 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java @@ -37,6 +37,7 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nullable; class MetricsTracer extends BigtableTracer { @@ -55,17 +56,15 @@ class MetricsTracer extends BigtableTracer { private final AtomicBoolean opFinished = new AtomicBoolean(); private final Stopwatch operationTimer = Stopwatch.createStarted(); private final Stopwatch firstResponsePerOpTimer = Stopwatch.createStarted(); - private long operationResponseCount = 0; // Attempt level metrics private int attemptCount = 0; private Stopwatch attemptTimer; - private long attemptResponseCount = 0; private volatile int attempt = 0; private volatile boolean reportBatchingLatency = false; - private volatile long batchThrottledLatency = 0; + private final AtomicLong batchThrottledLatency = new AtomicLong(0); private MetadataExtractorInterceptor.SidebandData sidebandData; MetricsTracer( @@ -145,7 +144,6 @@ public void attemptStarted(int attemptNumber) { attempt = attemptNumber; attemptCount++; attemptTimer = Stopwatch.createStarted(); - attemptResponseCount = 0; } @Override @@ -200,11 +198,11 @@ private void recordAttemptCompletion(@Nullable Throwable throwable) { } if (reportBatchingLatency) { - measures.put(RpcMeasureConstants.BIGTABLE_BATCH_THROTTLED_TIME, batchThrottledLatency); + measures.put(RpcMeasureConstants.BIGTABLE_BATCH_THROTTLED_TIME, batchThrottledLatency.get()); // Reset batch throttling latency for next attempt. This can't be done in attemptStarted // because batching flow control will add batching latency before the attempt has started. - batchThrottledLatency = 0; + batchThrottledLatency.set(0); } // Patch the throwable until it's fixed in gax. When an attempt failed, @@ -228,8 +226,6 @@ public void responseReceived() { if (firstResponsePerOpTimer.isRunning()) { firstResponsePerOpTimer.stop(); } - attemptResponseCount++; - operationResponseCount++; } @Override @@ -245,7 +241,7 @@ public void setSidebandData(MetadataExtractorInterceptor.SidebandData sidebandDa @Override public void batchRequestThrottled(long totalThrottledMs) { reportBatchingLatency = true; - batchThrottledLatency += totalThrottledMs; + batchThrottledLatency.addAndGet(totalThrottledMs); } private TagContextBuilder newTagCtxBuilder() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java index 51af4269ad..1db8b443ec 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java @@ -60,14 +60,6 @@ public class RpcViewConstants { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 100.0))); - private static final Aggregation AGGREGATION_WITH_POWERS_OF_2 = - Distribution.create( - BucketBoundaries.create( - ImmutableList.of( - 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, - 4096.0, 8192.0, 16384.0, 32768.0, 65536.0, 131072.0, 262144.0, 524288.0, - 1048576.0, 2097152.0))); - /** * {@link View} for Bigtable client roundtrip latency in milliseconds including all retry * attempts. diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BigtableTracerStreamingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BigtableTracerStreamingCallable.java index 562305798f..c45e608c0a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BigtableTracerStreamingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BigtableTracerStreamingCallable.java @@ -73,7 +73,8 @@ public void call( } } - private class BigtableTracerResponseObserver extends SafeResponseObserver { + private static class BigtableTracerResponseObserver + extends SafeResponseObserver { private final BigtableTracer tracer; private final ResponseObserver outerObserver; @@ -108,7 +109,7 @@ protected void onCompleteImpl() { } } - private class TracedStreamController implements StreamController { + private static class TracedStreamController implements StreamController { private final StreamController innerController; private final BigtableTracer tracer; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracer.java index d1d9fabc6e..d2fa015cf3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracer.java @@ -424,11 +424,6 @@ private void recordAttemptCompletion(@Nullable Throwable throwable) { } } - private static double convertToMs(long nanoSeconds) { - double toMs = 1e-6; - return nanoSeconds * toMs; - } - @Override public void setBatchWriteFlowControlTargetQps(double targetQps) { recorder.batchWriteFlowControlTargetQps.record(clientInfo, methodInfo, targetQps); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java index 2ff139081c..d722bcbe6e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java @@ -77,12 +77,11 @@ public Row createRowFromProto(com.google.bigtable.v2.Row row) { /** Internal implementation detail for {@link DefaultRowAdapter}. */ @InternalApi() - public class DefaultRowBuilder implements RowBuilder { + public static class DefaultRowBuilder implements RowBuilder { private ByteString currentKey; private TreeMap> cellsByFamily; private ImmutableList.Builder currentFamilyCells; private String previousFamily; - private int totalCellCount; private String family; private ByteString qualifier; @@ -134,7 +133,6 @@ public void finishCell() { RowCell rowCell = RowCell.create(family, qualifier, timestamp, labels, value); currentFamilyCells.add(rowCell); - totalCellCount++; } /** {@inheritDoc} */ @@ -143,7 +141,7 @@ public Row finishRow() { final ImmutableList sortedCells; // Optimization: If there are no cells, then just return the static empty list. - if (cellsByFamily.size() == 0) { + if (cellsByFamily.isEmpty()) { sortedCells = ImmutableList.of(); } else if (cellsByFamily.size() == 1) { // Optimization: If there is a single family, avoid copies and return that one list. @@ -170,7 +168,6 @@ public void reset() { cellsByFamily = new TreeMap<>(); currentFamilyCells = null; previousFamily = null; - totalCellCount = 0; family = null; qualifier = null; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java index 2f579e2bd2..f448f22ef1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java @@ -349,6 +349,7 @@ public static Query fromProto(@Nonnull ReadRowsRequest request) { return query; } + @Override public Query clone() { Query query = Query.create(targetId); query.builder = this.builder.clone(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Value.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Value.java index 80b8eedd4c..a7ea9f0c50 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Value.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Value.java @@ -127,7 +127,8 @@ public static Value fromProto(com.google.bigtable.v2.Value source) { return RawValue.create(source.getRawValue()); case RAW_TIMESTAMP_MICROS: return RawTimestamp.create(source.getRawTimestampMicros()); + default: + throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java index 50ce7f340d..1307349c92 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java @@ -102,11 +102,13 @@ interface Field extends ColumnMetadata { /** * @return the name of the field. Returns an empty string for fields without names. */ + @Override String name(); /** * @return the {@link SqlType} of the field */ + @Override SqlType type(); } @@ -160,6 +162,7 @@ interface Proto extends SqlType { * @param Java type of the protobuf enum */ @BetaApi("This feature is currently experimental and can change in the future") + @SuppressWarnings("JavaLangClash") interface Enum extends SqlType { /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java index 3b2a169910..e770e04ccb 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java @@ -111,6 +111,7 @@ private void sendPrimeRequestsBlocking(ManagedChannel managedChannel) { } } + @Override public ApiFuture sendPrimeRequestsAsync(ManagedChannel managedChannel) { ClientCall clientCall = managedChannel.newCall( diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index 2828d67f43..47bb9ccff9 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -151,7 +151,7 @@ public static BigtableClientContext create( ChannelPrimer channelPrimer = NoOpChannelPrimer.create(); // Inject channel priming if enabled - if (builder.isRefreshingChannel()) { + if (isRefreshingEnabled(builder)) { channelPrimer = BigtableChannelPrimer.create( builder.getProjectId(), @@ -182,6 +182,11 @@ public static BigtableClientContext create( } } + @SuppressWarnings("deprecation") + private static boolean isRefreshingEnabled(EnhancedBigtableStubSettings.Builder b) { + return b.isRefreshingChannel(); + } + private static void configureGrpcOtel( InstantiatingGrpcChannelProvider.Builder transportProvider, Metrics metrics) { @SuppressWarnings("rawtypes") diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStreamResumptionStrategy.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStreamResumptionStrategy.java index d10a10a24f..8eb907d673 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStreamResumptionStrategy.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStreamResumptionStrategy.java @@ -18,8 +18,8 @@ import com.google.api.core.InternalApi; import com.google.api.gax.retrying.StreamResumptionStrategy; -@InternalApi /** Expand StreamResumptionStrategy to also process the error. */ +@InternalApi public abstract class BigtableStreamResumptionStrategy implements StreamResumptionStrategy { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ConvertExceptionCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ConvertExceptionCallable.java index 31109abb03..ca99ebd02b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ConvertExceptionCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ConvertExceptionCallable.java @@ -22,6 +22,7 @@ import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.StreamController; import com.google.common.base.Throwables; +import java.util.Locale; /** * This callable converts the "Received rst stream" exception into a retryable {@link ApiException}. @@ -43,7 +44,7 @@ public void call( innerCallable.call(request, observer, context); } - private class ConvertExceptionResponseObserver + private static class ConvertExceptionResponseObserver extends SafeResponseObserver { private final ResponseObserver outerObserver; @@ -74,7 +75,7 @@ protected void onCompleteImpl() { } } - private Throwable convertException(Throwable t) { + private static Throwable convertException(Throwable t) { // Long lived connections sometimes are disconnected via an RST frame or a goaway. These errors // are transient and should be retried. if (isRstStreamError(t) || isGoAway(t) || isRetriableAuthError(t)) { @@ -83,7 +84,7 @@ private Throwable convertException(Throwable t) { return t; } - private boolean isRetriableAuthError(Throwable t) { + private static boolean isRetriableAuthError(Throwable t) { if (t instanceof InternalException && t.getMessage() != null) { String error = t.getMessage(); return error.contains("Authentication backend internal server error. Please retry"); @@ -91,15 +92,15 @@ private boolean isRetriableAuthError(Throwable t) { return false; } - private boolean isRstStreamError(Throwable t) { + private static boolean isRstStreamError(Throwable t) { if (t instanceof InternalException && t.getMessage() != null) { - String error = t.getMessage().toLowerCase(); + String error = t.getMessage().toLowerCase(Locale.ENGLISH); return error.contains("rst_stream") || error.contains("rst stream"); } return false; } - private boolean isGoAway(Throwable t) { + private static boolean isGoAway(Throwable t) { if (t instanceof InternalException) { Throwable rootCause = Throwables.getRootCause(t); String rootCauseMessage = rootCause.getMessage(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStats.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStats.java index 01fabe52cb..ad659d4623 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStats.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStats.java @@ -69,7 +69,7 @@ boolean setLastAdjustedTimestampMs(long last, long now) { return lastAdjustedTimestampMs.compareAndSet(last, now); } - private class DecayingAverage { + private static class DecayingAverage { private double decayConstant; private double mean; private double weightedCount; 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 0a20f04d64..44bcc00fb6 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 @@ -306,7 +306,7 @@ public UnaryCallable createReadRowCallable(RowAdapter .withRetrySettings(perOpSettings.readRowSettings.getRetrySettings()), clientContext.getTracerFactory(), getSpanName("ReadRow"), - /* allowNoResponses= */ true); + /* allowNoResponse= */ true); } private ServerStreamingCallable createReadRowsBaseCallable( @@ -524,7 +524,7 @@ private UnaryCallable> createBulkReadRowsCallable( * Simple wrapper around {@link #createSampleRowKeysCallableWithRequest()} to provide backwards * compatibility * - * @deprecated + * @deprecated Please use {@link #createSampleRowKeysCallableWithRequest()} */ @Deprecated private UnaryCallable> createSampleRowKeysCallable() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 1a416d51e4..db33e93fec 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -562,6 +562,7 @@ UnaryCallSettings pingAndWarmSettings() { } /** Returns a builder containing all the values of this settings class. */ + @Override public Builder toBuilder() { return new Builder(this); } @@ -936,6 +937,7 @@ public UnaryCallSettings.Builder prepareQu } @SuppressWarnings("unchecked") + @Override public EnhancedBigtableStubSettings build() { Preconditions.checkState(projectId != null, "Project id must be set"); Preconditions.checkState(instanceId != null, "Instance id must be set"); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java index 7d21a5f498..d38f164fc6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java @@ -196,6 +196,7 @@ private static ResponseParams extractResponseParams(Metadata metadata) { try { return ResponseParams.parseFrom(responseParams); } catch (InvalidProtocolBufferException e) { + // Fail silently and return null } } return null; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java index 4f4f788aac..121a581101 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java @@ -107,6 +107,7 @@ static class ConditionalRateLimiter { private final AtomicReference nextRateUpdateTime = new AtomicReference<>(Instant.now()); + @SuppressWarnings("LongDoubleConversion") public ConditionalRateLimiter(long defaultQps) { limiter = RateLimiter.create(defaultQps); logger.info( diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java index 4e1cb4463f..976992a255 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java @@ -17,7 +17,7 @@ import com.google.bigtable.v2.Mutation; import com.google.bigtable.v2.ReadChangeStreamResponse; -import com.google.bigtable.v2.ReadChangeStreamResponse.DataChange.Type; +import com.google.bigtable.v2.ReadChangeStreamResponse.DataChange; import com.google.cloud.bigtable.data.v2.models.ChangeStreamRecordAdapter.ChangeStreamRecordBuilder; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.cloud.bigtable.data.v2.models.Value; @@ -329,7 +329,7 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { validate( dataChange.getChunksCount() > 0, "AWAITING_NEW_STREAM_RECORD: First data change missing mods."); - if (dataChange.getType() == Type.GARBAGE_COLLECTION) { + if (dataChange.getType() == DataChange.Type.GARBAGE_COLLECTION) { validate( dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: GC mutation shouldn't have source cluster id."); @@ -339,7 +339,7 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { dataChange.getCommitTimestamp().getSeconds(), dataChange.getCommitTimestamp().getNanos()), dataChange.getTiebreaker()); - } else if (dataChange.getType() == Type.USER) { + } else if (dataChange.getType() == DataChange.Type.USER) { validate( !dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: User initiated data change missing source cluster" diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamResumptionStrategy.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamResumptionStrategy.java index fda608eda5..716e9eaf0c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamResumptionStrategy.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamResumptionStrategy.java @@ -18,7 +18,6 @@ import com.google.api.core.InternalApi; import com.google.api.gax.retrying.StreamResumptionStrategy; import com.google.bigtable.v2.ReadChangeStreamRequest; -import com.google.bigtable.v2.ReadChangeStreamRequest.Builder; import com.google.bigtable.v2.StreamContinuationToken; import com.google.bigtable.v2.StreamContinuationTokens; import com.google.cloud.bigtable.data.v2.models.ChangeStreamRecordAdapter; @@ -85,7 +84,7 @@ public ReadChangeStreamRequest getResumeRequest(ReadChangeStreamRequest original return originalRequest; } - Builder builder = originalRequest.toBuilder(); + ReadChangeStreamRequest.Builder builder = originalRequest.toBuilder(); // We need to clear the start_from and use the updated continuation_tokens // to resume the request. // The partition should always be the same as the one from the original request, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java index e8f7cc4987..4796ad48a0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java @@ -28,7 +28,6 @@ import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.v2.MutateRowsRequest; -import com.google.bigtable.v2.MutateRowsRequest.Builder; import com.google.bigtable.v2.MutateRowsResponse; import com.google.bigtable.v2.MutateRowsResponse.Entry; import com.google.cloud.bigtable.data.v2.models.MutateRowsException; @@ -39,7 +38,6 @@ import com.google.common.collect.Lists; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.MoreExecutors; -import com.google.rpc.Code; import java.util.List; import java.util.Set; import java.util.concurrent.Callable; @@ -93,7 +91,7 @@ class MutateRowsAttemptCallable implements Callable { private static final StatusCode LOCAL_UNKNOWN_STATUS = new StatusCode() { @Override - public Code getCode() { + public StatusCode.Code getCode() { return Code.UNKNOWN; } @@ -234,7 +232,7 @@ private void handleAttemptError(Throwable rpcError) { allFailures.addAll(permanentFailures); - Builder builder = lastRequest.toBuilder().clearEntries(); + MutateRowsRequest.Builder builder = lastRequest.toBuilder().clearEntries(); List newOriginalIndexes = Lists.newArrayList(); attemptSettings = retryAlgorithm.createNextAttempt(null, entryError, null, attemptSettings); @@ -273,7 +271,7 @@ private MutateRowsAttemptResult handleAttemptSuccess(List re List allFailures = Lists.newArrayList(permanentFailures); MutateRowsRequest lastRequest = currentRequest; - Builder builder = lastRequest.toBuilder().clearEntries(); + MutateRowsRequest.Builder builder = lastRequest.toBuilder().clearEntries(); List newOriginalIndexes = Lists.newArrayList(); boolean[] seenIndices = new boolean[currentRequest.getEntriesCount()]; @@ -281,7 +279,7 @@ private MutateRowsAttemptResult handleAttemptSuccess(List re for (Entry entry : response.getEntriesList()) { seenIndices[Ints.checkedCast(entry.getIndex())] = true; - if (entry.getStatus().getCode() == Code.OK_VALUE) { + if (entry.getStatus().getCode() == com.google.rpc.Code.OK_VALUE) { continue; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/LargeReadRowsResumptionStrategy.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/LargeReadRowsResumptionStrategy.java index 85c3171f2f..93b6b548dd 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/LargeReadRowsResumptionStrategy.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/LargeReadRowsResumptionStrategy.java @@ -19,7 +19,6 @@ import com.google.api.gax.retrying.StreamResumptionStrategy; import com.google.api.gax.rpc.ApiException; import com.google.bigtable.v2.ReadRowsRequest; -import com.google.bigtable.v2.ReadRowsRequest.Builder; import com.google.bigtable.v2.RowSet; import com.google.cloud.bigtable.data.v2.internal.RowSetUtil; import com.google.cloud.bigtable.data.v2.models.RowAdapter; @@ -88,6 +87,7 @@ public RowT processResponse(RowT response) { return response; } + @Override public Throwable processError(Throwable throwable) { ByteString rowKeyExtracted = extractLargeRowKey(throwable); if (rowKeyExtracted != null) { @@ -154,7 +154,7 @@ public ReadRowsRequest getResumeRequest(ReadRowsRequest originalRequest) { return ReadRowsRetryCompletedCallable.FULFILLED_REQUEST_MARKER; } - Builder builder = originalRequest.toBuilder().setRows(remaining); + ReadRowsRequest.Builder builder = originalRequest.toBuilder().setRows(remaining); if (originalRequest.getRowsLimit() > 0) { Preconditions.checkState( diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java index 68af76c34e..de5ef19cb1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java @@ -18,7 +18,6 @@ import com.google.api.core.InternalApi; import com.google.api.gax.retrying.StreamResumptionStrategy; import com.google.bigtable.v2.ReadRowsRequest; -import com.google.bigtable.v2.ReadRowsRequest.Builder; import com.google.bigtable.v2.RowSet; import com.google.cloud.bigtable.data.v2.internal.RowSetUtil; import com.google.cloud.bigtable.data.v2.models.RowAdapter; @@ -105,7 +104,7 @@ public ReadRowsRequest getResumeRequest(ReadRowsRequest originalRequest) { return ReadRowsRetryCompletedCallable.FULFILLED_REQUEST_MARKER; } - Builder builder = originalRequest.toBuilder().setRows(remaining); + ReadRowsRequest.Builder builder = originalRequest.toBuilder().setRows(remaining); if (originalRequest.getRowsLimit() > 0) { Preconditions.checkState( diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryCompletedCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryCompletedCallable.java index 6c698a51ca..c25eb4e015 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryCompletedCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryCompletedCallable.java @@ -48,6 +48,7 @@ public ReadRowsRetryCompletedCallable(ServerStreamingCallable responseObserver, ApiCallContext context) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/StateMachine.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/StateMachine.java index 64c1bcbe6f..9a6d1007a9 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/StateMachine.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/StateMachine.java @@ -106,7 +106,7 @@ final class StateMachine { * Initialize a new state machine that's ready for a new row. * * @param adapter The adapter that will build the final row. - * @param reversed + * @param reversed if the results will be streamed in reverse lexicographic order. */ StateMachine(RowBuilder adapter, boolean reversed) { this.adapter = adapter; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java index 6bbfba1398..188dc83ac0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java @@ -70,10 +70,8 @@ public class BigtableChannelPool extends ManagedChannel implements BigtableChann private final ChannelFactory channelFactory; private final ChannelPrimer channelPrimer; - private final ScheduledExecutorService executor; private final Object entryWriteLock = new Object(); @VisibleForTesting final AtomicReference> entries = new AtomicReference<>(); - private final ChannelPoolHealthChecker channelPoolHealthChecker; private final AtomicInteger indexTicker = new AtomicInteger(); private final String authority; private final Random rng = new Random(); @@ -108,9 +106,9 @@ public static BigtableChannelPool create( this.channelFactory = channelFactory; this.channelPrimer = channelPrimer; Clock systemClock = Clock.systemUTC(); - this.channelPoolHealthChecker = + ChannelPoolHealthChecker channelPoolHealthChecker = new ChannelPoolHealthChecker(entries::get, channelPrimer, executor, systemClock); - this.channelPoolHealthChecker.start(); + channelPoolHealthChecker.start(); ImmutableList.Builder initialListBuilder = ImmutableList.builder(); @@ -139,8 +137,6 @@ public static BigtableChannelPool create( "Unknown load balancing strategy %s", settings.getLoadBalancingStrategy())); } - this.executor = executor; - if (!settings.isStaticSize()) { this.resizeFuture = executor.scheduleAtFixedRate( diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java index 4ef21418ed..c88e0f056a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java @@ -23,6 +23,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import java.time.Duration; +import java.util.Locale; import java.util.logging.Logger; /** @@ -151,7 +152,7 @@ private static LoadBalancingStrategy loadBalancingStrategyFromEnv() { return DEFAULT_LOAD_BALANCING_STRATEGY; } try { - return LoadBalancingStrategy.valueOf(strategyString.trim().toUpperCase()); + return LoadBalancingStrategy.valueOf(strategyString.trim().toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new IllegalStateException( String.format("Invalid load-balancing strategy %s", strategyString)); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 3f69dd81ff..b75f145108 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -66,6 +66,7 @@ public boolean needsExecutor() { } @Override + @Deprecated public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService executor) { return withExecutor((Executor) executor); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/ChannelPoolHealthChecker.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/ChannelPoolHealthChecker.java index 5c5c689810..9634b778ae 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/ChannelPoolHealthChecker.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/ChannelPoolHealthChecker.java @@ -19,6 +19,7 @@ import com.google.auto.value.AutoValue; import com.google.bigtable.v2.PingAndWarmResponse; import com.google.cloud.bigtable.data.v2.stub.BigtableChannelPrimer; +import com.google.cloud.bigtable.data.v2.stub.NoOpChannelPrimer; import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool.Entry; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -99,6 +100,10 @@ public ChannelPoolHealthChecker( } void start() { + if (channelPrimer instanceof NoOpChannelPrimer) { + return; + } + if (!(channelPrimer instanceof BigtableChannelPrimer)) { logger.log( Level.WARNING, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/Callables.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/Callables.java index 3d696213a6..d25ec22a3a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/Callables.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/Callables.java @@ -74,7 +74,7 @@ public static ServerStreamingCallable innerCallable, retryingExecutor, settings.getResumptionStrategy()); } - public static + public static ServerStreamingCallable retryingForLargeRows( ServerStreamingCallable innerCallable, ServerStreamingCallSettings callSettings, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryingCallable.java index d78bf08322..d9cea20fce 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryingCallable.java @@ -36,15 +36,16 @@ public RetryingCallable( ApiCallContext callContextPrototype, UnaryCallable callable, RetryingExecutorWithContext executor) { - this.callContextPrototype = (ApiCallContext) Preconditions.checkNotNull(callContextPrototype); - this.callable = (UnaryCallable) Preconditions.checkNotNull(callable); - this.executor = (RetryingExecutorWithContext) Preconditions.checkNotNull(executor); + this.callContextPrototype = Preconditions.checkNotNull(callContextPrototype); + this.callable = Preconditions.checkNotNull(callable); + this.executor = Preconditions.checkNotNull(executor); } + @Override public RetryingFuture futureCall(RequestT request, ApiCallContext inputContext) { ApiCallContext context = this.callContextPrototype.nullToSelf(inputContext); AttemptCallable retryCallable = - new AttemptCallable(this.callable, request, context); + new AttemptCallable<>(this.callable, request, context); RetryingFuture retryingFuture = this.executor.createFuture(retryCallable, inputContext); retryCallable.setExternalFuture(retryingFuture); @@ -52,6 +53,7 @@ public RetryingFuture futureCall(RequestT request, ApiCallContext inp return retryingFuture; } + @Override public String toString() { return String.format("retrying(%s)", this.callable); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 4be773e8ef..8104ee146c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -635,6 +635,7 @@ public void testDropRowRange() { } @Test + @Deprecated public void testAwaitReplication() { // Setup Mockito.when(mockStub.awaitReplicationCallable()).thenReturn(mockAwaitReplicationCallable); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java index c6c34a01ec..0adc7462a7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java @@ -29,7 +29,6 @@ import com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest; import com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest; import com.google.cloud.bigtable.admin.v2.models.Instance; -import com.google.cloud.bigtable.admin.v2.models.Instance.Type; import com.google.cloud.bigtable.admin.v2.models.StaticClusterSize; import com.google.cloud.bigtable.admin.v2.models.StorageType; import com.google.cloud.bigtable.admin.v2.models.UpdateAppProfileRequest; @@ -258,7 +257,7 @@ public void appProfileTestDataBoost() { .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) .setDisplayName("Priority-Instance-Test") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); try { assertThat(client.exists(newInstanceId)).isTrue(); @@ -297,7 +296,7 @@ public void appProfileTestRowAffinity() { .addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD) .setDisplayName("Row-Affinity-Instance-Test") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); try { assertThat(client.exists(newInstanceId)).isTrue(); @@ -352,7 +351,7 @@ public void instanceAndClusterCreationDeletionTest() { .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 3, StorageType.SSD) .setDisplayName("Fresh-Instance-Name") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); try { assertThat(client.exists(newInstanceId)).isTrue(); @@ -426,7 +425,7 @@ public void createClusterWithAutoscalingTest() { .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.HDD) .setDisplayName("Multi-Cluster-Instance-Test") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); String clusterId = prefixGenerator.newPrefix(); CreateClusterRequest createClusterRequest = @@ -463,7 +462,7 @@ public void createClusterWithAutoscalingAndPartialUpdateTest() throws Exception .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) .setDisplayName("Multi-Cluster-Instance-Test") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); String clusterId = prefixGenerator.newPrefix(); CreateClusterRequest createClusterRequest = @@ -604,7 +603,7 @@ public void createClusterWithManualScalingTest() { .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) .setDisplayName("Multi-Cluster-Instance-Test") .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + .setType(Instance.Type.PRODUCTION)); String clusterId = prefixGenerator.newPrefix(); CreateClusterRequest createClusterRequest = diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index cfcc8d0b42..e88ccbb9b6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -224,9 +224,9 @@ public void dropRowRange() { } @Test - public void awaitReplication() { + public void awaitConsistency() { tableAdmin.createTable(CreateTableRequest.of(tableId)); - tableAdmin.awaitReplication(tableId); + tableAdmin.awaitConsistency(ConsistencyRequest.forReplication(tableId)); } /** diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index 0aad99b232..52e8956a0d 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -51,6 +51,7 @@ import org.threeten.bp.Duration; @RunWith(JUnit4.class) +@Deprecated public class AwaitConsistencyCallableTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/common/TypeTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/common/TypeTest.java index 3cb3488ae6..543a085008 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/common/TypeTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/common/TypeTest.java @@ -102,6 +102,7 @@ public void array_equals() { } @Test + @SuppressWarnings("TruthIncompatibleType") public void map_equals() { assertThat(Type.Map.create(Type.Bytes.create(), Type.String.create())) .isEqualTo(Type.Map.create(Type.Bytes.create(), Type.String.create())); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java index cfeaa6a69b..f5c9472b47 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java @@ -255,6 +255,8 @@ public void testCreateForInstanceWithAppProfileHasCorrectSettings() throws Excep @Test public void testCreateWithRefreshingChannel() throws Exception { int poolSize = 3; + // TODO: remove the suppression when setRefreshingChannel can be removed + @SuppressWarnings("deprecation") BigtableDataSettings.Builder builder = BigtableDataSettings.newBuilderForEmulator(server.getPort()) .setProjectId(DEFAULT_PROJECT_ID) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java index 9faffe7397..ec82f1c12c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java @@ -263,8 +263,10 @@ public void proxyReadChangeStreamCallableTest() { public void proxyReadRowAsyncTest() { Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); - bigtableDataClient.readRowAsync( - TableId.of("fake-table"), ByteString.copyFromUtf8("fake-row-key")); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + TableId.of("fake-table"), ByteString.copyFromUtf8("fake-row-key")); Mockito.verify(mockReadRowCallable) .futureCall(Query.create(TableId.of("fake-table")).rowKey("fake-row-key")); } @@ -273,9 +275,11 @@ public void proxyReadRowAsyncTest() { public void proxyReadRowOnAuthorizedViewAsyncTest() { Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); - bigtableDataClient.readRowAsync( - AuthorizedViewId.of("fake-table", "fake-authorized-view"), - ByteString.copyFromUtf8("fake-row-key")); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + AuthorizedViewId.of("fake-table", "fake-authorized-view"), + ByteString.copyFromUtf8("fake-row-key")); Mockito.verify(mockReadRowCallable) .futureCall( Query.create(AuthorizedViewId.of("fake-table", "fake-authorized-view")) @@ -286,7 +290,9 @@ public void proxyReadRowOnAuthorizedViewAsyncTest() { public void proxyReadRowStrAsyncTest() { Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); - bigtableDataClient.readRowAsync(TableId.of("fake-table"), "fake-row-key"); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync(TableId.of("fake-table"), "fake-row-key"); Mockito.verify(mockReadRowCallable) .futureCall(Query.create(TableId.of("fake-table")).rowKey("fake-row-key")); } @@ -295,8 +301,10 @@ public void proxyReadRowStrAsyncTest() { public void proxyReadRowOnAuthorizedViewStrAsyncTest() { Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); - bigtableDataClient.readRowAsync( - AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-row-key"); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-row-key"); Mockito.verify(mockReadRowCallable) .futureCall( Query.create(AuthorizedViewId.of("fake-table", "fake-authorized-view")) @@ -313,8 +321,11 @@ public void readRowFilterAsyncTest() { .chain() .filter(FILTERS.qualifier().regex("prefix.*")) .filter(FILTERS.limit().cellsPerRow(10)); - bigtableDataClient.readRowAsync( - TableId.of("fake-table"), ByteString.copyFromUtf8("fake-row-key"), filter); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + TableId.of("fake-table"), ByteString.copyFromUtf8("fake-row-key"), filter); Mockito.verify(mockReadRowCallable) .futureCall(Query.create(TableId.of("fake-table")).rowKey("fake-row-key").filter(filter)); @@ -330,10 +341,13 @@ public void readRowOnAuthorizedViewFilterAsyncTest() { .chain() .filter(FILTERS.qualifier().regex("prefix.*")) .filter(FILTERS.limit().cellsPerRow(10)); - bigtableDataClient.readRowAsync( - AuthorizedViewId.of("fake-table", "fake-authorized-view"), - ByteString.copyFromUtf8("fake-row-key"), - filter); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + AuthorizedViewId.of("fake-table", "fake-authorized-view"), + ByteString.copyFromUtf8("fake-row-key"), + filter); Mockito.verify(mockReadRowCallable) .futureCall( @@ -352,7 +366,10 @@ public void readRowFilterStrAsyncTest() { .chain() .filter(FILTERS.qualifier().regex("prefix.*")) .filter(FILTERS.limit().cellsPerRow(10)); - bigtableDataClient.readRowAsync(TableId.of("fake-table"), "fake-row-key", filter); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync(TableId.of("fake-table"), "fake-row-key", filter); Mockito.verify(mockReadRowCallable) .futureCall(Query.create(TableId.of("fake-table")).rowKey("fake-row-key").filter(filter)); @@ -368,8 +385,11 @@ public void readRowOnAuthorizedViewFilterStrAsyncTest() { .chain() .filter(FILTERS.qualifier().regex("prefix.*")) .filter(FILTERS.limit().cellsPerRow(10)); - bigtableDataClient.readRowAsync( - AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-row-key", filter); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.readRowAsync( + AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-row-key", filter); Mockito.verify(mockReadRowCallable) .futureCall( @@ -651,24 +671,30 @@ public void proxySampleRowKeysCallableTest() { .isSameInstanceAs(mockSampleRowKeysCallable); } - @SuppressWarnings("deprecation") @Test + @SuppressWarnings({"deprecation"}) public void proxySampleRowKeysTest() { Mockito.when(mockStub.sampleRowKeysCallableWithRequest()) .thenReturn(mockSampleRowKeysCallableWithRequest); - bigtableDataClient.sampleRowKeysAsync("fake-table"); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.sampleRowKeysAsync("fake-table"); + Mockito.verify(mockSampleRowKeysCallableWithRequest) .futureCall(SampleRowKeysRequest.create(TableId.of("fake-table"))); } @Test + @SuppressWarnings({"deprecation"}) public void proxySampleRowKeysOnAuthorizedViewTest() { Mockito.when(mockStub.sampleRowKeysCallableWithRequest()) .thenReturn(mockSampleRowKeysCallableWithRequest); - bigtableDataClient.sampleRowKeysAsync( - AuthorizedViewId.of("fake-table", "fake-authorized-view")); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + bigtableDataClient.sampleRowKeysAsync( + AuthorizedViewId.of("fake-table", "fake-authorized-view")); + Mockito.verify(mockSampleRowKeysCallableWithRequest) .futureCall( SampleRowKeysRequest.create(AuthorizedViewId.of("fake-table", "fake-authorized-view"))); @@ -712,6 +738,7 @@ public void proxyMutateRowCallableTest() { } @Test + @SuppressWarnings({"deprecation"}) public void proxyMutateRowTest() { Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable); @@ -719,7 +746,9 @@ public void proxyMutateRowTest() { RowMutation.create(TableId.of("fake-table"), "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); - bigtableDataClient.mutateRowAsync(request); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.mutateRowAsync(request); + Mockito.verify(mockMutateRowCallable).futureCall(request); } @@ -731,7 +760,9 @@ public void proxyMutateRowOnAuthorizedViewTest() { RowMutation.create(AuthorizedViewId.of("fake-table", "fake-authorized-view"), "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); - bigtableDataClient.mutateRowAsync(request); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.mutateRowAsync(request); + Mockito.verify(mockMutateRowCallable).futureCall(request); } @@ -777,7 +808,9 @@ public void proxyBulkMutatesRowTest() { "fake-key", Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); - bigtableDataClient.bulkMutateRowsAsync(request); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.bulkMutateRowsAsync(request); + Mockito.verify(mockBulkMutateRowsCallable).futureCall(request); } @@ -791,7 +824,9 @@ public void proxyBulkMutatesRowOnAuthorizedViewTest() { "fake-key", Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); - bigtableDataClient.bulkMutateRowsAsync(request); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.bulkMutateRowsAsync(request); + Mockito.verify(mockBulkMutateRowsCallable).futureCall(request); } @@ -967,7 +1002,9 @@ public void proxyCheckAndMutateRowTest() { ConditionalRowMutation mutation = ConditionalRowMutation.create(TableId.of("fake-table"), "fake-key") .then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); - bigtableDataClient.checkAndMutateRowAsync(mutation); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.checkAndMutateRowAsync(mutation); Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation); } @@ -980,7 +1017,9 @@ public void proxyCheckAndMutateRowOnAuthorizedViewTest() { ConditionalRowMutation.create( AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-key") .then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); - bigtableDataClient.checkAndMutateRowAsync(mutation); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.checkAndMutateRowAsync(mutation); Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation); } @@ -1013,6 +1052,7 @@ public void checkAndMutateRowOnAuthorizedViewTest() { ConditionalRowMutation.create( AuthorizedViewId.of("fake-table", "fake-authorized-view"), "fake-key") .then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); + bigtableDataClient.checkAndMutateRow(mutation); Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation); @@ -1025,7 +1065,10 @@ public void proxyReadModifyWriteRowTest() { ReadModifyWriteRow request = ReadModifyWriteRow.create(TableId.of("fake-table"), "some-key") .append("fake-family", "fake-qualifier", "suffix"); - bigtableDataClient.readModifyWriteRowAsync(request); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.readModifyWriteRowAsync(request); + Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request); } @@ -1037,7 +1080,10 @@ public void proxyReadModifyWriteRowOnAuthorizedViewTest() { ReadModifyWriteRow.create( AuthorizedViewId.of("fake-table", "fake-authorized-view"), "some-key") .append("fake-family", "fake-qualifier", "suffix"); - bigtableDataClient.readModifyWriteRowAsync(request); + + @SuppressWarnings("VariableUnused") + ApiFuture ignored = bigtableDataClient.readModifyWriteRowAsync(request); + Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataSettingsTest.java index 6b8d3f9c51..cb5ca95c5c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataSettingsTest.java @@ -27,6 +27,8 @@ public class BigtableDataSettingsTest { @Test public void testToString() { + // TODO: figure out how avoid using setRefreshingChannel + @SuppressWarnings("deprecation") BigtableDataSettings settings = BigtableDataSettings.newBuilder() .setProjectId("our-project-2-12") diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java index b34c0536bd..127a704784 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java @@ -1034,7 +1034,7 @@ public void getByIndex_worksWithDuplicateColumnName() { duplicatedValues.addAll(values); TestProtoStruct row = TestProtoStruct.create(metadata, duplicatedValues); - assertThat(expectedJavaValue).isEqualTo(getByIndex.apply(row, index)); + assertThat(getByIndex.apply(row, index)).isEqualTo(expectedJavaValue); } } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java index c0e2b7c3b9..44d80cec6b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java @@ -80,6 +80,7 @@ public class PreparedStatementImplTest { public void setUp() throws IOException { service = new TestBigtableSqlService(); serverRule.getServiceRegistry().addService(service); + BigtableDataSettings.Builder settings = BigtableDataSettings.newBuilder() .setProjectId(TestBigtableSqlService.DEFAULT_PROJECT_ID) @@ -91,8 +92,6 @@ public void setUp() throws IOException { .setTransportChannelProvider( FixedTransportChannelProvider.create( GrpcTransportChannel.create(serverRule.getChannel()))) - // Refreshing channel doesn't work with FixedTransportChannelProvider - .setRefreshingChannel(false) .build(); // Remove log noise from client side metrics settings.setMetricsProvider(NoopMetricsProvider.INSTANCE).disableInternalMetrics(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtilTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtilTest.java index 770d87cae9..26609216e6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtilTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtilTest.java @@ -21,6 +21,7 @@ import com.google.bigtable.v2.RowSet; import com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange; import com.google.common.base.Preconditions; +import com.google.common.base.Splitter; import com.google.protobuf.ByteString; import java.util.Arrays; import java.util.SortedSet; @@ -169,7 +170,7 @@ private static SortedSet splitPoints(String... s) { private static RowSet parse(String encodedRowSet) { RowSet.Builder builder = RowSet.newBuilder(); - for (String s : encodedRowSet.split(",")) { + for (String s : Splitter.on(",").split(encodedRowSet)) { if (s.contains("-")) { builder.addRowRanges(parseRange(s)); } else { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/SqlRowSubject.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/SqlRowSubject.java index 4e64c75cac..de88a9c8f4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/SqlRowSubject.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/SqlRowSubject.java @@ -24,11 +24,8 @@ /** Truth subject for {@link ProtoSqlRow}. Intended for ease-of-use in testing. */ public final class SqlRowSubject extends Subject { - private final @Nullable SqlRow actual; - private SqlRowSubject(FailureMetadata metadata, @Nullable SqlRow actual) { super(metadata, actual); - this.actual = actual; } public static Factory sqlRow() { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java index ad6ede7fad..8be676d6a8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java @@ -41,7 +41,6 @@ import com.google.protobuf.Empty; import com.google.protobuf.util.Timestamps; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.HistogramPointData; @@ -66,8 +65,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Answers; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -89,9 +86,6 @@ class BigtableCloudMonitoringExporter2Test { private Resource resource; private InstrumentationScopeInfo scope; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private MeterProvider meterProvider; - @BeforeEach public void setUp() { mockMetricServiceStub = new FakeMetricServiceStub(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java index f4e9abbc24..2e04d7c566 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java @@ -41,6 +41,7 @@ import com.google.monitoring.v3.CreateTimeSeriesRequest; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; +import com.google.protobuf.util.Timestamps; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; @@ -131,7 +132,10 @@ public void setUp() { } @After - public void tearDown() {} + public void tearDown() { + exporter.close(); + fakeMetricServiceClient.close(); + } @Test public void testExportingSumData() { @@ -184,9 +188,10 @@ public void testExportingSumData() { MetricLabels.CLIENT_UID.getKey(), taskId); assertThat(timeSeries.getPoints(0).getValue().getInt64Value()).isEqualTo(fakeValue); - assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos()) + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getStartTime())) .isEqualTo(startEpoch); - assertThat(timeSeries.getPoints(0).getInterval().getEndTime().getNanos()).isEqualTo(endEpoch); + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getEndTime())) + .isEqualTo(endEpoch); } @Test @@ -249,9 +254,10 @@ public void testExportingHistogramData() { taskId); Distribution distribution = timeSeries.getPoints(0).getValue().getDistributionValue(); assertThat(distribution.getCount()).isEqualTo(3); - assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos()) + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getStartTime())) .isEqualTo(startEpoch); - assertThat(timeSeries.getPoints(0).getInterval().getEndTime().getNanos()).isEqualTo(endEpoch); + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getEndTime())) + .isEqualTo(endEpoch); } @Test @@ -326,9 +332,10 @@ public void testExportingSumDataInBatches() { MetricLabels.CLIENT_UID.getKey(), taskId); assertThat(timeSeries.getPoints(0).getValue().getInt64Value()).isEqualTo(i); - assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos()) + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getStartTime())) .isEqualTo(startEpoch); - assertThat(timeSeries.getPoints(0).getInterval().getEndTime().getNanos()).isEqualTo(endEpoch); + assertThat(Timestamps.toNanos(timeSeries.getPoints(0).getInterval().getEndTime())) + .isEqualTo(endEpoch); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java index d69c48861b..0a19733b6c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java @@ -416,7 +416,7 @@ public void testMetricsWithErrorResponse() throws InterruptedException { assertThat(missingCount).isEqualTo(attempts); } - private class FakeService extends BigtableImplBase { + private static class FakeService extends BigtableImplBase { private final String defaultTableName = NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID.getTableId()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java index 2bccac71c4..4472c433f7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; +import com.google.api.core.ApiFuture; import com.google.api.gax.batching.Batcher; import com.google.api.gax.batching.BatcherImpl; import com.google.api.gax.batching.FlowController; @@ -41,7 +42,6 @@ import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext; import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub; import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider; -import com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews; import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableMap; @@ -80,6 +80,7 @@ import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) +@Deprecated public class MetricsTracerTest { private static final String PROJECT_ID = "fake-project"; private static final String INSTANCE_ID = "fake-instance"; @@ -110,12 +111,12 @@ public class MetricsTracerTest { private EnhancedBigtableStub stub; private BigtableDataSettings settings; - @SuppressWarnings("deprecation") @Before public void setUp() throws Exception { server = FakeServiceBuilder.create(mockService).start(); - RpcViews.registerBigtableClientViews(localStats.getViewManager()); + com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientViews( + localStats.getViewManager()); settings = BigtableDataSettings.newBuilderForEmulator(server.getPort()) @@ -192,10 +193,14 @@ public void testReadRowsOpCount() throws InterruptedException { .when(mockService) .readRows(any(ReadRowsRequest.class), any()); - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + @SuppressWarnings({"UnusedVariable", "MismatchedQueryAndUpdateOfCollection"}) ArrayList ignored = Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + @SuppressWarnings({ + "UnusedVariable", + "MismatchedQueryAndUpdateOfCollection", + "ModifiedButNotUsed" + }) ArrayList ignored2 = Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); @@ -213,6 +218,7 @@ public void testReadRowsOpCount() throws InterruptedException { } @Test + @SuppressWarnings("FutureReturnValueIgnored") public void testReadRowsFirstRow() throws InterruptedException { final long beforeSleep = 50; final long afterSleep = 50; @@ -392,7 +398,7 @@ public void testBatchReadRowsThrottledTime() throws Exception { try (Batcher batcher = stub.newBulkReadRowsBatcher(Query.create(TABLE_ID), GrpcCallContext.createDefault())) { - batcher.add(ByteString.copyFromUtf8("row1")); + ApiFuture ignored = batcher.add(ByteString.copyFromUtf8("row1")); } long throttledTimeMetric = @@ -452,7 +458,7 @@ public void testBatchMutateRowsThrottledTime() throws Exception { flowController, defaultContext)) { - batcher.add(RowMutationEntry.create("key").deleteRow()); + ApiFuture ignored = batcher.add(RowMutationEntry.create("key").deleteRow()); } long throttledTimeMetric = @@ -466,9 +472,4 @@ public void testBatchMutateRowsThrottledTime() throws Exception { APP_PROFILE_ID); assertThat(throttledTimeMetric).isAtLeast(throttled); } - - @SuppressWarnings("unchecked") - private static StreamObserver anyObserver(Class returnType) { - return (StreamObserver) any(returnType); - } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java index 9e8da3513d..f64d6663c6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java @@ -136,7 +136,7 @@ public class BuiltinMetricsTracerTest { private static final String PROJECT_ID = "fake-project"; private static final String INSTANCE_ID = "fake-instance"; private static final String APP_PROFILE_ID = "default"; - private static final String TABLE = "fake-table"; + private static final TableId TABLE = TableId.of("fake-table"); private static final String BAD_TABLE_ID = "non-exist-table"; private static final String FIRST_RESPONSE_TABLE_ID = "first-response"; @@ -229,6 +229,8 @@ public void sendHeaders(Metadata headers) { server = FakeServiceBuilder.create(fakeService).intercept(trailersInterceptor).start(); + // TODO: remove the suppression once setRefreshingChannel can be removed + @SuppressWarnings("deprecation") BigtableDataSettings settings = BigtableDataSettings.newBuilderForEmulator(server.getPort()) .setProjectId(PROJECT_ID) @@ -304,13 +306,13 @@ public void tearDown() { @Test public void testReadRowsOperationLatencies() { Stopwatch stopwatch = Stopwatch.createStarted(); - Lists.newArrayList(stub.readRowsCallable().call(Query.create(TableId.of(TABLE))).iterator()); + Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE)).iterator()); long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); Attributes expectedAttributes = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -335,7 +337,7 @@ public void testReadRowsOperationLatenciesOnAuthorizedView() { Attributes expectedAttributes = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -396,12 +398,12 @@ public void onComplete() {} @Test public void testGfeMetrics() { - Lists.newArrayList(stub.readRowsCallable().call(Query.create(TableId.of(TABLE)))); + Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE))); Attributes expectedAttributes = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) @@ -419,7 +421,7 @@ public void testGfeMetrics() { Attributes expected1 = expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, "global") .put(TableSchema.CLUSTER_ID_KEY, "") .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -428,7 +430,7 @@ public void testGfeMetrics() { Attributes expected2 = expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -449,7 +451,7 @@ public void testReadRowsApplicationLatencyWithAutoFlowControl() throws Exception // For auto flow control, application latency is the time application spent in onResponse. stub.readRowsCallable() .call( - Query.create(TableId.of(TABLE)), + Query.create(TABLE), new ResponseObserver() { @Override public void onStart(StreamController streamController) {} @@ -483,7 +485,7 @@ public void onComplete() { Attributes expectedAttributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) @@ -508,7 +510,7 @@ public void onComplete() { public void testReadRowsApplicationLatencyWithManualFlowControl() throws Exception { int counter = 0; - Iterator rows = stub.readRowsCallable().call(Query.create(TableId.of(TABLE))).iterator(); + Iterator rows = stub.readRowsCallable().call(Query.create(TABLE)).iterator(); while (rows.hasNext()) { counter++; Thread.sleep(APPLICATION_LATENCY); @@ -520,7 +522,7 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti Attributes expectedAttributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) @@ -547,12 +549,12 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti @Test public void testRetryCount() throws InterruptedException { stub.mutateRowCallable() - .call(RowMutation.create(TableId.of(TABLE), "random-row").setCell("cf", "q", "value")); + .call(RowMutation.create(TABLE, "random-row").setCell("cf", "q", "value")); MetricData metricData = getMetricData(metricReader, TableRetryCount.NAME); Attributes expectedAttributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) @@ -567,7 +569,7 @@ public void testRetryCount() throws InterruptedException { @Test public void testMutateRowAttemptsTagValues() throws InterruptedException { stub.mutateRowCallable() - .call(RowMutation.create(TableId.of(TABLE), "random-row").setCell("cf", "q", "value")); + .call(RowMutation.create(TABLE, "random-row").setCell("cf", "q", "value")); outstandingRpcCounter.waitUntilRpcsDone(); MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME); @@ -575,7 +577,7 @@ public void testMutateRowAttemptsTagValues() throws InterruptedException { Attributes expected1 = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, "global") .put(TableSchema.CLUSTER_ID_KEY, "") .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow") @@ -586,7 +588,7 @@ public void testMutateRowAttemptsTagValues() throws InterruptedException { Attributes expected2 = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow") @@ -600,11 +602,11 @@ public void testMutateRowAttemptsTagValues() throws InterruptedException { @Test public void testMutateRowsPartialError() throws InterruptedException { - Batcher batcher = stub.newMutateRowsBatcher(TableId.of(TABLE), null); + Batcher batcher = stub.newMutateRowsBatcher(TABLE, null); int numMutations = 6; for (int i = 0; i < numMutations; i++) { String key = i % 2 == 0 ? "key" : "fail-key"; - batcher.add(RowMutationEntry.create(key).setCell("f", "q", "v")); + ApiFuture ignored = batcher.add(RowMutationEntry.create(key).setCell("f", "q", "v")); } assertThrows(BatchingException.class, batcher::close); @@ -614,7 +616,7 @@ public void testMutateRowsPartialError() throws InterruptedException { Attributes expected = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") @@ -632,7 +634,7 @@ public void testMutateRowsRpcError() { int numMutations = 6; for (int i = 0; i < numMutations; i++) { String key = i % 2 == 0 ? "key" : "fail-key"; - batcher.add(RowMutationEntry.create(key).setCell("f", "q", "v")); + ApiFuture ignored = batcher.add(RowMutationEntry.create(key).setCell("f", "q", "v")); } assertThrows(BatchingException.class, batcher::close); @@ -655,14 +657,14 @@ public void testMutateRowsRpcError() { @Test public void testReadRowsAttemptsTagValues() { - Lists.newArrayList(stub.readRowsCallable().call(Query.create(TableId.of(TABLE))).iterator()); + Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE)).iterator()); MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME); Attributes expected1 = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, "global") .put(TableSchema.CLUSTER_ID_KEY, "") .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -673,7 +675,7 @@ public void testReadRowsAttemptsTagValues() { Attributes expected2 = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -689,7 +691,8 @@ public void testReadRowsAttemptsTagValues() { public void testBatchBlockingLatencies() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { for (int i = 0; i < 6; i++) { - batcher.add(RowMutationEntry.create("key").setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add(RowMutationEntry.create("key").setCell("f", "q", "v")); } // closing the batcher to trigger the third flush @@ -701,7 +704,7 @@ public void testBatchBlockingLatencies() throws InterruptedException { Attributes expectedAttributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") @@ -719,8 +722,7 @@ public void testBatchBlockingLatencies() throws InterruptedException { @Test public void testQueuedOnChannelServerStreamLatencies() throws Exception { - ApiFuture> f = - stub.readRowsCallable().all().futureCall(Query.create(TableId.of(TABLE))); + ApiFuture> f = stub.readRowsCallable().all().futureCall(Query.create(TABLE)); Duration proxyDelayPriorTest = delayProxyDetector.getCurrentDelayUsed(); f.get(); @@ -728,7 +730,7 @@ public void testQueuedOnChannelServerStreamLatencies() throws Exception { Attributes attributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -746,7 +748,7 @@ public void testQueuedOnChannelServerStreamLatencies() throws Exception { public void testQueuedOnChannelUnaryLatencies() throws Exception { ApiFuture f = stub.mutateRowCallable() - .futureCall(RowMutation.create(TableId.of(TABLE), "a-key").setCell("f", "q", "v")); + .futureCall(RowMutation.create(TABLE, "a-key").setCell("f", "q", "v")); Duration proxyDelayPriorTest = delayProxyDetector.getCurrentDelayUsed(); f.get(); @@ -755,7 +757,7 @@ public void testQueuedOnChannelUnaryLatencies() throws Exception { Attributes attributes = expectedBaseAttributes.toBuilder() - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow") @@ -798,13 +800,13 @@ public void testPermanentFailure() { @Test public void testRemainingDeadline() { - stub.readRowsCallable().all().call(Query.create(TableId.of(TABLE))); + stub.readRowsCallable().all().call(Query.create(TABLE)); MetricData deadlineMetric = getMetricData(metricReader, TableRemainingDeadline.NAME); Attributes retryAttributes = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") .put(TableSchema.ZONE_ID_KEY, "global") .put(TableSchema.CLUSTER_ID_KEY, "") @@ -824,7 +826,7 @@ public void testRemainingDeadline() { Attributes okAttributes = expectedBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") - .put(TableSchema.TABLE_ID_KEY, TABLE) + .put(TableSchema.TABLE_ID_KEY, TABLE.getTableId()) .put(TableSchema.ZONE_ID_KEY, ZONE) .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") @@ -846,8 +848,10 @@ public void testRemainingDeadline() { @Test public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { - batcher.add( - RowMutationEntry.create("batch-write-flow-control-success-12").setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create("batch-write-flow-control-success-12") + .setCell("f", "q", "v")); // closing the batcher to trigger the flush batcher.close(); @@ -860,7 +864,7 @@ public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedExce .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); double expected_qps = 12; - assertThat(expected_qps).isEqualTo(actual_qps); + assertThat(actual_qps).isEqualTo(expected_qps); MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = @@ -872,15 +876,17 @@ public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedExce .build(); double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes); double expected_factor_mean = 1.2; - assertThat(expected_factor_mean).isEqualTo(actual_factor_mean); + assertThat(actual_factor_mean).isEqualTo(expected_factor_mean); } } @Test public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { - batcher.add( - RowMutationEntry.create("batch-write-flow-control-success-08").setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create("batch-write-flow-control-success-08") + .setCell("f", "q", "v")); // closing the batcher to trigger the flush batcher.close(); @@ -893,7 +899,7 @@ public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedExce .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); double expected_qps = 8.0; - assertThat(expected_qps).isEqualTo(actual_qps); + assertThat(actual_qps).isEqualTo(expected_qps); MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = @@ -904,15 +910,17 @@ public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedExce .build(); double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes); double expected_factor_mean = 0.8; - assertThat(expected_factor_mean).isEqualTo(actual_factor_mean); + assertThat(actual_factor_mean).isEqualTo(expected_factor_mean); } } @Test public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { - batcher.add( - RowMutationEntry.create("batch-write-flow-control-success-18").setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create("batch-write-flow-control-success-18") + .setCell("f", "q", "v")); // closing the batcher to trigger the flush batcher.close(); @@ -926,7 +934,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws Interru double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); // Factor is 1.8 but capped at 1.3 so updated QPS is 13. double expected_qps = 13; - assertThat(expected_qps).isEqualTo(actual_qps); + assertThat(actual_qps).isEqualTo(expected_qps); MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = @@ -938,15 +946,17 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws Interru double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes); // Factor is 1.8 but capped at 1.3 double expected_factor_mean = 1.3; - assertThat(expected_factor_mean).isEqualTo(actual_factor_mean); + assertThat(actual_factor_mean).isEqualTo(expected_factor_mean); } } @Test public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { - batcher.add( - RowMutationEntry.create("batch-write-flow-control-success-05").setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create("batch-write-flow-control-success-05") + .setCell("f", "q", "v")); // closing the batcher to trigger the flush batcher.close(); @@ -960,7 +970,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws Interru double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); // Factor is 0.5 but capped at 0.7 so updated QPS is 7. double expected_qps = 7; - assertThat(expected_qps).isEqualTo(actual_qps); + assertThat(actual_qps).isEqualTo(expected_qps); MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = @@ -972,16 +982,17 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws Interru double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes); // Factor is 0.5 but capped at 0.7 double expected_factor_mean = 0.7; - assertThat(expected_factor_mean).isEqualTo(actual_factor_mean); + assertThat(actual_factor_mean).isEqualTo(expected_factor_mean); } } @Test public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws InterruptedException { try (Batcher batcher = stub.newMutateRowsBatcher(TABLE, null)) { - batcher.add( - RowMutationEntry.create("batch-write-flow-control-fail-unavailable") - .setCell("f", "q", "v")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create("batch-write-flow-control-fail-unavailable") + .setCell("f", "q", "v")); // closing the batcher to trigger the flush batcher.close(); @@ -995,7 +1006,7 @@ public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws Interru double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); // On error, min factor is applied. double expected_qps = 7; - assertThat(expected_qps).isEqualTo(actual_qps); + assertThat(actual_qps).isEqualTo(expected_qps); MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = @@ -1007,7 +1018,7 @@ public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws Interru double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes); // On error, min factor is applied. double expected_factor_mean = 0.7; - assertThat(expected_factor_mean).isEqualTo(actual_factor_mean); + assertThat(actual_factor_mean).isEqualTo(expected_factor_mean); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/ChannelPoolMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/ChannelPoolMetricsTracerTest.java index fca44b08de..d265e76267 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/ChannelPoolMetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/ChannelPoolMetricsTracerTest.java @@ -171,7 +171,7 @@ public void testSingleRun() { // Arrange tracker.registerChannelInsightsProvider(mockInsightsProvider); tracker.registerLoadBalancingStrategy(LoadBalancingStrategy.LEAST_IN_FLIGHT); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); // Outstanding RPCs when(mockInsight1.getOutstandingUnaryRpcs()).thenReturn(5); @@ -229,7 +229,7 @@ public void testMultipleRuns() { // Arrange tracker.registerChannelInsightsProvider(mockInsightsProvider); tracker.registerLoadBalancingStrategy(LoadBalancingStrategy.ROUND_ROBIN); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); // First run when(mockInsight1.getOutstandingUnaryRpcs()).thenReturn(1); @@ -291,7 +291,7 @@ public void testMultipleRuns() { public void testErrorMetricsOnlyRecordedForAllChannels() { // Arrange tracker.registerChannelInsightsProvider(mockInsightsProvider); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); // Insight 1: Active (has successes) when(mockInsight1.getAndResetErrorCount()).thenReturn(0L); @@ -320,7 +320,7 @@ public void testErrorMetricsOnlyRecordedForAllChannels() { public void testDefaultLbPolicy() { // Arrange: Only register insights provider, not LB strategy tracker.registerChannelInsightsProvider(mockInsightsProvider); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); runTrackerTask(); Collection metrics = metricReader.collectAllMetrics(); @@ -337,7 +337,7 @@ public void testDefaultLbPolicy() { @Test public void testNoMetricsIfChannelInsightsProviderInactive() { - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); runTrackerTask(); assertThat(metricReader.collectAllMetrics()).isEmpty(); } @@ -346,7 +346,7 @@ public void testNoMetricsIfChannelInsightsProviderInactive() { public void testNoMetricsIfChannelInsightsEmpty() { tracker.registerChannelInsightsProvider(mockInsightsProvider); when(mockInsightsProvider.getChannelInfos()).thenReturn(ImmutableList.of()); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); runTrackerTask(); assertThat(metricReader.collectAllMetrics()).isEmpty(); } @@ -355,7 +355,7 @@ public void testNoMetricsIfChannelInsightsEmpty() { public void testNoMetricsIfChannelInsightsNull() { tracker.registerChannelInsightsProvider(mockInsightsProvider); when(mockInsightsProvider.getChannelInfos()).thenReturn(null); - tracker.start(mockScheduler); + ScheduledFuture ignored = tracker.start(mockScheduler); runTrackerTask(); assertThat(metricReader.collectAllMetrics()).isEmpty(); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java index 2aa7f69251..cb944a2aec 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java @@ -184,7 +184,7 @@ public void testBuiltinMetricsWithDefaultOTEL() throws Exception { clientDefault.mutateRow( RowMutation.create(TableId.of(tableDefault.getId()), "a-new-key") .setCell("cf", "q", "abc")); - ArrayList rows = + ArrayList ignored = Lists.newArrayList( clientDefault.readRows(Query.create(TableId.of(tableDefault.getId())).limit(10))); @@ -247,7 +247,7 @@ public void testBuiltinMetricsWithCustomOTEL() throws Exception { clientCustomOtel.mutateRow( RowMutation.create(TableId.of(tableCustomOtel.getId()), "a-new-key") .setCell("cf", "q", "abc")); - ArrayList rows = + ArrayList ignored = Lists.newArrayList( clientCustomOtel.readRows(Query.create(TableId.of(tableCustomOtel.getId())).limit(10))); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java index f54774b803..bd2e8e5352 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java @@ -22,6 +22,7 @@ import static com.google.common.truth.TruthJUnit.assume; import static org.junit.Assert.fail; +import com.google.api.core.ApiFuture; import com.google.api.gax.batching.Batcher; import com.google.api.gax.batching.BatcherImpl; import com.google.api.gax.batching.BatchingSettings; @@ -74,7 +75,8 @@ public void test() throws IOException, InterruptedException { long initial = batcher.getFlowController().getCurrentElementCountLimit(); for (long i = 0; i < initial * 3; i++) { String key = rowPrefix + "test-key" + i; - batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i)); + ApiFuture ignored = + batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i)); } batcher.flush(); assertThat(events.getLastFlowControlEvent()).isNotNull(); @@ -117,9 +119,10 @@ public void testOnAuthorizedView() throws IOException, InterruptedException { String familyId = testEnvRule.env().getFamilyId(); - batcher.add( - RowMutationEntry.create(rowPrefix + "test-key") - .setCell(familyId, AUTHORIZED_VIEW_COLUMN_QUALIFIER, "value")); + ApiFuture ignored = + batcher.add( + RowMutationEntry.create(rowPrefix + "test-key") + .setCell(familyId, AUTHORIZED_VIEW_COLUMN_QUALIFIER, "value")); batcher.flush(); // Query a key to make sure the write succeeded @@ -172,7 +175,7 @@ public void testManyMutations() throws IOException, InterruptedException { for (long j = 0; j < 50001; j++) { rowMutationEntry.setCell(familyId, "q" + j + i, j); } - batcher.add(rowMutationEntry); + ApiFuture ignored = batcher.add(rowMutationEntry); } batcher.flush(); // Query a key to make sure the write succeeded @@ -219,7 +222,7 @@ public void testManyMutationsOnAuthorizedView() throws IOException, InterruptedE for (long j = 0; j < 50001; j++) { rowMutationEntry.setCell(familyId, AUTHORIZED_VIEW_COLUMN_QUALIFIER + j + i, j); } - batcher.add(rowMutationEntry); + ApiFuture ignored = batcher.add(rowMutationEntry); } batcher.flush(); // Query a key to make sure the write succeeded @@ -242,7 +245,8 @@ public void testManyMutationsOnAuthorizedView() throws IOException, InterruptedE RowMutationEntry rowMutationEntry = RowMutationEntry.create(keyOutsideAuthorizedView); rowMutationEntry.setCell( testEnvRule.env().getFamilyId(), AUTHORIZED_VIEW_COLUMN_QUALIFIER, "test-value"); - batcherOutsideAuthorizedView.add(rowMutationEntry); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = batcherOutsideAuthorizedView.add(rowMutationEntry); batcherOutsideAuthorizedView.flush(); } fail("Should not be able to apply bulk mutation on rows outside authorized view"); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/DirectPathFallbackIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/DirectPathFallbackIT.java index f3cbb3ecae..9f1e2f7104 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/DirectPathFallbackIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/DirectPathFallbackIT.java @@ -36,6 +36,7 @@ import io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoopGroup; import io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel; import io.grpc.netty.shaded.io.netty.util.ReferenceCountUtil; +import io.grpc.netty.shaded.io.netty.util.concurrent.Future; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -132,7 +133,7 @@ public void teardown() { instrumentedClient.close(); } if (eventLoopGroup != null) { - eventLoopGroup.shutdownGracefully(); + Future ignored = eventLoopGroup.shutdownGracefully(); } } @@ -225,7 +226,8 @@ public void connect( super.connect(ctx, remoteAddress, localAddress, promise); } else { // Fail the connection fast - promise.setFailure(new IOException("fake error")); + @SuppressWarnings("UnusedVariable") + ChannelPromise ignored = promise.setFailure(new IOException("fake error")); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java index 79dc4786d2..51adc4abb6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java @@ -668,7 +668,10 @@ public void reversedWithForcedResumption() throws IOException, InterruptedExcept random.nextBytes(valueBytes); ByteString value = ByteString.copyFrom(valueBytes); - batcher.add(RowMutationEntry.create(key).setCell(familyId, qualifier, timestamp, value)); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = + batcher.add( + RowMutationEntry.create(key).setCell(familyId, qualifier, timestamp, value)); expectedResults.add( Row.create( key, diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/RowMutationEntryBatcherIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/RowMutationEntryBatcherIT.java index 90cd873f1e..c6ace17ade 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/RowMutationEntryBatcherIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/RowMutationEntryBatcherIT.java @@ -22,6 +22,7 @@ import static com.google.common.truth.TruthJUnit.assume; import static org.junit.Assert.fail; +import com.google.api.core.ApiFuture; import com.google.api.gax.batching.Batcher; import com.google.api.gax.rpc.ServerStream; import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; @@ -58,9 +59,11 @@ public void testNewBatcher() throws Exception { try (Batcher batcher = client.newBulkMutationBatcher(tableId)) { for (int i = 0; i < 10; i++) { - batcher.add( - RowMutationEntry.create(rowPrefix + "-" + i) - .setCell(family, "qualifier", 10_000L, "value-" + i)); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = + batcher.add( + RowMutationEntry.create(rowPrefix + "-" + i) + .setCell(family, "qualifier", 10_000L, "value-" + i)); } } @@ -99,9 +102,11 @@ public void testNewBatcherOnAuthorizedView() throws Exception { try (Batcher batcher = client.newBulkMutationBatcher(AuthorizedViewId.of(tableId, testAuthorizedView.getId()))) { for (int i = 0; i < 10; i++) { - batcher.add( - RowMutationEntry.create(rowPrefix + "-" + i) - .setCell(family, AUTHORIZED_VIEW_COLUMN_QUALIFIER, 10_000L, "value-" + i)); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = + batcher.add( + RowMutationEntry.create(rowPrefix + "-" + i) + .setCell(family, AUTHORIZED_VIEW_COLUMN_QUALIFIER, 10_000L, "value-" + i)); } } @@ -127,9 +132,11 @@ public void testNewBatcherOnAuthorizedView() throws Exception { try { try (Batcher batcher = client.newBulkMutationBatcher(AuthorizedViewId.of(tableId, testAuthorizedView.getId()))) { - batcher.add( - RowMutationEntry.create(rowKeyOutsideAuthorizedView) - .setCell(family, AUTHORIZED_VIEW_COLUMN_QUALIFIER, 10_000L, "value")); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = + batcher.add( + RowMutationEntry.create(rowKeyOutsideAuthorizedView) + .setCell(family, AUTHORIZED_VIEW_COLUMN_QUALIFIER, 10_000L, "value")); } fail("Should not be able to apply bulk mutation on rows outside authorized view"); } catch (Exception e) { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java index 5ef5f68888..09ab6e0851 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java @@ -145,6 +145,7 @@ public void testFailure() { @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") ArrayList ignored = Lists.newArrayList(client.readRows(query)); } catch (NotFoundException ignored) { + // dont care } Collection allMetricData = metricReader.collectAllMetrics(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/AuthorizedViewIdTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/AuthorizedViewIdTest.java index b20a99ec11..431125fb8c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/AuthorizedViewIdTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/AuthorizedViewIdTest.java @@ -45,7 +45,6 @@ public void testEquality() { assertThat(authorizedViewId).isEqualTo(AuthorizedViewId.of(TABLE_ID, AUTHORIZED_VIEW_ID)); assertThat(authorizedViewId) .isNotEqualTo(AuthorizedViewId.of(TABLE_ID, "another-authorized-view")); - assertThat(authorizedViewId).isNotEqualTo(TableId.of(TABLE_ID)); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java index 3c17ef052e..1f74d72b7c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java @@ -78,7 +78,7 @@ public void getTokenFromHeartbeatTest() { .setContinuationToken( StreamContinuationToken.newBuilder().setToken("heartbeat-token").build()) .build()); - Assert.assertEquals(adapter.getTokenFromHeartbeat(heartbeatRecord), "heartbeat-token"); + Assert.assertEquals("heartbeat-token", adapter.getTokenFromHeartbeat(heartbeatRecord)); } @Test @@ -118,8 +118,8 @@ public void getTokenFromChangeStreamMutationTest() { .setEstimatedLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); Assert.assertEquals( - adapter.getTokenFromChangeStreamMutation(changeStreamMutationRecord), - "change-stream-mutation-token"); + "change-stream-mutation-token", + adapter.getTokenFromChangeStreamMutation(changeStreamMutationRecord)); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/EntryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/EntryTest.java index 748df81af6..645859f5aa 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/EntryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/EntryTest.java @@ -67,7 +67,7 @@ public void serializationTest() throws IOException, ClassNotFoundException { public void deleteFamilyTest() { Entry deleteFamilyEntry = DeleteFamily.create("fake-family"); DeleteFamily deleteFamily = (DeleteFamily) deleteFamilyEntry; - assertThat("fake-family").isEqualTo(deleteFamily.getFamilyName()); + assertThat(deleteFamily.getFamilyName()).isEqualTo("fake-family"); } @Test @@ -78,10 +78,10 @@ public void deleteCellsTest() { ByteString.copyFromUtf8("fake-qualifier"), Range.TimestampRange.create(1000L, 2000L)); DeleteCells deleteCells = (DeleteCells) deleteCellEntry; - assertThat("fake-family").isEqualTo(deleteCells.getFamilyName()); - assertThat(ByteString.copyFromUtf8("fake-qualifier")).isEqualTo(deleteCells.getQualifier()); - assertThat(Range.TimestampRange.create(1000L, 2000L)) - .isEqualTo(deleteCells.getTimestampRange()); + assertThat(deleteCells.getFamilyName()).isEqualTo("fake-family"); + assertThat(deleteCells.getQualifier()).isEqualTo(ByteString.copyFromUtf8("fake-qualifier")); + assertThat(deleteCells.getTimestampRange()) + .isEqualTo(Range.TimestampRange.create(1000L, 2000L)); } @Test @@ -93,9 +93,9 @@ public void setSellTest() { 1000, ByteString.copyFromUtf8("fake-value")); SetCell setCell = (SetCell) setCellEntry; - assertThat("fake-family").isEqualTo(setCell.getFamilyName()); - assertThat(ByteString.copyFromUtf8("fake-qualifier")).isEqualTo(setCell.getQualifier()); - assertThat(1000).isEqualTo(setCell.getTimestamp()); - assertThat(ByteString.copyFromUtf8("fake-value")).isEqualTo(setCell.getValue()); + assertThat(setCell.getFamilyName()).isEqualTo("fake-family"); + assertThat(setCell.getQualifier()).isEqualTo(ByteString.copyFromUtf8("fake-qualifier")); + assertThat(setCell.getTimestamp()).isEqualTo(1000); + assertThat(setCell.getValue()).isEqualTo(ByteString.copyFromUtf8("fake-value")); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java index e5fcd133f5..b8311f592e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java @@ -714,7 +714,7 @@ private static void checkSpawnedFilters( private static void checkClassDeclaresSerialVersionUid(Class cls) { String uid = "serialVersionUID"; for (Field field : cls.getDeclaredFields()) { - if (field.getName() == uid) { + if (uid.equals(field.getName())) { int modifiers = field.getModifiers(); assertWithMessage(field + " is not static").that(Modifier.isStatic(modifiers)).isTrue(); assertWithMessage(field + " is not final").that(Modifier.isFinal(modifiers)).isTrue(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MaterializedViewIdTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MaterializedViewIdTest.java index 8978f8ff99..2f944c3ee0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MaterializedViewIdTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MaterializedViewIdTest.java @@ -44,7 +44,6 @@ public void testEquality() { assertThat(authorizedViewId).isEqualTo(MaterializedViewId.of(MATERIALIZED_VIEW_ID)); assertThat(authorizedViewId).isNotEqualTo(MaterializedViewId.of("another-materialized-view")); - assertThat(authorizedViewId).isNotEqualTo(TableId.of(TABLE_ID)); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java index 473e04d57a..b7c394eb15 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertThrows; import com.google.bigtable.v2.ReadRowsRequest; -import com.google.bigtable.v2.ReadRowsRequest.Builder; import com.google.bigtable.v2.RowFilter; import com.google.bigtable.v2.RowRange; import com.google.bigtable.v2.RowSet; @@ -113,7 +112,7 @@ public void rowRangeTest() { .range(ByteString.copyFromUtf8("byte-begin"), ByteString.copyFromUtf8("byte-end")) .range(ByteStringRange.create("range-begin", "range-end")); - Builder expectedProto = expectedReadFromTableProtoBuilder(); + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder(); expectedProto .getRowsBuilder() .addRowRanges( @@ -204,7 +203,7 @@ public void filterTest() { // Table query test. Query query = Query.create(TABLE_ID).filter(FILTERS.key().regex(".*")); - Builder expectedProto = + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder() .setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))); @@ -227,7 +226,7 @@ public void limitTest() { // Table query test. Query query = Query.create(TABLE_ID).limit(10); - Builder expectedProto = expectedReadFromTableProtoBuilder().setRowsLimit(10); + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder().setRowsLimit(10); ReadRowsRequest actualProto = query.toProto(requestContext); assertThat(actualProto).isEqualTo(expectedProto.build()); @@ -633,7 +632,7 @@ public void testQueryPaginatorRangeLimitReached() { Query nextQuery = paginator.getNextQuery(); - Builder expectedProto = + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder() .setRows( RowSet.newBuilder() @@ -707,7 +706,7 @@ public void testQueryPaginatorRangeLimitMultiplyOfChunkSize() { Query nextQuery = paginator.getNextQuery(); - Builder expectedProto = + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder() .setRows( RowSet.newBuilder() @@ -781,7 +780,7 @@ public void testQueryPaginatorRagneNoLimit() { Query nextQuery = paginator.getNextQuery(); - Builder expectedProto = + ReadRowsRequest.Builder expectedProto = expectedReadFromTableProtoBuilder() .setRows( RowSet.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java index 6f1061f8dc..6baea36099 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java @@ -315,6 +315,6 @@ public void byteStringRangeToByteStringTest() throws InvalidProtocolBufferExcept ByteString serialized = ByteStringRange.serializeToByteString(expected); ByteStringRange deserialized = ByteStringRange.toByteStringRange(serialized); - assertThat(expected).isEqualTo(deserialized); + assertThat(deserialized).isEqualTo(expected); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java index 2c1b2a2109..a8b9ab5022 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertThrows; import com.google.bigtable.v2.ReadChangeStreamRequest; -import com.google.bigtable.v2.ReadChangeStreamRequest.Builder; import com.google.bigtable.v2.RowRange; import com.google.bigtable.v2.StreamContinuationToken; import com.google.bigtable.v2.StreamContinuationTokens; @@ -71,7 +70,7 @@ public void streamPartitionTest() { ReadChangeStreamQuery query1 = ReadChangeStreamQuery.create(TABLE_ID).streamPartition("simple-begin", "simple-end"); ReadChangeStreamRequest actualProto1 = query1.toProto(requestContext); - Builder expectedProto1 = expectedProtoBuilder(); + ReadChangeStreamRequest.Builder expectedProto1 = expectedProtoBuilder(); expectedProto1.setPartition( StreamPartition.newBuilder() .setRowRange( @@ -88,7 +87,7 @@ public void streamPartitionTest() { .streamPartition( ByteString.copyFromUtf8("byte-begin"), ByteString.copyFromUtf8("byte-end")); ReadChangeStreamRequest actualProto2 = query2.toProto(requestContext); - Builder expectedProto2 = expectedProtoBuilder(); + ReadChangeStreamRequest.Builder expectedProto2 = expectedProtoBuilder(); expectedProto2.setPartition( StreamPartition.newBuilder() .setRowRange( @@ -104,7 +103,7 @@ public void streamPartitionTest() { ReadChangeStreamQuery.create(TABLE_ID) .streamPartition(ByteStringRange.create("range-begin", "range-end")); ReadChangeStreamRequest actualProto3 = query3.toProto(requestContext); - Builder expectedProto3 = expectedProtoBuilder(); + ReadChangeStreamRequest.Builder expectedProto3 = expectedProtoBuilder(); expectedProto3.setPartition( StreamPartition.newBuilder() .setRowRange( @@ -120,7 +119,7 @@ public void streamPartitionTest() { public void startTimeTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).startTime(FAKE_START_TIME); - Builder expectedProto = + ReadChangeStreamRequest.Builder expectedProto = expectedProtoBuilder() .setStartTime( Timestamp.newBuilder() @@ -135,7 +134,7 @@ public void startTimeTest() { public void endTimeTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).endTime(FAKE_END_TIME); - Builder expectedProto = + ReadChangeStreamRequest.Builder expectedProto = expectedProtoBuilder() .setEndTime( Timestamp.newBuilder() @@ -151,7 +150,7 @@ public void heartbeatDurationTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).heartbeatDuration(java.time.Duration.ofSeconds(5)); - Builder expectedProto = + ReadChangeStreamRequest.Builder expectedProto = expectedProtoBuilder().setHeartbeatDuration(Duration.newBuilder().setSeconds(5).build()); ReadChangeStreamRequest actualProto = query.toProto(requestContext); @@ -176,7 +175,7 @@ public void continuationTokensTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).continuationTokens(Collections.singletonList(token)); - Builder expectedProto = + ReadChangeStreamRequest.Builder expectedProto = expectedProtoBuilder() .setContinuationTokens( StreamContinuationTokens.newBuilder().addTokens(tokenProto).build()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/BoundStatementTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/BoundStatementTest.java index c089138286..71f46610a2 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/BoundStatementTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/BoundStatementTest.java @@ -827,9 +827,7 @@ public void builderValidatesTypesMatch() { IllegalArgumentException eLong = assertThrows(IllegalArgumentException.class, () -> builder.setLongParam("bytesParam", 1L)); assertThat(eLong.getMessage()).contains("Invalid type passed for query param"); - IllegalArgumentException eDouble = - assertThrows( - IllegalArgumentException.class, () -> builder.setDoubleParam("bytesParam", 1.1d)); + assertThrows(IllegalArgumentException.class, () -> builder.setDoubleParam("bytesParam", 1.1d)); assertThat(eLong.getMessage()).contains("Invalid type passed for query param"); IllegalArgumentException eFloat = assertThrows( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java index 73ecdb1cff..2b07044c9a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java @@ -82,7 +82,8 @@ public void testMultipleResponses() throws Exception { false); callable.logger = Mockito.mock(Logger.class); - ApiFuture f = callable.futureCall("fake"); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = callable.futureCall("fake"); MockServerStreamingCall call = inner.popLastCall(); call.getController().getObserver().onResponse("first"); call.getController().getObserver().onResponse("second"); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java index b4a7d0cc01..182fd68726 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java @@ -302,7 +302,7 @@ public void testSampleRowKeys() { @Test public void testReadChangeStream() { - for (ChangeStreamRecord record : + for (ChangeStreamRecord ignored : client.readChangeStream(ReadChangeStreamQuery.create("table"))) {} assertThat(fakeService.count.get()).isGreaterThan(1); @@ -462,7 +462,7 @@ public void testNoCookieSucceedSampleRowKeys() { public void testNoCookieSucceedReadChangeStream() { fakeService.returnCookie = false; - for (ChangeStreamRecord record : + for (ChangeStreamRecord ignored : client.readChangeStream(ReadChangeStreamQuery.create("table"))) {} assertThat(fakeService.count.get()).isGreaterThan(1); @@ -598,12 +598,17 @@ public void testAllMethodsAreCalled() { client.readModifyWriteRow(ReadModifyWriteRow.create(TABLE_ID, "key").append("cf", "q", "v")); fakeService.count.set(0); - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + @SuppressWarnings({ + "MismatchedQueryAndUpdateOfCollection", + "UnusedVariable", + "ModifiedButNotUsed" + }) ArrayList ignored2 = Lists.newArrayList(client.generateInitialChangeStreamPartitions("fake-table")); fakeService.count.set(0); - for (ChangeStreamRecord record : + for (@SuppressWarnings("UnusedVariable") + ChangeStreamRecord ignored1 : client.readChangeStream(ReadChangeStreamQuery.create("fake-table"))) {} fakeService.count.set(0); @@ -649,7 +654,11 @@ public void testCookieSetWithBigtableClientFactory() throws Exception { fakeService.count.set(0); serverMetadata.clear(); - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + @SuppressWarnings({ + "MismatchedQueryAndUpdateOfCollection", + "UnusedVariable", + "ModifiedButNotUsed" + }) ArrayList ignored2 = Lists.newArrayList(client2.readRows(Query.create(TABLE_ID))); assertThat(fakeService.count.get()).isGreaterThan(1); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlCallableTest.java index f9c1c89a51..5a493653a7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlCallableTest.java @@ -244,7 +244,9 @@ public void testDeadlineExceeded() throws Exception { // very high latency with deadline exceeded exception, limits should be decreased Map> extraHeaders = new HashMap<>(); extraHeaders.put(LATENCY_HEADER, Arrays.asList(String.valueOf(DEADLINE_EXCEEDED_LATENCY))); - callableToTest.futureCall(request, context.withExtraHeaders(extraHeaders)); + @SuppressWarnings("VariableUnused") + ApiFuture ignored = + callableToTest.futureCall(request, context.withExtraHeaders(extraHeaders)); assertThat(flowController.getCurrentElementCountLimit()) .isEqualTo( INITIAL_ELEMENT diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStatsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStatsTest.java index 2a407dda93..8863b4a1a9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStatsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/DynamicFlowControlStatsTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiClock; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -73,7 +73,7 @@ public void testUpdate() { public void testConcurrentUpdates() throws InterruptedException, ExecutionException { final DynamicFlowControlStats stats = new DynamicFlowControlStats(); ExecutorService executor = Executors.newCachedThreadPool(); - List> futures = new LinkedList<>(); + List> futures = new ArrayList<>(); for (int i = 1; i <= 50; i++) { final long latency = i; Runnable r = diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java index a718073b94..b974649a53 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java @@ -37,7 +37,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.atomic.AtomicInteger; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -54,7 +53,6 @@ public class EnhancedBigtableStubCloseRetryTest { private ExecutorService testExecutor; private BlockingQueue requests; - private AtomicInteger numRequests; private Server server; private EnhancedBigtableStub stub; @@ -63,7 +61,6 @@ public class EnhancedBigtableStubCloseRetryTest { public void setUp() throws Exception { testExecutor = Executors.newCachedThreadPool(); requests = new ArrayBlockingQueue<>(10); - numRequests = new AtomicInteger(); server = FakeServiceBuilder.create(new FakeBigtable()).start(); @@ -71,8 +68,7 @@ public void setUp() throws Exception { BigtableDataSettings.newBuilderForEmulator(server.getPort()) .setProjectId(PROJECT_ID) .setInstanceId(INSTANCE_ID) - .setCredentialsProvider(NoCredentialsProvider.create()) - .setRefreshingChannel(false); + .setCredentialsProvider(NoCredentialsProvider.create()); stub = EnhancedBigtableStub.create(settingBuilder.build().getStubSettings()); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java index e918378691..74d05e37fe 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java @@ -27,12 +27,14 @@ import com.google.cloud.bigtable.data.v2.FakeServiceBuilder; import com.google.cloud.bigtable.data.v2.models.Query; import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.TableId; import com.google.common.util.concurrent.SettableFuture; import io.grpc.Server; import io.grpc.stub.StreamObserver; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -81,19 +83,14 @@ public void tearDown() throws Exception { @Test public void outstandingRequestsFinishAfterClose() throws Exception { ApiFuture> resultFuture = - stub.readRowsCallable().all().futureCall(Query.create("table1")); + stub.readRowsCallable().all().futureCall(Query.create(TableId.of("table1"))); // Wait for the server to receive the request requestReceivedBarrier.get(1, MINUTES); // Close the client - must happen in a separate thread because close will block until all // requests have completed, which can't happen until the clientClosedBarrier is released. - testExecutor.submit( - new Runnable() { - @Override - public void run() { - stub.close(); - } - }); + @SuppressWarnings("UnusedVariable") + Future ignored = testExecutor.submit(() -> stub.close()); Thread.sleep(200); // give the closer a chance to run clientClosedBarrier.set(null); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java index 715c9fed12..bf16ab1c62 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java @@ -55,6 +55,7 @@ import org.threeten.bp.Duration; @RunWith(JUnit4.class) +@SuppressWarnings("deprecation") // TODO: remove this public class EnhancedBigtableStubSettingsTest { @Test public void instanceNameIsRequiredTest() { @@ -80,8 +81,6 @@ public void settingsAreNotLostTest() { CredentialsProvider credentialsProvider = Mockito.mock(CredentialsProvider.class); WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class); Duration watchdogInterval = Duration.ofSeconds(12); - boolean enableRoutingCookie = false; - boolean enableRetryInfo = false; String metricsEndpoint = "test-endpoint:443"; EnhancedBigtableStubSettings.Builder builder = @@ -106,8 +105,6 @@ public void settingsAreNotLostTest() { credentialsProvider, watchdogProvider, watchdogInterval, - enableRoutingCookie, - enableRetryInfo, metricsEndpoint); verifySettings( builder.build(), @@ -119,8 +116,6 @@ public void settingsAreNotLostTest() { credentialsProvider, watchdogProvider, watchdogInterval, - enableRoutingCookie, - enableRetryInfo, metricsEndpoint); verifyBuilder( builder.build().toBuilder(), @@ -132,8 +127,6 @@ public void settingsAreNotLostTest() { credentialsProvider, watchdogProvider, watchdogInterval, - enableRoutingCookie, - enableRetryInfo, metricsEndpoint); } @@ -147,8 +140,6 @@ private void verifyBuilder( CredentialsProvider credentialsProvider, WatchdogProvider watchdogProvider, Duration watchdogInterval, - boolean enableRoutingCookie, - boolean enableRetryInfo, String metricsEndpoint) { assertThat(builder.getProjectId()).isEqualTo(projectId); assertThat(builder.getInstanceId()).isEqualTo(instanceId); @@ -171,8 +162,6 @@ private void verifySettings( CredentialsProvider credentialsProvider, WatchdogProvider watchdogProvider, Duration watchdogInterval, - boolean enableRoutingCookie, - boolean enableRetryInfo, String metricsEndpoint) { assertThat(settings.getProjectId()).isEqualTo(projectId); assertThat(settings.getInstanceId()).isEqualTo(instanceId); @@ -198,7 +187,7 @@ public void multipleChannelsByDefaultTest() { InstantiatingGrpcChannelProvider provider = (InstantiatingGrpcChannelProvider) builder.getTransportChannelProvider(); - assertThat(provider.toBuilder().getPoolSize()).isGreaterThan(1); + assertThat(provider.getChannelPoolSettings().getInitialChannelCount()).isGreaterThan(1); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java index 5606451e50..a9eda04356 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java @@ -109,7 +109,6 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.Metadata; -import io.grpc.Metadata.Key; import io.grpc.MethodDescriptor; import io.grpc.Server; import io.grpc.ServerCall; @@ -234,7 +233,8 @@ public void testJwtAudience() // Send rpc and grab the credentials sent Metadata metadata = metadataInterceptor.headers.take(); - String authValue = metadata.get(Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)); + String authValue = + metadata.get(Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)); assertThat(authValue).isNotNull(); String expectedPrefix = "Bearer "; assertThat(authValue).startsWith(expectedPrefix); @@ -261,6 +261,8 @@ public void testBatchJwtAudience() ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build(); + // TODO: remove this suppression when setRefreshingChannel can be removed + @SuppressWarnings("deprecation") EnhancedBigtableStubSettings settings = EnhancedBigtableStubSettings.newBuilder() .setProjectId("fake-project") @@ -285,7 +287,8 @@ public void testBatchJwtAudience() } channel.shutdown(); - String authValue = metadata.get(Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)); + String authValue = + metadata.get(Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)); assertThat(authValue).isNotNull(); String expectedPrefix = "Bearer "; assertThat(authValue).startsWith(expectedPrefix); @@ -300,7 +303,7 @@ public void testFeatureFlags() throws InterruptedException, IOException, Executi Metadata metadata = metadataInterceptor.headers.take(); String encodedFeatureFlags = - metadata.get(Key.of("bigtable-features", Metadata.ASCII_STRING_MARSHALLER)); + metadata.get(Metadata.Key.of("bigtable-features", Metadata.ASCII_STRING_MARSHALLER)); assertThat(encodedFeatureFlags).isNotNull(); FeatureFlags featureFlags = FeatureFlags.parseFrom(BaseEncoding.base64Url().decode(encodedFeatureFlags)); @@ -310,8 +313,9 @@ public void testFeatureFlags() throws InterruptedException, IOException, Executi } @Test - public void testPingAndWarmFeatureFlags() - throws InterruptedException, IOException, ExecutionException { + public void testPingAndWarmFeatureFlags() throws InterruptedException, IOException { + // TODO: remove the suppression once setRefreshingChannel can be removed + @SuppressWarnings("deprecation") EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).build(); try (EnhancedBigtableStub ignored = EnhancedBigtableStub.create(settings)) { @@ -320,7 +324,7 @@ public void testPingAndWarmFeatureFlags() Metadata metadata = metadataInterceptor.headers.take(); String encodedFeatureFlags = - metadata.get(Key.of("bigtable-features", Metadata.ASCII_STRING_MARSHALLER)); + metadata.get(Metadata.Key.of("bigtable-features", Metadata.ASCII_STRING_MARSHALLER)); assertThat(encodedFeatureFlags).isNotNull(); FeatureFlags featureFlags = FeatureFlags.parseFrom(BaseEncoding.base64Url().decode(encodedFeatureFlags)); @@ -394,7 +398,7 @@ public void testMutateRowRequestParams() throws ExecutionException, InterruptedE // RequestParamsExtractor String reqParams = - reqMetadata.get(Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER)); + reqMetadata.get(Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER)); assertThat(reqParams).contains("table_name=" + TABLE_NAME.replace("/", "%2F")); assertThat(reqParams).contains(String.format("app_profile_id=%s", APP_PROFILE_ID)); @@ -466,7 +470,7 @@ public void testPrepareQueryRequestParams() throws ExecutionException, Interrupt // RequestParamsExtractor String reqParams = - reqMetadata.get(Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER)); + reqMetadata.get(Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER)); assertThat(reqParams).contains("name=" + INSTANCE_NAME.replace("/", "%2F")); assertThat(reqParams).contains(String.format("app_profile_id=%s", APP_PROFILE_ID)); @@ -542,6 +546,8 @@ public void testCreateReadRowsRawCallable() throws InterruptedException { @Test public void testChannelPrimerConfigured() throws IOException { + // TODO: remove the suppression once setRefreshingChannel can be removed + @SuppressWarnings("deprecation") EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).build(); @@ -653,9 +659,9 @@ public void testBulkMutationFlowControllerConfigured() throws Exception { // Creating 2 batchers from the same stub, they should share the same FlowController and // FlowControlEventStats try (BatcherImpl batcher1 = - (BatcherImpl) stub1.newMutateRowsBatcher("my-table1", null); + (BatcherImpl) stub1.newMutateRowsBatcher(TableId.of("my-table1"), null); BatcherImpl batcher2 = - (BatcherImpl) stub1.newMutateRowsBatcher("my-table2", null)) { + (BatcherImpl) stub1.newMutateRowsBatcher(TableId.of("my-table2"), null)) { assertThat(batcher1.getFlowController()).isNotNull(); assertThat(batcher1.getFlowController().getFlowControlEventStats()).isNotNull(); assertThat(batcher1).isNotSameInstanceAs(batcher2); @@ -680,9 +686,9 @@ public void testBulkMutationFlowControllerConfigured() throws Exception { // Creating 2 batchers from different stubs, they should not share the same FlowController and // FlowControlEventStats try (BatcherImpl batcher1 = - (BatcherImpl) stub1.newMutateRowsBatcher("my-table1", null); + (BatcherImpl) stub1.newMutateRowsBatcher(TableId.of("my-table1"), null); BatcherImpl batcher2 = - (BatcherImpl) stub2.newMutateRowsBatcher("my-table2", null)) { + (BatcherImpl) stub2.newMutateRowsBatcher(TableId.of("my-table2"), null)) { assertThat(batcher1.getFlowController()).isNotNull(); assertThat(batcher1.getFlowController().getFlowControlEventStats()).isNotNull(); assertThat(batcher1.getFlowController()).isNotSameInstanceAs(batcher2.getFlowController()); @@ -700,7 +706,7 @@ public void testBulkMutationFlowControllerConfigured() throws Exception { .getStubSettings()); ) { try (BatcherImpl batcher = - (BatcherImpl) stub2.newMutateRowsBatcher("my-table", null)) { + (BatcherImpl) stub2.newMutateRowsBatcher(TableId.of("my-table"), null)) { assertThat(batcher.getFlowController().getMaxElementCountLimit()).isEqualTo(100L); assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isEqualTo(100L); assertThat(batcher.getFlowController().getMinElementCountLimit()).isEqualTo(100L); @@ -711,8 +717,7 @@ public void testBulkMutationFlowControllerConfigured() throws Exception { @Test public void testCallContextPropagatedInMutationBatcher() throws IOException, InterruptedException, ExecutionException { - EnhancedBigtableStubSettings settings = - defaultSettings.toBuilder().setRefreshingChannel(true).build(); + EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().build(); try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) { // clear the previous contexts @@ -724,7 +729,7 @@ public void testCallContextPropagatedInMutationBatcher() // Send a batch try (Batcher batcher = - stub.newMutateRowsBatcher("table1", clientCtx)) { + stub.newMutateRowsBatcher(TableId.of("table1"), clientCtx)) { batcher.add(RowMutationEntry.create("key").deleteRow()).get(); } @@ -738,8 +743,7 @@ public void testCallContextPropagatedInMutationBatcher() @Test public void testCallContextPropagatedInReadBatcher() throws IOException, InterruptedException, ExecutionException { - EnhancedBigtableStubSettings settings = - defaultSettings.toBuilder().setRefreshingChannel(true).build(); + EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().build(); try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) { // clear the previous contexts @@ -843,10 +847,13 @@ public void testReadChangeStreamWaitTimeoutIsSet() throws Exception { @Test public void testBatchMutationsPartialFailure() { Batcher batcher = - enhancedBigtableStub.newMutateRowsBatcher("table1", GrpcCallContext.createDefault()); + enhancedBigtableStub.newMutateRowsBatcher( + TableId.of("table1"), GrpcCallContext.createDefault()); - batcher.add(RowMutationEntry.create("key0").deleteRow()); - batcher.add(RowMutationEntry.create("key1").deleteRow()); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = batcher.add(RowMutationEntry.create("key0").deleteRow()); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored1 = batcher.add(RowMutationEntry.create("key1").deleteRow()); Mockito.doAnswer( invocationOnMock -> { @@ -884,7 +891,7 @@ public void testBatchMutationsPartialFailure() { @Test public void testBatchMutationRPCErrorCode() { Batcher batcher = - enhancedBigtableStub.newMutateRowsBatcher("table1", GrpcCallContext.createDefault()); + enhancedBigtableStub.newMutateRowsBatcher(TABLE_ID, GrpcCallContext.createDefault()); Mockito.doAnswer( invocationOnMock -> { @@ -895,7 +902,8 @@ public void testBatchMutationRPCErrorCode() { .when(fakeDataService) .mutateRows(Mockito.any(MutateRowsRequest.class), Mockito.any()); - batcher.add(RowMutationEntry.create("key0").deleteRow()); + @SuppressWarnings("UnusedVariable") + ApiFuture ignored = batcher.add(RowMutationEntry.create("key0").deleteRow()); BatchingException batchingException = assertThrows(BatchingException.class, batcher::close); assertThat(batchingException.getMessage()) .contains( @@ -1081,6 +1089,7 @@ public void readRows( try { Thread.sleep(WATCHDOG_CHECK_DURATION.toMillis() * 2); } catch (Exception ignored) { + // dont care about interruption } } requests.add(request); @@ -1106,6 +1115,7 @@ public void readChangeStream( try { Thread.sleep(WATCHDOG_CHECK_DURATION.toMillis() * 2); } catch (Exception ignored) { + // dont care about interruption } } readChangeReadStreamRequests.add(request); @@ -1129,6 +1139,7 @@ public void executeQuery( try { Thread.sleep(WATCHDOG_CHECK_DURATION.toMillis() * 2); } catch (Exception ignored) { + // dont care about interruption } } executeQueryRequests.add(request); @@ -1143,6 +1154,7 @@ public void prepareQuery( try { Thread.sleep(WATCHDOG_CHECK_DURATION.toMillis() * 2); } catch (Exception ignored) { + // dont care about interruption } } prepareRequests.add(request); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java index 3bb7de6fd5..146cc1017f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java @@ -21,6 +21,7 @@ import static com.google.cloud.bigtable.data.v2.stub.sql.SqlProtoFactory.stringType; import static com.google.common.truth.Truth.assertThat; +import com.google.api.core.ApiFuture; import com.google.api.gax.batching.Batcher; import com.google.api.gax.rpc.FixedHeaderProvider; import com.google.api.gax.rpc.HeaderProvider; @@ -43,9 +44,11 @@ import com.google.cloud.bigtable.data.v2.BigtableDataSettings; import com.google.cloud.bigtable.data.v2.FakeServiceBuilder; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; +import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.cloud.bigtable.data.v2.models.Mutation; import com.google.cloud.bigtable.data.v2.models.Query; import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; +import com.google.cloud.bigtable.data.v2.models.Row; import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; import com.google.cloud.bigtable.data.v2.models.TableId; @@ -58,6 +61,7 @@ import io.grpc.ServerInterceptor; import io.grpc.stub.StreamObserver; import java.util.HashMap; +import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import org.junit.After; @@ -133,20 +137,22 @@ public void readRowsTest() { @Test public void sampleRowKeysTest() { - client.sampleRowKeysAsync(TABLE_ID); + @SuppressWarnings("UnusedVariable") + ApiFuture> ignored = client.sampleRowKeysAsync(TABLE_ID); verifyHeaderSent(); } @Test public void mutateRowTest() { - client.mutateRowAsync(RowMutation.create(TABLE_ID, "fake-key").deleteRow()); + ApiFuture ignored = + client.mutateRowAsync(RowMutation.create(TABLE_ID, "fake-key").deleteRow()); verifyHeaderSent(); } @Test public void mutateRowsTest() throws InterruptedException { try (Batcher batcher = client.newBulkMutationBatcher(TABLE_ID)) { - batcher.add(RowMutationEntry.create("fake-key").deleteRow()); + ApiFuture ignored = batcher.add(RowMutationEntry.create("fake-key").deleteRow()); } catch (RuntimeException e) { // Ignore the errors: none of the methods are actually implemented } @@ -155,15 +161,18 @@ public void mutateRowsTest() throws InterruptedException { @Test public void checkAndMutateRowTest() { - client.checkAndMutateRowAsync( - ConditionalRowMutation.create(TABLE_ID, "fake-key").then(Mutation.create().deleteRow())); + ApiFuture ignored = + client.checkAndMutateRowAsync( + ConditionalRowMutation.create(TABLE_ID, "fake-key") + .then(Mutation.create().deleteRow())); verifyHeaderSent(); } @Test public void readModifyWriteTest() { - client.readModifyWriteRowAsync( - ReadModifyWriteRow.create(TABLE_ID, "fake-key").increment("cf", "q", 1)); + ApiFuture ignored = + client.readModifyWriteRowAsync( + ReadModifyWriteRow.create(TABLE_ID, "fake-key").increment("cf", "q", 1)); verifyHeaderSent(); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RetryInfoTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RetryInfoTest.java index cf57f915b6..4903433a65 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RetryInfoTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RetryInfoTest.java @@ -397,34 +397,6 @@ private void verifyRetryInfoIsUsed(Runnable runnable, boolean retryableError) { assertThat(stopwatch.elapsed()).isAtLeast(Duration.ofSeconds(defaultDelay.getSeconds())); } - // Test the case where server returns retry info but client disabled handling of retry info - private void verifyRetryInfoCanBeDisabled(Runnable runnable) { - enqueueRetryableExceptionWithDelay(defaultDelay); - Stopwatch stopwatch = Stopwatch.createStarted(); - runnable.run(); - stopwatch.stop(); - - assertThat(attemptCounter.get()).isEqualTo(2); - assertThat(stopwatch.elapsed()).isLessThan(Duration.ofSeconds(defaultDelay.getSeconds())); - - attemptCounter.set(0); - ApiException expectedApiException = enqueueNonRetryableExceptionWithDelay(defaultDelay); - ApiException actualException = - assertThrows("non retryable operations should fail", ApiException.class, runnable::run); - if (actualException instanceof MutateRowsException) { - assertThat( - ((MutateRowsException) actualException) - .getFailedMutations() - .get(0) - .getError() - .getStatusCode()) - .isEqualTo(expectedApiException.getStatusCode()); - } else { - assertThat(actualException.getStatusCode()).isEqualTo(expectedApiException.getStatusCode()); - } - assertThat(attemptCounter.get()).isEqualTo(1); - } - // Test the case where server does not return retry info private void verifyNoRetryInfo(Runnable runnable, boolean operationRetryable) { verifyNoRetryInfo(runnable, operationRetryable, defaultDelay); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableWithRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableWithRequestTest.java index f974076ceb..8bd40a363b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableWithRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableWithRequestTest.java @@ -56,7 +56,8 @@ public void setUp() { @Test public void requestIsCorrect() { - callable.futureCall(SampleRowKeysRequest.create(TableId.of("my-table"))); + ApiFuture> ignored = + callable.futureCall(SampleRowKeysRequest.create(TableId.of("my-table"))); assertThat(inner.request) .isEqualTo( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java index 1bdd61ce1f..40f7e5b17a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java @@ -62,7 +62,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -172,7 +171,8 @@ private void test(Supplier> invoker, T fakeResponse) try { future.get(1, TimeUnit.MINUTES); } catch (TimeoutException e) { - Assert.fail("timed out waiting for the trailer optimization future to resolve"); + throw new AssertionError( + "timed out waiting for the trailer optimization future to resolve", e); } // The tracer will be notified in parallel to the future being resolved diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamMergingAcceptanceTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamMergingAcceptanceTest.java index 0465b87efe..ce278f50c8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamMergingAcceptanceTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamMergingAcceptanceTest.java @@ -24,7 +24,7 @@ import com.google.bigtable.v2.Mutation; import com.google.bigtable.v2.ReadChangeStreamRequest; import com.google.bigtable.v2.ReadChangeStreamResponse; -import com.google.bigtable.v2.ReadChangeStreamResponse.DataChange.Type; +import com.google.bigtable.v2.ReadChangeStreamResponse.DataChange; import com.google.bigtable.v2.RowRange; import com.google.bigtable.v2.StreamContinuationToken; import com.google.bigtable.v2.StreamPartition; @@ -49,6 +49,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -90,7 +91,7 @@ public static Collection data() throws IOException { .that(dataJson) .isNotNull(); - InputStreamReader reader = new InputStreamReader(dataJson); + InputStreamReader reader = new InputStreamReader(dataJson, StandardCharsets.UTF_8); ChangeStreamTestFile.Builder testBuilder = ChangeStreamTestFile.newBuilder(); JsonFormat.parser().merge(reader, testBuilder); ChangeStreamTestFile testDefinition = testBuilder.build(); @@ -195,12 +196,12 @@ public void test() throws Exception { ReadChangeStreamTest.TestChangeStreamMutation.Builder builder = ReadChangeStreamTest.TestChangeStreamMutation.newBuilder(); builder.setRowKey(changeStreamMutation.getRowKey()); - Type type = Type.UNRECOGNIZED; + DataChange.Type type = DataChange.Type.UNRECOGNIZED; if (changeStreamMutation.getType() == ChangeStreamMutation.MutationType.USER) { - type = Type.USER; + type = DataChange.Type.USER; } else if (changeStreamMutation.getType() == ChangeStreamMutation.MutationType.GARBAGE_COLLECTION) { - type = Type.GARBAGE_COLLECTION; + type = DataChange.Type.GARBAGE_COLLECTION; } builder.setType(type); if (changeStreamMutation.getSourceClusterId() != null) { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsErrorConverterUnaryCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsErrorConverterUnaryCallableTest.java index 1b6ba2ff1e..7f2de3e728 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsErrorConverterUnaryCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsErrorConverterUnaryCallableTest.java @@ -93,7 +93,7 @@ public void testPartialFailure() { MutateRowsException.class, () -> callable.call(BulkMutation.create(TABLE_ID))); assertThat(exception).isInstanceOf(MutateRowsException.class); - assertThat((exception).isRetryable()).isTrue(); + assertThat(exception.isRetryable()).isTrue(); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java index 8e20d67fb0..ce2f7a6c7c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java @@ -73,8 +73,6 @@ public void setUp() throws IOException { .setTransportChannelProvider( FixedTransportChannelProvider.create( GrpcTransportChannel.create(serverRule.getChannel()))) - // channel priming doesn't work with FixedTransportChannelProvider. Disable it for the test - .setRefreshingChannel(false) .build(); this.client = BigtableDataClient.create(settings.build()); @@ -97,10 +95,10 @@ public void testRetryRstStream() { BulkMutation.create(TableId.of("fake-table")) .add(RowMutationEntry.create("row-key-1").setCell("cf", "q", "v"))); } catch (ApiException e) { - Assert.fail("Rst stream errors should be retried"); + throw new AssertionError("Rst stream errors should be retried", e); } - Assert.assertEquals(attemptCounter.get(), 2); + Assert.assertEquals(2, attemptCounter.get()); } private class FakeBigtableService extends BigtableGrpc.BigtableImplBase { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java index 8a455d3c1b..fa3a2030c0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -70,7 +71,7 @@ public static Collection data() throws IOException { .that(dataJson) .isNotNull(); - InputStreamReader reader = new InputStreamReader(dataJson); + InputStreamReader reader = new InputStreamReader(dataJson, StandardCharsets.UTF_8); TestFile.Builder testBuilder = TestFile.newBuilder(); JsonFormat.parser().merge(reader, testBuilder); TestFile testDefinition = testBuilder.build(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java index ee2e6cd633..599d7cae5e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java @@ -31,7 +31,6 @@ import com.google.bigtable.v2.ReadRowsResponse; import com.google.bigtable.v2.ReadRowsResponse.CellChunk; import com.google.bigtable.v2.RowRange; -import com.google.bigtable.v2.RowSet; import com.google.cloud.bigtable.data.v2.BigtableDataClient; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; import com.google.cloud.bigtable.data.v2.internal.NameUtil; @@ -56,6 +55,7 @@ import io.grpc.stub.StreamObserver; import io.grpc.testing.GrpcServerRule; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -99,8 +99,6 @@ public void setUp() throws IOException { .setTransportChannelProvider( FixedTransportChannelProvider.create( GrpcTransportChannel.create(serverRule.getChannel()))) - // Refreshing channel doesn't work with FixedTransportChannelProvider - .setRefreshingChannel(false) .build(); client = BigtableDataClient.create(settings.build()); @@ -148,7 +146,8 @@ public ApiException createLargeRowException(String rowKey) { .setReason("LargeRowReadError") .setDomain("bigtable.googleapis.com") .putMetadata( - "rowKeyBase64Encoded", Base64.getEncoder().encodeToString(rowKey.getBytes())) + "rowKeyBase64Encoded", + Base64.getEncoder().encodeToString(rowKey.getBytes(StandardCharsets.UTF_8))) .build(); Any packedErrorInfo = Any.pack(errorInfo); @@ -160,11 +159,11 @@ public ApiException createLargeRowException(String rowKey) { byte[] status = com.google.rpc.Status.newBuilder().addDetails(Any.pack(errorInfo)).build().toByteArray(); trailers.put(ERROR_DETAILS_KEY, status); - return (new UnavailableException( + return new UnavailableException( new StatusRuntimeException(Status.FAILED_PRECONDITION, trailers), GrpcStatusCode.of(Code.FAILED_PRECONDITION), false, - errorDetails)); + errorDetails); } @Test @@ -172,7 +171,6 @@ public void readRowsWithLimitSkippingLargeRowsTest() { // Large rows is r2 for range r1 to r8 ApiException largeRowExceptionWithTrailersR2 = createLargeRowException("r2"); - List> rangeList; List actualResults; // TEST - range end is large row || row limit @@ -709,19 +707,13 @@ RpcExpectation expectRequest(String... keys) { } RpcExpectation expectRequestForMultipleRowRanges(List> rowRanges) { - RowSet.Builder rowRange = requestBuilder.getRowsBuilder(); for (Range range : rowRanges) { rowRangeBuilder(range); } return this; } - /** - * Build Row Range - * - * @param range - * @return - */ + /** Build Row Range */ RowRange rowRangeBuilder(Range range) { RowRange.Builder rowRange = requestBuilder.getRowsBuilder().addRowRangesBuilder(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java index 9c960b4537..0d51e2d8f0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java @@ -70,7 +70,7 @@ public FakePreparedStatement() { } @Override - public PreparedQueryData markExpiredAndStartRefresh( + public synchronized PreparedQueryData markExpiredAndStartRefresh( PreparedQueryVersion expiredPreparedQueryVersion) { return getLatestPrepareResponse(); } @@ -127,7 +127,7 @@ public void testExecuteQueryRequestsSetDefaultDeadline() { SqlServerStream stream = stub.executeQueryCallable().call(PREPARED_STATEMENT.bind().build()); // We don't care about this, just assert we get a response boolean rowReceived = false; - for (SqlRow sqlRow : stream.rows()) { + for (@SuppressWarnings("UnusedVariable") SqlRow ignored : stream.rows()) { rowReceived = true; } assertThat(rowReceived).isTrue(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java index 95f5edf268..d6c41397b1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java @@ -97,8 +97,6 @@ public static BigtableDataSettings.Builder defaultSettings(GrpcServerRule server .setTransportChannelProvider( FixedTransportChannelProvider.create( GrpcTransportChannel.create(serverRule.getChannel()))) - // Refreshing channel doesn't work with FixedTransportChannelProvider - .setRefreshingChannel(false) .build(); // Remove log noise from client side metrics settings.setMetricsProvider(NoopMetricsProvider.INSTANCE).disableInternalMetrics(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/PlanRefreshingCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/PlanRefreshingCallableTest.java index f1e214e10c..3511f51eae 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/PlanRefreshingCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/PlanRefreshingCallableTest.java @@ -65,6 +65,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Test; @@ -261,17 +262,19 @@ public void planRefreshDelayIsFactoredIntoExecuteTimeout() throws InterruptedExc // This deadline is used for the prepare call and the ultimate execute call after // that completes. It needs to leave a lot of margin for error for the scheduler below to // be slower than expected to resolve. Previously 100ms deadline was not enough. - Duration originalAttemptTimeout = Duration.ofMillis(5000); - scheduler.schedule( - () -> { - prepareFuture.set( - PrepareResponse.fromProto( - prepareResponse( - ByteString.copyFromUtf8("initialPlan"), - metadata(columnMetadata("strCol", stringType()))))); - }, - 50, - TimeUnit.MILLISECONDS); + Duration originalAttemptTimeout = Duration.ofSeconds(5); + @SuppressWarnings("UnusedVariable") + ScheduledFuture ignored = + scheduler.schedule( + () -> { + prepareFuture.set( + PrepareResponse.fromProto( + prepareResponse( + ByteString.copyFromUtf8("initialPlan"), + metadata(columnMetadata("strCol", stringType()))))); + }, + 50, + TimeUnit.MILLISECONDS); ApiCallContext context = GrpcCallContext.createDefault().withTimeoutDuration(originalAttemptTimeout); // prepare takes 50 ms to resolve. Despite that the execute timeout should be around 100ms from diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ProtoRowsMergingStateMachineTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ProtoRowsMergingStateMachineTest.java index e24445cf98..9da5224cf2 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ProtoRowsMergingStateMachineTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ProtoRowsMergingStateMachineTest.java @@ -170,6 +170,7 @@ public void stateMachine_mergesPartialBatches() { } @Test + @SuppressWarnings("InlineMeInliner") public void stateMachine_mergesPartialBatches_withRandomChunks() { ResultSetMetadata metadata = ProtoResultSetMetadata.fromProto( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/SqlProtoFactory.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/SqlProtoFactory.java index 21ff25f8b5..1a3441a209 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/SqlProtoFactory.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/SqlProtoFactory.java @@ -622,7 +622,7 @@ public PreparedQueryData getLatestPrepareResponse() { } @Override - public PreparedQueryData markExpiredAndStartRefresh( + public synchronized PreparedQueryData markExpiredAndStartRefresh( PreparedQueryVersion expiredPreparedQueryVersion) { return planOnRefresh; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserverTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserverTest.java index 23df3726d3..6adc71cae0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserverTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserverTest.java @@ -290,32 +290,33 @@ public void testConcurrentCancel() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(2); - executor.submit( - new Runnable() { - @Override - public void run() { - while (!outerObserver.isDone()) { - outerObserver.popNextResponse(); - } - latch.countDown(); - } - }); + @SuppressWarnings("UnusedVariable") + Future ignored = + executor.submit( + () -> { + while (!outerObserver.isDone()) { + outerObserver.popNextResponse(); + } + latch.countDown(); + }); - executor.submit( - new Runnable() { - @Override - public void run() { - while (!innerController.isCancelled()) { - if (innerController.popLastPull() > 0) { - innerController.getObserver().onResponse("a"); + @SuppressWarnings("UnusedVariable") + Future ignored2 = + executor.submit( + new Runnable() { + @Override + public void run() { + while (!innerController.isCancelled()) { + if (innerController.popLastPull() > 0) { + innerController.getObserver().onResponse("a"); + } + } + innerController + .getObserver() + .onError(new RuntimeException("Some other upstream error")); + latch.countDown(); } - } - innerController - .getObserver() - .onError(new RuntimeException("Some other upstream error")); - latch.countDown(); - } - }); + }); outerObserver.getController().cancel(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStatusCode.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStatusCode.java index f1662dcd04..51c4f37880 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStatusCode.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStatusCode.java @@ -37,6 +37,7 @@ public Code getTransportCode() { } @Override + @SuppressWarnings("EqualsGetClass") public boolean equals(Object o) { if (this == o) { return true; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java index 7e9e2a654e..70e6a579ac 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java @@ -68,7 +68,7 @@ public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) + retryCount); // Exponential backoff delay starting at 100ms. double expSleep = 100 * Math.pow(2, retryCount); - Thread.sleep((long) Math.min(expSleep, TimeUnit.MINUTES.toMillis(1))); + Thread.sleep(Math.min((long) expSleep, TimeUnit.MINUTES.toMillis(1))); } } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java index 55d66d47cf..fe849af468 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java @@ -397,6 +397,7 @@ public TableId getTableId() { return tableId; } + @Override public String getKmsKeyName() { return kmsKeyName; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java index 9e530e2721..2ba3bd72c1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java @@ -63,7 +63,6 @@ void start() throws Exception { BigtableDataSettings.newBuilderForEmulator(emulator.getPort()) .setProjectId("fake-project") .setInstanceId("fake-instance") - .setRefreshingChannel(false) .setMetricsProvider(NoopMetricsProvider.INSTANCE) .disableInternalMetrics() .build(); @@ -140,6 +139,7 @@ public BigtableInstanceAdminClient getInstanceAdminClient() { throw new UnsupportedOperationException("InstanceAdminClient is not supported with emulator"); } + @Override public String getKmsKeyName() { throw new UnsupportedOperationException("CMEK is not supported with emulator"); }