diff --git a/src/main/java/io/lettuce/core/SocketOptions.java b/src/main/java/io/lettuce/core/SocketOptions.java index 87fc919a3b..aa2f6f8fb0 100644 --- a/src/main/java/io/lettuce/core/SocketOptions.java +++ b/src/main/java/io/lettuce/core/SocketOptions.java @@ -36,7 +36,7 @@ public class SocketOptions { public static final boolean DEFAULT_SO_KEEPALIVE = false; - public static final boolean DEFAULT_SO_NO_DELAY = false; + public static final boolean DEFAULT_SO_NO_DELAY = true; private final Duration connectTimeout; @@ -148,10 +148,13 @@ public Builder keepAlive(boolean keepAlive) { } /** - * Sets whether to disable Nagle's algorithm. Defaults to {@code false} (Nagle enabled). See + * Sets whether to disable/enable Nagle's algorithm. Defaults to {@code true} (Nagle disabled). See * {@link #DEFAULT_SO_NO_DELAY}. + *
+ * Disabling TCP NoDelay delays TCP {@code ACK} packets to await more data input before confirming the packet. * - * @param tcpNoDelay {@code true} to disable Nagle's algorithm, {@code false} to enable Nagle's algorithm. + * @param tcpNoDelay {@code false} to disable TCP NoDelay (enable Nagle's algorithm), {@code true} to enable TCP NoDelay + * (disable Nagle's algorithm). * @return {@code this} * @see java.net.SocketOptions#TCP_NODELAY */ diff --git a/src/test/java/io/lettuce/core/SocketOptionsUnitTests.java b/src/test/java/io/lettuce/core/SocketOptionsUnitTests.java index e7f5300f21..d28661d116 100644 --- a/src/test/java/io/lettuce/core/SocketOptionsUnitTests.java +++ b/src/test/java/io/lettuce/core/SocketOptionsUnitTests.java @@ -37,11 +37,11 @@ void testNew() { @Test void testBuilder() { - SocketOptions sut = SocketOptions.builder().connectTimeout(1, TimeUnit.MINUTES).keepAlive(true).tcpNoDelay(true) + SocketOptions sut = SocketOptions.builder().connectTimeout(1, TimeUnit.MINUTES).keepAlive(true).tcpNoDelay(false) .build(); assertThat(sut.isKeepAlive()).isTrue(); - assertThat(sut.isTcpNoDelay()).isTrue(); + assertThat(sut.isTcpNoDelay()).isFalse(); assertThat(sut.getConnectTimeout()).isEqualTo(Duration.ofMinutes(1)); } @@ -67,7 +67,7 @@ void testCopy() { void checkAssertions(SocketOptions sut) { assertThat(sut.isKeepAlive()).isFalse(); - assertThat(sut.isTcpNoDelay()).isFalse(); + assertThat(sut.isTcpNoDelay()).isTrue(); assertThat(sut.getConnectTimeout()).isEqualTo(Duration.ofSeconds(10)); } }