From cf215dea7117d086c35b0ee8d3e8ef351de2142a Mon Sep 17 00:00:00 2001 From: Thach Le Date: Fri, 13 Sep 2024 19:51:42 +0700 Subject: [PATCH] Default ClientOptions.timeoutOptions to TimeoutOptions.enabled() (#2927) * Default ClientOptions.timeoutOptions to TimeoutOptions.enabled() * Update ConnectionFailureIntegrationTests * Update ClientOptionsIntegrationTests, RedisClusterSetupTest, AtMostOneceTest * Update AtLeastOnceTest --- .../java/io/lettuce/core/ClientOptions.java | 2 +- .../core/ClientOptionsIntegrationTests.java | 29 ++++++++++++------- .../core/cluster/RedisClusterSetupTest.java | 15 ++++++---- .../ConnectionFailureIntegrationTests.java | 17 +++++++---- .../core/reliability/AtLeastOnceTest.java | 4 ++- .../core/reliability/AtMostOnceTest.java | 4 ++- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/lettuce/core/ClientOptions.java b/src/main/java/io/lettuce/core/ClientOptions.java index aa3d2ba188..3e32967bf1 100644 --- a/src/main/java/io/lettuce/core/ClientOptions.java +++ b/src/main/java/io/lettuce/core/ClientOptions.java @@ -67,7 +67,7 @@ public class ClientOptions implements Serializable { public static final boolean DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL = false; - public static final TimeoutOptions DEFAULT_TIMEOUT_OPTIONS = TimeoutOptions.create(); + public static final TimeoutOptions DEFAULT_TIMEOUT_OPTIONS = TimeoutOptions.enabled(); private final boolean autoReconnect; diff --git a/src/test/java/io/lettuce/core/ClientOptionsIntegrationTests.java b/src/test/java/io/lettuce/core/ClientOptionsIntegrationTests.java index 347ec18e92..8ca4c896e6 100644 --- a/src/test/java/io/lettuce/core/ClientOptionsIntegrationTests.java +++ b/src/test/java/io/lettuce/core/ClientOptionsIntegrationTests.java @@ -92,7 +92,8 @@ void variousClientOptions() { @Test void requestQueueSize() { - client.setOptions(ClientOptions.builder().requestQueueSize(10).build()); + client.setOptions(ClientOptions.builder().requestQueueSize(10) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); StatefulRedisConnection connection = client.connect(); getConnectionWatchdog(connection).setListenOnChannelInactive(false); @@ -115,7 +116,8 @@ void requestQueueSize() { @Test void requestQueueSizeAppliedForReconnect() { - client.setOptions(ClientOptions.builder().requestQueueSize(10).build()); + client.setOptions(ClientOptions.builder().requestQueueSize(10) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAsyncCommands connection = client.connect().async(); testHitRequestQueueLimit(connection); @@ -127,7 +129,7 @@ void testHitRequestQueueLimitReconnectWithAuthCommand() { WithPassword.run(client, () -> { client.setOptions(ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).pingBeforeActivateConnection(false) - .requestQueueSize(10).build()); + .requestQueueSize(10).timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAsyncCommands connection = client.connect().async(); connection.auth(passwd); @@ -142,7 +144,7 @@ void testHitRequestQueueLimitReconnectWithAuthUsernamePasswordCommand() { WithPassword.run(client, () -> { client.setOptions(ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).pingBeforeActivateConnection(false) - .requestQueueSize(10).build()); + .requestQueueSize(10).timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAsyncCommands connection = client.connect().async(); connection.auth(username, passwd); @@ -154,7 +156,9 @@ void testHitRequestQueueLimitReconnectWithAuthUsernamePasswordCommand() { void testHitRequestQueueLimitReconnectWithUriAuth() { WithPassword.run(client, () -> { - client.setOptions(ClientOptions.builder().requestQueueSize(10).build()); + client.setOptions(ClientOptions.builder().requestQueueSize(10) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); + ; RedisURI redisURI = RedisURI.create(host, port); redisURI.setPassword(passwd); @@ -169,7 +173,8 @@ void testHitRequestQueueLimitReconnectWithUriAuthPingCommand() { WithPassword.run(client, () -> { - client.setOptions(ClientOptions.builder().requestQueueSize(10).build()); + client.setOptions(ClientOptions.builder().requestQueueSize(10) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisURI redisURI = RedisURI.create(host, port); redisURI.setPassword(passwd); @@ -207,7 +212,8 @@ private void testHitRequestQueueLimit(RedisAsyncCommands connect @Test void requestQueueSizeOvercommittedReconnect() { - client.setOptions(ClientOptions.builder().requestQueueSize(10).build()); + client.setOptions(ClientOptions.builder().requestQueueSize(10) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); StatefulRedisConnection connection = client.connect(); ConnectionWatchdog watchdog = getConnectionWatchdog(connection); @@ -262,8 +268,8 @@ void disconnectedWithoutReconnect() { @Test void disconnectedRejectCommands() { - client.setOptions( - ClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build()); + client.setOptions(ClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAsyncCommands connection = client.connect().async(); @@ -471,7 +477,8 @@ void timeoutExpiresBatchedCommands() { @Test void pingBeforeConnectWithQueuedCommandsAndReconnect() throws Exception { - + client.setOptions( + ClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); StatefulRedisConnection controlConnection = client.connect(); StatefulRedisConnection redisConnection = client.connect(RedisURI.create("redis://localhost:6479/5")); @@ -513,6 +520,8 @@ void authenticatedPingBeforeConnectWithQueuedCommandsAndReconnect() { WithPassword.run(client, () -> { RedisURI redisURI = RedisURI.Builder.redis(host, port).withPassword(passwd).withDatabase(5).build(); + client.setOptions( + ClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); StatefulRedisConnection controlConnection = client.connect(redisURI); StatefulRedisConnection redisConnection = client.connect(redisURI); diff --git a/src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java b/src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java index ce956e0dea..14e7a4bed4 100644 --- a/src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java +++ b/src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java @@ -31,6 +31,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import io.lettuce.core.TimeoutOptions; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -303,10 +304,12 @@ public void slotMigrationShouldUseAsking() { public void disconnectedConnectionRejectTest() throws Exception { clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED) - .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build()); + .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAdvancedClusterAsyncCommands clusterConnection = clusterClient.connect().async(); - clusterClient.setOptions(ClusterClientOptions.builder() - .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build()); + clusterClient.setOptions( + ClusterClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); ClusterSetup.setup2Masters(clusterHelper); assertRoutedExecution(clusterConnection); @@ -330,9 +333,11 @@ public void disconnectedConnectionRejectTest() throws Exception { @Test public void atLeastOnceForgetNodeFailover() throws Exception { - clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED).build()); + clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisAdvancedClusterAsyncCommands clusterConnection = clusterClient.connect().async(); - clusterClient.setOptions(ClusterClientOptions.create()); + clusterClient.setOptions( + ClusterClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); ClusterSetup.setup2Masters(clusterHelper); assertRoutedExecution(clusterConnection); diff --git a/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java b/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java index 38f759c371..d2f720d3fe 100644 --- a/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java +++ b/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java @@ -89,7 +89,8 @@ void invalidFirstByte() throws Exception { @Test void failOnReconnect() throws Exception { - ClientOptions clientOptions = ClientOptions.builder().suspendReconnectOnProtocolFailure(true).build(); + ClientOptions clientOptions = ClientOptions.builder().suspendReconnectOnProtocolFailure(true) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build(); client.setOptions(clientOptions); RandomResponseServer ts = getRandomResponseServer(); @@ -133,7 +134,8 @@ void failOnReconnect() throws Exception { @Test void failOnReconnectShouldSendEvents() throws Exception { - client.setOptions(ClientOptions.builder().suspendReconnectOnProtocolFailure(false).build()); + client.setOptions(ClientOptions.builder().suspendReconnectOnProtocolFailure(false) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RandomResponseServer ts = getRandomResponseServer(); @@ -181,7 +183,8 @@ void failOnReconnectShouldSendEvents() throws Exception { @Test void cancelCommandsOnReconnectFailure() throws Exception { - client.setOptions(ClientOptions.builder().cancelCommandsOnReconnectFailure(true).build()); + client.setOptions(ClientOptions.builder().cancelCommandsOnReconnectFailure(true) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RandomResponseServer ts = getRandomResponseServer(); @@ -235,7 +238,8 @@ void emitEventOnReconnectFailure() throws Exception { RedisURI redisUri = RedisURI.create(defaultRedisUri.toURI()); RedisClient client = RedisClient.create(clientResources); - client.setOptions(ClientOptions.builder().build()); + client.setOptions( + ClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); try { RedisAsyncCommandsImpl connection = (RedisAsyncCommandsImpl) client @@ -329,7 +333,8 @@ public void afterChannelInitialized(Channel channel) { RedisURI redisUri = RedisURI.create(TestSettings.host(), TestSettings.port()); RedisClient client = RedisClient.create(clientResources, redisUri); - client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build()); + client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); StatefulRedisConnection connection = client.connect(); @@ -365,6 +370,8 @@ public void afterChannelInitialized(Channel channel) { void closingDisconnectedConnectionShouldDisableConnectionWatchdog() { client.setOptions(ClientOptions.create()); + client.setOptions( + ClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); RedisURI redisUri = RedisURI.Builder.redis(TestSettings.host(), TestSettings.port()).withTimeout(Duration.ofMinutes(10)) .build(); diff --git a/src/test/java/io/lettuce/core/reliability/AtLeastOnceTest.java b/src/test/java/io/lettuce/core/reliability/AtLeastOnceTest.java index b290075057..9243d301d5 100644 --- a/src/test/java/io/lettuce/core/reliability/AtLeastOnceTest.java +++ b/src/test/java/io/lettuce/core/reliability/AtLeastOnceTest.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import io.lettuce.core.TimeoutOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,7 +45,8 @@ class AtLeastOnceTest extends AbstractRedisClientTest { @BeforeEach void before() { - client.setOptions(ClientOptions.builder().autoReconnect(true).build()); + client.setOptions(ClientOptions.builder().autoReconnect(true) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); // needs to be increased on slow systems...perhaps... client.setDefaultTimeout(3, TimeUnit.SECONDS); diff --git a/src/test/java/io/lettuce/core/reliability/AtMostOnceTest.java b/src/test/java/io/lettuce/core/reliability/AtMostOnceTest.java index 7963d5a98e..4bc3406c09 100644 --- a/src/test/java/io/lettuce/core/reliability/AtMostOnceTest.java +++ b/src/test/java/io/lettuce/core/reliability/AtMostOnceTest.java @@ -9,6 +9,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import io.lettuce.core.TimeoutOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,7 +47,8 @@ class AtMostOnceTest extends AbstractRedisClientTest { @BeforeEach void before() { - client.setOptions(ClientOptions.builder().autoReconnect(false).build()); + client.setOptions(ClientOptions.builder().autoReconnect(false) + .timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build()); // needs to be increased on slow systems...perhaps... client.setDefaultTimeout(3, TimeUnit.SECONDS);