Search in sources :

Example 1 with NettyCustomizer

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);
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) Channel(io.netty.channel.Channel) NettyCustomizer(io.lettuce.core.resource.NettyCustomizer) Test(org.junit.jupiter.api.Test)

Example 2 with NettyCustomizer

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);
    }
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) Channel(io.netty.channel.Channel) NettyCustomizer(io.lettuce.core.resource.NettyCustomizer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

ClientResources (io.lettuce.core.resource.ClientResources)2 NettyCustomizer (io.lettuce.core.resource.NettyCustomizer)2 Channel (io.netty.channel.Channel)2 Test (org.junit.jupiter.api.Test)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1