-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Low level transform with metadata for Projection gRPC
- Loading branch information
1 parent
8583f12
commit 991cb41
Showing
4 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ction-grpc/src/test/scala/akka/projection/grpc/producer/scaladsl/TransformationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.projection.grpc.producer.scaladsl | ||
|
||
import akka.projection.grpc.producer.scaladsl.EventProducer.Transformation | ||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import scala.concurrent.Future | ||
|
||
class TransformationSpec extends AnyWordSpec with Matchers with ScalaFutures { | ||
|
||
"The gRPC event Transformation" should { | ||
|
||
"transform simple" in { | ||
val transformer = Transformation.empty.registerMapper((_: String) => Some("mapped")) | ||
transformer("whatever", None).futureValue should ===(Some("mapped")) | ||
} | ||
|
||
"transform filter out simple" in { | ||
val transformer = Transformation.empty.registerMapper((_: String) => None) | ||
transformer("whatever", None).futureValue should ===(None) | ||
} | ||
|
||
"transform simple async" in { | ||
val transformer = Transformation.empty.registerAsyncMapper((_: String) => Future.successful(Some("mapped"))) | ||
transformer("whatever", None).futureValue should ===(Some("mapped")) | ||
} | ||
|
||
"transform low level with metadata" in { | ||
val transformer = | ||
Transformation.empty.registerLowLevelMapper((_: String, meta) => Future.successful(meta)) | ||
transformer("whatever", Some("meta")).futureValue should ===(Some("meta")) | ||
} | ||
|
||
"fail by default if no transformer exist for event" in { | ||
val transformer = Transformation.empty | ||
transformer("whatever", Some("meta")).failed.futureValue | ||
} | ||
|
||
"fallback if no transformer exist for event" in { | ||
val transformer = Transformation.empty.registerOrElseMapper(_ => Some("fallback")) | ||
transformer("whatever", Some("meta")).futureValue should ===(Some("fallback")) | ||
} | ||
|
||
"fallback low level with metadata if no transformer exist for event" in { | ||
val transformer = Transformation.empty.registerLowLevelOrElseMapper((_, meta) => Future.successful(meta)) | ||
transformer("whatever", Some("meta")).futureValue should ===(Some("meta")) | ||
} | ||
} | ||
|
||
} |