Last active
February 4, 2019 17:59
-
-
Save fpopic/38087eac33abee7f3aaba41f831c5407 to your computer and use it in GitHub Desktop.
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
| import org.apache.beam.sdk.testing.{NeedsRunner, PAssert, TestPipeline} | |
| import org.apache.beam.sdk.transforms.DoFn.ProcessElement | |
| import org.apache.beam.sdk.transforms.{Create, DoFn, ParDo} | |
| import org.junit.experimental.categories.Category | |
| import org.junit.{Rule, Test} | |
| import org.scalatest.junit.JUnitSuite | |
| import scala.annotation.meta.getter | |
| import scala.collection.JavaConverters._ | |
| class TimesTwoDoFn extends DoFn[Int, Int] { | |
| @ProcessElement | |
| def processElement(c: ProcessContext): Unit = { | |
| c.output(c.element * 2) | |
| } | |
| } | |
| class TimesFiveDoFn extends DoFn[Int, Int] { | |
| @ProcessElement | |
| def processElement(c: ProcessContext): Unit = { | |
| c.output(c.element * 5) | |
| } | |
| } | |
| class MinimalPipelineTest extends JUnitSuite { | |
| @(Rule@getter) // The @Rule 'pipeline' must be public. | |
| val pipeline: TestPipeline = TestPipeline.create() | |
| @Test | |
| @Category(Array(classOf[NeedsRunner])) | |
| def myTimesTenPipelineTest(): Unit = { | |
| val input = Iterable(1, 2, 3).asJava | |
| val actualOutput = pipeline.apply(Create.of(input)) | |
| .apply("x2", ParDo.of(new TimesTwoDoFn())) | |
| .apply("x5", ParDo.of(new TimesFiveDoFn())) | |
| val expectedOutput = Iterable(10, 20, 30).asJava | |
| PAssert that actualOutput containsInAnyOrder expectedOutput | |
| pipeline.run().waitUntilFinish() | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For testing the whole pipeline ensure the following in build.sbt: