From 84cab2eccc6e3fd4fc1895f4111356fe96d50c5b Mon Sep 17 00:00:00 2001 From: renjiez Date: Fri, 14 Jun 2024 17:12:36 +0000 Subject: [PATCH] Update common-jvm to 0.85.0 --- MODULE.bazel | 2 +- MODULE.bazel.lock | 70 ++++++------- .../org/wfanet/measurement/common/BUILD.bazel | 5 - .../measurement/common/ExponentialBackoff.kt | 84 ---------------- .../duchy/daemon/herald/BUILD.bazel | 1 - .../internal/computationcontrol/BUILD.bazel | 1 - .../loadtest/measurementconsumer/BUILD.bazel | 1 - .../org/wfanet/measurement/common/BUILD.bazel | 12 --- .../common/ExponentialBackoffTest.kt | 98 ------------------- 9 files changed, 36 insertions(+), 238 deletions(-) delete mode 100644 src/main/kotlin/org/wfanet/measurement/common/ExponentialBackoff.kt delete mode 100644 src/test/kotlin/org/wfanet/measurement/common/ExponentialBackoffTest.kt diff --git a/MODULE.bazel b/MODULE.bazel index 186522d9805..fcd4bd10283 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -124,7 +124,7 @@ bazel_dep( ) bazel_dep( name = "common-jvm", - version = "0.83.0", + version = "0.85.0", repo_name = "wfa_common_jvm", ) bazel_dep( diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 77af001540d..0463b7fbb4d 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 6, - "moduleFileHash": "e414b86bdbb16e52a2f5fee383d824ac72a430286f041c27d2e6b3a899b42328", + "moduleFileHash": "7730fca7d457c3664097ac88f886c42bf9fd8a3e3f3872754a127dad27d987df", "flags": { "cmdRegistries": [ "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main", @@ -371,7 +371,7 @@ "wfa_rules_kotlin_jvm": "rules_kotlin_jvm@0.2.0", "wfa_rules_swig": "rules_swig@0.1.0", "wfa_rules_cue": "rules_cue@0.4.0", - "wfa_common_jvm": "common-jvm@0.83.0", + "wfa_common_jvm": "common-jvm@0.85.0", "wfa_common_cpp": "common-cpp@0.12.0", "wfa_measurement_proto": "cross-media-measurement-api@0.62.0", "wfa_consent_signaling_client": "consent-signaling-client@0.22.0", @@ -2021,10 +2021,10 @@ } } }, - "common-jvm@0.83.0": { + "common-jvm@0.85.0": { "name": "common-jvm", - "version": "0.83.0", - "key": "common-jvm@0.83.0", + "version": "0.85.0", + "key": "common-jvm@0.85.0", "repoName": "wfa_common_jvm", "executionPlatformsToRegister": [], "toolchainsToRegister": [], @@ -2032,9 +2032,9 @@ { "extensionBzlFile": "@rules_jvm_external//:extensions.bzl", "extensionName": "maven", - "usingModule": "common-jvm@0.83.0", + "usingModule": "common-jvm@0.85.0", "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 82, "column": 22 }, @@ -2053,7 +2053,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 83, "column": 15 } @@ -2068,7 +2068,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 89, "column": 15 } @@ -2083,7 +2083,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 95, "column": 15 } @@ -2098,7 +2098,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 101, "column": 15 } @@ -2113,7 +2113,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 107, "column": 15 } @@ -2128,7 +2128,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 113, "column": 15 } @@ -2143,7 +2143,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 119, "column": 15 } @@ -2158,7 +2158,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 125, "column": 15 } @@ -2173,7 +2173,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 131, "column": 15 } @@ -2188,7 +2188,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 137, "column": 15 } @@ -2203,7 +2203,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 143, "column": 15 } @@ -2218,7 +2218,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 149, "column": 15 } @@ -2235,7 +2235,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 155, "column": 15 } @@ -2250,7 +2250,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 163, "column": 15 } @@ -2325,7 +2325,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 170, "column": 14 } @@ -2337,9 +2337,9 @@ { "extensionBzlFile": "@rules_oci//oci:extensions.bzl", "extensionName": "oci", - "usingModule": "common-jvm@0.83.0", + "usingModule": "common-jvm@0.85.0", "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 253, "column": 20 }, @@ -2361,7 +2361,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 254, "column": 9 } @@ -2378,7 +2378,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 261, "column": 9 } @@ -2390,9 +2390,9 @@ { "extensionBzlFile": "//:MODULE.bazel", "extensionName": "_repo_rules", - "usingModule": "common-jvm@0.83.0", + "usingModule": "common-jvm@0.85.0", "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 0, "column": 0 }, @@ -2414,7 +2414,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 276, "column": 13 } @@ -2430,7 +2430,7 @@ }, "devDependency": false, "location": { - "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/MODULE.bazel", + "file": "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/MODULE.bazel", "line": 283, "column": 13 } @@ -2461,12 +2461,12 @@ "ruleClassName": "http_archive", "attributes": { "urls": [ - "https://github.com/world-federation-of-advertisers/common-jvm/archive/refs/tags/v0.83.0.tar.gz" + "https://github.com/world-federation-of-advertisers/common-jvm/archive/refs/tags/v0.85.0.tar.gz" ], - "integrity": "sha256-nHVHcqSkkgOrgflYekqwYxOtQepehGedsXKzJzRir64=", - "strip_prefix": "common-jvm-0.83.0", + "integrity": "sha256-tvMyIYUjoogWNpzlXym+u2o9AP47Xx4OMJYWgodxreI=", + "strip_prefix": "common-jvm-0.85.0", "remote_patches": { - "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.83.0/patches/module_dot_bazel.patch": "sha256-+kOSNaR+TGjfNzU/v/9Kg8I9lMPKGFFL6v/EJ84YIwI=" + "https://raw.githubusercontent.com/world-federation-of-advertisers/bazel-registry/main/modules/common-jvm/0.85.0/patches/module_dot_bazel.patch": "sha256-koY4IUT+PBKl1OafjFXLTJ2slD3fUa4fvNQg3diB9CA=" }, "remote_patch_strip": 0 } @@ -2604,7 +2604,7 @@ "deps": { "wfa_rules_kotlin_jvm": "rules_kotlin_jvm@0.2.0", "wfa_measurement_proto": "cross-media-measurement-api@0.62.0", - "wfa_common_jvm": "common-jvm@0.83.0", + "wfa_common_jvm": "common-jvm@0.85.0", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" }, diff --git a/src/main/kotlin/org/wfanet/measurement/common/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/common/BUILD.bazel index 2c474d42e4f..c904b6d5c9c 100644 --- a/src/main/kotlin/org/wfanet/measurement/common/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/common/BUILD.bazel @@ -2,11 +2,6 @@ load("@wfa_rules_kotlin_jvm//kotlin:defs.bzl", "kt_jvm_library") package(default_visibility = ["//visibility:public"]) -kt_jvm_library( - name = "exponential_backoff", - srcs = ["ExponentialBackoff.kt"], -) - kt_jvm_library( name = "flows", srcs = ["Flows.kt"], diff --git a/src/main/kotlin/org/wfanet/measurement/common/ExponentialBackoff.kt b/src/main/kotlin/org/wfanet/measurement/common/ExponentialBackoff.kt deleted file mode 100644 index e9ed772c77d..00000000000 --- a/src/main/kotlin/org/wfanet/measurement/common/ExponentialBackoff.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2023 The Cross-Media Measurement Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.wfanet.measurement.common - -import java.time.Duration -import kotlin.math.pow -import kotlin.random.Random - -/** - * Exponential backoff durations at millisecond resolution. - * - * TODO(@SanjayVas): Move this to common-jvm. - */ -data class ExponentialBackoff( - val initialDelay: Duration = Duration.ofMillis(500), - val multiplier: Double = 1.5, - val randomnessFactor: Double = 0.5, - val random: Random = Random, -) { - init { - require(initialDelay >= MIN_INITIAL_DELAY) { - "Initial delay must be at least $MIN_INITIAL_DELAY" - } - require(randomnessFactor >= 0.0) { "Randomness factor may not be negative" } - } - - /** Returns the [Duration] for the specified [attemptNumber], starting at `1`. */ - fun durationForAttempt(attemptNumber: Int): Duration { - return random.randomizedDuration( - exponentialDuration( - initialDelay = initialDelay, - multiplier = multiplier, - attemptNumber = attemptNumber, - ), - randomnessFactor = randomnessFactor, - ) - } - - companion object { - /** Minimum initial delay. */ - val MIN_INITIAL_DELAY: Duration = Duration.ofMillis(1) - - private fun exponentialDuration( - initialDelay: Duration, - multiplier: Double, - attemptNumber: Int, - ): Duration { - require(attemptNumber > 0) { "Attempts start at 1" } - if (attemptNumber == 1) { - // Minor optimization to avoid unnecessary floating point math. - return initialDelay - } - return Duration.ofMillis( - (initialDelay.toMillis() * (multiplier.pow(attemptNumber - 1))).toLong() - ) - } - - private fun Random.randomizedDuration(delay: Duration, randomnessFactor: Double): Duration { - if (randomnessFactor == 0.0) { - return delay - } - val maxOffset = randomnessFactor * delay.toMillis() - return delay.plusMillis(nextDouble(-maxOffset, maxOffset).toLong()) - } - } -} - -fun Duration.coerceAtMost(maximumValue: Duration): Duration { - return if (this <= maximumValue) this else maximumValue -} diff --git a/src/main/kotlin/org/wfanet/measurement/duchy/daemon/herald/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/duchy/daemon/herald/BUILD.bazel index 913963bccce..49ba8ba95b6 100644 --- a/src/main/kotlin/org/wfanet/measurement/duchy/daemon/herald/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/duchy/daemon/herald/BUILD.bazel @@ -31,7 +31,6 @@ kt_jvm_library( deps = [ "continuation_token_manager", "//src/main/kotlin/org/wfanet/measurement/api:public_api_version", - "//src/main/kotlin/org/wfanet/measurement/common:exponential_backoff", "//src/main/kotlin/org/wfanet/measurement/duchy:computation_stage", "//src/main/kotlin/org/wfanet/measurement/duchy/daemon/utils:computation_conversions", "//src/main/kotlin/org/wfanet/measurement/duchy/daemon/utils:duchy_order", diff --git a/src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationcontrol/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationcontrol/BUILD.bazel index 13e4e14af38..88eefa1f029 100644 --- a/src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationcontrol/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationcontrol/BUILD.bazel @@ -17,7 +17,6 @@ kt_jvm_library( ], deps = [ ":protocol_stages", - "//src/main/kotlin/org/wfanet/measurement/common:exponential_backoff", "//src/main/kotlin/org/wfanet/measurement/duchy/db/computation", "//src/main/proto/wfa/measurement/internal/duchy:async_computation_control_service_kt_jvm_grpc_proto", "@wfa_common_jvm//imports/java/com/google/protobuf", diff --git a/src/main/kotlin/org/wfanet/measurement/loadtest/measurementconsumer/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/loadtest/measurementconsumer/BUILD.bazel index b08e39470b7..078b9d1b509 100644 --- a/src/main/kotlin/org/wfanet/measurement/loadtest/measurementconsumer/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/loadtest/measurementconsumer/BUILD.bazel @@ -39,7 +39,6 @@ kt_jvm_library( "//src/main/kotlin/org/wfanet/measurement/api/v2alpha:packed_messages", "//src/main/kotlin/org/wfanet/measurement/api/v2alpha:resource_key", "//src/main/kotlin/org/wfanet/measurement/api/v2alpha/testing", - "//src/main/kotlin/org/wfanet/measurement/common:exponential_backoff", "//src/main/kotlin/org/wfanet/measurement/common/identity", "//src/main/kotlin/org/wfanet/measurement/kingdom/service/api/v2alpha:api_key_authentication_server_interceptor", "//src/main/kotlin/org/wfanet/measurement/loadtest/common:sample_vids", diff --git a/src/test/kotlin/org/wfanet/measurement/common/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/common/BUILD.bazel index 4a41c2cfec9..4aefadf820b 100644 --- a/src/test/kotlin/org/wfanet/measurement/common/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/common/BUILD.bazel @@ -2,18 +2,6 @@ load("@wfa_rules_kotlin_jvm//kotlin:defs.bzl", "kt_jvm_test") package(default_testonly = True) -kt_jvm_test( - name = "ExponentialBackoffTest", - srcs = ["ExponentialBackoffTest.kt"], - test_class = "org.wfanet.measurement.common.ExponentialBackoffTest", - deps = [ - "//src/main/kotlin/org/wfanet/measurement/common:exponential_backoff", - "@wfa_common_jvm//imports/java/com/google/common/truth", - "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//imports/kotlin/kotlin/test", - ], -) - kt_jvm_test( name = "sorted_lists_test", srcs = ["SortedListsTest.kt"], diff --git a/src/test/kotlin/org/wfanet/measurement/common/ExponentialBackoffTest.kt b/src/test/kotlin/org/wfanet/measurement/common/ExponentialBackoffTest.kt deleted file mode 100644 index d0de24d8fce..00000000000 --- a/src/test/kotlin/org/wfanet/measurement/common/ExponentialBackoffTest.kt +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2023 The Cross-Media Measurement Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.wfanet.measurement.common - -import com.google.common.truth.Truth.assertThat -import java.time.Duration -import kotlin.random.Random -import kotlin.test.assertFailsWith -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -/** Test for [ExponentialBackoff]. */ -@RunWith(JUnit4::class) -class ExponentialBackoffTest { - @Test - fun `durationForAttempt returns initial delay for attempt 1`() { - val backoff = ExponentialBackoff(initialDelay = Duration.ofMillis(250), randomnessFactor = 0.0) - - val duration: Duration = backoff.durationForAttempt(1) - - assertThat(duration).isEqualTo(backoff.initialDelay) - } - - @Test - fun `durationForAttempt returns multiplied value with no randomness factor`() { - val backoff = - ExponentialBackoff( - initialDelay = Duration.ofMillis(500), - multiplier = 2.0, - randomnessFactor = 0.0, - ) - - val duration: Duration = backoff.durationForAttempt(4) - - assertThat(duration).isEqualTo(Duration.ofMillis(4000)) - } - - @Test - fun `durationForAttempt returns multiplied value with randomness factor`() { - val backoff = - ExponentialBackoff( - initialDelay = Duration.ofMillis(500), - multiplier = 2.0, - randomnessFactor = 0.5, - random = Random(RANDOM_SEED), - ) - - val duration: Duration = backoff.durationForAttempt(4) - - assertThat(duration).isEqualTo(Duration.ofMillis(2559)) - } - - @Test - fun `durationForAttempt throws IllegalArgumentException for invalid attempt number`() { - val backoff = ExponentialBackoff() - - val exception = assertFailsWith { backoff.durationForAttempt(0) } - - assertThat(exception).hasMessageThat().ignoringCase().contains("attempt") - } - - @Test - fun `init throws IllegalArgumentException for invalid randomness factor`() { - val exception = - assertFailsWith { ExponentialBackoff(randomnessFactor = -0.5) } - - assertThat(exception).hasMessageThat().ignoringCase().contains("randomness") - } - - @Test - fun `init throws IllegalArgumentException for invalid initial delay`() { - val exception = - assertFailsWith { - ExponentialBackoff(initialDelay = Duration.ofNanos(1)) - } - - assertThat(exception).hasMessageThat().ignoringCase().contains("delay") - } - - companion object { - private const val RANDOM_SEED = 1L - } -}