Skip to content

Commit a6dd3c3

Browse files
authored
test on Play 2.8, 2.9, and 3.0 (#1400)
1 parent 0b2d1e0 commit a6dd3c3

File tree

5 files changed

+123
-61
lines changed

5 files changed

+123
-61
lines changed

build.sbt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ lazy val `kamon-play` = (project in file("instrumentation/kamon-play"))
612612
crossScalaVersions := Seq(`scala_2.13_version`)
613613
)
614614
.dependsOn(
615-
`kamon-akka` % "compile,test-common,test-play-2.8,test-play-2.7",
616-
`kamon-akka-http` % "compile,test-common,test-play-2.8,test-play-2.7",
617-
`kamon-testkit` % "test-common,test-play-2.8,test-play-2.7"
615+
`kamon-akka` % "compile,test-common,test-play-28,test-play-29",
616+
`kamon-akka-http` % "compile,test-common,test-play-28,test-play-29",
617+
`kamon-pekko` % "compile,test-common,test-play-30",
618+
`kamon-pekko-http` % "compile,test-common,test-play-30",
619+
`kamon-testkit` % "test-common,test-play-28,test-play-29,test-play-30"
618620
)
619621

620622
lazy val `kamon-okhttp` = (project in file("instrumentation/kamon-okhttp"))

instrumentation/kamon-play/build.sbt

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
11
import sbt.Tests._
22

3-
val `Play-2.7-version` = "2.7.9"
4-
val `Play-2.8-version` = "2.8.2"
3+
val `Play-2.8-version` = "2.8.22"
4+
val `Play-2.9-version` = "2.9.7"
5+
val `Play-3.0-version` = "3.0.7"
56

67
/**
78
* Test Configurations
89
*/
910
lazy val TestCommon = config("test-common") extend (Compile)
10-
lazy val `Test-Play-2.7` = config("test-play-2.7")
11-
lazy val `Test-Play-2.8` = config("test-play-2.8")
11+
lazy val `Test-Play-28` = config("test-play-28")
12+
lazy val `Test-Play-29` = config("test-play-29")
13+
lazy val `Test-Play-30` = config("test-play-30")
1214

1315
configs(
1416
TestCommon,
15-
`Test-Play-2.8`,
16-
`Test-Play-2.7`
17+
`Test-Play-28`,
18+
`Test-Play-29`,
19+
`Test-Play-30`
1720
)
1821

1922
libraryDependencies ++= Seq(
2023
kanelaAgent % "provided",
21-
"com.typesafe.play" %% "play" % `Play-2.7-version` % "provided,test-common,test-play-2.7",
22-
"com.typesafe.play" %% "play-netty-server" % `Play-2.7-version` % "provided,test-common,test-play-2.7",
23-
"com.typesafe.play" %% "play-akka-http-server" % `Play-2.7-version` % "provided,test-common,test-play-2.7",
24-
"com.typesafe.play" %% "play-ws" % `Play-2.7-version` % "provided,test-common,test-play-2.7",
25-
"com.typesafe.play" %% "play-test" % `Play-2.7-version` % "provided,test-common,test-play-2.7",
26-
"com.typesafe.play" %% "play-logback" % `Play-2.7-version` % "test-common,test-play-2.7",
27-
scalatest % "test-common,test-play-2.8,test-play-2.7",
28-
"org.scalatestplus.play" %% "scalatestplus-play" % "4.0.3" % "test-play-2.8,test-play-2.7"
24+
scalatest % "test-common,test-play-28,test-play-29,test-play-30"
2925
)
3026

