@Test public void connectIsLazy() { SocketAddress addr = mock(SocketAddress.class); createTransportSet(addr); int transportsCreated = 0; verify(mockTransportFactory, times(transportsCreated)).newClientTransport(addr, authority); assertNotNull(transportSet.obtainActiveTransport()); verify(mockTransportFactory, times(++transportsCreated)).newClientTransport(addr, authority); transports.poll().listener.transportShutdown(Status.UNAVAILABLE); fakeClock.forwardMillis(10); verify(mockTransportFactory, times(transportsCreated)).newClientTransport(addr, authority); assertNotNull(transportSet.obtainActiveTransport()); verify(mockTransportFactory, times(++transportsCreated)).newClientTransport(addr, authority); transports.poll().listener.transportShutdown(Status.UNAVAILABLE); assertNotNull(transportSet.obtainActiveTransport()); verify(mockTransportFactory, times(transportsCreated)).newClientTransport(addr, authority); fakeClock.forwardMillis(100); verify(mockTransportFactory, times(++transportsCreated)).newClientTransport(addr, authority); }
final ClientTransport obtainActiveTransport() { ClientTransport savedTransport = activeTransport; if (savedTransport != null) { return savedTransport; } synchronized (lock) { if (activeTransport == null) { if (shutdown) { return SHUTDOWN_TRANSPORT; } DelayedClientTransport delayedTransport = new DelayedClientTransport(appExecutor); transports.add(delayedTransport); delayedTransport.start(new BaseTransportListener(delayedTransport)); activeTransport = delayedTransport; scheduleConnection(delayedTransport); } return activeTransport; } }
TransportSet implements WithLogId { final ClientTransport obtainActiveTransport() { ClientTransport savedTransport = activeTransport; if (savedTransport != null) { return savedTransport; } synchronized (lock) { if (activeTransport == null) { if (shutdown) { return SHUTDOWN_TRANSPORT; } DelayedClientTransport delayedTransport = new DelayedClientTransport(appExecutor); transports.add(delayedTransport); delayedTransport.start(new BaseTransportListener(delayedTransport)); activeTransport = delayedTransport; scheduleConnection(delayedTransport); } return activeTransport; } } }
TransportSet implements WithLogId { final ClientTransport obtainActiveTransport() { ClientTransport savedTransport = activeTransport; if (savedTransport != null) { return savedTransport; } synchronized (lock) { if (activeTransport == null) { if (shutdown) { return SHUTDOWN_TRANSPORT; } DelayedClientTransport delayedTransport = new DelayedClientTransport(appExecutor); transports.add(delayedTransport); delayedTransport.start(new BaseTransportListener(delayedTransport)); activeTransport = delayedTransport; scheduleConnection(delayedTransport); } return activeTransport; } } TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback); @VisibleForTesting  TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback, Stopwatch backoffWatch); }
TransportSet implements WithLogId { final ClientTransport obtainActiveTransport() { ClientTransport savedTransport = activeTransport; if (savedTransport != null) { return savedTransport; } synchronized (lock) { if (activeTransport == null) { if (shutdown) { return SHUTDOWN_TRANSPORT; } DelayedClientTransport delayedTransport = new DelayedClientTransport(appExecutor); transports.add(delayedTransport); delayedTransport.start(new BaseTransportListener(delayedTransport)); activeTransport = delayedTransport; scheduleConnection(delayedTransport); } return activeTransport; } } TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback); @VisibleForTesting  TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback, Stopwatch backoffWatch); @Override String getLogId(); }
TransportSet implements WithLogId { final ClientTransport obtainActiveTransport() { ClientTransport savedTransport = activeTransport; if (savedTransport != null) { return savedTransport; } synchronized (lock) { if (activeTransport == null) { if (shutdown) { return SHUTDOWN_TRANSPORT; } DelayedClientTransport delayedTransport = new DelayedClientTransport(appExecutor); transports.add(delayedTransport); delayedTransport.start(new BaseTransportListener(delayedTransport)); activeTransport = delayedTransport; scheduleConnection(delayedTransport); } return activeTransport; } } TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback); @VisibleForTesting  TransportSet(EquivalentAddressGroup addressGroup, String authority,
      LoadBalancer<ClientTransport> loadBalancer, BackoffPolicy.Provider backoffPolicyProvider,
      ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor,
      Executor appExecutor, Callback callback, Stopwatch backoffWatch); @Override String getLogId();  }