Search in sources :

Example 6 with ConnectionWatchdog

use of io.lettuce.core.protocol.ConnectionWatchdog in project lettuce-core by lettuce-io.

the class ConnectionBuilder method createConnectionWatchdog.

protected ConnectionWatchdog createConnectionWatchdog() {
    if (connectionWatchdog != null) {
        return connectionWatchdog;
    }
    LettuceAssert.assertState(bootstrap != null, "Bootstrap must be set for autoReconnect=true");
    LettuceAssert.assertState(socketAddressSupplier != null, "SocketAddressSupplier must be set for autoReconnect=true");
    ConnectionWatchdog watchdog = new ConnectionWatchdog(clientResources.reconnectDelay(), clientOptions, bootstrap, clientResources.timer(), clientResources.eventExecutorGroup(), socketAddressSupplier, reconnectionListener, connection, clientResources.eventBus(), endpoint);
    endpoint.registerConnectionWatchdog(watchdog);
    connectionWatchdog = watchdog;
    return watchdog;
}
Also used : ConnectionWatchdog(io.lettuce.core.protocol.ConnectionWatchdog)

Example 7 with ConnectionWatchdog

use of io.lettuce.core.protocol.ConnectionWatchdog in project lettuce-core by lettuce-io.

the class AtLeastOnceTest method commandNotFailedChannelClosesWhileFlush.

@Test
void commandNotFailedChannelClosesWhileFlush() {
    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));
    StatefulRedisConnection<String, String> connection = client.connect();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);
    RedisCommands<String, String> sync = connection.sync();
    sync.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");
    final CountDownLatch block = new CountDownLatch(1);
    ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(connection);
    AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);
    channelWriter.write(command);
    connectionWatchdog.setReconnectSuspended(true);
    Channel channel = ConnectionTestUtil.getChannel(connection);
    channel.unsafe().disconnect(channel.newPromise());
    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    assertThat(verificationConnection.get(key)).isEqualTo("1");
    assertThat(ConnectionTestUtil.getStack(connection)).isEmpty();
    assertThat(ConnectionTestUtil.getCommandBuffer(connection)).isNotEmpty().contains(command);
    connection.close();
}
Also used : ConnectionWatchdog(io.lettuce.core.protocol.ConnectionWatchdog) Channel(io.netty.channel.Channel) RedisChannelWriter(io.lettuce.core.RedisChannelWriter) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractRedisClientTest(io.lettuce.core.AbstractRedisClientTest) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionWatchdog (io.lettuce.core.protocol.ConnectionWatchdog)7 AbstractRedisClientTest (io.lettuce.core.AbstractRedisClientTest)5 Test (org.junit.jupiter.api.Test)5 Channel (io.netty.channel.Channel)3 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 RedisCommandTimeoutException (io.lettuce.core.RedisCommandTimeoutException)1 RedisException (io.lettuce.core.RedisException)1 AsyncCloseable (io.lettuce.core.internal.AsyncCloseable)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionStage (java.util.concurrent.CompletionStage)1