diff --git a/src/main/java/io/nats/client/impl/NatsJetStreamPullSubscription.java b/src/main/java/io/nats/client/impl/NatsJetStreamPullSubscription.java index b814d5dd4..bb50859ff 100644 --- a/src/main/java/io/nats/client/impl/NatsJetStreamPullSubscription.java +++ b/src/main/java/io/nats/client/impl/NatsJetStreamPullSubscription.java @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; -import static io.nats.client.support.Validator.validatePullBatchSize; +import static io.nats.client.support.Validator.validateGtZero; public class NatsJetStreamPullSubscription extends NatsJetStreamSubscription { @@ -100,7 +100,7 @@ public void pullExpiresIn(int batchSize, long expiresInMillis) { } private void _pull(int batchSize, boolean noWait, Duration expiresIn) { - int batch = validatePullBatchSize(batchSize); + int batch = validateGtZero(batchSize, "Pull batch size"); String publishSubject = js.prependPrefix(String.format(JSAPI_CONSUMER_MSG_NEXT, stream, consumerName)); connection.publish(publishSubject, getSubject(), getPullJson(batch, noWait, expiresIn)); connection.lenientFlushBuffer(); diff --git a/src/main/java/io/nats/client/support/NatsJetStreamConstants.java b/src/main/java/io/nats/client/support/NatsJetStreamConstants.java index c43175101..9c378bb5a 100644 --- a/src/main/java/io/nats/client/support/NatsJetStreamConstants.java +++ b/src/main/java/io/nats/client/support/NatsJetStreamConstants.java @@ -2,8 +2,9 @@ public interface NatsJetStreamConstants { /** - * The maximum pull size + * The maximum pull size [NO LONGER ENFORCED] */ + @Deprecated int MAX_PULL_SIZE = 256; /** diff --git a/src/main/java/io/nats/client/support/Validator.java b/src/main/java/io/nats/client/support/Validator.java index 0257adbfa..eb1d5d2cc 100644 --- a/src/main/java/io/nats/client/support/Validator.java +++ b/src/main/java/io/nats/client/support/Validator.java @@ -18,7 +18,6 @@ import static io.nats.client.support.NatsConstants.DOT; import static io.nats.client.support.NatsJetStreamConstants.MAX_HISTORY_PER_KEY; -import static io.nats.client.support.NatsJetStreamConstants.MAX_PULL_SIZE; public abstract class Validator { private Validator() { @@ -174,13 +173,6 @@ public static String validateNonWildcardKvKey(String s, String label, boolean re }); } - public static int validatePullBatchSize(int pullBatchSize) { - if (pullBatchSize < 1 || pullBatchSize > MAX_PULL_SIZE) { - throw new IllegalArgumentException("Pull Batch Size must be between 1 and " + MAX_PULL_SIZE + " inclusive [" + pullBatchSize + "]"); - } - return pullBatchSize; - } - public static long validateMaxConsumers(long max) { return validateGtZeroOrMinus1(max, "Max Consumers"); } @@ -256,6 +248,13 @@ public static void validateNotNull(Object o, String fieldName) { } } + public static int validateGtZero(int i, String label) { + if (i < 1) { + throw new IllegalArgumentException(label + " must be greater than zero"); + } + return i; + } + public static long validateGtZeroOrMinus1(long l, String label) { if (zeroOrLtMinus1(l)) { throw new IllegalArgumentException(label + " must be greater than zero or -1 for unlimited"); diff --git a/src/test/java/io/nats/client/support/ValidatorTests.java b/src/test/java/io/nats/client/support/ValidatorTests.java index 448d7baef..558cbc69c 100644 --- a/src/test/java/io/nats/client/support/ValidatorTests.java +++ b/src/test/java/io/nats/client/support/ValidatorTests.java @@ -21,7 +21,6 @@ import java.util.List; import static io.nats.client.support.NatsConstants.EMPTY; -import static io.nats.client.support.NatsJetStreamConstants.MAX_PULL_SIZE; import static io.nats.client.support.Validator.*; import static io.nats.client.utils.ResourceUtils.dataAsLines; import static io.nats.client.utils.TestBase.*; @@ -79,15 +78,6 @@ public void testValidateDurable() { allowedNotRequiredEmptyAsNull(Validator::validateDurable, Arrays.asList(null, EMPTY)); } - @Test - public void testValidatePullBatchSize() { - assertEquals(1, validatePullBatchSize(1)); - assertEquals(MAX_PULL_SIZE, validatePullBatchSize(MAX_PULL_SIZE)); - assertThrows(IllegalArgumentException.class, () -> validatePullBatchSize(0)); - assertThrows(IllegalArgumentException.class, () -> validatePullBatchSize(-1)); - assertThrows(IllegalArgumentException.class, () -> validatePullBatchSize(MAX_PULL_SIZE + 1)); - } - @Test public void testValidateMaxConsumers() { assertEquals(1, validateMaxConsumers(1)); @@ -304,6 +294,13 @@ public void testZeroOrLtMinus1() { assertFalse(zeroOrLtMinus1(-1)); } + @Test + public void testValidateGtZero() { + assertEquals(1, validateGtZero(1, "test")); + assertThrows(IllegalArgumentException.class, () -> validateGtZero(0, "test")); + assertThrows(IllegalArgumentException.class, () -> validateGtZero(-1, "test")); + } + @Test public void testValidateGtZeroOrMinus1() { assertEquals(1, validateGtZeroOrMinus1(1, "test"));