Skip to content

Commit

Permalink
Merge pull request #479 from sentenza/upgrade-play28
Browse files Browse the repository at this point in the history
Upgrade Play 2.9.0 and drop Java 8
  • Loading branch information
mkurz authored Dec 21, 2023
2 parents 6a3d10d + 58ac5f8 commit deeea2e
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ updates.pin = [
# Prevent updates to 3.2.x and beyond
{ groupId = "org.scalatest", artifactId = "scalatest", version = "3.1."}
]

updatePullRequests = false
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
- "check-docs"
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 11, 8
scala: 2.12.x, 2.13.x
java: 17, 11
scala: 2.13.x
cmd: sbt ++$MATRIX_SCALA test

finish:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ on:
jobs:
publish-artifacts:
name: Publish / Artifacts
uses: playframework/.github/.github/workflows/publish.yml@v2
uses: playframework/.github/.github/workflows/publish.yml@v3
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
node_modules/
/docs/build/
/docs/package*.json
logs/
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ val playGenerators = Project(id = "play-grpc-generators", file("play-generators"
buildInfoPackage := "play.grpc.gen",
// Only used in build tools (like sbt), so only 2.12 is needed:
crossScalaVersions := Seq(scala212),
scalaVersion := scala212,
)

val playTestkit = Project("play-grpc-testkit", file("play-testkit"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ trait ServerGrpcClient extends AkkaGrpcClientHelpers { this: BaseOneServerPerTes
): AkkaGrpcClientFactory.Configured[T] = {
AkkaGrpcClientHelpers.factoryForAppEndpoints(running.app, running.endpoints)
}

protected override def newServerForTest(app: Application, testData: TestData): RunningServer =
DefaultTestServerFactory.start(app)

}
1 change: 1 addition & 0 deletions play-scalatest/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
play.ws.ssl.loose.acceptAnyCertificate = true
50 changes: 50 additions & 0 deletions play-scalatest/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.classic.AsyncAppender"/>
<import class="ch.qos.logback.core.FileAppender"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSClient
import play.api.routing.Router
import play.api.Application
import play.grpc.testkit.SslTestServerFactory

/**
* Test for the Play gRPC ScalaTest APIs
Expand All @@ -26,6 +27,8 @@ class PlayActionsScalaTestSpec
with ScalaFutures
with IntegrationPatience {

override def testServerFactory = new SslTestServerFactory

override def fakeApplication(): Application = {
GuiceApplicationBuilder()
.overrides(bind[Router].to[GreeterServiceWithActionsImpl])
Expand All @@ -36,7 +39,7 @@ class PlayActionsScalaTestSpec

"A Play server bound to a gRPC router using actions" must {
"give a 404 when routing a non-gRPC request" in {
val result = wsUrl("/").get.futureValue
val result = wsUrl("/", true).get.futureValue
result.status must be(404) // Maybe should be a 426, see #396
}
// this test results in a 500
Expand All @@ -54,7 +57,7 @@ class PlayActionsScalaTestSpec
// result.header("grpc-status") mustEqual Some(Status.Code.UNIMPLEMENTED.value().toString)
// }
"give a grpc 'invalid argument' error when routing an empty request to a gRPC method" in {
val result = wsUrl(s"/${GreeterService.name}/SayHello")
val result = wsUrl(s"/${GreeterService.name}/SayHello", true)
.addHttpHeaders("Content-Type" -> GrpcProtocolNative.contentType.toString)
.get
.futureValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSClient
import play.api.routing.Router
import play.api.Application
import play.grpc.testkit.SslTestServerFactory

/**
* Test for the Play gRPC ScalaTest APIs
Expand All @@ -26,6 +27,8 @@ class PlayScalaTestSpec
with ScalaFutures
with IntegrationPatience {

override def testServerFactory = new SslTestServerFactory

override def fakeApplication(): Application = {
GuiceApplicationBuilder()
.overrides(bind[Router].to[GreeterServiceImpl])
Expand All @@ -36,23 +39,23 @@ class PlayScalaTestSpec

"A Play server bound to a gRPC router" must {
"give a 404 when routing a non-gRPC request" in {
val result = wsUrl("/").get.futureValue
val result = wsUrl("/", true).get.futureValue
result.status must be(404) // Maybe should be a 426, see #396
}
"give a 415 error when not using a gRPC content-type" in {
val result = wsUrl(s"/${GreeterService.name}/FooBar").get.futureValue
val result = wsUrl(s"/${GreeterService.name}/FooBar", true).get.futureValue
result.status must be(415)
}
"give a grpc 'unimplemented' error when routing a non-existent gRPC method" in {
val result = wsUrl(s"/${GreeterService.name}/FooBar")
val result = wsUrl(s"/${GreeterService.name}/FooBar", true)
.addHttpHeaders("Content-Type" -> GrpcProtocolNative.contentType.toString)
.get
.futureValue
result.status must be(200) // Maybe should be a 426, see #396
result.header("grpc-status") mustEqual Some(Status.Code.UNIMPLEMENTED.value().toString)
}
"give a grpc 'invalid argument' error when routing an empty request to a gRPC method" in {
val result = wsUrl(s"/${GreeterService.name}/SayHello")
val result = wsUrl(s"/${GreeterService.name}/SayHello", true)
.addHttpHeaders("Content-Type" -> GrpcProtocolNative.contentType.toString)
.get
.futureValue
Expand Down
1 change: 1 addition & 0 deletions play-specs2/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
play.ws.ssl.loose.acceptAnyCertificate = true
50 changes: 50 additions & 0 deletions play-specs2/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.classic.AsyncAppender"/>
<import class="ch.qos.logback.core.FileAppender"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ import play.api.libs.ws.WSClient
import play.api.libs.ws.WSRequest
import play.api.routing.Router
import play.api.test._
import play.grpc.testkit.SslTestServerFactory

/**
* Test for the Play gRPC Specs2 APIs
*/
@RunWith(classOf[JUnitRunner])
class PlaySpecs2Spec extends ForServer with ServerGrpcClient with PlaySpecification with ApplicationFactories {

override def testServerFactory = new SslTestServerFactory

protected def applicationFactory: ApplicationFactory =
withGuiceApp(GuiceApplicationBuilder().overrides(bind[Router].to[GreeterServiceImpl]))

// RICH: Still need to work out how to make WSClient work properly with endpoints
def wsUrl(path: String)(implicit running: RunningServer): WSRequest = {
val ws = running.app.injector.instanceOf[WSClient]
val url = running.endpoints.httpEndpoint.get.pathUrl(path)
val url = running.endpoints.httpsEndpoint.get.pathUrl(path)
ws.url(url)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ServerEndpoint getHttp2Endpoint(final ServerEndpoints serverEndpoi
.endpoints()
.filter(e -> e.protocols().contains("HTTP/2.0" /* Play's HttpProtocol.HTTP_2_0 */))
.toIterable();
if (possibleEndpoints.size() == 0) {
if (possibleEndpoints.isEmpty()) {
throw new IllegalArgumentException(
String.format(
"gRPC client can't automatically find HTTP/2 connection: "
Expand Down Expand Up @@ -60,7 +60,7 @@ public static GrpcClientSettings grpcClientSettings(
.getOrElse(
() -> {
throw new IllegalArgumentException(
"GrpcClientSettings requires a server endpoint with ssl, but non provided");
"GrpcClientSettings requires a server endpoint with ssl, but none provided");
});

return grpcClientSettings(http2Endpoint, sslContext, actorSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import play.libs.ws.*;

public final class PlayJavaFunctionalTest {
private final TestServerFactory testServerFactory = new DefaultTestServerFactory();
private final TestServerFactory testServerFactory = new SslTestServerFactory();

private Application app;
private RunningServer runningServer;
Expand Down Expand Up @@ -49,7 +49,7 @@ public void stopServer() throws Exception {

private WSResponse wsGet(final String path) throws Exception {
final WSClient wsClient = app.injector().instanceOf(WSClient.class);
final String url = runningServer.endpoints().httpEndpoint().get().pathUrl(path);
final String url = runningServer.endpoints().httpsEndpoint().get().pathUrl(path);
return wsClient
.url(url)
.addHeader("Content-Type", GrpcProtocolNative.contentType().toString())
Expand Down
4 changes: 3 additions & 1 deletion play-testkit/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
play.server.provider = play.core.server.AkkaHttpServerProvider
play.server.provider = play.core.server.AkkaHttpServerProvider

play.ws.ssl.loose.acceptAnyCertificate = true
50 changes: 50 additions & 0 deletions play-testkit/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.classic.AsyncAppender"/>
<import class="ch.qos.logback.core.FileAppender"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
*/
package play.grpc.testkit

import akka.annotation.ApiMayChange
import play.api.test.DefaultTestServerFactory
import play.api.Application
import play.core.server.ServerConfig

/**
* A test server factory that configures the server to use SSL.
*/
@ApiMayChange class SslTestServerFactory extends DefaultTestServerFactory {
override def serverConfig(app: Application): ServerConfig = {
super
.serverConfig(app)
.copy(
port = None,
sslPort = Some(0),
)
}
}
5 changes: 4 additions & 1 deletion project/CommonPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ object CommonPlugin extends AutoPlugin {
Nil
},
doc / javacOptions --= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
crossScalaVersions := Seq(scala212, scala213),
Test / javaOptions ++= Seq("--add-exports=java.base/sun.security.x509=ALL-UNNAMED"),
Test / fork := true,
crossScalaVersions := Seq(scala213),
scalaVersion := scala213,
)

val scalaVersionNumber = Def.setting(VersionNumber(scalaVersion.value))
Expand Down
Loading

0 comments on commit deeea2e

Please sign in to comment.