Repository navigation
Update PortableTimersExecutionTest to use PAssert, to prevent a concurrency issue, collecting the pipeline results #7214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mxm
merged 2 commits into
apache:master
from
ajamato:java_sdk_metrics_enqueuing_receiver_fixup_flink_test
Dec 6, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| */ | ||
| package org.apache.beam.runners.flink; | ||
|
|
||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| import static org.hamcrest.core.Is.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
|
|
@@ -31,6 +30,7 @@ | |
| import org.apache.beam.model.jobmanagement.v1.JobApi.JobState.Enum; | ||
| import org.apache.beam.model.pipeline.v1.RunnerApi; | ||
| import org.apache.beam.runners.core.construction.Environments; | ||
| import org.apache.beam.runners.core.construction.JavaReadViaImpulse; | ||
| import org.apache.beam.runners.core.construction.PipelineTranslation; | ||
| import org.apache.beam.sdk.Pipeline; | ||
| import org.apache.beam.sdk.coders.StringUtf8Coder; | ||
|
|
@@ -45,11 +45,13 @@ | |
| import org.apache.beam.sdk.state.TimerSpecs; | ||
| import org.apache.beam.sdk.state.ValueState; | ||
| import org.apache.beam.sdk.testing.CrashingRunner; | ||
| import org.apache.beam.sdk.testing.PAssert; | ||
| import org.apache.beam.sdk.transforms.DoFn; | ||
| import org.apache.beam.sdk.transforms.Impulse; | ||
| import org.apache.beam.sdk.transforms.ParDo; | ||
| import org.apache.beam.sdk.transforms.windowing.BoundedWindow; | ||
| import org.apache.beam.sdk.values.KV; | ||
| import org.apache.beam.sdk.values.PCollection; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
@@ -74,11 +76,8 @@ public static Object[] testModes() { | |
|
|
||
| private transient ListeningExecutorService flinkJobExecutor; | ||
|
|
||
| private static List<KV<String, Integer>> results = new ArrayList<>(); | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| results.clear(); | ||
| flinkJobExecutor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); | ||
| } | ||
|
|
||
|
|
@@ -87,7 +86,7 @@ public void tearDown() { | |
| flinkJobExecutor.shutdown(); | ||
| } | ||
|
|
||
| @Test(timeout = 60_000) | ||
| @Test(timeout = 120_000) | ||
| public void testTimerExecution() throws Exception { | ||
| PipelineOptions options = PipelineOptionsFactory.create(); | ||
| options.setRunner(CrashingRunner.class); | ||
|
|
@@ -116,6 +115,7 @@ public void testTimerExecution() throws Exception { | |
| expectedOutput.add(KV.of(key.toString(), i + offset)); | ||
| } | ||
| } | ||
|
|
||
| Collections.shuffle(input); | ||
|
|
||
| DoFn<byte[], KV<String, Integer>> inputFn = | ||
|
|
@@ -157,20 +157,13 @@ public void onTimer( | |
| } | ||
| }; | ||
|
|
||
| DoFn<KV<String, Integer>, Void> collectResults = | ||
| new DoFn<KV<String, Integer>, Void>() { | ||
| @ProcessElement | ||
| public void processElement(ProcessContext context) { | ||
| results.add(context.element()); | ||
| } | ||
| }; | ||
|
|
||
| final Pipeline pipeline = Pipeline.create(options); | ||
| pipeline | ||
| .apply(Impulse.create()) | ||
| .apply(ParDo.of(inputFn)) | ||
| .apply(ParDo.of(testFn)) | ||
| .apply(ParDo.of(collectResults)); | ||
| PCollection<KV<String, Integer>> output = | ||
| pipeline.apply(Impulse.create()).apply(ParDo.of(inputFn)).apply(ParDo.of(testFn)); | ||
| PAssert.that(output).containsInAnyOrder(expectedOutput); | ||
| // This is line below required to convert the PAssert's read to an impulse, which is expected | ||
| // by the GreedyPipelineFuser. | ||
| pipeline.replaceAll(Collections.singletonList(JavaReadViaImpulse.boundedOverride())); | ||
|
|
||
| RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(pipeline); | ||
|
|
||
|
|
@@ -185,11 +178,9 @@ public void processElement(ProcessContext context) { | |
| Collections.emptyList()); | ||
|
|
||
| jobInvocation.start(); | ||
| long timeout = System.currentTimeMillis() + 60 * 1000; | ||
| while (jobInvocation.getState() != Enum.DONE && System.currentTimeMillis() < timeout) { | ||
| while (jobInvocation.getState() != Enum.DONE) { | ||
| Thread.sleep(1000); | ||
| } | ||
| assertThat(jobInvocation.getState(), is(Enum.DONE)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also remove this line if we remove the timeout because the while loop will only return when it is done.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| assertThat(results, containsInAnyOrder(expectedOutput.toArray())); | ||
| } | ||
| } | ||
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.
+1 to use PAssert to verify result of a Pipeline.
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.
+1