Skip to content

Commit 969508f

Browse files
authored
Merge pull request #40 from daddykotex/scala3
Support Scala 3
2 parents 8b45377 + 6542a7b commit 969508f

File tree

8 files changed

+45
-43
lines changed

8 files changed

+45
-43
lines changed

build.sbt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
val scala211 = "2.11.12"
22
val scala212 = "2.12.12"
33
val scala213 = "2.13.2"
4+
val scala30 = "3.0.0"
45

56
val commonSettings = commonSmlBuildSettings ++ ossPublishSettings
67

@@ -13,14 +14,14 @@ lazy val retry = (projectMatrix in file("retry"))
1314
name := "retry",
1415
description := "a library of simple primitives for asynchronously retrying Scala Futures",
1516
libraryDependencies ++=
16-
Seq("org.scalatest" %%% "scalatest" % "3.1.4" % "test",
17-
"com.softwaremill.odelay" %%% "odelay-core" % "0.3.2",
18-
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.6"
17+
Seq("org.scalatest" %%% "scalatest" % "3.2.9" % "test",
18+
"com.softwaremill.odelay" %%% "odelay-core" % "0.3.3",
19+
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.6.0"
1920
)
2021
)
2122
.jvmPlatform(
22-
scalaVersions = List(scala211, scala212, scala213)
23+
scalaVersions = List(scala211, scala212, scala213, scala30)
2324
)
2425
.jsPlatform(
25-
scalaVersions = List(scala212, scala213)
26+
scalaVersions = List(scala212, scala213, scala30)
2627
)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.12
1+
sbt.version=1.6.2

project/plugins.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.7.0")
2-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.1")
3-
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
1+
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0")
2+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.9.0")
3+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.3")
44

55
val sbtSoftwaremillVersion = "1.9.15"
66
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-common" % sbtSoftwaremillVersion)