3127
libraryDependencies ++= Seq(
32-
"com.typesafe.play" %% "play-akka-http2-support" % `Play-2.8-version` % "test-play-2.8",
33-
"com.typesafe.play" %% "play" % `Play-2.8-version` % "test-play-2.8",
34-
"com.typesafe.play" %% "play-netty-server" % `Play-2.8-version` % "test-play-2.8",
35-
"com.typesafe.play" %% "play-akka-http-server" % `Play-2.8-version` % "test-play-2.8",
36-
"com.typesafe.play" %% "play-ws" % `Play-2.8-version` % "test-play-2.8",
37-
"com.typesafe.play" %% "play-test" % `Play-2.8-version` % "test-play-2.8",
38-
"com.typesafe.play" %% "play-logback" % `Play-2.8-version` % "test-play-2.8"
28+
"com.typesafe.play" %% "play-akka-http2-support" % `Play-2.8-version` % "provided,test-common,test-play-28",
29+
"com.typesafe.play" %% "play" % `Play-2.8-version` % "provided,test-common,test-play-28",
30+
"com.typesafe.play" %% "play-netty-server" % `Play-2.8-version` % "provided,test-common,test-play-28",
31+
"com.typesafe.play" %% "play-akka-http-server" % `Play-2.8-version` % "provided,test-common,test-play-28",
32+
"com.typesafe.play" %% "play-ws" % `Play-2.8-version` % "provided,test-common,test-play-28",
33+
"com.typesafe.play" %% "play-test" % `Play-2.8-version` % "provided,test-common,test-play-28",
34+
"com.typesafe.play" %% "play-logback" % `Play-2.8-version` % "provided,test-common,test-play-28",
35+
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % "provided,test-common,test-play-28",
36+
"com.google.inject" % "guice" % "5.1.0" % "test-play-28",
37+
"com.google.inject.extensions" % "guice-assistedinject" % "5.1.0" % "test-play-28"
38+
)
39+
40+
libraryDependencies ++= Seq(
41+
"com.typesafe.play" %% "play-akka-http2-support" % `Play-2.9-version` % "test-play-29",
42+
"com.typesafe.play" %% "play" % `Play-2.9-version` % "test-play-29",
43+
"com.typesafe.play" %% "play-netty-server" % `Play-2.9-version` % "test-play-29",
44+
"com.typesafe.play" %% "play-akka-http-server" % `Play-2.9-version` % "test-play-29",
45+
"com.typesafe.play" %% "play-ws" % `Play-2.9-version` % "test-play-29",
46+
"com.typesafe.play" %% "play-test" % `Play-2.9-version` % "test-play-29",
47+
"com.typesafe.play" %% "play-logback" % `Play-2.9-version` % "test-play-29",
48+
"org.scalatestplus.play" %% "scalatestplus-play" % "6.0.1" % "test-play-29"
49+
)
50+
51+
libraryDependencies ++= Seq(
52+
"org.playframework" %% "play-pekko-http2-support" % `Play-3.0-version` % "test-play-30",
53+
"org.playframework" %% "play" % `Play-3.0-version` % "test-play-30",
54+
"org.playframework" %% "play-netty-server" % `Play-3.0-version` % "test-play-30",
55+
"org.playframework" %% "play-pekko-http-server" % `Play-3.0-version` % "test-play-30",
56+
"org.playframework" %% "play-ws" % `Play-3.0-version` % "test-play-30",
57+
"org.playframework" %% "play-test" % `Play-3.0-version` % "test-play-30",
58+
"org.playframework" %% "play-logback" % `Play-3.0-version` % "test-play-30",
59+
"org.scalatestplus.play" %% "scalatestplus-play" % "7.0.1" % "test-play-30"
3960
)
4061

