From a4661044c49ff440b068c1b09b4513eaaf67507e Mon Sep 17 00:00:00 2001 From: Alex Amato Date: Wed, 5 Dec 2018 12:35:24 -0800 Subject: [PATCH 1/2] Update PortableTimersExecutionTest to use PAssert, to prevent a concurrency issue collecting the test results. --- .../flink/PortableTimersExecutionTest.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java b/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java index 8fbb68652881..db153426cc2c 100644 --- a/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java +++ b/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java @@ -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> 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> inputFn = @@ -157,20 +157,13 @@ public void onTimer( } }; - DoFn, Void> collectResults = - new DoFn, 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> 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,10 @@ public void processElement(ProcessContext context) { Collections.emptyList()); jobInvocation.start(); - long timeout = System.currentTimeMillis() + 60 * 1000; + long timeout = System.currentTimeMillis() + 2 * 60 * 1000; while (jobInvocation.getState() != Enum.DONE && System.currentTimeMillis() < timeout) { Thread.sleep(1000); } assertThat(jobInvocation.getState(), is(Enum.DONE)); - assertThat(results, containsInAnyOrder(expectedOutput.toArray())); } } From 79df7843bf55a913f9ccecc689afdfe7622ad8db Mon Sep 17 00:00:00 2001 From: Alex Amato Date: Thu, 6 Dec 2018 09:42:14 -0800 Subject: [PATCH 2/2] Remove extra timeout code from PortableTimersExecutionTest. --- .../apache/beam/runners/flink/PortableTimersExecutionTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java b/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java index db153426cc2c..58db1baad164 100644 --- a/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java +++ b/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java @@ -178,8 +178,7 @@ public void onTimer( Collections.emptyList()); jobInvocation.start(); - long timeout = System.currentTimeMillis() + 2 * 60 * 1000; - while (jobInvocation.getState() != Enum.DONE && System.currentTimeMillis() < timeout) { + while (jobInvocation.getState() != Enum.DONE) { Thread.sleep(1000); } assertThat(jobInvocation.getState(), is(Enum.DONE));