use of io.lettuce.core.resource.NettyCustomizer in project lettuce-core by lettuce-io.
the class ConnectionFailureIntegrationTests method pingOnConnectFailureShouldCloseConnectionOnReconnect.
@Test
void pingOnConnectFailureShouldCloseConnectionOnReconnect() throws Exception {
BlockingQueue<Channel> ref = new LinkedBlockingQueue<>();
ClientResources clientResources = ClientResources.builder().nettyCustomizer(new NettyCustomizer() {
@Override
public void afterChannelInitialized(Channel channel) {
ref.add(channel);
}
}).build();
RedisURI redisUri = RedisURI.create(TestSettings.host(), TestSettings.port());
RedisClient client = RedisClient.create(clientResources, redisUri);
client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
StatefulRedisConnection<String, String> connection = client.connect();
ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(connection);
connectionWatchdog.setListenOnChannelInactive(false);
connection.async().quit();
// Cluster node with auth
redisUri.setPort(7385);
connectionWatchdog.setListenOnChannelInactive(true);
connectionWatchdog.scheduleReconnect();
Wait.untilTrue(() -> ref.size() > 1).waitOrTimeout();
redisUri.setPort(TestSettings.port());
Channel initial = ref.take();
assertThat(initial.isOpen()).isFalse();
Channel reconnect = ref.take();
Wait.untilTrue(() -> !reconnect.isOpen()).waitOrTimeout();
assertThat(reconnect.isOpen()).isFalse();
FastShutdown.shutdown(client);
FastShutdown.shutdown(clientResources);
}
use of io.lettuce.core.resource.NettyCustomizer in project lettuce-core by lettuce-io.
the class ConnectionFailureIntegrationTests method pingOnConnectFailureShouldCloseConnection.
@Test
void pingOnConnectFailureShouldCloseConnection() throws Exception {
AtomicReference<Channel> ref = new AtomicReference<>();
ClientResources clientResources = ClientResources.builder().nettyCustomizer(new NettyCustomizer() {
@Override
public void afterChannelInitialized(Channel channel) {
ref.set(channel);
}
}).build();
// Cluster node with auth
RedisURI redisUri = RedisURI.create(TestSettings.host(), 7385);
RedisClient client = RedisClient.create(clientResources);
client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
try {
client.connect(redisUri);
fail("Missing Exception");
} catch (Exception e) {
Wait.untilEquals(false, ref.get()::isRegistered).waitOrTimeout();
assertThat(ref.get().isOpen()).isFalse();
Wait.untilEquals(false, () -> ref.get().isRegistered()).waitOrTimeout();
} finally {
FastShutdown.shutdown(client);
FastShutdown.shutdown(clientResources);
}
}
Aggregations