retry/src/main/scala/Policy.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ object Directly {
2929
implicit success: Success[T],
3030
executor: ExecutionContext): Future[T] = {
3131
def run(): Future[T] = {
32-
retry(promise, run, { _: Future[T] =>
32+
retry(promise, run, { (_: Future[T]) =>
3333
run()
3434
})
3535
}
36-
run
36+
run()
3737
}
3838
}
3939

@@ -61,7 +61,7 @@ object Pause {
6161
def run(): Future[T] = {
6262
val nextRun: () => Future[T] = () =>
6363
Delay(delay)(run()).future.flatMap(identity)
64-
retry(promise, nextRun, { _: Future[T] =>
64+
retry(promise, nextRun, { (_: Future[T]) =>
6565
nextRun()
6666
})
6767
}
@@ -131,7 +131,7 @@ object JitterBackoff {
131131
Delay(delay) {
132132
run(attempt + 1, jitter(delay, sleep, attempt))
133133
}.future.flatMap(identity)
134-
retry(promise, nextRun, { _: Future[T] =>
134+
retry(promise, nextRun, { (_: Future[T]) =>
135135
nextRun()
136136
})
137137
}
@@ -173,7 +173,7 @@ object Backoff {
173173
Delay(delay) {
174174
run(Duration(delay.length * base, delay.unit))
175175
}.future.flatMap(identity)
176-
retry(promise, nextRun, { _: Future[T] =>
176+
retry(promise, nextRun, { (_: Future[T]) =>
177177
nextRun()
178178
})
179179
}
@@ -246,7 +246,7 @@ trait CountingPolicy extends Policy {
246246
// consider this successful if our predicate says so _or_
247247
// we've reached the end out our countdown
248248
val countedSuccess = success.or(max < 1)
249-
retry(promise, () => orElse(max - 1), { f: Future[T] =>
249+
retry(promise, () => orElse(max - 1), { (f: Future[T]) =>
250250
if (max < 1) f else orElse(max - 1)
251251
})(countedSuccess, executor)
252252
}

retry/src/test/scala/JitterSpec.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import java.util.Random
44
import java.util.concurrent.TimeUnit
55
import java.util.concurrent.atomic.AtomicInteger
66

7-
import org.scalatest.FunSpec
7+
import org.scalatest.funspec.AnyFunSpec
88
import scala.concurrent.duration._
99

10-
class JitterSpec extends FunSpec {
10+
class JitterSpec extends AnyFunSpec {
1111
val rng = new java.util.Random()
1212
val rand = Jitter.randomSource(rng)
13-
val cap = 2000 milliseconds
13+
val cap = 2000.millis
1414

1515
def testJitter(jitter: Jitter)(): Unit = {
16-
val min = rand(1, 100) milliseconds
17-
var sleep = rand(1, 1000) milliseconds
16+
val min = rand(1, 100).millis
17+
var sleep = rand(1, 1000).millis
1818

1919
for (i <- 0 until 10000) {
2020
val delay = sleep
@@ -60,25 +60,25 @@ class JitterSpec extends FunSpec {
6060

6161
describe("retry.Jitter.none") {
6262
it("should perform backoff correctly") {
63-
testJitter(Jitter.none(cap))
63+
testJitter(Jitter.none(cap))()
6464
}
6565
}
6666

6767
describe("retry.Jitter.decorrelated") {
6868
it("should perform decorrelated jitter correctly") {
69-
testJitter(Jitter.decorrelated(cap))
69+
testJitter(Jitter.decorrelated(cap))()
7070
}
7171
}
7272

7373
describe("retry.Jitter.full") {
7474
it("should perform full jitter correctly") {
75-
testJitter(Jitter.full(cap))
75+
testJitter(Jitter.full(cap))()
7676
}
7777
}
7878

7979
describe("retry.Jitter.equal") {
8080
it("should perform equal jitter correctly") {
81-
testJitter(Jitter.equal(cap))
81+
testJitter(Jitter.equal(cap))()
8282
}
8383
}
8484

retry/src/test/scala/PolicySpec.scala

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import java.util.Random
44
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, AtomicLong}
55

66
import odelay.Timer
7-
import org.scalatest.{AsyncFunSpec, BeforeAndAfterAll}
7+
import org.scalatest.BeforeAndAfterAll
8+
import org.scalatest.funspec.AsyncFunSpec
89

910
import scala.collection.compat.immutable.LazyList
1011
import scala.concurrent.Future
@@ -101,7 +102,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
101102
Future(true)
102103
}
103104
val policy = Directly.forever
104-
policy(run).map { result =>
105+
policy(run()).map { result =>
105106
assert(result === true)
106107
assert(retried.get() == 10000)
107108
}
@@ -135,7 +136,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
135136
Future(true)
136137
}
137138
val policy = Pause.forever(1.millis)
138-
policy(run).map { result =>
139+
policy(run()).map { result =>
139140
assert(result === true)
140141
assert(retried.get() == 1000)
141142
}
@@ -168,7 +169,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
168169
Future(true)
169170
}
170171
val policy = Backoff.forever(1.millis)
171-
policy(run).map { result =>
172+
policy(run()).map { result =>
172173
assert(result === true)
173174
assert(retried.get() == 5)
174175
}
@@ -181,15 +182,15 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
181182

182183
it("should retry a future for a specified number of times") {
183184
implicit val success = Success[Int](_ == 3)
184-
implicit val algo = algoCreator(10.millis)
185+
implicit val algo: Jitter = algoCreator(10.millis)
185186
val tries = forwardCountingFutureStream().iterator
186187
val policy = JitterBackoff(3, 1.milli)
187188
policy(tries.next).map(result =>
188189
assert(success.predicate(result) === true))
189190
}
190191

191192
it("should fail when expected") {
192-
implicit val algo = algoCreator(10.millis)
193+
implicit val algo: Jitter = algoCreator(10.millis)
193194
val success = implicitly[Success[Option[Int]]]
194195
val tries = Future(None: Option[Int])
195196
val policy = JitterBackoff(3, 1.milli)
@@ -200,7 +201,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
200201

201202
it("should deal with future failures") {
202203
implicit val success = Success.always
203-
implicit val algo = algoCreator(10.millis)
204+
implicit val algo: Jitter = algoCreator(10.millis)
204205
val policy = JitterBackoff(3, 5.millis)
205206
val counter = new AtomicInteger()
206207
val future = policy { () =>
@@ -213,7 +214,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
213214

214215
it("should retry futures passed by-name instead of caching results") {
215216
implicit val success = Success.always
216-
implicit val algo = algoCreator(10.millis)
217+
implicit val algo: Jitter = algoCreator(10.millis)
217218
val counter = new AtomicInteger()
218219
val policy = JitterBackoff(1, 1.milli)
219220
val future = policy {
@@ -227,7 +228,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
227228

228229
it("should pause with multiplier and jitter between retries") {
229230
implicit val success = Success[Int](_ == 2)
230-
implicit val algo = algoCreator(1000.millis)
231+
implicit val algo: Jitter = algoCreator(1000.millis)
231232
val tries = forwardCountingFutureStream().iterator
232233
val policy = JitterBackoff(5, 50.millis)
233234
val marker_base = System.currentTimeMillis
@@ -242,7 +243,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
242243

243244
it("should also work when invoked as forever") {
244245
implicit val success = Success[Int](_ == 5)
245-
implicit val algo = algoCreator(1000.millis)
246+
implicit val algo: Jitter = algoCreator(1000.millis)
246247
val tries = forwardCountingFutureStream().iterator
247248
val policy = JitterBackoff.forever(50.millis)
248249
val marker_base = System.currentTimeMillis
@@ -267,7 +268,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
267268
Future(true)
268269
}
269270
val policy = JitterBackoff.forever(1.millis)
270-
policy(run).map { result =>
271+
policy(run()).map { result =>
271272
assert(result === true)
272273
assert(retried.get() == 10)
273274
}
@@ -325,7 +326,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
325326
// lift an exception into a new policy
326327
case RetryAfter(duration) => Pause(delay = duration)
327328
}
328-
policy(run).map(result => assert(result === true))
329+
policy(run()).map(result => assert(result === true))
329330
}
330331

331332
it("should repeat on failure until success") {
@@ -344,7 +345,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
344345
// lift an exception into a new policy
345346
case _: MyException => Directly.forever
346347
}
347-
policy(run).map { result =>
348+
policy(run()).map { result =>
348349
assert(result === true)
349350
assert(retried.get() == 10000)
350351
}
@@ -367,7 +368,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
367368
case _: MyException => Pause.forever(1.millis)
368369

369370
}
370-
policy(run).map { result =>
371+
policy(run()).map { result =>
371372
assert(result === true)
372373
assert(retried.get() == 1000)
373374
}
@@ -389,7 +390,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
389390
// lift an exception into a new policy
390391
case _: MyException => Backoff.forever(1.millis)
391392
}
392-
policy(run).map { result =>
393+
policy(run()).map { result =>
393394
assert(result === true)
394395
assert(retried.get() == 5)
395396
}
@@ -411,7 +412,7 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
411412
// lift an exception into a new policy
412413
case _: MyException => JitterBackoff.forever(1.millis)
413414
}
414-
policy(run).map { result =>
415+
policy(run()).map { result =>
415416
assert(result === true)
416417
assert(retried.get() == 10)
417418
}

retry/src/test/scala/SuccessSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package retry
22

3-
import org.scalatest.FunSpec
3+
import org.scalatest.funspec.AnyFunSpec
44

55
import scala.util.Try
66

7-
class SuccessSpec extends FunSpec {
7+
class SuccessSpec extends AnyFunSpec {
88
describe("retry.Success.either") {
99
val either = implicitly[Success[Either[String, String]]]
1010
it("should be successful on a Right") {

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "0.3.4-SNAPSHOT"
1+
ThisBuild / version := "0.3.4-SNAPSHOT"

0 commit comments

Comments
 (0)