NettyChannelHealthChecker implements ChannelHealthChecker { @Override public Future<Boolean> isHealthy( Channel channel ) { if ( isTooOld( channel ) ) { return channel.eventLoop().newSucceededFuture( Boolean.FALSE ); } if ( hasBeenIdleForTooLong( channel ) ) { return ping( channel ); } return ACTIVE.isHealthy( channel ); } NettyChannelHealthChecker( PoolSettings poolSettings, Clock clock, Logging logging ); @Override Future<Boolean> isHealthy( Channel channel );  }
@Test void shouldDropTooOldChannelsWhenMaxLifetimeEnabled() { int maxLifetime = 1000; PoolSettings settings = new PoolSettings( DEFAULT_MAX_CONNECTION_POOL_SIZE, DEFAULT_CONNECTION_ACQUISITION_TIMEOUT, maxLifetime, DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST ); Clock clock = Clock.SYSTEM; NettyChannelHealthChecker healthChecker = newHealthChecker( settings, clock ); setCreationTimestamp( channel, clock.millis() - maxLifetime * 2 ); Future<Boolean> healthy = healthChecker.isHealthy( channel ); assertThat( await( healthy ), is( false ) ); }
@Test void shouldAllowVeryOldChannelsWhenMaxLifetimeDisabled() { PoolSettings settings = new PoolSettings( DEFAULT_MAX_CONNECTION_POOL_SIZE, DEFAULT_CONNECTION_ACQUISITION_TIMEOUT, NOT_CONFIGURED, DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST ); NettyChannelHealthChecker healthChecker = newHealthChecker( settings, Clock.SYSTEM ); setCreationTimestamp( channel, 0 ); Future<Boolean> healthy = healthChecker.isHealthy( channel ); assertThat( await( healthy ), is( true ) ); }