Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default ClientOptions.timeoutOptions to TimeoutOptions.enabled() #2927

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
29 changes: 19 additions & 10 deletions src/test/java/io/lettuce/core/ClientOptionsIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> connection = client.connect();
getConnectionWatchdog(connection).setListenOnChannelInactive(false);
Expand All @@ -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<String, String> connection = client.connect().async();
testHitRequestQueueLimit(connection);
Expand All @@ -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<String, String> connection = client.connect().async();
connection.auth(passwd);
Expand All @@ -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<String, String> connection = client.connect().async();
connection.auth(username, passwd);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -207,7 +212,8 @@ private void testHitRequestQueueLimit(RedisAsyncCommands<String, String> 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<String, String> connection = client.connect();
ConnectionWatchdog watchdog = getConnectionWatchdog(connection);
Expand Down Expand Up @@ -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<String, String> connection = client.connect().async();

Expand Down Expand Up @@ -471,7 +477,8 @@ void timeoutExpiresBatchedCommands() {

@Test
void pingBeforeConnectWithQueuedCommandsAndReconnect() throws Exception {

client.setOptions(
ClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build());
StatefulRedisConnection<String, String> controlConnection = client.connect();

StatefulRedisConnection<String, String> redisConnection = client.connect(RedisURI.create("redis://localhost:6479/5"));
Expand Down Expand Up @@ -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<String, String> controlConnection = client.connect(redisURI);

StatefulRedisConnection<String, String> redisConnection = client.connect(redisURI);
Expand Down
15 changes: 10 additions & 5 deletions src/test/java/io/lettuce/core/cluster/RedisClusterSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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);
Expand All @@ -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<String, String> clusterConnection = clusterClient.connect().async();
clusterClient.setOptions(ClusterClientOptions.create());
clusterClient.setOptions(
ClusterClientOptions.builder().timeoutOptions(TimeoutOptions.builder().timeoutCommands(false).build()).build());
ClusterSetup.setup2Masters(clusterHelper);

assertRoutedExecution(clusterConnection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<String, String> connection = (RedisAsyncCommandsImpl<String, String>) client
Expand Down Expand Up @@ -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<String, String> connection = client.connect();

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Loading