From 1e99b299e19694b4715dacb35eac13638ff70089 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 19 Jan 2017 12:16:05 -0800 Subject: [PATCH] all: ErrorProne fixes and avoid @Beta in Guava --- .../java/io/grpc/internal/ManagedChannelImpl2.java | 7 ++----- .../java/io/grpc/internal/NoopClientStream.java | 2 +- .../internal/ManagedChannelImpl2IdlenessTest.java | 13 ++----------- .../io/grpc/internal/ManagedChannelImpl2Test.java | 8 ++++---- .../testing/integration/AbstractInteropTest.java | 2 +- .../main/java/io/grpc/netty/GrpcSslContexts.java | 6 +++--- .../io/grpc/internal/testing/StatsTestUtils.java | 5 +++-- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl2.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl2.java index a882a34fbc..a1acaac3af 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl2.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl2.java @@ -98,9 +98,6 @@ public final class ManagedChannelImpl2 extends ManagedChannel implements WithLog @VisibleForTesting static final long SUBCHANNEL_SHUTDOWN_DELAY_SECONDS = 5; - private static final ClientTransport SHUTDOWN_TRANSPORT = - new FailingClientTransport(Status.UNAVAILABLE.withDescription("Channel is shutdown")); - @VisibleForTesting static final Status SHUTDOWN_NOW_STATUS = Status.UNAVAILABLE.withDescription("Channel shutdownNow invoked"); @@ -631,12 +628,12 @@ public final class ManagedChannelImpl2 extends ManagedChannel implements WithLog } @Override - public void onInUse(InternalSubchannel is) { + void onInUse(InternalSubchannel is) { inUseStateAggregator.updateObjectInUse(is, true); } @Override - public void onNotInUse(InternalSubchannel is) { + void onNotInUse(InternalSubchannel is) { inUseStateAggregator.updateObjectInUse(is, false); } }); diff --git a/core/src/main/java/io/grpc/internal/NoopClientStream.java b/core/src/main/java/io/grpc/internal/NoopClientStream.java index 221525b44e..9a7e38afa3 100644 --- a/core/src/main/java/io/grpc/internal/NoopClientStream.java +++ b/core/src/main/java/io/grpc/internal/NoopClientStream.java @@ -42,7 +42,7 @@ import java.io.InputStream; * An implementation of {@link ClientStream} that silently does nothing for the operations. */ public class NoopClientStream implements ClientStream { - public static NoopClientStream INSTANCE = new NoopClientStream(); + public static final NoopClientStream INSTANCE = new NoopClientStream(); @Override public void setAuthority(String authority) {} diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImpl2IdlenessTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImpl2IdlenessTest.java index 6af0cc6937..e4760f01d1 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImpl2IdlenessTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImpl2IdlenessTest.java @@ -168,14 +168,10 @@ public class ManagedChannelImpl2IdlenessTest { @Test public void newCallExitsIdleness() throws Exception { - final EquivalentAddressGroup addressGroup = addressGroupList.get(1); - ClientCall call = channel.newCall(method, CallOptions.DEFAULT); call.start(mockCallListener, new Metadata()); - ArgumentCaptor helperCaptor = ArgumentCaptor.forClass(null); - verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture()); - Helper helper = helperCaptor.getValue(); + verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class)); verify(mockNameResolver).start(nameResolverListenerCaptor.capture()); // Simulate new address resolved to make sure the LoadBalancer is correctly linked to @@ -186,17 +182,13 @@ public class ManagedChannelImpl2IdlenessTest { @Test public void newCallRefreshesIdlenessTimer() throws Exception { - final EquivalentAddressGroup addressGroup = addressGroupList.get(1); - // First call to exit the initial idleness, then immediately cancel the call. ClientCall call = channel.newCall(method, CallOptions.DEFAULT); call.start(mockCallListener, new Metadata()); call.cancel("For testing", null); // Verify that we have exited the idle mode - ArgumentCaptor helperCaptor = ArgumentCaptor.forClass(null); - verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture()); - Helper helper = helperCaptor.getValue(); + verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class)); assertFalse(channel.inUseStateAggregator.isInUse()); // Move closer to idleness, but not yet. @@ -297,7 +289,6 @@ public class ManagedChannelImpl2IdlenessTest { @Test public void oobTransportDoesNotAffectIdleness() { - FakeClock oobExecutor = new FakeClock(); // Start a call, which goes to delayed transport ClientCall call = channel.newCall(method, CallOptions.DEFAULT); call.start(mockCallListener, new Metadata()); diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImpl2Test.java b/core/src/test/java/io/grpc/internal/ManagedChannelImpl2Test.java index 0fc0178eb0..2f8a3f5954 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImpl2Test.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImpl2Test.java @@ -816,8 +816,8 @@ public class ManagedChannelImpl2Test { @Test public void subchannelsNoConnectionShutdownNow() { createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR); - Subchannel sub1 = helper.createSubchannel(addressGroup, Attributes.EMPTY); - Subchannel sub2 = helper.createSubchannel(addressGroup, Attributes.EMPTY); + helper.createSubchannel(addressGroup, Attributes.EMPTY); + helper.createSubchannel(addressGroup, Attributes.EMPTY); channel.shutdownNow(); verify(mockLoadBalancer).shutdown(); @@ -975,8 +975,8 @@ public class ManagedChannelImpl2Test { @Test public void oobChannelsNoConnectionShutdownNow() { createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR); - ManagedChannel oob1 = helper.createOobChannel(addressGroup, "oob1Authority"); - ManagedChannel oob2 = helper.createOobChannel(addressGroup, "oob2Authority"); + helper.createOobChannel(addressGroup, "oob1Authority"); + helper.createOobChannel(addressGroup, "oob2Authority"); channel.shutdownNow(); verify(mockLoadBalancer).shutdown(); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 9dd4d0c8dc..d9898395e6 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -42,13 +42,13 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; -import com.google.api.client.repackaged.com.google.common.base.Throwables; import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.ComputeEngineCredentials; import com.google.auth.oauth2.GoogleCredentials; import com.google.auth.oauth2.OAuth2Credentials; import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.net.HostAndPort; diff --git a/netty/src/main/java/io/grpc/netty/GrpcSslContexts.java b/netty/src/main/java/io/grpc/netty/GrpcSslContexts.java index 3278fba2f5..9598234c68 100644 --- a/netty/src/main/java/io/grpc/netty/GrpcSslContexts.java +++ b/netty/src/main/java/io/grpc/netty/GrpcSslContexts.java @@ -81,19 +81,19 @@ public class GrpcSslContexts { * These configs use ACCEPT due to limited support in OpenSSL. Actual protocol enforcement is * done in ProtocolNegotiators. */ - private static ApplicationProtocolConfig ALPN = new ApplicationProtocolConfig( + private static final ApplicationProtocolConfig ALPN = new ApplicationProtocolConfig( Protocol.ALPN, SelectorFailureBehavior.NO_ADVERTISE, SelectedListenerFailureBehavior.ACCEPT, NEXT_PROTOCOL_VERSIONS); - private static ApplicationProtocolConfig NPN = new ApplicationProtocolConfig( + private static final ApplicationProtocolConfig NPN = new ApplicationProtocolConfig( Protocol.NPN, SelectorFailureBehavior.NO_ADVERTISE, SelectedListenerFailureBehavior.ACCEPT, NEXT_PROTOCOL_VERSIONS); - private static ApplicationProtocolConfig NPN_AND_ALPN = new ApplicationProtocolConfig( + private static final ApplicationProtocolConfig NPN_AND_ALPN = new ApplicationProtocolConfig( Protocol.NPN_AND_ALPN, SelectorFailureBehavior.NO_ADVERTISE, SelectedListenerFailureBehavior.ACCEPT, diff --git a/testing/src/main/java/io/grpc/internal/testing/StatsTestUtils.java b/testing/src/main/java/io/grpc/internal/testing/StatsTestUtils.java index 75dacde53d..199b5bd2ec 100644 --- a/testing/src/main/java/io/grpc/internal/testing/StatsTestUtils.java +++ b/testing/src/main/java/io/grpc/internal/testing/StatsTestUtils.java @@ -35,7 +35,6 @@ import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteStreams; import com.google.instrumentation.stats.MeasurementDescriptor; import com.google.instrumentation.stats.MeasurementMap; import com.google.instrumentation.stats.MeasurementValue; @@ -44,6 +43,8 @@ import com.google.instrumentation.stats.StatsContextFactory; import com.google.instrumentation.stats.TagKey; import com.google.instrumentation.stats.TagValue; +import io.grpc.internal.IoUtils; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -138,7 +139,7 @@ public class StatsTestUtils { public StatsContext deserialize(InputStream buffer) { String serializedString; try { - serializedString = new String(ByteStreams.toByteArray(buffer), UTF_8); + serializedString = new String(IoUtils.toByteArray(buffer), UTF_8); } catch (IOException e) { throw new RuntimeException(e); }