This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push: new ae7139f5 PROTON-2803 Fix default reconnect options max reconnect delay ae7139f5 is described below commit ae7139f5de691f1abd834a7c4d29631bbbe755a4 Author: Timothy Bish <tabish...@gmail.com> AuthorDate: Tue Mar 12 17:38:37 2024 -0400 PROTON-2803 Fix default reconnect options max reconnect delay Set the max reconnect delay in client reconnect options to the default value of 30s and not the initial delay of 10ms. Adds some tests --- .../qpid/protonj2/client/ReconnectOptions.java | 8 +++-- .../protonj2/client/RecconnectOptionsTest.java | 35 ++++++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/ReconnectOptions.java b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/ReconnectOptions.java index 4c0fe40f..6bf96d26 100644 --- a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/ReconnectOptions.java +++ b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/ReconnectOptions.java @@ -19,6 +19,7 @@ package org.apache.qpid.protonj2.client; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; /** * Options that control the reconnection behavior of a client {@link Connection}. @@ -40,7 +41,7 @@ public class ReconnectOptions implements Cloneable { private int maxInitialConnectionAttempts = INFINITE; private int maxReconnectAttempts = INFINITE; private int reconnectDelay = DEFAULT_RECONNECT_DELAY; - private int maxReconnectDelay = DEFAULT_RECONNECT_DELAY; + private int maxReconnectDelay = DEFAULT_MAX_RECONNECT_DELAY; private boolean useReconnectBackOff = DEFAULT_USE_RECONNECT_BACKOFF; private double reconnectBackOffMultiplier = DEFAULT_RECONNECT_BACKOFF_MULTIPLIER; @@ -127,6 +128,7 @@ public class ReconnectOptions implements Cloneable { * @return this {@link ReconnectOptions} instance. */ public ReconnectOptions addReconnectLocation(String host, int port) { + Objects.requireNonNull(host, "Reconnect host cannot be null"); reconnectHosts.add(new ReconnectLocation(host, port)); return this; } @@ -169,7 +171,7 @@ public class ReconnectOptions implements Cloneable { /** * For a client that has never connected to a remote peer before this option controls how many attempts * are made to connect before reporting the connection as failed. The default behavior is to use the - * value of maxReconnectAttempts. + * value of maxReconnectAttempts (which defaults to try forever). * * @param maxInitialConnectionAttempts * the maximum number of initial connection attempts to try before giving up. @@ -203,7 +205,7 @@ public class ReconnectOptions implements Cloneable { } /** - * @return the configured reconnect delay to use after between attempts to connect or reconnect. + * @return the configured reconnect delay to use in between attempts to connect or reconnect. */ public int reconnectDelay() { return reconnectDelay; diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/RecconnectOptionsTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/RecconnectOptionsTest.java index 6a8ee93a..1adeff06 100644 --- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/RecconnectOptionsTest.java +++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/RecconnectOptionsTest.java @@ -17,32 +17,41 @@ package org.apache.qpid.protonj2.client; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Test; public class RecconnectOptionsTest { @Test - void testCreate() { - ConnectionOptions options = new ConnectionOptions(); - - assertNull(options.password()); - assertNull(options.user()); + public void testCreate() { + ReconnectOptions options = new ReconnectOptions(); + + assertEquals(options.reconnectEnabled(), ReconnectOptions.DEFAULT_RECONNECT_ENABLED); + assertEquals(options.warnAfterReconnectAttempts(), ReconnectOptions.DEFAULT_WARN_AFTER_RECONNECT_ATTEMPTS); + assertEquals(options.maxInitialConnectionAttempts(), ReconnectOptions.INFINITE); + assertEquals(options.maxReconnectAttempts(), ReconnectOptions.INFINITE); + assertEquals(options.reconnectBackOffMultiplier(), ReconnectOptions.DEFAULT_RECONNECT_BACKOFF_MULTIPLIER); + assertEquals(options.useReconnectBackOff(), ReconnectOptions.DEFAULT_USE_RECONNECT_BACKOFF); + assertEquals(options.maxReconnectDelay(), ReconnectOptions.DEFAULT_MAX_RECONNECT_DELAY); + assertEquals(options.reconnectDelay(), ReconnectOptions.DEFAULT_RECONNECT_DELAY); } @Test - void testCopy() { - ConnectionOptions options = new ConnectionOptions(); + public void testCopy() { + ReconnectOptions options = new ReconnectOptions(); - options.user("test"); - options.password("test-pass"); + options.useReconnectBackOff(true); + options.maxReconnectAttempts(50); + options.maxReconnectDelay(15); - ConnectionOptions copy = options.clone(); + ReconnectOptions copy = options.clone(); assertNotSame(copy, options); - assertEquals(options.user(), copy.user()); - assertEquals(options.password(), copy.password()); + assertFalse(options.reconnectEnabled()); + assertEquals(options.useReconnectBackOff(), true); + assertEquals(options.maxReconnectAttempts(), 50); + assertEquals(options.maxReconnectDelay(), 15); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org