@Test public void subchannels() { createChannel(); Attributes attrs1 = Attributes.newBuilder().set(SUBCHANNEL_ATTR_KEY, "attr1").build(); Attributes attrs2 = Attributes.newBuilder().set(SUBCHANNEL_ATTR_KEY, "attr2").build(); Subchannel sub1 = createSubchannelSafely(helper, addressGroup, attrs1); Subchannel sub2 = createSubchannelSafely(helper, addressGroup, attrs2); assertNotSame(sub1, sub2); assertNotSame(attrs1, attrs2); assertSame(attrs1, sub1.getAttributes()); assertSame(attrs2, sub2.getAttributes()); assertSame(addressGroup, sub1.getAddresses()); assertSame(addressGroup, sub2.getAddresses()); verify(mockTransportFactory, never()) .newClientTransport(any(SocketAddress.class), any(ClientTransportOptions.class)); sub1.requestConnection(); verify(mockTransportFactory).newClientTransport(socketAddress, clientTransportOptions); MockClientTransportInfo transportInfo1 = transports.poll(); assertNotNull(transportInfo1); sub2.requestConnection(); verify(mockTransportFactory, times(2)) .newClientTransport(socketAddress, clientTransportOptions); MockClientTransportInfo transportInfo2 = transports.poll(); assertNotNull(transportInfo2); sub1.requestConnection(); sub2.requestConnection(); verify(mockTransportFactory, times(2)) .newClientTransport(socketAddress, clientTransportOptions); sub1.shutdown(); timer.forwardTime(ManagedChannelImpl.SUBCHANNEL_SHUTDOWN_DELAY_SECONDS - 1, TimeUnit.SECONDS); sub1.shutdown(); verify(transportInfo1.transport, never()).shutdown(any(Status.class)); timer.forwardTime(1, TimeUnit.SECONDS); verify(transportInfo1.transport).shutdown(same(ManagedChannelImpl.SUBCHANNEL_SHUTDOWN_STATUS)); verify(mockLoadBalancer, never()).shutdown(); channel.shutdown(); verify(mockLoadBalancer).shutdown(); verify(transportInfo2.transport, never()).shutdown(any(Status.class)); sub2.shutdown(); verify(transportInfo2.transport).shutdown(same(ManagedChannelImpl.SHUTDOWN_STATUS)); transportInfo1.listener.transportShutdown(Status.UNAVAILABLE); transportInfo1.listener.transportTerminated(); transportInfo2.listener.transportShutdown(Status.UNAVAILABLE); transportInfo2.listener.transportTerminated(); timer.forwardTime(ManagedChannelImpl.SUBCHANNEL_SHUTDOWN_DELAY_SECONDS, TimeUnit.SECONDS); }
@Override public ManagedChannelImpl shutdown() { channelLogger.log(ChannelLogLevel.DEBUG, "shutdown() called"); if (!shutdown.compareAndSet(false, true)) { return this; } final class Shutdown implements Runnable { @Override public void run() { channelLogger.log(ChannelLogLevel.INFO, "Entering SHUTDOWN state"); channelStateManager.gotoState(SHUTDOWN); } } syncContext.executeLater(new Shutdown()); uncommittedRetriableStreamsRegistry.onShutdown(SHUTDOWN_STATUS); final class CancelIdleTimer implements Runnable { @Override public void run() { cancelIdleTimer( true); } } syncContext.execute(new CancelIdleTimer()); return this; }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public ManagedChannelImpl shutdown() { channelLogger.log(ChannelLogLevel.DEBUG, "shutdown() called"); if (!shutdown.compareAndSet(false, true)) { return this; } final class Shutdown implements Runnable { @Override public void run() { channelLogger.log(ChannelLogLevel.INFO, "Entering SHUTDOWN state"); channelStateManager.gotoState(SHUTDOWN); } } syncContext.executeLater(new Shutdown()); uncommittedRetriableStreamsRegistry.onShutdown(SHUTDOWN_STATUS); final class CancelIdleTimer implements Runnable { @Override public void run() { cancelIdleTimer( true); } } syncContext.execute(new CancelIdleTimer()); return this; } }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public ManagedChannelImpl shutdown() { channelLogger.log(ChannelLogLevel.DEBUG, "shutdown() called"); if (!shutdown.compareAndSet(false, true)) { return this; } final class Shutdown implements Runnable { @Override public void run() { channelLogger.log(ChannelLogLevel.INFO, "Entering SHUTDOWN state"); channelStateManager.gotoState(SHUTDOWN); } } syncContext.executeLater(new Shutdown()); uncommittedRetriableStreamsRegistry.onShutdown(SHUTDOWN_STATUS); final class CancelIdleTimer implements Runnable { @Override public void run() { cancelIdleTimer( true); } } syncContext.execute(new CancelIdleTimer()); return this; } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public ManagedChannelImpl shutdown() { channelLogger.log(ChannelLogLevel.DEBUG, "shutdown() called"); if (!shutdown.compareAndSet(false, true)) { return this; } final class Shutdown implements Runnable { @Override public void run() { channelLogger.log(ChannelLogLevel.INFO, "Entering SHUTDOWN state"); channelStateManager.gotoState(SHUTDOWN); } } syncContext.executeLater(new Shutdown()); uncommittedRetriableStreamsRegistry.onShutdown(SHUTDOWN_STATUS); final class CancelIdleTimer implements Runnable { @Override public void run() { cancelIdleTimer( true); } } syncContext.execute(new CancelIdleTimer()); return this; } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); @Override ListenableFuture<ChannelStats> getStats(); @Override InternalLogId getLogId(); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override ConnectivityState getState(boolean requestConnection); @Override void notifyWhenStateChanged(final ConnectivityState source, final Runnable callback); @Override void resetConnectBackoff(); @Override void enterIdle(); @Override String toString(); @Override Map<String, String> getLoadBalanceModeMap(); @Override void setLoadBalanceModeMap(Map<String, String> map); @Override NameResolver getNameResolver(); @Override LoadBalancer getLoadBalancer(); }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public ManagedChannelImpl shutdown() { channelLogger.log(ChannelLogLevel.DEBUG, "shutdown() called"); if (!shutdown.compareAndSet(false, true)) { return this; } final class Shutdown implements Runnable { @Override public void run() { channelLogger.log(ChannelLogLevel.INFO, "Entering SHUTDOWN state"); channelStateManager.gotoState(SHUTDOWN); } } syncContext.executeLater(new Shutdown()); uncommittedRetriableStreamsRegistry.onShutdown(SHUTDOWN_STATUS); final class CancelIdleTimer implements Runnable { @Override public void run() { cancelIdleTimer( true); } } syncContext.execute(new CancelIdleTimer()); return this; } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); @Override ListenableFuture<ChannelStats> getStats(); @Override InternalLogId getLogId(); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override ConnectivityState getState(boolean requestConnection); @Override void notifyWhenStateChanged(final ConnectivityState source, final Runnable callback); @Override void resetConnectBackoff(); @Override void enterIdle(); @Override String toString(); @Override Map<String, String> getLoadBalanceModeMap(); @Override void setLoadBalanceModeMap(Map<String, String> map); @Override NameResolver getNameResolver(); @Override LoadBalancer getLoadBalancer();  }