From cea4282c0624237afda00b0b28a432060130a4aa Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Thu, 11 Nov 2021 16:56:28 -0500 Subject: [PATCH] chore: remove warnings and clean up codebase (#1554) * chore: remove warnings * Clean up * No more Java 7 * Remove unnecessary code --- .../ServerStreamingCallableBenchmark.java | 6 +- build.gradle | 4 +- .../google/api/gax/grpc/GrpcCallContext.java | 232 +++++++++--------- .../google/api/gax/grpc/GrpcCallSettings.java | 2 +- .../grpc/GrpcMetadataHandlerInterceptor.java | 1 - .../longrunning/OperationsSettings.java | 4 +- .../api/gax/grpc/CallOptionsUtilTest.java | 6 +- .../google/api/gax/grpc/ChannelPoolTest.java | 14 +- .../api/gax/grpc/GrpcCallableFactoryTest.java | 8 +- .../api/gax/grpc/GrpcClientCallsTest.java | 28 +-- ...GrpcDirectServerStreamingCallableTest.java | 4 +- .../grpc/GrpcDirectStreamingCallableTest.java | 1 - .../gax/grpc/GrpcResponseMetadataTest.java | 2 +- .../gax/grpc/GrpcTransportDescriptorTest.java | 17 +- .../InstantiatingGrpcChannelProviderTest.java | 15 +- .../grpc/RefreshingManagedChannelTest.java | 98 ++++---- .../grpc/SafeShutdownManagedChannelTest.java | 34 +-- .../com/google/api/gax/grpc/SettingsTest.java | 23 +- .../com/google/api/gax/grpc/TimeoutTest.java | 6 +- .../longrunning/OperationsClientTest.java | 5 +- .../api/gax/httpjson/HttpRequestRunnable.java | 9 +- .../stub/HttpJsonOperationsStub.java | 191 ++++---------- .../ApiMessageOperationTransformersTest.java | 25 +- .../httpjson/HttpJsonCallableFactoryTest.java | 4 +- .../api/gax/httpjson/MockHttpServiceTest.java | 2 +- .../longrunning/OperationsClientTest.java | 25 +- .../gax/httpjson/testing/MockHttpService.java | 7 +- .../rpc/internal/ApiCallContextOptions.java | 5 +- .../gax/rpc/OperationCallableImplTest.java | 13 +- 29 files changed, 331 insertions(+), 460 deletions(-) diff --git a/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java b/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java index b37379055..201d08e55 100644 --- a/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java +++ b/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java @@ -338,7 +338,7 @@ static class GrpcStreamingObserver private final SettableFuture future = SettableFuture.create(); private final boolean autoFlowControl; private final Blackhole blackhole; - private ClientCallStreamObserver inner; + private ClientCallStreamObserver inner; public GrpcStreamingObserver(boolean autoFlowControl, Blackhole blackhole) { this.autoFlowControl = autoFlowControl; @@ -350,11 +350,11 @@ void awaitCompletion() throws InterruptedException, ExecutionException, TimeoutE } @Override - public void beforeStart(ClientCallStreamObserver observer) { + public void beforeStart(ClientCallStreamObserver observer) { if (!autoFlowControl) { observer.disableAutoInboundFlowControl(); } - this.inner = observer; + inner = observer; } @Override diff --git a/build.gradle b/build.gradle index 14f2d322e..d9cdce322 100644 --- a/build.gradle +++ b/build.gradle @@ -153,13 +153,13 @@ configure(javaProjects) { javadoc.options { encoding = 'UTF-8' - links 'https://docs.oracle.com/javase/7/docs/api/' + links 'https://docs.oracle.com/javase/8/docs/api/' if (JavaVersion.current().isJava8Compatible()) { addStringOption('Xdoclint:all,-missing', '-quiet') } if (JavaVersion.current().isJava11Compatible()) { - addStringOption('-release', '7') + addStringOption('-release', '8') } } diff --git a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index d3fdd990e..22dc53c24 100644 --- a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -185,16 +185,16 @@ public GrpcCallContext withTimeout(@Nullable Duration timeout) { } return new GrpcCallContext( - this.channel, - this.callOptions, + channel, + callOptions, timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, + retrySettings, + retryableCodes); } @Nullable @@ -211,16 +211,16 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeou } return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, + channel, + callOptions, + timeout, streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, + retrySettings, + retryableCodes); } @Override @@ -231,31 +231,31 @@ public GrpcCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeou } return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, + channel, + callOptions, + timeout, + streamWaitTimeout, streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + channelAffinity, + extraHeaders, + options, + retrySettings, + retryableCodes); } @BetaApi("The surface for channel affinity is not stable yet and may change in the future.") public GrpcCallContext withChannelAffinity(@Nullable Integer affinity) { return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, + channel, + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, affinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + extraHeaders, + options, + retrySettings, + retryableCodes); } @BetaApi("The surface for extra headers is not stable yet and may change in the future.") @@ -265,55 +265,55 @@ public GrpcCallContext withExtraHeaders(Map> extraHeaders) ImmutableMap> newExtraHeaders = Headers.mergeHeaders(this.extraHeaders, extraHeaders); return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, + channel, + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, newExtraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + options, + retrySettings, + retryableCodes); } @Override public RetrySettings getRetrySettings() { - return this.retrySettings; + return retrySettings; } @Override public GrpcCallContext withRetrySettings(RetrySettings retrySettings) { return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, + channel, + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, retrySettings, - this.retryableCodes); + retryableCodes); } @Override public Set getRetryableCodes() { - return this.retryableCodes; + return retryableCodes; } @Override public GrpcCallContext withRetryableCodes(Set retryableCodes) { return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, + channel, + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, + retrySettings, retryableCodes); } @@ -331,56 +331,56 @@ public ApiCallContext merge(ApiCallContext inputCallContext) { Channel newChannel = grpcCallContext.channel; if (newChannel == null) { - newChannel = this.channel; + newChannel = channel; } Deadline newDeadline = grpcCallContext.callOptions.getDeadline(); if (newDeadline == null) { - newDeadline = this.callOptions.getDeadline(); + newDeadline = callOptions.getDeadline(); } CallCredentials newCallCredentials = grpcCallContext.callOptions.getCredentials(); if (newCallCredentials == null) { - newCallCredentials = this.callOptions.getCredentials(); + newCallCredentials = callOptions.getCredentials(); } ApiTracer newTracer = grpcCallContext.callOptions.getOption(TRACER_KEY); if (newTracer == null) { - newTracer = this.callOptions.getOption(TRACER_KEY); + newTracer = callOptions.getOption(TRACER_KEY); } Duration newTimeout = grpcCallContext.timeout; if (newTimeout == null) { - newTimeout = this.timeout; + newTimeout = timeout; } Duration newStreamWaitTimeout = grpcCallContext.streamWaitTimeout; if (newStreamWaitTimeout == null) { - newStreamWaitTimeout = this.streamWaitTimeout; + newStreamWaitTimeout = streamWaitTimeout; } Duration newStreamIdleTimeout = grpcCallContext.streamIdleTimeout; if (newStreamIdleTimeout == null) { - newStreamIdleTimeout = this.streamIdleTimeout; + newStreamIdleTimeout = streamIdleTimeout; } Integer newChannelAffinity = grpcCallContext.channelAffinity; if (newChannelAffinity == null) { - newChannelAffinity = this.channelAffinity; + newChannelAffinity = channelAffinity; } RetrySettings newRetrySettings = grpcCallContext.retrySettings; if (newRetrySettings == null) { - newRetrySettings = this.retrySettings; + newRetrySettings = retrySettings; } Set newRetryableCodes = grpcCallContext.retryableCodes; if (newRetryableCodes == null) { - newRetryableCodes = this.retryableCodes; + newRetryableCodes = retryableCodes; } ImmutableMap> newExtraHeaders = - Headers.mergeHeaders(this.extraHeaders, grpcCallContext.extraHeaders); + Headers.mergeHeaders(extraHeaders, grpcCallContext.extraHeaders); ApiCallContextOptions newOptions = options.merge(grpcCallContext.options); @@ -422,6 +422,7 @@ public CallOptions getCallOptions() { * * @see ApiCallContext#withStreamWaitTimeout(Duration) */ + @Override @BetaApi("The surface for streaming is not stable yet and may change in the future.") @Nullable public Duration getStreamWaitTimeout() { @@ -433,6 +434,7 @@ public Duration getStreamWaitTimeout() { * * @see ApiCallContext#withStreamIdleTimeout(Duration) */ + @Override @BetaApi("The surface for streaming is not stable yet and may change in the future.") @Nullable public Duration getStreamIdleTimeout() { @@ -450,37 +452,37 @@ public Integer getChannelAffinity() { @BetaApi("The surface for extra headers is not stable yet and may change in the future.") @Override public Map> getExtraHeaders() { - return this.extraHeaders; + return extraHeaders; } /** Returns a new instance with the channel set to the given channel. */ public GrpcCallContext withChannel(Channel newChannel) { return new GrpcCallContext( newChannel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, + retrySettings, + retryableCodes); } /** Returns a new instance with the call options set to the given call options. */ public GrpcCallContext withCallOptions(CallOptions newCallOptions) { return new GrpcCallContext( - this.channel, + channel, newCallOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, - this.options, - this.retrySettings, - this.retryableCodes); + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, + options, + retrySettings, + retryableCodes); } public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams) { @@ -513,16 +515,16 @@ public GrpcCallContext withTracer(@Nonnull ApiTracer tracer) { public GrpcCallContext withOption(Key key, T value) { ApiCallContextOptions newOptions = options.withOption(key, value); return new GrpcCallContext( - this.channel, - this.callOptions, - this.timeout, - this.streamWaitTimeout, - this.streamIdleTimeout, - this.channelAffinity, - this.extraHeaders, + channel, + callOptions, + timeout, + streamWaitTimeout, + streamIdleTimeout, + channelAffinity, + extraHeaders, newOptions, - this.retrySettings, - this.retryableCodes); + retrySettings, + retryableCodes); } /** {@inheritDoc} */ @@ -556,21 +558,21 @@ public boolean equals(Object o) { } GrpcCallContext that = (GrpcCallContext) o; - return Objects.equals(this.channel, that.channel) - && Objects.equals(this.callOptions, that.callOptions) - && Objects.equals(this.timeout, that.timeout) - && Objects.equals(this.streamWaitTimeout, that.streamWaitTimeout) - && Objects.equals(this.streamIdleTimeout, that.streamIdleTimeout) - && Objects.equals(this.channelAffinity, that.channelAffinity) - && Objects.equals(this.extraHeaders, that.extraHeaders) - && Objects.equals(this.options, that.options) - && Objects.equals(this.retrySettings, that.retrySettings) - && Objects.equals(this.retryableCodes, that.retryableCodes); + return Objects.equals(channel, that.channel) + && Objects.equals(callOptions, that.callOptions) + && Objects.equals(timeout, that.timeout) + && Objects.equals(streamWaitTimeout, that.streamWaitTimeout) + && Objects.equals(streamIdleTimeout, that.streamIdleTimeout) + && Objects.equals(channelAffinity, that.channelAffinity) + && Objects.equals(extraHeaders, that.extraHeaders) + && Objects.equals(options, that.options) + && Objects.equals(retrySettings, that.retrySettings) + && Objects.equals(retryableCodes, that.retryableCodes); } Metadata getMetadata() { Metadata metadata = new Metadata(); - for (Map.Entry> header : this.extraHeaders.entrySet()) { + for (Map.Entry> header : extraHeaders.entrySet()) { String headerKey = header.getKey(); for (String headerValue : header.getValue()) { metadata.put(Metadata.Key.of(headerKey, Metadata.ASCII_STRING_MARSHALLER), headerValue); diff --git a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallSettings.java b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallSettings.java index 739b480a8..177dde6ed 100644 --- a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallSettings.java +++ b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallSettings.java @@ -40,7 +40,7 @@ public class GrpcCallSettings { private final RequestParamsExtractor paramsExtractor; private final boolean alwaysAwaitTrailers; - private GrpcCallSettings(Builder builder) { + private GrpcCallSettings(Builder builder) { this.methodDescriptor = builder.methodDescriptor; this.paramsExtractor = builder.paramsExtractor; this.alwaysAwaitTrailers = builder.shouldAwaitTrailers; diff --git a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcMetadataHandlerInterceptor.java b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcMetadataHandlerInterceptor.java index e405336c2..c3940f4db 100644 --- a/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcMetadataHandlerInterceptor.java +++ b/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcMetadataHandlerInterceptor.java @@ -33,7 +33,6 @@ import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; -import io.grpc.ClientCall.Listener; import io.grpc.ClientInterceptor; import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; diff --git a/gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java b/gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java index 507711f47..16035fc6f 100644 --- a/gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java +++ b/gax-grpc/src/main/java/com/google/longrunning/OperationsSettings.java @@ -29,8 +29,6 @@ */ package com.google.longrunning; -import static com.google.longrunning.OperationsClient.ListOperationsPagedResponse; - import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; import com.google.api.gax.core.GoogleCredentialsProvider; @@ -40,6 +38,7 @@ import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.PagedCallSettings; import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.longrunning.OperationsClient.ListOperationsPagedResponse; import com.google.longrunning.stub.OperationsStubSettings; import com.google.protobuf.Empty; import java.io.IOException; @@ -103,6 +102,7 @@ public static Builder newBuilder(ClientContext clientContext) { } /** Returns a builder containing all the values of this settings class. */ + @Override public Builder toBuilder() { return new Builder(this); } diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/CallOptionsUtilTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/CallOptionsUtilTest.java index f566ca074..26a6b925f 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/CallOptionsUtilTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/CallOptionsUtilTest.java @@ -41,7 +41,7 @@ public class CallOptionsUtilTest { @Test - public void testPutAndGetDynamicHeaderOption() throws Exception { + public void testPutAndGetDynamicHeaderOption() { String encodedRequestParams = "param1=value¶m2.param3=value23"; CallOptions options = CallOptionsUtil.putRequestParamsDynamicHeaderOption( @@ -54,7 +54,7 @@ public void testPutAndGetDynamicHeaderOption() throws Exception { } @Test - public void testPutAndGetDynamicHeaderOptionEmpty() throws Exception { + public void testPutAndGetDynamicHeaderOptionEmpty() { CallOptions options = CallOptionsUtil.putRequestParamsDynamicHeaderOption(CallOptions.DEFAULT, ""); assertSame(CallOptions.DEFAULT, options); @@ -63,7 +63,7 @@ public void testPutAndGetDynamicHeaderOptionEmpty() throws Exception { } @Test(expected = NullPointerException.class) - public void testPutAndGetHeaderOptionNull() throws Exception { + public void testPutAndGetHeaderOptionNull() { CallOptionsUtil.putRequestParamsDynamicHeaderOption(CallOptions.DEFAULT, null); } } diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java index a660ca1c6..d6ae65202 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java @@ -180,23 +180,21 @@ public void channelPrimerShouldCallPoolConstruction() throws IOException { // Test channelPrimer is called periodically, if there's an executorService @Test - public void channelPrimerIsCalledPeriodically() throws IOException, InterruptedException { + public void channelPrimerIsCalledPeriodically() throws IOException { ChannelPrimer mockChannelPrimer = Mockito.mock(ChannelPrimer.class); ManagedChannel channel1 = Mockito.mock(RefreshingManagedChannel.class); ManagedChannel channel2 = Mockito.mock(RefreshingManagedChannel.class); ManagedChannel channel3 = Mockito.mock(RefreshingManagedChannel.class); - final List channelRefreshers = new ArrayList<>(); + List channelRefreshers = new ArrayList<>(); ScheduledExecutorService scheduledExecutorService = Mockito.mock(ScheduledExecutorService.class); - Answer extractChannelRefresher = - new Answer() { - public Object answer(InvocationOnMock invocation) { - channelRefreshers.add((Runnable) invocation.getArgument(0)); - return Mockito.mock(ScheduledFuture.class); - } + Answer extractChannelRefresher = + invocation -> { + channelRefreshers.add((Runnable) invocation.getArgument(0)); + return Mockito.mock(ScheduledFuture.class); }; Mockito.doAnswer(extractChannelRefresher) diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java index 163f43d1c..2ebe93b7f 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java @@ -88,7 +88,7 @@ public void tearDown() { } @Test - public void createServerStreamingCallableRetryableExceptions() throws Exception { + public void createServerStreamingCallableRetryableExceptions() { GrpcCallSettings grpcCallSettings = GrpcCallSettings.create(FakeServiceGrpc.METHOD_STREAMING_RECOGNIZE_ERROR); @@ -147,7 +147,7 @@ public void createServerStreamingCallableRetryableExceptions() throws Exception @Test public void testGetSpanName() { @SuppressWarnings("unchecked") - MethodDescriptor descriptor = + MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("google.bigtable.v2.Bigtable/ReadRows") @@ -162,7 +162,7 @@ public void testGetSpanName() { @Test public void testGetSpanNameUnqualified() { @SuppressWarnings("unchecked") - MethodDescriptor descriptor = + MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("UnqualifiedService/ReadRows") @@ -180,7 +180,7 @@ public void testGetSpanNameInvalid() { for (String invalidName : invalidNames) { @SuppressWarnings("unchecked") - MethodDescriptor descriptor = + MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName(invalidName) diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java index 9722f8634..ef0d58ce9 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java @@ -53,8 +53,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.threeten.bp.Duration; public class GrpcClientCallsTest { @@ -105,22 +103,19 @@ public void testExtraHeaders() { @SuppressWarnings("unchecked") ClientCall.Listener mockListener = Mockito.mock(ClientCall.Listener.class); - @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); Mockito.doAnswer( - new Answer() { - public Void answer(InvocationOnMock invocation) { - Metadata clientCallHeaders = (Metadata) invocation.getArguments()[1]; - Metadata.Key key1 = - Metadata.Key.of("header-key-1", Metadata.ASCII_STRING_MARSHALLER); - Metadata.Key key2 = - Metadata.Key.of("header-key-2", Metadata.ASCII_STRING_MARSHALLER); - assertThat(clientCallHeaders.getAll(key1)) - .containsExactly("header-value-11", "header-value-12"); - assertThat(clientCallHeaders.getAll(key2)).containsExactly("header-value-21"); - return null; - } + invocation -> { + Metadata clientCallHeaders = (Metadata) invocation.getArguments()[1]; + Metadata.Key key1 = + Metadata.Key.of("header-key-1", Metadata.ASCII_STRING_MARSHALLER); + Metadata.Key key2 = + Metadata.Key.of("header-key-2", Metadata.ASCII_STRING_MARSHALLER); + assertThat(clientCallHeaders.getAll(key1)) + .containsExactly("header-value-11", "header-value-12"); + assertThat(clientCallHeaders.getAll(key2)).containsExactly("header-value-21"); + return null; }) .when(mockClientCall) .start(Mockito.>any(), Mockito.any()); @@ -143,7 +138,6 @@ public void testTimeoutToDeadlineConversion() { @SuppressWarnings("unchecked") ClientCall.Listener mockListener = Mockito.mock(ClientCall.Listener.class); - @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); @@ -175,7 +169,6 @@ public void testTimeoutAfterDeadline() { @SuppressWarnings("unchecked") ClientCall.Listener mockListener = Mockito.mock(ClientCall.Listener.class); - @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); @@ -209,7 +202,6 @@ public void testTimeoutBeforeDeadline() { @SuppressWarnings("unchecked") ClientCall.Listener mockListener = Mockito.mock(ClientCall.Listener.class); - @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectServerStreamingCallableTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectServerStreamingCallableTest.java index fa5a41fbd..335a70966 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectServerStreamingCallableTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectServerStreamingCallableTest.java @@ -129,7 +129,7 @@ public void testBadContext() { } @Test - public void testServerStreamingStart() throws Exception { + public void testServerStreamingStart() { CountDownLatch latch = new CountDownLatch(1); MoneyObserver moneyObserver = new MoneyObserver(true, latch); @@ -240,7 +240,7 @@ protected void onCompleteImpl() { } @Test - public void testBlockingServerStreaming() throws Exception { + public void testBlockingServerStreaming() { Color request = Color.newBuilder().setRed(0.5f).build(); ServerStream response = streamingCallable.call(request); List responseData = Lists.newArrayList(response); diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamingCallableTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamingCallableTest.java index 733f4d02d..95d4550b0 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamingCallableTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamingCallableTest.java @@ -141,7 +141,6 @@ public void testBidiStreamingClientError() throws Exception { GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch); - Color request = Color.newBuilder().setRed(0.5f).build(); ClientStream stream = streamingCallable.splitCall(moneyObserver); Throwable clientError = new StatusRuntimeException(Status.CANCELLED); stream.closeSendWithError(clientError); diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcResponseMetadataTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcResponseMetadataTest.java index 8f259e8c3..80b041a37 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcResponseMetadataTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcResponseMetadataTest.java @@ -147,7 +147,7 @@ public void tearDown() { } @Test - public void testResponseMetadataUnaryCall() throws Exception { + public void testResponseMetadataUnaryCall() { GrpcCallSettings grpcCallSettings = GrpcCallSettings.create(FakeServiceGrpc.METHOD_RECOGNIZE); diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcTransportDescriptorTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcTransportDescriptorTest.java index 9cd1aaa89..456d4e73b 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcTransportDescriptorTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcTransportDescriptorTest.java @@ -58,7 +58,7 @@ public class GrpcTransportDescriptorTest { private static boolean IS_RETRYABLE = true; @Test - public void translateException_StatusException_noRetry() throws Exception { + public void translateException_StatusException_noRetry() { Throwable originalException = new StatusException(Status.INVALID_ARGUMENT); GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>( @@ -73,7 +73,7 @@ public void translateException_StatusException_noRetry() throws Exception { } @Test - public void translateException_StatusException_withRetry() throws Exception { + public void translateException_StatusException_withRetry() { Throwable originalException = new StatusException(Status.UNAVAILABLE); GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>( @@ -88,7 +88,7 @@ public void translateException_StatusException_withRetry() throws Exception { } @Test - public void translateException_StatusRuntimeException_noRetry() throws Exception { + public void translateException_StatusRuntimeException_noRetry() { Throwable originalException = new StatusRuntimeException(Status.INVALID_ARGUMENT); GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>( @@ -103,7 +103,7 @@ public void translateException_StatusRuntimeException_noRetry() throws Exception } @Test - public void translateException_StatusRuntimeException_withRetry() throws Exception { + public void translateException_StatusRuntimeException_withRetry() { Throwable originalException = new StatusRuntimeException(Status.UNAVAILABLE); GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>( @@ -118,7 +118,7 @@ public void translateException_StatusRuntimeException_withRetry() throws Excepti } @Test - public void translateException_cancelled() throws Exception { + public void translateException_cancelled() { GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>(inactiveCallable(), Collections.emptySet()); ApiFuture result = exceptionCallable.futureCall(0); @@ -129,7 +129,7 @@ public void translateException_cancelled() throws Exception { } @Test - public void translateException_ApiException() throws Exception { + public void translateException_ApiException() { Throwable originalException = new RuntimeException("stuff went wrong"); Throwable apiException = new DataLossException( @@ -147,7 +147,7 @@ public void translateException_ApiException() throws Exception { } @Test - public void translateException_RuntimeException() throws Exception { + public void translateException_RuntimeException() { Throwable originalException = new RuntimeException("stuff went wrong"); GrpcExceptionCallable exceptionCallable = new GrpcExceptionCallable<>( @@ -180,8 +180,7 @@ public ApiFuture futureCall(Integer request, ApiCallContext context) { } public void assertInnerExceptionIsInstanceOf( - Throwable thrownException, Class clazz, boolean retryable, Throwable originalException) - throws Exception { + Throwable thrownException, Class clazz, boolean retryable, Throwable originalException) { Truth.assertThat(thrownException).isInstanceOf(clazz); ApiException apiException = (ApiException) thrownException; Truth.assertThat(apiException.isRetryable()).isEqualTo(retryable); diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index ed01d241e..a3f88d554 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -232,10 +232,10 @@ public void testChannelConfigurator() throws IOException { ApiFunction channelConfigurator = Mockito.mock(ApiFunction.class); - ArgumentCaptor channelBuilderCaptor = + ArgumentCaptor> channelBuilderCaptor = ArgumentCaptor.forClass(ManagedChannelBuilder.class); - ManagedChannelBuilder swappedBuilder = Mockito.mock(ManagedChannelBuilder.class); + ManagedChannelBuilder swappedBuilder = Mockito.mock(ManagedChannelBuilder.class); ManagedChannel fakeChannel = Mockito.mock(ManagedChannel.class); Mockito.when(swappedBuilder.build()).thenReturn(fakeChannel); @@ -327,13 +327,10 @@ public void testWithDirectPathDisabled() throws IOException { executor.shutdown(); ApiFunction channelConfigurator = - new ApiFunction() { - @Override - public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) { - // Clients without setting attemptDirectPath flag will not attempt DirectPath - assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isFalse(); - return channelBuilder; - } + channelBuilder -> { + // Clients without setting attemptDirectPath flag will not attempt DirectPath + assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isFalse(); + return channelBuilder; }; TransportChannelProvider provider = diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/RefreshingManagedChannelTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/RefreshingManagedChannelTest.java index ece24086a..b56070bf3 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/RefreshingManagedChannelTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/RefreshingManagedChannelTest.java @@ -52,7 +52,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) @@ -65,13 +64,11 @@ public void channelRefreshShouldSwapChannels() throws IOException { // mock executor service to capture the runnable scheduled so we can invoke it when we want to ScheduledExecutorService scheduledExecutorService = Mockito.mock(ScheduledExecutorService.class); - final List channelRefreshers = new ArrayList<>(); - Answer extractChannelRefresher = - new Answer() { - public Object answer(InvocationOnMock invocation) { - channelRefreshers.add((Runnable) invocation.getArgument(0)); - return null; - } + List channelRefreshers = new ArrayList<>(); + Answer extractChannelRefresher = + invocation -> { + channelRefreshers.add((Runnable) invocation.getArgument(0)); + return null; }; Mockito.doAnswer(extractChannelRefresher) @@ -104,39 +101,33 @@ public Object answer(InvocationOnMock invocation) { @Test public void randomizeTest() throws IOException, InterruptedException, ExecutionException { int channelCount = 10; - final ManagedChannel[] underlyingChannels = new ManagedChannel[channelCount]; - final Random r = new Random(); + ManagedChannel[] underlyingChannels = new ManagedChannel[channelCount]; + Random r = new Random(); for (int i = 0; i < channelCount; i++) { - final ManagedChannel mockManagedChannel = Mockito.mock(ManagedChannel.class); + ManagedChannel mockManagedChannel = Mockito.mock(ManagedChannel.class); underlyingChannels[i] = mockManagedChannel; - final Answer waitAndSendMessage = - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - // add a little time to sleep so calls don't always complete right away - TimeUnit.MICROSECONDS.sleep(r.nextInt(1000)); - // when sending message on the call, the channel cannot be shutdown - Mockito.verify(mockManagedChannel, Mockito.never()).shutdown(); - return invocation.callRealMethod(); - } + Answer waitAndSendMessage = + invocation -> { + // add a little time to sleep so calls don't always complete right away + TimeUnit.MICROSECONDS.sleep(r.nextInt(1000)); + // when sending message on the call, the channel cannot be shutdown + Mockito.verify(mockManagedChannel, Mockito.never()).shutdown(); + return invocation.callRealMethod(); }; - Answer createNewCall = - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - // create a new client call for every new call to the underlying channel - MockClientCall mockClientCall = new MockClientCall<>(1, Status.OK); - MockClientCall spyClientCall = Mockito.spy(mockClientCall); - - // spy into clientCall to verify that the channel is not shutdown - Mockito.doAnswer(waitAndSendMessage) - .when(spyClientCall) - .sendMessage(Mockito.anyString()); - - return spyClientCall; - } + Answer createNewCall = + invocation -> { + // create a new client call for every new call to the underlying channel + MockClientCall mockClientCall = new MockClientCall<>(1, Status.OK); + MockClientCall spyClientCall = Mockito.spy(mockClientCall); + + // spy into clientCall to verify that the channel is not shutdown + Mockito.doAnswer(waitAndSendMessage) + .when(spyClientCall) + .sendMessage(Mockito.anyString()); + + return spyClientCall; }; // return a new mocked client call when requesting new call on the channel @@ -147,15 +138,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } // mock executor service to capture the runnable scheduled so we can invoke it when we want to - final List channelRefreshers = new ArrayList<>(); + List channelRefreshers = new ArrayList<>(); ScheduledExecutorService scheduledExecutorService = Mockito.mock(ScheduledExecutorService.class); - Answer extractChannelRefresher = - new Answer() { - public Object answer(InvocationOnMock invocation) { - channelRefreshers.add((Runnable) invocation.getArgument(0)); - return null; - } + Answer extractChannelRefresher = + invocation -> { + channelRefreshers.add((Runnable) invocation.getArgument(0)); + return null; }; Mockito.doAnswer(extractChannelRefresher) .when(scheduledExecutorService) @@ -163,7 +152,7 @@ public Object answer(InvocationOnMock invocation) { Mockito.any(Runnable.class), Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS)); FakeChannelFactory channelFactory = new FakeChannelFactory(Arrays.asList(underlyingChannels)); - final ManagedChannel refreshingManagedChannel = + ManagedChannel refreshingManagedChannel = new RefreshingManagedChannel(channelFactory, scheduledExecutorService); // send a bunch of request to RefreshingManagedChannel, executor needs more than 1 thread to @@ -178,18 +167,15 @@ public Object answer(InvocationOnMock invocation) { int whenToRefresh = r.nextInt(requestCount); for (int j = 0; j < requestCount; j++) { Runnable createNewCall = - new Runnable() { - @Override - public void run() { - // create a new call and send message on refreshingManagedChannel - ClientCall call = - refreshingManagedChannel.newCall( - FakeMethodDescriptor.create(), CallOptions.DEFAULT); - @SuppressWarnings("unchecked") - ClientCall.Listener listener = Mockito.mock(ClientCall.Listener.class); - call.start(listener, new Metadata()); - call.sendMessage("message"); - } + () -> { + // create a new call and send message on refreshingManagedChannel + ClientCall call = + refreshingManagedChannel.newCall( + FakeMethodDescriptor.create(), CallOptions.DEFAULT); + @SuppressWarnings("unchecked") + ClientCall.Listener listener = Mockito.mock(ClientCall.Listener.class); + call.start(listener, new Metadata()); + call.sendMessage("message"); }; futures.add(executor.submit(createNewCall)); // at the randomly chosen point, refresh the channel diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/SafeShutdownManagedChannelTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/SafeShutdownManagedChannelTest.java index ed5659b1f..91b16dcbf 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/SafeShutdownManagedChannelTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/SafeShutdownManagedChannelTest.java @@ -40,7 +40,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) @@ -61,13 +60,10 @@ public void callShouldCompleteAfterCreation() { Mockito.>any(), Mockito.any(CallOptions.class))) .thenReturn(spyClientCall); - Answer verifyChannelNotShutdown = - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); - return invocation.callRealMethod(); - } + Answer verifyChannelNotShutdown = + invocation -> { + Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); + return invocation.callRealMethod(); }; // verify that underlying channel is not shutdown when clientCall is still sending message @@ -108,13 +104,10 @@ public void callShouldCompleteAfterStarted() { Mockito.>any(), Mockito.any(CallOptions.class))) .thenReturn(spyClientCall); - Answer verifyChannelNotShutdown = - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); - return invocation.callRealMethod(); - } + Answer verifyChannelNotShutdown = + invocation -> { + Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); + return invocation.callRealMethod(); }; // verify that underlying channel is not shutdown when clientCall is still sending message @@ -154,13 +147,10 @@ public void channelShouldShutdown() { Mockito.>any(), Mockito.any(CallOptions.class))) .thenReturn(spyClientCall); - Answer verifyChannelNotShutdown = - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); - return invocation.callRealMethod(); - } + Answer verifyChannelNotShutdown = + invocation -> { + Mockito.verify(underlyingChannel, Mockito.never()).shutdown(); + return invocation.callRealMethod(); }; // verify that underlying channel is not shutdown when clientCall is still sending message diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index f40716d4f..e24e36c68 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -170,16 +170,17 @@ public static Builder newBuilder() { return Builder.createDefault(); } + @Override public Builder toBuilder() { return new Builder(this); } - private FakeStubSettings(Builder settingsBuilder) throws IOException { + private FakeStubSettings(Builder settingsBuilder) { super(settingsBuilder); - this.fakeMethodSimple = settingsBuilder.fakeMethodSimple().build(); - this.fakePagedMethod = settingsBuilder.fakePagedMethod().build(); - this.fakeMethodBatching = settingsBuilder.fakeMethodBatching().build(); + fakeMethodSimple = settingsBuilder.fakeMethodSimple().build(); + fakePagedMethod = settingsBuilder.fakePagedMethod().build(); + fakeMethodBatching = settingsBuilder.fakeMethodBatching().build(); } private static class Builder extends StubSettings.Builder { @@ -318,24 +319,24 @@ public void channelCustomCredentialScopes() throws IOException { // ==== @Test - public void callSettingsToBuilder() throws IOException { - UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); - UnaryCallSettings settingsA = builderA.build(); - UnaryCallSettings.Builder builderB = settingsA.toBuilder(); - UnaryCallSettings settingsB = builderB.build(); + public void callSettingsToBuilder() { + UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); + UnaryCallSettings settingsA = builderA.build(); + UnaryCallSettings.Builder builderB = settingsA.toBuilder(); + UnaryCallSettings settingsB = builderB.build(); assertEquals(settingsA, settingsB); } @Test - public void unaryCallSettingsBuilderBuildDoesNotFailUnsetProperties() throws IOException { + public void unaryCallSettingsBuilderBuildDoesNotFailUnsetProperties() { UnaryCallSettings.Builder builder = UnaryCallSettings.newUnaryCallSettingsBuilder(); builder.build(); } @Test - public void callSettingsBuildFromTimeoutNoRetries() throws IOException { + public void callSettingsBuildFromTimeoutNoRetries() { Duration timeout = Duration.ofMillis(60000); UnaryCallSettings.Builder builderA = diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index 8a4df4244..3b0d8ebc5 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -32,12 +32,10 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.times; -import com.google.api.core.ApiFuture; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.RequestParamsExtractor; -import com.google.api.gax.rpc.ServerStream; import com.google.api.gax.rpc.ServerStreamingCallSettings; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.StatusCode; @@ -365,7 +363,7 @@ private CallOptions setupUnaryCallable( ClientContext.newBuilder().setDefaultCallContext(context).build()); try { - ApiFuture future = callable.futureCall("Is your refrigerator running?"); + callable.futureCall("Is your refrigerator running?"); } catch (ApiException e) { } @@ -426,7 +424,7 @@ private CallOptions setupServerStreamingCallable( ClientContext.newBuilder().setDefaultCallContext(context).build()); try { - ServerStream stream = callable.call("Is your refrigerator running?"); + callable.call("Is your refrigerator running?"); } catch (ApiException e) { } diff --git a/gax-grpc/src/test/java/com/google/longrunning/OperationsClientTest.java b/gax-grpc/src/test/java/com/google/longrunning/OperationsClientTest.java index aa335e91c..0c5eaa302 100644 --- a/gax-grpc/src/test/java/com/google/longrunning/OperationsClientTest.java +++ b/gax-grpc/src/test/java/com/google/longrunning/OperationsClientTest.java @@ -29,14 +29,13 @@ */ package com.google.longrunning; -import static com.google.longrunning.OperationsClient.ListOperationsPagedResponse; - import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.testing.LocalChannelProvider; import com.google.api.gax.grpc.testing.MockGrpcService; import com.google.api.gax.grpc.testing.MockServiceHelper; import com.google.api.gax.rpc.InvalidArgumentException; import com.google.common.collect.Lists; +import com.google.longrunning.OperationsClient.ListOperationsPagedResponse; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Duration; import com.google.protobuf.Empty; @@ -84,7 +83,7 @@ public void setUp() throws IOException { } @After - public void tearDown() throws Exception { + public void tearDown() { client.close(); } diff --git a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index 250d0a47f..f3a7ffd6c 100644 --- a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -43,7 +43,6 @@ import com.google.api.client.json.JsonObjectParser; import com.google.api.client.util.GenericData; import com.google.api.core.SettableApiFuture; -import com.google.api.gax.rpc.ApiExceptionFactory; import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter; import com.google.auto.value.AutoValue; @@ -189,12 +188,6 @@ public void run() { try { HttpRequest httpRequest = createHttpRequest(); HttpResponse httpResponse = httpRequest.execute(); - if (!httpResponse.isSuccessStatusCode()) { - ApiExceptionFactory.createException( - null, - HttpJsonStatusCode.of(httpResponse.getStatusCode(), httpResponse.getStatusMessage()), - false); - } if (getApiMethodDescriptor().getResponseParser() != null) { ResponseT response = @@ -213,7 +206,7 @@ public void run() { static Builder newBuilder() { return new AutoValue_HttpRequestRunnable.Builder() - .setHeaderEnhancers(new LinkedList()); + .setHeaderEnhancers(new LinkedList<>()); } @AutoValue.Builder diff --git a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/HttpJsonOperationsStub.java b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/HttpJsonOperationsStub.java index ccc9ae2c9..4aadf7a60 100644 --- a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/HttpJsonOperationsStub.java +++ b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/HttpJsonOperationsStub.java @@ -29,25 +29,20 @@ */ package com.google.api.gax.httpjson.longrunning.stub; -import static com.google.api.gax.httpjson.longrunning.OperationsClient.ListOperationsPagedResponse; - import com.google.api.client.http.HttpMethods; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.httpjson.ApiMethodDescriptor; -import com.google.api.gax.httpjson.FieldsExtractor; import com.google.api.gax.httpjson.HttpJsonCallSettings; import com.google.api.gax.httpjson.HttpJsonLongRunningClient; import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; -import com.google.api.gax.httpjson.OperationSnapshotFactory; -import com.google.api.gax.httpjson.PollingRequestFactory; import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; -import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.httpjson.longrunning.OperationsClient.ListOperationsPagedResponse; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.LongRunningClient; import com.google.api.gax.rpc.UnaryCallable; @@ -83,37 +78,24 @@ public class HttpJsonOperationsStub extends OperationsStub { ProtoMessageRequestFormatter.newBuilder() .setPath( "/v1/{name=operations}", - new FieldsExtractor>() { - @Override - public Map extract(ListOperationsRequest request) { - Map fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - serializer.putPathParam(fields, "name", request.getName()); - return fields; - } + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; }) .setQueryParamsExtractor( - new FieldsExtractor>>() { - @Override - public Map> extract( - ListOperationsRequest request) { - Map> fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - serializer.putQueryParam(fields, "filter", request.getFilter()); - serializer.putQueryParam(fields, "pageSize", request.getPageSize()); - serializer.putQueryParam(fields, "pageToken", request.getPageToken()); - return fields; - } - }) - .setRequestBodyExtractor( - new FieldsExtractor() { - @Override - public String extract(ListOperationsRequest request) { - return null; - } + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; }) + .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() @@ -130,53 +112,25 @@ public String extract(ListOperationsRequest request) { ProtoMessageRequestFormatter.newBuilder() .setPath( "/v1/{name=operations/**}", - new FieldsExtractor>() { - @Override - public Map extract(GetOperationRequest request) { - Map fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - serializer.putPathParam(fields, "name", request.getName()); - return fields; - } - }) - .setQueryParamsExtractor( - new FieldsExtractor>>() { - @Override - public Map> extract(GetOperationRequest request) { - Map> fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - return fields; - } - }) - .setRequestBodyExtractor( - new FieldsExtractor() { - @Override - public String extract(GetOperationRequest request) { - return null; - } + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; }) + .setQueryParamsExtractor(request -> new HashMap<>()) + .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Operation.getDefaultInstance()) .build()) .setOperationSnapshotFactory( - new OperationSnapshotFactory() { - @Override - public OperationSnapshot create( - GetOperationRequest request, Operation response) { - return HttpJsonOperationSnapshot.create(response); - } - }) + (request, response) -> HttpJsonOperationSnapshot.create(response)) .setPollingRequestFactory( - new PollingRequestFactory() { - @Override - public GetOperationRequest create(String compoundOperationId) { - return GetOperationRequest.newBuilder().setName(compoundOperationId).build(); - } - }) + compoundOperationId -> + GetOperationRequest.newBuilder().setName(compoundOperationId).build()) .build(); private static final ApiMethodDescriptor @@ -188,34 +142,15 @@ public GetOperationRequest create(String compoundOperationId) { ProtoMessageRequestFormatter.newBuilder() .setPath( "/v1/{name=operations/**}", - new FieldsExtractor>() { - @Override - public Map extract(DeleteOperationRequest request) { - Map fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - serializer.putPathParam(fields, "name", request.getName()); - return fields; - } - }) - .setQueryParamsExtractor( - new FieldsExtractor>>() { - @Override - public Map> extract( - DeleteOperationRequest request) { - Map> fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - return fields; - } - }) - .setRequestBodyExtractor( - new FieldsExtractor() { - @Override - public String extract(DeleteOperationRequest request) { - return null; - } + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; }) + .setQueryParamsExtractor(request -> new HashMap<>()) + .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() @@ -232,34 +167,15 @@ public String extract(DeleteOperationRequest request) { ProtoMessageRequestFormatter.newBuilder() .setPath( "/v1/{name=operations/**}:cancel", - new FieldsExtractor>() { - @Override - public Map extract(CancelOperationRequest request) { - Map fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - serializer.putPathParam(fields, "name", request.getName()); - return fields; - } - }) - .setQueryParamsExtractor( - new FieldsExtractor>>() { - @Override - public Map> extract( - CancelOperationRequest request) { - Map> fields = new HashMap<>(); - ProtoRestSerializer serializer = - ProtoRestSerializer.create(); - return fields; - } - }) - .setRequestBodyExtractor( - new FieldsExtractor() { - @Override - public String extract(CancelOperationRequest request) { - return null; - } + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; }) + .setQueryParamsExtractor(request -> new HashMap<>()) + .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() @@ -355,35 +271,34 @@ protected HttpJsonOperationsStub( .setTypeRegistry(typeRegistry) .build(); - this.listOperationsCallable = + listOperationsCallable = callableFactory.createUnaryCallable( listOperationsTransportSettings, settings.listOperationsSettings(), clientContext); - this.listOperationsPagedCallable = + listOperationsPagedCallable = callableFactory.createPagedCallable( listOperationsTransportSettings, settings.listOperationsSettings(), clientContext); - this.getOperationCallable = + getOperationCallable = callableFactory.createUnaryCallable( getOperationTransportSettings, settings.getOperationSettings(), clientContext); - this.deleteOperationCallable = + deleteOperationCallable = callableFactory.createUnaryCallable( deleteOperationTransportSettings, settings.deleteOperationSettings(), clientContext); - this.cancelOperationCallable = + cancelOperationCallable = callableFactory.createUnaryCallable( cancelOperationTransportSettings, settings.cancelOperationSettings(), clientContext); - this.longRunningClient = - new HttpJsonLongRunningClient( + longRunningClient = + new HttpJsonLongRunningClient<>( getOperationCallable, getOperationMethodDescriptor.getOperationSnapshotFactory(), getOperationMethodDescriptor.getPollingRequestFactory()); - this.backgroundResources = - new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); } @InternalApi - public static List getMethodDescriptors() { - List methodDescriptors = new ArrayList<>(); + public static List> getMethodDescriptors() { + List> methodDescriptors = new ArrayList<>(); methodDescriptors.add(listOperationsMethodDescriptor); methodDescriptors.add(getOperationMethodDescriptor); methodDescriptors.add(deleteOperationMethodDescriptor); diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/ApiMessageOperationTransformersTest.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/ApiMessageOperationTransformersTest.java index edf0f56ce..d498e56c5 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/ApiMessageOperationTransformersTest.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/ApiMessageOperationTransformersTest.java @@ -54,7 +54,7 @@ public void testResponseTransformer() { ResponseTransformer transformer = ResponseTransformer.create(EmptyMessage.class); EmptyMessage emptyResponse = EmptyMessage.getDefaultInstance(); - FakeMetadataMessage metadata = new FakeMetadataMessage(Status.PENDING, Code.OK); + FakeMetadataMessage metadata = new FakeMetadataMessage<>(Status.PENDING, Code.OK); OperationSnapshot operationSnapshot = new OperationSnapshotImpl( new FakeOperationMessage<>("Pending; no response method", emptyResponse, metadata)); @@ -66,7 +66,7 @@ public void testResponseTransformer() { public void testResponseTransformer_exception() { ResponseTransformer transformer = ResponseTransformer.create(EmptyMessage.class); EmptyMessage emptyResponse = EmptyMessage.getDefaultInstance(); - FakeMetadataMessage metadata = new FakeMetadataMessage(Status.PENDING, Code.UNAVAILABLE); + FakeMetadataMessage metadata = new FakeMetadataMessage<>(Status.PENDING, Code.UNAVAILABLE); OperationSnapshot operationSnapshot = new OperationSnapshotImpl( new FakeOperationMessage<>("Unavailable; no response method", emptyResponse, metadata)); @@ -81,7 +81,7 @@ public void testResponseTransformer_exception() { @Test public void testResponseTransformer_mismatchedTypes() { ResponseTransformer transformer = ResponseTransformer.create(EmptyMessage.class); - FakeMetadataMessage metadata = new FakeMetadataMessage(Status.PENDING, Code.OK); + FakeMetadataMessage metadata = new FakeMetadataMessage<>(Status.PENDING, Code.OK); ApiMessage bananaResponse = new FakeApiMessage(ImmutableMap.of("name", "banana"), null, null); OperationSnapshot operationSnapshot = @@ -100,8 +100,9 @@ public void testMetadataTransformer() { MetadataTransformer transformer = MetadataTransformer.create(FakeMetadataMessage.class); EmptyMessage returnType = EmptyMessage.getDefaultInstance(); - FakeMetadataMessage metadataMessage = new FakeMetadataMessage(Status.PENDING, Code.OK); - FakeOperationMessage operation = new FakeOperationMessage<>("foo", returnType, metadataMessage); + FakeMetadataMessage metadataMessage = new FakeMetadataMessage<>(Status.PENDING, Code.OK); + FakeOperationMessage operation = + new FakeOperationMessage<>("foo", returnType, metadataMessage); OperationSnapshot operationSnapshot = new OperationSnapshotImpl(operation); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(metadataMessage); } @@ -110,10 +111,10 @@ public void testMetadataTransformer() { public void testMetadataTransformer_mismatchedTypes() { MetadataTransformer transformer = MetadataTransformer.create(FakeOperationMessage.class); - FakeMetadataMessage metadataMessage = new FakeMetadataMessage(Status.PENDING, Code.OK); + FakeMetadataMessage metadataMessage = new FakeMetadataMessage<>(Status.PENDING, Code.OK); ApiMessage bananaResponse = new FakeApiMessage(ImmutableMap.of("name", "banana"), null, null); - FakeOperationMessage metadata = + FakeOperationMessage metadata = new FakeOperationMessage<>("No response method", bananaResponse, metadataMessage); OperationSnapshot operationSnapshot = new OperationSnapshotImpl(metadata); try { @@ -139,6 +140,7 @@ public FakeMetadataMessage(Status status, Code code) { this.code = code; } + @Override public Object getFieldValue(String fieldName) { if ("status".equals(fieldName)) { return status; @@ -149,10 +151,12 @@ public Object getFieldValue(String fieldName) { return null; } + @Override public List getFieldMask() { return null; } + @Override public ApiMessage getApiMessageRequestBody() { return null; } @@ -172,6 +176,7 @@ public FakeOperationMessage(String name, ResponseT responseT, MetadataT metadata this.metadata = metadata; } + @Override public Object getFieldValue(String fieldName) { if ("name".equals(fieldName)) { return name; @@ -185,10 +190,12 @@ public Object getFieldValue(String fieldName) { return null; } + @Override public List getFieldMask() { return null; } + @Override public ResponseT getApiMessageRequestBody() { return responseT; } @@ -196,9 +203,9 @@ public ResponseT getApiMessageRequestBody() { private static class OperationSnapshotImpl implements OperationSnapshot { - private final FakeOperationMessage operation; + private final FakeOperationMessage operation; - public OperationSnapshotImpl(FakeOperationMessage operation) { + public OperationSnapshotImpl(FakeOperationMessage operation) { this.operation = operation; } diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java index 9efa4cd7a..4d0785f24 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java @@ -55,7 +55,7 @@ public void testGetSpanName() { for (Entry entry : validNames.entrySet()) { @SuppressWarnings("unchecked") - ApiMethodDescriptor descriptor = + ApiMethodDescriptor descriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName(entry.getKey()) .setHttpMethod(HttpMethods.POST) @@ -74,7 +74,7 @@ public void testGetSpanNameInvalid() { for (String invalidName : invalidNames) { @SuppressWarnings("unchecked") - ApiMethodDescriptor descriptor = + ApiMethodDescriptor descriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName(invalidName) .setHttpMethod(HttpMethods.POST) diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/MockHttpServiceTest.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/MockHttpServiceTest.java index 3571275e9..0fab4d9a0 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/MockHttpServiceTest.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/MockHttpServiceTest.java @@ -143,7 +143,7 @@ public PathTemplate getPathTemplate() { .setResponseParser(PET_RESPONSE_PARSER) .build(); - private static final List SERVER_METHOD_DESCRIPTORS = + private static final List> SERVER_METHOD_DESCRIPTORS = Lists.newArrayList(methodDescriptor); private static MockHttpService testService = diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/longrunning/OperationsClientTest.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/longrunning/OperationsClientTest.java index 96a8ac740..1240ba742 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/longrunning/OperationsClientTest.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/longrunning/OperationsClientTest.java @@ -29,10 +29,9 @@ */ package com.google.api.gax.httpjson.longrunning; -import static com.google.api.gax.httpjson.longrunning.OperationsClient.ListOperationsPagedResponse; - import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.longrunning.OperationsClient.ListOperationsPagedResponse; import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; import com.google.api.gax.httpjson.testing.MockHttpService; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -52,7 +51,6 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -81,16 +79,13 @@ public static void stopServer() { client.close(); } - @Before - public void setUp() {} - @After - public void tearDown() throws Exception { + public void tearDown() { mockService.reset(); } @Test - public void listOperationsTest() throws Exception { + public void listOperationsTest() { Operation responsesElement = Operation.newBuilder().build(); ListOperationsResponse expectedResponse = ListOperationsResponse.newBuilder() @@ -125,7 +120,7 @@ public void listOperationsTest() throws Exception { } @Test - public void listOperationsExceptionTest() throws Exception { + public void listOperationsExceptionTest() { ApiException exception = ApiExceptionFactory.createException( new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); @@ -142,7 +137,7 @@ public void listOperationsExceptionTest() throws Exception { } @Test - public void getOperationTest() throws Exception { + public void getOperationTest() { Operation expectedResponse = Operation.newBuilder() .setName("operations/hey1") @@ -172,7 +167,7 @@ public void getOperationTest() throws Exception { } @Test - public void getOperationExceptionTest() throws Exception { + public void getOperationExceptionTest() { ApiException exception = ApiExceptionFactory.createException( new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); @@ -188,7 +183,7 @@ public void getOperationExceptionTest() throws Exception { } @Test - public void deleteOperationTest() throws Exception { + public void deleteOperationTest() { Empty expectedResponse = Empty.newBuilder().build(); mockService.addResponse(expectedResponse); @@ -212,7 +207,7 @@ public void deleteOperationTest() throws Exception { } @Test - public void deleteOperationExceptionTest() throws Exception { + public void deleteOperationExceptionTest() { ApiException exception = ApiExceptionFactory.createException( new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); @@ -228,7 +223,7 @@ public void deleteOperationExceptionTest() throws Exception { } @Test - public void cancelOperationTest() throws Exception { + public void cancelOperationTest() { Empty expectedResponse = Empty.newBuilder().build(); mockService.addResponse(expectedResponse); @@ -252,7 +247,7 @@ public void cancelOperationTest() throws Exception { } @Test - public void cancelOperationExceptionTest() throws Exception { + public void cancelOperationExceptionTest() { ApiException exception = ApiExceptionFactory.createException( new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java index 68f6fa6b8..d644afd6d 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java @@ -55,7 +55,7 @@ public final class MockHttpService extends MockHttpTransport { private final Multimap requestHeaders = LinkedListMultimap.create(); private final List requestPaths = new LinkedList<>(); private final Queue responseHandlers = new LinkedList<>(); - private List serviceMethodDescriptors; + private List> serviceMethodDescriptors; private String endpoint; /** @@ -66,9 +66,10 @@ public final class MockHttpService extends MockHttpTransport { * @param pathPrefix - the fixed portion of the endpoint URL that prefixes the methods' path * template substring. */ - public MockHttpService(List serviceMethodDescriptors, String pathPrefix) { + public MockHttpService( + List> serviceMethodDescriptors, String pathPrefix) { this.serviceMethodDescriptors = ImmutableList.copyOf(serviceMethodDescriptors); - this.endpoint = pathPrefix; + endpoint = pathPrefix; } @Override diff --git a/gax/src/main/java/com/google/api/gax/rpc/internal/ApiCallContextOptions.java b/gax/src/main/java/com/google/api/gax/rpc/internal/ApiCallContextOptions.java index daf64679c..a0873f309 100644 --- a/gax/src/main/java/com/google/api/gax/rpc/internal/ApiCallContextOptions.java +++ b/gax/src/main/java/com/google/api/gax/rpc/internal/ApiCallContextOptions.java @@ -57,7 +57,7 @@ public static ApiCallContextOptions getDefaultOptions() { public ApiCallContextOptions withOption(Key key, T value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); - ImmutableMap.Builder builder = ImmutableMap.builder(); + ImmutableMap.Builder builder = ImmutableMap.builder(); if (!options.containsKey(key)) { builder.putAll(options).put(key, value); } else { @@ -80,7 +80,8 @@ public T getOption(Key key) { /** Merge new options into existing ones. Any existing values of the keys are overwritten. */ public ApiCallContextOptions merge(ApiCallContextOptions newOptions) { Preconditions.checkNotNull(newOptions); - ImmutableMap.Builder builder = ImmutableMap.builder().putAll(newOptions.options); + ImmutableMap.Builder builder = + ImmutableMap.builder().putAll(newOptions.options); for (Key key : options.keySet()) { if (!newOptions.options.containsKey(key)) { builder.put(key, options.get(key)); diff --git a/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index edcd4908a..5779f72f7 100644 --- a/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -192,7 +192,7 @@ public Currency apply(OperationSnapshot operationSnapshot) { } @After - public void tearDown() throws Exception { + public void tearDown() { executor.shutdown(); } @@ -537,10 +537,9 @@ public void testFutureCallContextPropagation() throws Exception { String opName = "testFutureCallContextPropagation"; Color resp = getColor(0.5f); - Currency meta1 = Currency.getInstance("UAH"); - Currency meta2 = Currency.getInstance("USD"); + Currency meta = Currency.getInstance("USD"); OperationSnapshot initialOperation = getOperation(opName, null, null, null, false); - OperationSnapshot resultOperation = getOperation(opName, resp, null, meta2, true); + OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true); UnaryCallable initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation); @@ -841,7 +840,7 @@ public void testPollServerSideCancel() throws Exception { } @Test - public void call() throws Exception { + public void call() { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable callable = @@ -853,7 +852,7 @@ public void call() throws Exception { } @Test - public void callWithContext() throws Exception { + public void callWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = @@ -1251,7 +1250,7 @@ private ApiFuture newFuture( } private void assertExceptionMatchesCode(FakeStatusCode code, Throwable exception) { - Class expectedClass; + Class expectedClass; switch (code.getCode()) { case CANCELLED: expectedClass = CancelledException.class;