This repository was archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Testkit sink write #1065
Merged
Merged
Testkit sink write #1065
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
08a6cf5
clceanup, rename cloudflowAkkastream to cloudflowAkka.
RayRoestenburg 0af4feb
Added flow to taps.
RayRoestenburg 8fd90ec
Minor doc fix.
RayRoestenburg 54fe17e
Testkit SinkRef.write future is completed per element.
RayRoestenburg 9e314b5
Test for TestSinkRef.
RayRoestenburg 8340689
Completed message is not sent per write on sinkRef anymore.
RayRoestenburg 4cd5f23
Formatting.
RayRoestenburg a957c15
Cleanup.
RayRoestenburg 55eeddf
Copyright update.
RayRoestenburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| { | ||
| "namespace": "cloudflow.akkastream.testdata", | ||
| "type": "record", | ||
| "name": "TestData", | ||
| "fields":[ | ||
| { | ||
| "name": "id", "type": "int" | ||
| }, | ||
| { | ||
| "name": "name", "type": "string" | ||
| } | ||
| ] | ||
| } |
97 changes: 97 additions & 0 deletions
97
.../cloudflow-akka-testkit/src/test/scala/cloudflow/akkastream/testkit/TestSinkRefSpec.scala
This file contains hidden or 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,97 @@ | ||
| /* | ||
| * Copyright (C) 2016-2020 Lightbend Inc. <https://www.lightbend.com> | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package cloudflow.akkastream.testkit | ||
|
|
||
| import akka.actor.ActorSystem | ||
| import akka.stream.scaladsl.{ RunnableGraph, Source } | ||
| import akka.testkit.TestKit | ||
| import cloudflow.akkastream.{ AkkaStreamlet, AkkaStreamletLogic } | ||
| import cloudflow.akkastream.scaladsl.RunnableGraphStreamletLogic | ||
| import cloudflow.streamlets.StreamletShape | ||
| import cloudflow.akkastream.testdata.TestData | ||
| import cloudflow.akkastream.testkit.scaladsl._ | ||
| import cloudflow.streamlets.avro.{ AvroInlet, AvroOutlet } | ||
| import org.scalatest._ | ||
| import org.scalatest.wordspec.AnyWordSpec | ||
| import org.scalatest.matchers.must.Matchers | ||
| import scala.concurrent.Future | ||
|
|
||
| class TestSinkRefSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll { | ||
| private implicit val system = ActorSystem("CloudflowAkkaTestkitErrorReproducerSpec") | ||
|
|
||
| override def afterAll: Unit = | ||
| TestKit.shutdownActorSystem(system) | ||
|
|
||
| object TestFixture { | ||
| val msgs = List.tabulate(10)(i => TestData(i, i.toString)) | ||
|
|
||
| class TestStreamlet extends AkkaStreamlet { | ||
| val in = AvroInlet[TestData]("in") | ||
| val out = AvroOutlet[TestData]("out") | ||
|
|
||
| override val shape: StreamletShape = StreamletShape(in).withOutlets(out) | ||
|
|
||
| override protected def createLogic(): AkkaStreamletLogic = new RunnableGraphStreamletLogic() { | ||
| override def runnableGraph(): RunnableGraph[_] = { | ||
| val snk = sinkRef(out) | ||
| sourceWithCommittableContext(in) | ||
| .mapAsync(parallelism = 1) { element => | ||
| snk.write(element) | ||
| } | ||
| .to(committableSink) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| import TestFixture._ | ||
|
|
||
| "Cloudflow Akka TestKit" should { | ||
| "emit a dedicated completed messages after each message emitted via sinkRef.write, but should not" in { | ||
| val testkit = AkkaStreamletTestKit(system) | ||
| val s = new TestStreamlet() | ||
| val in = testkit.inletFromSource(s.in, Source(msgs)) | ||
| val out = testkit.outletAsTap(s.out) | ||
|
|
||
| testkit.run(s, List(in), List(out), () => { | ||
| val results = out.probe.receiveN(msgs.size) | ||
|
|
||
| val resultWithoutIndex = results.asInstanceOf[Seq[(_, TestData)]].map(_._2) | ||
| resultWithoutIndex must contain allElementsOf msgs | ||
| }) | ||
| } | ||
|
|
||
| (0 until 300).foreach { i => | ||
| s"maintain the order in which messages are emitted via sinkRef.write (run #$i), but should not" in { | ||
| val testkit = AkkaStreamletTestKit(system) | ||
| val s = new TestStreamlet() | ||
| val in = testkit.inletFromSource(s.in, Source(msgs)) | ||
| val out = testkit.outletAsTap(s.out) | ||
|
|
||
| testkit.run(s, List(in), List(out), () => { | ||
| val got = out.probe | ||
| .receiveN(msgs.size) | ||
| .map { | ||
| case (_, m: TestData) => m | ||
| } | ||
| got mustEqual msgs | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2016-2021 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch