Skip to content

Commit d2b33a4

Browse files
committed
refactor: move code from using akka to pekko
1 parent d7bddea commit d2b33a4

File tree

13 files changed

+142
-130
lines changed

13 files changed

+142
-130
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ or see https://github.com/Doikor/jsonapi-scala-example
4646
There is a very generic JsonApiClient interface for implementing a simple client
4747
interface for handling the http query writing side of this
4848

49-
The subproject "akka-client" has an implementation of this using akka-http
49+
The subproject "pekko-client" has an implementation of this using pekko-http
5050

5151
The subproject "http4s-client" has an implementation of this using http4s
5252

@@ -74,19 +74,19 @@ val filtered = jac.filter[BillingAccount]("some nice filter string here")
7474

7575
### Setup
7676

77-
#### akka-http client
77+
#### pekko-http client
7878
```scala
79-
// needs ActorSystem and Materializer for akka-http
79+
// needs ActorSystem and Materializer for pekko-http
8080
// the ApiEndPoint is used to as the "root" where to launch queries
8181
import io.lemonlabs.uri.typesafe.dsl._
82-
import akka.actor.ActorSystem
83-
import akka.stream.ActorMaterializer
82+
import org.apache.pekko.actor.ActorSystem
83+
import org.apache.pekko.stream.Materializer
8484
import com.qvantel.jsonapi.ApiEndpoint
8585
import com.qvantel.jsonapi.JsonApiClient
86-
import com.qvantel.jsonapi.client.akka.AkkaClient._
86+
import com.qvantel.jsonapi.client.pekko.PekkoClient._
8787

8888
implicit val system: ActorSystem = ActorSystem()
89-
implicit val materializer: ActorMaterializer = ActorMaterializer()
89+
implicit val materializer: Materializer = Materializer(system)
9090
implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api")
9191

9292
val jac = JsonApiClient.instance

build.sbt

+24-21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28+
import Dependencies.*
29+
2830
val scala213 = Seq(
2931
"-deprecation", // Emit warning and location for usages of deprecated APIs.
3032
"-encoding",
@@ -220,15 +222,12 @@ lazy val model = (project in file("model"))
220222
libraryDependencies ++= testDeps
221223
)
222224

223-
val akkaVersion = "2.6.20"
224-
val akkaHttpVersion = "10.2.10"
225-
226-
lazy val akkaClient = (project in file("akka-client"))
225+
lazy val pekkoClient = (project in file("pekko-client"))
227226
.dependsOn(core)
228227
.enablePlugins(MacrosCompiler)
229228
.settings(scalafixSettings)
230229
.settings(
231-
name := "jsonapi-scala-akka-client",
230+
name := "jsonapi-scala-pekko-client",
232231
scalaVersion := scalaVersion213,
233232
crossScalaVersions := Seq(scalaVersion212, scalaVersion213),
234233
scalacOptions ++= {
@@ -238,19 +237,21 @@ lazy val akkaClient = (project in file("akka-client"))
238237
scala213
239238
},
240239
libraryDependencies ++= Seq(
241-
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided,
242-
"com.typesafe.akka" %% "akka-actor" % akkaVersion % Provided,
243-
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided,
244-
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion % Provided
240+
`pekko-stream` % Provided,
241+
`pekko-actor` % Provided,
242+
`pekko-http` % Provided,
243+
`pekko-http-spray-json` % Provided,
244+
"io.lemonlabs" %% "scala-uri" % "4.0.3" % Test,
245+
"org.parboiled" %% "parboiled" % "2.5.1" % Test
245246
) ++ testDeps
246247
)
247248

248-
lazy val akka = (project in file("akka"))
249+
lazy val pekko = (project in file("pekko"))
249250
.dependsOn(core, model)
250251
.enablePlugins(MacrosCompiler)
251252
.settings(scalafixSettings)
252253
.settings(
253-
name := "jsonapi-scala-akka",
254+
name := "jsonapi-scala-pekko",
254255
scalaVersion := scalaVersion213,
255256
crossScalaVersions := Seq(scalaVersion212, scalaVersion213),
256257
scalacOptions ++= {
@@ -260,16 +261,18 @@ lazy val akka = (project in file("akka"))
260261
scala213
261262
},
262263
libraryDependencies ++= Seq(
263-
"com.typesafe.akka" %% "akka-actor" % akkaVersion % Provided excludeAll (
264-
ExclusionRule(organization = "com.typesafe.akka", name = "akka-cluster"),
265-
ExclusionRule(organization = "com.typesafe.akka", name = "akka-remote")
264+
`pekko-actor` % Provided excludeAll (
265+
ExclusionRule(organization = "org.apache.pekko", name = "pekko-cluster"),
266+
ExclusionRule(organization = "org.apache.pekko", name = "pekko-remote")
266267
),
267-
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided,
268-
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided,
269-
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion % Provided,
270-
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
271-
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
272-
"org.scalatest" %% "scalatest" % "3.2.14" % Test
268+
`pekko-stream` % Provided,
269+
`pekko-http` % Provided,
270+
`pekko-http-core` % Provided,
271+
`pekko-http-testkit` % Test,
272+
`pekko-testkit` % Test,
273+
"io.lemonlabs" %% "scala-uri" % "4.0.3" % Test,
274+
"org.parboiled" %% "parboiled" % "2.5.1" % Test,
275+
"org.scalatest" %% "scalatest" % "3.2.18" % Test
273276
) ++ testDeps
274277
)
275278

@@ -298,7 +301,7 @@ lazy val http4sClient = (project in file("http4s-client"))
298301
)
299302

300303
lazy val root = (project in file("."))
301-
.aggregate(core, model, akkaClient, http4sClient, akka)
304+
.aggregate(core, model, pekkoClient, http4sClient, pekko)
302305
.settings(
303306
publishArtifact := false,
304307
name := "jsonapi-scala",

akka-client/src/main/scala/com/qvantel/jsonapi/client/akka/AkkaClient.scala renamed to pekko-client/src/main/scala/com/qvantel/jsonapi/client/pekko/PekkoClient.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
package com.qvantel.jsonapi.client.akka
1+
package com.qvantel.jsonapi.client.pekko
22

33
import _root_.spray.json._
4-
import akka.actor.ActorSystem
5-
import akka.http.scaladsl.Http
6-
import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding}
7-
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
8-
import akka.http.scaladsl.model._
9-
import akka.http.scaladsl.model.headers.HttpEncodings
10-
import akka.http.scaladsl.unmarshalling.Unmarshaller._
11-
import akka.http.scaladsl.unmarshalling._
12-
import akka.stream.ActorMaterializer
4+
import org.apache.pekko.actor.ActorSystem
5+
import org.apache.pekko.http.scaladsl.Http
6+
import org.apache.pekko.http.scaladsl.coding.{Deflate, Gzip, NoCoding}
7+
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
8+
import org.apache.pekko.http.scaladsl.model._
9+
import org.apache.pekko.http.scaladsl.model.headers.HttpEncodings
10+
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller._
11+
import org.apache.pekko.http.scaladsl.unmarshalling._
12+
import org.apache.pekko.stream.Materializer
1313
import cats.effect.{ContextShift, IO}
1414
import io.lemonlabs.uri.Url
1515
import io.lemonlabs.uri.typesafe.dsl._
1616

1717
import com.qvantel.jsonapi._
1818

19-
object AkkaClient {
20-
implicit def instance(implicit m: ActorMaterializer, system: ActorSystem, endpoint: ApiEndpoint): JsonApiClient = {
19+
object PekkoClient {
20+
implicit def instance(implicit m: Materializer, system: ActorSystem, endpoint: ApiEndpoint): JsonApiClient = {
2121
import system.dispatcher
2222
implicit val cs: ContextShift[IO] = IO.contextShift(system.dispatcher)
2323

@@ -186,7 +186,7 @@ object AkkaClient {
186186
reqUrl: String,
187187
method: HttpMethod = HttpMethods.GET,
188188
entity: RequestEntity = HttpEntity.Empty,
189-
headers: List[HttpHeader])(implicit m: ActorMaterializer, system: ActorSystem): IO[HttpResponse] = {
189+
headers: List[HttpHeader])(implicit m: Materializer, system: ActorSystem): IO[HttpResponse] = {
190190
import system.dispatcher
191191
implicit val cs: ContextShift[IO] = IO.contextShift(system.dispatcher)
192192

akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/AkkaClientSpec.scala renamed to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/PekkoClientSpec.scala

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
package com.qvantel.jsonapi.client.akka
1+
package com.qvantel.jsonapi.client.pekko
22

33
import scala.language.experimental.macros
4-
54
import scala.concurrent.Await
65
import scala.concurrent.duration.Duration
7-
import akka.actor.ActorSystem
8-
import akka.stream.ActorMaterializer
6+
import org.apache.pekko.actor.ActorSystem
7+
import org.apache.pekko.stream.Materializer
98
import cats.syntax.traverse._
109
import cats.data.OptionT
1110
import cats.instances.list._
1211
import io.lemonlabs.uri.typesafe.dsl._
1312
import org.specs2.matcher.MatcherMacros
1413
import org.specs2.mutable.Specification
1514
import org.specs2.specification.AfterAll
16-
1715
import com.qvantel.jsonapi._
18-
import com.qvantel.jsonapi.client.akka.AkkaClient._
16+
import PekkoClient._
1917

20-
class AkkaClientSpec extends Specification with MatcherMacros with AfterAll {
18+
class PekkoClientSpec extends Specification with MatcherMacros with AfterAll {
2119
// this is an integration test.
2220
// to run these tests uncomment this and start a jsonapi.org compatible server in the url specified for the endpoint
2321
skipAll
2422

2523
implicit val system: ActorSystem = ActorSystem()
26-
implicit val m: ActorMaterializer = ActorMaterializer()
24+
implicit val m: Materializer = Materializer(system)
2725
implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api", Map())
2826

2927
val jac = JsonApiClient.instance

akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/TestClasses.scala renamed to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/TestClasses.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.qvantel.jsonapi.client.akka
1+
package com.qvantel.jsonapi.client.pekko
22

33
import com.qvantel.jsonapi.{ToMany, ToOne, jsonApiResource}
44
import spray.json.DefaultJsonProtocol._

akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/package.scala renamed to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import com.qvantel.jsonapi.ApiRoot
55
/**
66
* Created by ahuttunen on 27/04/2017.
77
*/
8-
package object akka {
8+
package object pekko {
99
implicit val apiroot: ApiRoot = ApiRoot.empty
1010
}

akka/src/main/scala/com/qvantel/jsonapi/akka/JsonApiSupport.scala renamed to pekko/src/main/scala/com/qvantel/jsonapi/pekko/JsonApiSupport.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
package com.qvantel.jsonapi.akka
28-
29-
import _root_.akka.http.scaladsl.Http
30-
import _root_.akka.http.scaladsl.client.RequestBuilding
31-
import _root_.akka.http.scaladsl.marshalling._
32-
import _root_.akka.http.scaladsl.model._
33-
import _root_.akka.http.scaladsl.model.headers._
34-
import _root_.akka.http.scaladsl.unmarshalling._
35-
import _root_.akka.stream.Materializer
36-
import _root_.akka.stream.scaladsl._
37-
import _root_.akka.util.{ByteString, Timeout}
27+
package com.qvantel.jsonapi.pekko
28+
29+
import _root_.org.apache.pekko.http.scaladsl.Http
30+
import _root_.org.apache.pekko.http.scaladsl.client.RequestBuilding
31+
import _root_.org.apache.pekko.http.scaladsl.marshalling._
32+
import _root_.org.apache.pekko.http.scaladsl.model._
33+
import _root_.org.apache.pekko.http.scaladsl.model.headers._
34+
import _root_.org.apache.pekko.http.scaladsl.unmarshalling._
35+
import _root_.org.apache.pekko.stream.Materializer
36+
import _root_.org.apache.pekko.stream.scaladsl._
37+
import _root_.org.apache.pekko.util.{ByteString, Timeout}
3838
import _root_.spray.json._
3939

4040
import scala.concurrent.{ExecutionContext, Future}
@@ -168,9 +168,9 @@ trait JsonApiSupport0 {
168168
/** Custom SendReceive that adds the include params into X-Internal-Include
169169
* header that can be read by FromResponseUnmarshaller
170170
*/
171-
object JsonApiClientAkka extends RequestBuilding {
172-
import _root_.akka.actor._
173-
import _root_.akka.http.scaladsl.settings.{ClientConnectionSettings, ConnectionPoolSettings}
171+
object JsonApiClientPekko extends RequestBuilding {
172+
import _root_.org.apache.pekko.actor._
173+
import _root_.org.apache.pekko.http.scaladsl.settings.{ClientConnectionSettings, ConnectionPoolSettings}
174174

175175
import scala.concurrent.duration._
176176

akka/src/main/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandler.scala renamed to pekko/src/main/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandler.scala

+16-21
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,26 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
package com.qvantel.jsonapi.akka
28-
29-
import com.qvantel.jsonapi.model.ErrorObject
27+
package com.qvantel.jsonapi.pekko
3028

3129
import _root_.spray.json.DefaultJsonProtocol._
3230
import _root_.spray.json._
33-
34-
import akka.event.LoggingAdapter
35-
import akka.http.scaladsl.model.StatusCodes._
36-
import akka.http.scaladsl.model.{StatusCode, IllegalRequestException, ContentType}
37-
import akka.http.scaladsl.settings.RoutingSettings
38-
import akka.http.scaladsl.model.{HttpEntity, HttpResponse, MediaTypes}
39-
import akka.http.scaladsl.server.Directives._
40-
import akka.http.scaladsl.server._
41-
import akka.http.scaladsl.server.AuthenticationFailedRejection._
31+
import com.qvantel.jsonapi.model.ErrorObject
32+
import org.apache.pekko.event.LoggingAdapter
33+
import org.apache.pekko.http.scaladsl.model.StatusCodes._
34+
import org.apache.pekko.http.scaladsl.model._
35+
import org.apache.pekko.http.scaladsl.server.AuthenticationFailedRejection._
36+
import org.apache.pekko.http.scaladsl.server.Directives._
37+
import org.apache.pekko.http.scaladsl.server._
38+
import org.apache.pekko.http.scaladsl.settings.RoutingSettings
4239

4340
import scala.util.control.NonFatal
4441

45-
trait AkkaExceptionHandlerTrait {
42+
trait PekkoExceptionHandlerTrait {
4643

47-
import AkkaExceptionHandlerObject._
44+
import PekkoExceptionHandlerObject._
4845

49-
val defaultAkkaRejectionHandler: RejectionHandler = RejectionHandler
46+
val defaultPekkoRejectionHandler: RejectionHandler = RejectionHandler
5047
.newBuilder()
5148
.handle {
5249
case AuthenticationFailedRejection(cause, _) =>
@@ -146,27 +143,25 @@ trait AkkaExceptionHandlerTrait {
146143
}
147144
.result()
148145

149-
def defaultAkkaExceptionHandler(implicit settings: RoutingSettings, log: LoggingAdapter): ExceptionHandler =
146+
def defaultPekkoExceptionHandler(implicit settings: RoutingSettings, log: LoggingAdapter): ExceptionHandler =
150147
ExceptionHandler {
151-
case e: IllegalRequestException => {
148+
case e: IllegalRequestException =>
152149
extractRequestContext { ctx =>
153150
log.warning("Illegal request {}\n\t{}\n\tCompleting with '{}' response", ctx.request, e.getMessage, e.status)
154151
complete(jsonApiErrorResponse(e.status, "Illegal Request", e.info.format(settings.verboseErrorMessages)))
155152
}
156-
}
157-
case NonFatal(e) => {
153+
case NonFatal(e) =>
158154
extractRequestContext { ctx =>
159155
log.error(e, "Error during processing of request {}", ctx.request)
160156
complete(
161157
jsonApiErrorResponse(InternalServerError,
162158
InternalServerError.reason,
163159
if (e.getMessage != null) e.getMessage else InternalServerError.defaultMessage))
164160
}
165-
}
166161
}
167162
}
168163

169-
object AkkaExceptionHandlerObject extends Rejection {
164+
object PekkoExceptionHandlerObject extends Rejection {
170165

171166
def jsonApiError(code: StatusCode, title: String, detail: String): JsValue =
172167
JsObject("errors" -> List(

akka/src/test/scala/com/qvantel/jsonapi/JsonApiSortingAkkaSpec.scala renamed to pekko/src/test/scala/com/qvantel/jsonapi/JsonApiSortingPekkoSpec.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727
package com.qvantel.jsonapi
2828

29-
import akka.JsonApiSupport._
30-
31-
import org.specs2.mutable._
29+
import pekko.JsonApiSupport._
30+
import _root_.org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest
3231
import _root_.spray.json.DefaultJsonProtocol._
3332
import _root_.spray.json._
34-
import _root_.akka.http.scaladsl.testkit.Specs2RouteTest
3533
import io.lemonlabs.uri.typesafe.dsl._
34+
import org.apache.pekko.actor.ActorSystem
35+
import org.specs2.mutable._
3636

37-
final class JsonApiSortingAkkaSpec extends Specification with Specs2RouteTest {
38-
def actorRefFactory = system
37+
final class JsonApiSortingPekkoSpec extends Specification with Specs2RouteTest {
38+
def actorRefFactory: ActorSystem = system
3939

4040
implicit val apiRoot: com.qvantel.jsonapi.ApiRoot = ApiRoot(Some("/api"))
4141

akka/src/test/scala/com/qvantel/jsonapi/RelatedResponseAkkaSpec.scala renamed to pekko/src/test/scala/com/qvantel/jsonapi/RelatedResponsePekkoSpec.scala

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727
package com.qvantel.jsonapi
2828

29-
import com.qvantel.jsonapi.akka.JsonApiSupport._
30-
29+
import pekko.JsonApiSupport._
3130
import org.specs2.mutable._
31+
import _root_.org.apache.pekko.http.scaladsl.model._
32+
import _root_.org.apache.pekko.http.scaladsl.server.Directives._
33+
import _root_.org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest
3234
import _root_.spray.json._
33-
import _root_.spray.json.DefaultJsonProtocol._
34-
import _root_.akka.http.scaladsl.testkit.Specs2RouteTest
35-
import _root_.akka.http.scaladsl.model._
36-
import _root_.akka.http.scaladsl.server.Directives._
35+
import org.apache.pekko.actor.ActorSystem
36+
import org.specs2.mutable._
37+
import spray.json._
38+
import DefaultJsonProtocol._
3739

38-
class RelatedResponseAkkaSpec extends Specification with Specs2RouteTest {
39-
def actorRefFactory = system
40+
class RelatedResponsePekkoSpec extends Specification with Specs2RouteTest {
41+
def actorRefFactory: ActorSystem = system
4042
implicit val apiRoot: com.qvantel.jsonapi.ApiRoot = ApiRoot(None)
4143
@jsonApiResource final case class Test(id: String, name: String)
4244

0 commit comments

Comments
 (0)