diff --git a/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java b/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java index 0955f3a3b1..8a0f4f1085 100644 --- a/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java +++ b/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java @@ -90,8 +90,8 @@ public class CallCredentialsApplyingTest { @Mock private SocketAddress address; - private static final String authority = "testauthority"; - private static final String userAgent = "testuseragent"; + private static final String AUTHORITY = "testauthority"; + private static final String USER_AGENT = "testuseragent"; private static final Attributes.Key ATTR_KEY = Attributes.Key.of("somekey"); private static final String ATTR_VALUE = "somevalue"; private static final MethodDescriptor method = MethodDescriptor.create( @@ -112,16 +112,16 @@ public class CallCredentialsApplyingTest { public void setUp() { MockitoAnnotations.initMocks(this); origHeaders.put(ORIG_HEADER_KEY, ORIG_HEADER_VALUE); - when(mockTransportFactory.newClientTransport(address, authority, userAgent)) + when(mockTransportFactory.newClientTransport(address, AUTHORITY, USER_AGENT)) .thenReturn(mockTransport); when(mockTransport.newStream(same(method), any(Metadata.class), any(CallOptions.class))) .thenReturn(mockStream); ClientTransportFactory transportFactory = new CallCredentialsApplyingTransportFactory( mockTransportFactory, mockExecutor); transport = (ForwardingConnectionClientTransport) transportFactory.newClientTransport( - address, authority, userAgent); + address, AUTHORITY, USER_AGENT); callOptions = CallOptions.DEFAULT.withCallCredentials(mockCreds); - verify(mockTransportFactory).newClientTransport(address, authority, userAgent); + verify(mockTransportFactory).newClientTransport(address, AUTHORITY, USER_AGENT); assertSame(mockTransport, transport.delegate()); } @@ -137,7 +137,7 @@ public class CallCredentialsApplyingTest { any(MetadataApplier.class)); Attributes attrs = attrsCaptor.getValue(); assertSame(ATTR_VALUE, attrs.get(ATTR_KEY)); - assertSame(authority, attrs.get(CallCredentials.ATTR_AUTHORITY)); + assertSame(AUTHORITY, attrs.get(CallCredentials.ATTR_AUTHORITY)); assertSame(SecurityLevel.NONE, attrs.get(CallCredentials.ATTR_SECURITY_LEVEL)); } diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java index b99c992fab..f1aed26075 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java @@ -62,7 +62,6 @@ import io.grpc.ResolvedServerInfo; import io.grpc.ResolvedServerInfoGroup; import io.grpc.Status; import io.grpc.StringMarshaller; -import io.grpc.TransportManager.InterimTransport; import io.grpc.TransportManager.OobTransportProvider; import io.grpc.TransportManager; import io.grpc.internal.TestUtils.MockClientTransportInfo; @@ -98,8 +97,8 @@ import java.util.concurrent.TimeUnit; public class ManagedChannelImplIdlenessTest { private final FakeClock timer = new FakeClock(); private final FakeClock executor = new FakeClock(); - private static final String authority = "fakeauthority"; - private static final String userAgent = "fakeagent"; + private static final String AUTHORITY = "fakeauthority"; + private static final String USER_AGENT = "fakeagent"; private static final long IDLE_TIMEOUT_SECONDS = 30; private ManagedChannelImpl channel; @@ -128,7 +127,7 @@ public class ManagedChannelImplIdlenessTest { when(mockLoadBalancerFactory .newLoadBalancer(anyString(), Matchers.>any())) .thenReturn(mockLoadBalancer); - when(mockNameResolver.getServiceAuthority()).thenReturn(authority); + when(mockNameResolver.getServiceAuthority()).thenReturn(AUTHORITY); when(mockNameResolverFactory .newNameResolver(any(URI.class), any(Attributes.class))) .thenReturn(mockNameResolver); @@ -138,7 +137,7 @@ public class ManagedChannelImplIdlenessTest { mockTransportFactory, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), timerService, timer.getStopwatchSupplier(), TimeUnit.SECONDS.toMillis(IDLE_TIMEOUT_SECONDS), - executor.getScheduledExecutorService(), userAgent, + executor.getScheduledExecutorService(), USER_AGENT, Collections.emptyList()); newTransports = TestUtils.captureTransports(mockTransportFactory); @@ -187,7 +186,7 @@ public class ManagedChannelImplIdlenessTest { // LoadBalancer is used right after created. verify(mockLoadBalancer).pickTransport(any(Attributes.class)); verify(mockTransportFactory).newClientTransport( - addressGroup.getAddresses().get(0), authority, userAgent); + addressGroup.getAddresses().get(0), AUTHORITY, USER_AGENT); // Simulate new address resolved nameResolverListenerCaptor.getValue().onUpdate(servers, Attributes.EMPTY); @@ -202,13 +201,13 @@ public class ManagedChannelImplIdlenessTest { for (EquivalentAddressGroup addressGroup : addressGroupList) { channel.tm.getTransport(addressGroup); verify(mockTransportFactory).newClientTransport( - addressGroup.getAddresses().get(0), authority, userAgent); + addressGroup.getAddresses().get(0), AUTHORITY, USER_AGENT); } ArrayList transports = new ArrayList(); newTransports.drainTo(transports); assertEquals(addressGroupList.size(), transports.size()); - InterimTransport interimTransport = channel.tm.createInterimTransport(); + channel.tm.createInterimTransport(); // Without actually using these transports, will eventually enter idle mode walkIntoIdleMode(transports); @@ -216,7 +215,6 @@ public class ManagedChannelImplIdlenessTest { @Test public void interimTransportHoldsOffIdleness() throws Exception { - final EquivalentAddressGroup addressGroup = addressGroupList.get(1); doAnswer(new Answer() { @Override public ClientTransport answer(InvocationOnMock invocation) throws Throwable { @@ -321,7 +319,7 @@ public class ManagedChannelImplIdlenessTest { assertSame(ManagedChannelImpl.IDLE_MODE_TRANSPORT, channel.tm.getTransport(addressGroupList.get(0))); OobTransportProvider oobProvider = - channel.tm.createOobTransportProvider(addressGroupList.get(0), "authority"); + channel.tm.createOobTransportProvider(addressGroupList.get(0), AUTHORITY); assertSame(ManagedChannelImpl.IDLE_MODE_TRANSPORT, oobProvider.get()); oobProvider.close(); verify(mockTransportFactory, never()).newClientTransport( diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java index dab7bf46eb..cbb705310d 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java @@ -833,7 +833,6 @@ public class ManagedChannelImplTest { @Test public void informationPropagatedToNewStreamAndCallCredentials() { createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR); - Metadata headers = new Metadata(); CallOptions callOptions = CallOptions.DEFAULT.withCallCredentials(creds); final Context.Key testKey = Context.key("testing"); Context ctx = Context.current().withValue(testKey, "testValue"); diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTransportManagerTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTransportManagerTest.java index 9a97e95a14..425a26dc1f 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTransportManagerTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTransportManagerTest.java @@ -89,8 +89,8 @@ import java.util.concurrent.TimeUnit; @RunWith(JUnit4.class) public class ManagedChannelImplTransportManagerTest { - private static final String authority = "fakeauthority"; - private static final String userAgent = "mosaic"; + private static final String AUTHORITY = "fakeauthority"; + private static final String USER_AGENT = "mosaic"; private final ExecutorService executor = Executors.newSingleThreadExecutor(); private final MethodDescriptor method = MethodDescriptor.create( @@ -120,7 +120,7 @@ public class ManagedChannelImplTransportManagerTest { MockitoAnnotations.initMocks(this); when(mockBackoffPolicyProvider.get()).thenReturn(mockBackoffPolicy); - when(mockNameResolver.getServiceAuthority()).thenReturn(authority); + when(mockNameResolver.getServiceAuthority()).thenReturn(AUTHORITY); when(mockNameResolverFactory .newNameResolver(any(URI.class), any(Attributes.class))) .thenReturn(mockNameResolver); @@ -135,7 +135,7 @@ public class ManagedChannelImplTransportManagerTest { mockTransportFactory, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), GrpcUtil.TIMER_SERVICE, GrpcUtil.STOPWATCH_SUPPLIER, ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE, - executor, userAgent, Collections.emptyList()); + executor, USER_AGENT, Collections.emptyList()); ArgumentCaptor> tmCaptor = ArgumentCaptor.forClass(null); @@ -160,7 +160,7 @@ public class ManagedChannelImplTransportManagerTest { SocketAddress addr = mock(SocketAddress.class); EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(addr); ClientTransport t1 = tm.getTransport(addressGroup); - verify(mockTransportFactory, timeout(1000)).newClientTransport(addr, authority, userAgent); + verify(mockTransportFactory, timeout(1000)).newClientTransport(addr, AUTHORITY, USER_AGENT); // The real transport MockClientTransportInfo transportInfo = transports.poll(1, TimeUnit.SECONDS); transportInfo.listener.transportReady(); @@ -185,7 +185,7 @@ public class ManagedChannelImplTransportManagerTest { // Pick the first transport ClientTransport t1 = tm.getTransport(addressGroup); assertNotNull(t1); - verify(mockTransportFactory, timeout(1000)).newClientTransport(addr1, authority, userAgent); + verify(mockTransportFactory, timeout(1000)).newClientTransport(addr1, AUTHORITY, USER_AGENT); verify(mockBackoffPolicyProvider, times(backoffReset)).get(); // Fail the first transport, without setting it to ready MockClientTransportInfo transportInfo = transports.poll(1, TimeUnit.SECONDS); @@ -197,7 +197,7 @@ public class ManagedChannelImplTransportManagerTest { assertNotNull(t2); t2.newStream(method, new Metadata(), callOptions); // Will keep the previous back-off policy, and not consult back-off policy - verify(mockTransportFactory, timeout(1000)).newClientTransport(addr2, authority, userAgent); + verify(mockTransportFactory, timeout(1000)).newClientTransport(addr2, AUTHORITY, USER_AGENT); verify(mockBackoffPolicyProvider, times(backoffReset)).get(); transportInfo = transports.poll(1, TimeUnit.SECONDS); ClientTransport rt2 = transportInfo.transport; @@ -215,7 +215,7 @@ public class ManagedChannelImplTransportManagerTest { ClientTransport t3 = tm.getTransport(addressGroup); t3.newStream(method2, new Metadata(), callOptions2); verify(mockTransportFactory, timeout(1000).times(2)) - .newClientTransport(addr1, authority, userAgent); + .newClientTransport(addr1, AUTHORITY, USER_AGENT); // Still no back-off policy creation, because an address succeeded. verify(mockBackoffPolicyProvider, times(backoffReset)).get(); transportInfo = transports.poll(1, TimeUnit.SECONDS); @@ -249,7 +249,7 @@ public class ManagedChannelImplTransportManagerTest { ClientTransport t1 = tm.getTransport(addressGroup); assertNotNull(t1); verify(mockTransportFactory, timeout(1000).times(++transportsAddr1)) - .newClientTransport(addr1, authority, userAgent); + .newClientTransport(addr1, AUTHORITY, USER_AGENT); // Back-off policy was unset initially. verify(mockBackoffPolicyProvider, times(backoffReset)).get(); MockClientTransportInfo transportInfo = transports.poll(1, TimeUnit.SECONDS); @@ -263,7 +263,7 @@ public class ManagedChannelImplTransportManagerTest { ClientTransport t2 = tm.getTransport(addressGroup); assertNotNull(t2); verify(mockTransportFactory, timeout(1000).times(++transportsAddr1)) - .newClientTransport(addr1, authority, userAgent); + .newClientTransport(addr1, AUTHORITY, USER_AGENT); // Back-off policy was not reset. verify(mockBackoffPolicyProvider, times(backoffReset)).get(); transports.poll(1, TimeUnit.SECONDS).listener.transportShutdown(Status.UNAVAILABLE); @@ -273,7 +273,7 @@ public class ManagedChannelImplTransportManagerTest { ClientTransport t3 = tm.getTransport(addressGroup); assertNotNull(t3); verify(mockTransportFactory, timeout(1000).times(++transportsAddr2)) - .newClientTransport(addr2, authority, userAgent); + .newClientTransport(addr2, AUTHORITY, USER_AGENT); // Back-off policy was not reset. verify(mockBackoffPolicyProvider, times(backoffReset)).get(); transports.poll(1, TimeUnit.SECONDS).listener.transportShutdown(Status.UNAVAILABLE); @@ -285,7 +285,7 @@ public class ManagedChannelImplTransportManagerTest { // If backoff's DelayedTransport is still active, this is necessary. Otherwise it would be racy. t4.newStream(method, new Metadata(), CallOptions.DEFAULT.withWaitForReady()); verify(mockTransportFactory, timeout(1000).times(++transportsAddr1)) - .newClientTransport(addr1, authority, userAgent); + .newClientTransport(addr1, AUTHORITY, USER_AGENT); // Back-off policy was reset and consulted. verify(mockBackoffPolicyProvider, times(++backoffReset)).get(); verify(mockBackoffPolicy, times(++backoffConsulted)).nextBackoffMillis(); @@ -344,7 +344,7 @@ public class ManagedChannelImplTransportManagerTest { ClientTransport t1 = p1.get(); assertNotNull(t1); assertSame(t1, p1.get()); - verify(mockTransportFactory, timeout(1000)).newClientTransport(addr, oobAuthority, userAgent); + verify(mockTransportFactory, timeout(1000)).newClientTransport(addr, oobAuthority, USER_AGENT); MockClientTransportInfo transportInfo1 = transports.poll(1, TimeUnit.SECONDS); // OOB transport providers are not indexed by addresses, thus each time it creates @@ -354,7 +354,7 @@ public class ManagedChannelImplTransportManagerTest { assertNotSame(p1, p2); ClientTransport t2 = p2.get(); verify(mockTransportFactory, timeout(1000).times(2)) - .newClientTransport(addr, oobAuthority, userAgent); + .newClientTransport(addr, oobAuthority, USER_AGENT); assertNotSame(t1, t2); MockClientTransportInfo transportInfo2 = transports.poll(1, TimeUnit.SECONDS); assertNotSame(transportInfo1.transport, transportInfo2.transport); diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java index 8f4cb039c5..1a67c4faab 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java @@ -80,7 +80,6 @@ import io.netty.handler.codec.http2.StreamBufferingEncoder; import io.netty.handler.logging.LogLevel; import java.nio.channels.ClosedChannelException; -import java.util.Random; import java.util.concurrent.Executor; import java.util.logging.Level; import java.util.logging.Logger; @@ -108,7 +107,6 @@ class NettyClientHandler extends AbstractNettyHandler { private final Http2Connection.PropertyKey streamKey; private final ClientTransportLifecycleManager lifecycleManager; private final Ticker ticker; - private final Random random = new Random(); private WriteQueue clientWriteQueue; private Http2Ping ping; diff --git a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java index 03ac983208..3b1f5c9d02 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java @@ -566,7 +566,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase