diff --git a/pom.xml b/pom.xml index 1c6e8f9e9..f1ed92340 100644 --- a/pom.xml +++ b/pom.xml @@ -394,7 +394,7 @@ 4.12.0 4.7.7 3.6.1 - 5.4.4 + 5.6.3 1.21.0 3.0.7 1.5.3.Final diff --git a/src/main/java/com/mindee/v2/MindeeClient.java b/src/main/java/com/mindee/v2/MindeeClient.java index 9f9f2042c..2648fa688 100644 --- a/src/main/java/com/mindee/v2/MindeeClient.java +++ b/src/main/java/com/mindee/v2/MindeeClient.java @@ -261,12 +261,10 @@ private TResponse pollAndFetch( JobResponse resp = initialJob; int attempts = 0; int max = pollingOptions.getMaxRetries(); - double currentIntervalSec = pollingOptions.getIntervalSec(); - double maxIntervalSec = pollingOptions.getMaxIntervalSec(); - double backoffMultiplier = pollingOptions.getBackoffMultiplier(); + long intervalMillis = (long) (pollingOptions.getIntervalSec() * 1000); while (attempts < max) { - interruptibleSleep((long) (currentIntervalSec * 1000), pollingOptions); + interruptibleSleep(intervalMillis, pollingOptions); resp = getJob(initialJob.getJob().getId()); if (resp.getJob().getStatus().equals("Failed")) { @@ -275,7 +273,6 @@ private TResponse pollAndFetch( if (resp.getJob().getStatus().equals("Processed")) { return getResult(responseClass, resp.getJob().getId()); } - currentIntervalSec = Math.min(currentIntervalSec * backoffMultiplier, maxIntervalSec); attempts++; } diff --git a/src/main/java/com/mindee/v2/clientoptions/PollingOptions.java b/src/main/java/com/mindee/v2/clientoptions/PollingOptions.java index 20003cb08..1588fdc01 100644 --- a/src/main/java/com/mindee/v2/clientoptions/PollingOptions.java +++ b/src/main/java/com/mindee/v2/clientoptions/PollingOptions.java @@ -6,21 +6,6 @@ import lombok.Getter; public class PollingOptions extends BasePollingOptions { - - /** - * Multiplier applied to {@code intervalSec} after each poll attempt to implement - * exponential backoff. Must be ≥ 1.0. A value of 1.0 disables backoff. - */ - @Getter - private final Double backoffMultiplier; - - /** - * Upper bound (in seconds) for the polling interval after backoff is applied. - * Must be ≥ {@code intervalSec}. - */ - @Getter - private final Double maxIntervalSec; - /** * Optional cancellation signal. When it evaluates to {@code true}, polling is * aborted with a {@link java.util.concurrent.CancellationException}. Also, @@ -34,21 +19,10 @@ public PollingOptions( Double initialDelaySec, Double intervalSec, Integer maxRetries, - Double backoffMultiplier, - Double maxIntervalSec, BooleanSupplier cancelToken ) { super(initialDelaySec, intervalSec, maxRetries, 3.0, 1.5, 100, 1.0, 1.0, 2); - this.backoffMultiplier = backoffMultiplier == null ? 1.5 : backoffMultiplier; - if (this.backoffMultiplier < 1.0) { - throw new IllegalArgumentException("Backoff multiplier must be ≥ 1.0"); - } - this.maxIntervalSec = maxIntervalSec == null ? 60.0 : maxIntervalSec; - if (this.maxIntervalSec < this.getIntervalSec()) { - throw new IllegalArgumentException( - "Max interval must be ≥ interval (" + this.getIntervalSec() + ")" - ); - } + this.cancelToken = cancelToken == null ? () -> false : cancelToken; } } diff --git a/src/test/java/com/mindee/v2/MindeeClientTest.java b/src/test/java/com/mindee/v2/MindeeClientTest.java index 0ccc98b49..772ee8e9d 100644 --- a/src/test/java/com/mindee/v2/MindeeClientTest.java +++ b/src/test/java/com/mindee/v2/MindeeClientTest.java @@ -233,7 +233,7 @@ void blankUrl_throws() { } @Nested - @DisplayName("polling with cancellation and backoff") + @DisplayName("polling with cancellation") class Polling { private JobResponse processing() throws JsonProcessingException { String json = "{\"job\": {\"id\": \"dummy-id\", \"status\": \"Processing\"}}"; @@ -284,21 +284,5 @@ public JobResponse reqGetJobById(String jobId) { assertTrue(jobCalls.get() >= 1, "at least one poll should occur before cancellation"); } - @Test - @DisplayName("interval grows with backoff up to maxIntervalSec") - void polling_backoff_caps() { - var options = PollingOptions - .builder() - .intervalSec(1.0) - .backoffMultiplier(2.0) - .maxIntervalSec(5.0) - .build(); - - double interval = options.getIntervalSec(); - for (int i = 0; i < 10; i++) { - interval = Math.min(interval * options.getBackoffMultiplier(), options.getMaxIntervalSec()); - } - assertEquals(5.0, interval); - } } } diff --git a/src/test/java/com/mindee/v2/clientoptions/PollingOptionsTest.java b/src/test/java/com/mindee/v2/clientoptions/PollingOptionsTest.java index 18a95f2bf..5b51e2e1c 100644 --- a/src/test/java/com/mindee/v2/clientoptions/PollingOptionsTest.java +++ b/src/test/java/com/mindee/v2/clientoptions/PollingOptionsTest.java @@ -13,8 +13,6 @@ void shouldSetDefaultValues() { Assertions.assertEquals(3.0, pollingOptions.getInitialDelaySec()); Assertions.assertEquals(1.5, pollingOptions.getIntervalSec()); Assertions.assertEquals(100, pollingOptions.getMaxRetries()); - Assertions.assertEquals(1.5, pollingOptions.getBackoffMultiplier()); - Assertions.assertEquals(60.0, pollingOptions.getMaxIntervalSec()); Assertions.assertNotNull(pollingOptions.getCancelToken()); Assertions.assertFalse(pollingOptions.getCancelToken().getAsBoolean()); } @@ -27,16 +25,12 @@ void shouldSetCustomValues() { .initialDelaySec(4.0) .intervalSec(2.5) .maxRetries(50) - .backoffMultiplier(2.0) - .maxIntervalSec(30.0) .cancelToken(cancelled::get) .build(); Assertions.assertEquals(4.0, pollingOptions.getInitialDelaySec()); Assertions.assertEquals(2.5, pollingOptions.getIntervalSec()); Assertions.assertEquals(50, pollingOptions.getMaxRetries()); - Assertions.assertEquals(2.0, pollingOptions.getBackoffMultiplier()); - Assertions.assertEquals(30.0, pollingOptions.getMaxIntervalSec()); Assertions.assertFalse(pollingOptions.getCancelToken().getAsBoolean()); cancelled.set(true); @@ -52,24 +46,4 @@ void shouldThrowWhenInitialDelayIsTooLow() { ); Assertions.assertEquals("Initial delay must be ≥ 1.0", exception.getMessage()); } - - @Test - void shouldThrowWhenBackoffMultiplierIsTooLow() { - IllegalArgumentException exception = Assertions - .assertThrows( - IllegalArgumentException.class, - () -> PollingOptions.builder().backoffMultiplier(0.9).build() - ); - Assertions.assertEquals("Backoff multiplier must be ≥ 1.0", exception.getMessage()); - } - - @Test - void shouldThrowWhenMaxIntervalIsBelowInterval() { - IllegalArgumentException exception = Assertions - .assertThrows( - IllegalArgumentException.class, - () -> PollingOptions.builder().intervalSec(5.0).maxIntervalSec(2.0).build() - ); - Assertions.assertTrue(exception.getMessage().startsWith("Max interval must be ≥ interval")); - } }