Skip to content

Commit 215b154

Browse files
Iterating on tests
1 parent 1a81db7 commit 215b154

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

core/src/test/scala/iterable.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ with DispatchCleanup {
4747

4848
property("iterable future values") = forAll(Gen.alphaStr) {
4949
(sampleL: String) =>
50-
val sample = sampleL.take(10) // n^2 concurrent requests
50+
val sample: String = sampleL.take(10) // n^2 concurrent requests
5151
val values: Future[Iterable[(Int,Int)]] = for {
5252
chr1 <- split(sample).values.flatten
5353
chr2 <- split(sample.reverse).values
5454
c1 <- value(chr1)
5555
c2 <- value(chr2)
5656
} yield (c1, c2)
57+
5758
values() ?= (for {
5859
c1 <- sample
5960
c2 <- sample.reverse
@@ -67,7 +68,7 @@ with DispatchCleanup {
6768
chr1 <- split(sample).either.right.values
6869
c1 <- value(chr1)
6970
} yield Right(c1)
70-
values().right.get ?= (for {
71+
values().toOption.get ?= (for {
7172
c1 <- sample
7273
} yield c1.toInt)
7374
}

core/src/test/scala/retry.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ with DispatchCleanup {
4242
def succeedOn(successRetry: Int)() = {
4343
Http.default(localhost << Map("echo" -> retried.getAndIncrement.toString)
4444
OK as.String).either.map { eth =>
45-
eth.right.flatMap { numstr =>
45+
eth.flatMap { numstr =>
4646
val num = numstr.toInt
4747
if (num == successRetry)
4848
Right(num)
@@ -55,19 +55,19 @@ with DispatchCleanup {
5555

5656
property("succeed on the first request") = forAll(smallNums) { maxRetries =>
5757
val rc = new RetryCounter
58-
val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0))
58+
val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0)())
5959
p() ?= Right(0)
6060
}
6161

6262
property("succeed on the max retry") = forAll(smallNums) { maxRetries =>
6363
val rc = new RetryCounter
64-
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries))
64+
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries)())
6565
p() ?= Right(maxRetries)
6666
}
6767

6868
property("fail after max retries") = forAll(smallNums) { maxRetries =>
6969
val rc = new RetryCounter
70-
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1))
70+
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1)())
7171
p() ?= Left(maxRetries)
7272
}
7373

@@ -76,7 +76,7 @@ with DispatchCleanup {
7676
val p = retry.Backoff(
7777
max,
7878
Duration(2, TimeUnit.MICROSECONDS)
79-
)(() => rc.succeedOn(max))
79+
)(() => rc.succeedOn(max)())
8080
p() ?= Right(max)
8181
}
8282

@@ -85,7 +85,7 @@ with DispatchCleanup {
8585
val p = retry.Pause(
8686
max,
8787
Duration(500, TimeUnit.MICROSECONDS)
88-
)(() => rc.succeedOn(max + 1))
88+
)(() => rc.succeedOn(max + 1)())
8989
p() ?= Left(max)
9090
}
9191
}

json4sjackson/src/test/scala/json.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ with DispatchCleanup {
3030

3131
object In extends Params.Extract("in", Params.first)
3232
netty.Server.local(port).handler(netty.cycle.Planify {
33-
case Params(In(in)) => Json(("out" -> in))
33+
case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]]
3434
}).start()
3535
}
3636

@@ -42,6 +42,9 @@ with DispatchCleanup {
4242
val res = Http.default(
4343
localhost <:< Map("Accept" -> "application/json") <<? Map("in" -> sample) > as.json4s.Json
4444
)
45-
sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head
45+
sample == (for {
46+
case JObject(fields) <- res()
47+
case JField("out", JString(o)) <- fields
48+
} yield o).head
4649
}
4750
}

json4snative/src/test/scala/json.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dispatch.spec
22

33
import org.scalacheck._
4+
import org.scalacheck.util.Pretty.prettyAny
45

56
object BasicSpecification
67
extends Properties("Json4s Native Json")
@@ -30,7 +31,7 @@ with DispatchCleanup {
3031

3132
object In extends Params.Extract("in", Params.first)
3233
netty.Server.local(port).handler(netty.cycle.Planify {
33-
case Params(In(in)) => Json(("out" -> in))
34+
case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]]
3435
}).start()
3536
}
3637

@@ -42,6 +43,9 @@ with DispatchCleanup {
4243
val res = Http.default(
4344
localhost <:< Map("Accept" -> "application/json") <<? Map("in" -> sample) > as.json4s.Json
4445
)
45-
sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head
46+
sample == (for {
47+
case JObject(fields) <- res()
48+
case JField("out", JString(o)) <- fields
49+
} yield o).head
4650
}
4751
}

jsoup/src/test/scala/soup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ with DispatchCleanup {
2525
object Echo extends Params.Extract("echo", Params.first)
2626
netty.Server.local(port).handler(netty.cycle.Planify {
2727
case Path("/echo") & Params(Echo(echo)) =>
28-
Html(<html><head></head><body><div id="echo">{echo}</div></body></html>)
28+
ResponseString(Html(<html><head></head><body><div id="echo">{echo}</div></body></html>).toString())
2929
case Path("/unclean") & Params(Echo(echo)) =>
3030
HtmlContent ~> ResponseString(UnsafeFormat format echo)
3131
case Path("/relative") & Params(Echo(echo)) =>

project/common.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sbt._
33
object Common {
44
import Keys._
55

6-
val defaultScalaVersion = "2.13.14"
6+
val defaultScalaVersion = "3.4.2"
77

88
val testSettings:Seq[Setting[_]] = Seq(
99
Test / testOptions += Tests.Cleanup { loader =>

tagsoup/src/test/scala/soup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ with DispatchCleanup {
1515
object Echo extends Params.Extract("echo", Params.first)
1616
netty.Server.local(port).handler(netty.cycle.Planify {
1717
case Path("/echo") & Params(Echo(echo)) =>
18-
Html(<html><head></head><body><div id="echo">{echo}</div></body></html>)
18+
ResponseString(Html(<html><head></head><body><div id="echo">{echo}</div></body></html>).toString())
1919
}).start()
2020
}
2121

0 commit comments

Comments
 (0)