22 lines
668 B
Java
22 lines
668 B
Java
package com.example.mtusi_messenger.queue;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.time.Duration;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
class RetryPolicyTest {
|
|
@Test
|
|
void appliesExponentialBackoffWithBoundedJitter() {
|
|
RetryPolicy policy = new RetryPolicy(Duration.ofSeconds(1), Duration.ofSeconds(30));
|
|
|
|
for (int attempt = 2; attempt <= 8; attempt++) {
|
|
long ceiling = Math.min(30_000L, 1_000L << (attempt - 2));
|
|
long delay = policy.delayForAttempt(attempt).toMillis();
|
|
assertTrue(delay >= Math.max(1, ceiling / 2));
|
|
assertTrue(delay <= ceiling);
|
|
}
|
|
}
|
|
}
|