4162
/**
@@ -53,15 +74,28 @@ inConfig(TestCommon)(Defaults.testSettings ++ instrumentationSettings ++ baseTes
5374
crossScalaVersions := Seq(`scala_2.13_version`)
5475
))
5576

56-
inConfig(`Test-Play-2.7`)(Defaults.testSettings ++ instrumentationSettings ++ baseTestSettings ++ Seq(
57-
sources := joinSources(TestCommon, `Test-Play-2.7`).value,
77+
inConfig(`Test-Play-28`)(Defaults.testSettings ++ instrumentationSettings ++ baseTestSettings ++ Seq(
78+
sources := joinSources(TestCommon, `Test-Play-28`).value,
79+
crossScalaVersions := Seq(`scala_2.13_version`),
80+
testGrouping := singleTestPerJvm(definedTests.value, javaOptions.value),
81+
unmanagedResourceDirectories ++= (Compile / unmanagedResourceDirectories).value,
82+
unmanagedResourceDirectories ++= (TestCommon / unmanagedResourceDirectories).value,
83+
javaOptions ++= Seq(
84+
"--add-exports=java.base/sun.security.x509=ALL-UNNAMED",
85+
"--add-opens=java.base/sun.security.ssl=ALL-UNNAMED"
86+
)
87+
))
88+
89+
inConfig(`Test-Play-29`)(Defaults.testSettings ++ instrumentationSettings ++ baseTestSettings ++ Seq(
90+
sources := joinSources(TestCommon, `Test-Play-29`).value,
91+
crossScalaVersions := Seq(`scala_2.13_version`),
5892
testGrouping := singleTestPerJvm(definedTests.value, javaOptions.value),
5993
unmanagedResourceDirectories ++= (Compile / unmanagedResourceDirectories).value,
6094
unmanagedResourceDirectories ++= (TestCommon / unmanagedResourceDirectories).value
6195
))
6296

63-
inConfig(`Test-Play-2.8`)(Defaults.testSettings ++ instrumentationSettings ++ baseTestSettings ++ Seq(
64-
sources := joinSources(TestCommon, `Test-Play-2.8`).value,
97+
inConfig(`Test-Play-30`)(Defaults.testSettings ++ instrumentationSettings ++ baseTestSettings ++ Seq(
98+
sources := joinSources(TestCommon, `Test-Play-30`).value,
6599
crossScalaVersions := Seq(`scala_2.13_version`),
66100
testGrouping := singleTestPerJvm(definedTests.value, javaOptions.value),
67101
unmanagedResourceDirectories ++= (Compile / unmanagedResourceDirectories).value,
@@ -70,8 +104,9 @@ inConfig(`Test-Play-2.8`)(Defaults.testSettings ++ instrumentationSettings ++ ba
70104

71105
Test / test := Def.taskDyn {
72106
Def.task {
73-
(`Test-Play-2.7` / test).value
74-
(`Test-Play-2.8` / test).value
107+
(`Test-Play-28` / test).value
108+
(`Test-Play-29` / test).value
109+
(`Test-Play-30` / test).value
75110
}
76111
}.value
77112

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.9.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include "application.conf"
2+
3+
play.server.provider=play.core.server.PekkoHttpServerProvider
4+
play.server.pekko.http2.enabled = false

instrumentation/kamon-play/src/test-common/scala/kamon/instrumentation/play/RequestInstrumentationSpec.scala

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.scalatest.OptionValues
2727
import org.scalatest.wordspec.AnyWordSpecLike
2828
import org.scalatestplus.play._
2929
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
30+
import play.core.PlayVersion
3031
import play.api.Application
3132
import play.api.inject.guice.GuiceApplicationBuilder
3233
import play.api.libs.ws.WSClient
@@ -41,65 +42,84 @@ import play.api.test._
4142
import scala.concurrent.{ExecutionContext, Future}
4243

4344
class AkkaHTTPRequestHandlerInstrumentationSpec extends {
44-
val confFile = "/instrumentation/kamon-play/src/test-common/resources/conf/application-akka-http.conf"
45-
//https://www.playframaework.com/documentation/2.6.x/NettyServer#Verifying-that-the-Netty-server-is-running
46-
//The Akka HTTP backend will not set a value for this request attribute.
47-
val expectedServer = "play.server.akka-http"
48-
} with RequestHandlerInstrumentationSpec
45+
// https://www.playframaework.com/documentation/2.6.x/NettyServer#Verifying-that-the-Netty-server-is-running
46+
// The Akka HTTP backend will not set a value for this request attribute.
47+
val (confFile, expectedServer) = {
48+
if (PlayVersion.current.startsWith("2")) {
49+
(
50+
"/instrumentation/kamon-play/src/test-common/resources/conf/application-akka-http.conf",
51+
"play.server.akka-http"
52+
)
53+
} else {
54+
(
55+
"/instrumentation/kamon-play/src/test-common/resources/conf/application-pekko-http.conf",
56+
"pekko.http.server"
57+
)
58+
}
59+
}
60+
61+
} with RequestHandlerInstrumentationSpec
4962

5063
class NettyRequestHandlerInstrumentationSpec extends {
51-
val confFile = "/instrumentation/kamon-play/src/test-common/resources/conf/application-netty.conf"
52-
val expectedServer = "play.server.netty"
53-
} with RequestHandlerInstrumentationSpec
64+
val confFile = "/instrumentation/kamon-play/src/test-common/resources/conf/application-netty.conf"
65+
val expectedServer = "play.server.netty"
66+
} with RequestHandlerInstrumentationSpec
5467

5568
abstract class RequestHandlerInstrumentationSpec extends PlaySpecShim with GuiceOneServerPerSuite with ScalaFutures
56-
with Eventually with SpanSugar with InitAndStopKamonAfterAll with MetricInspection.Syntax with OptionValues with TestSpanReporter {
69+
with Eventually with SpanSugar with InitAndStopKamonAfterAll with MetricInspection.Syntax with OptionValues
70+
with TestSpanReporter {
5771

5872
val confFile: String
5973
val expectedServer: String
6074

6175
System.setProperty("config.file", System.getProperty("user.dir") + confFile)
62-
6376
implicit val executor: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
6477

6578
def testRoutes(app: Application): PartialFunction[(String, String), Handler] = {
6679
val action = app.injector.instanceOf(classOf[DefaultActionBuilder])
6780

6881
{
69-
case ("GET", "/ok") => handler(action { Ok })
70-
case ("GET", "/request-id") => handler(action { Ok(Kamon.currentContext().getTag(option("request-id")).getOrElse("undefined")) })
71-
case ("GET", "/async") => handler(action.async { Future { Ok } })
72-
case ("GET", "/not-found") => handler(action { NotFound })
73-
case ("GET", "/server") => handler(action { req => Ok(serverImplementationName(req)) })
74-
case ("GET", "/error") => handler(action(_ => sys.error("This page generates an error!")))
82+
case ("GET", "/ok") => handler(action { Ok })
83+
case ("GET", "/request-id") =>
84+
handler(action { Ok(Kamon.currentContext().getTag(option("request-id")).getOrElse("undefined")) })
85+
case ("GET", "/async") => handler(action.async { Future { Ok } })
86+
case ("GET", "/not-found") => handler(action { NotFound })
87+
case ("GET", "/server") => handler(action { req => Ok(serverImplementationName(req)) })
88+
case ("GET", "/error") => handler(action(_ => sys.error("This page generates an error!")))
7589
}
7690
}
7791

7892
def serverImplementationName(req: Request[AnyContent]): String = {
7993
req.attrs.get(RequestAttrKey.Server)
80-
.map(s => if(s == "netty") "play.server.netty" else "unknown")
81-
.getOrElse("play.server.akka-http")
94+
.map(s => if (s == "netty") "play.server.netty" else "unknown")
95+
.getOrElse(expectedServer) // The `Server` attribute is only set when unsing Netty
8296
}
8397

8498
// Adds the HandlerDef attribute to the request which simulates what would happen when a generated router handles
8599
// the request.
86100
def handler[T](action: Action[T]): Handler = {
87-
Stage.modifyRequest(req => {
88-
req.addAttr(Router.Attrs.HandlerDef, HandlerDef(
89-
classLoader = getClass.getClassLoader,
90-
routerPackage = "kamon",
91-
controller = "kamon.TestController",
92-
method = "testMethod",
93-
parameterTypes = Seq.empty,
94-
verb = req.method,
95-
path = req.path
96-
))
97-
}, action)
101+
Stage.modifyRequest(
102+
req => {
103+
req.addAttr(
104+
Router.Attrs.HandlerDef,
105+
HandlerDef(
106+
classLoader = getClass.getClassLoader,
107+
routerPackage = "kamon",
108+
controller = "kamon.TestController",
109+
method = "testMethod",
110+
parameterTypes = Seq.empty,
111+
verb = req.method,
112+
path = req.path
113+
)
114+
)
115+
},
116+
action
117+
)
98118
}
99119

100120
override def fakeApplication(): Application = new GuiceApplicationBuilder()
101121
.appRoutes(testRoutes)
102-
.build
122+
.build()
103123

104124
"the Request instrumentation" should {
105125
"check the right server is configured" in {
@@ -178,4 +198,4 @@ abstract class RequestHandlerInstrumentationSpec extends PlaySpecShim with Guice
178198
}
179199
}
180200
}
181-
}
201+
}

0 commit comments

Comments
 (0)