You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/03/29 15:37:33 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #14272: [BEAM-3415] Amend TestPipeline to work with JUnit5

TheNeuralBit commented on a change in pull request #14272:
URL: https://github.com/apache/beam/pull/14272#discussion_r603389335



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipelineJunit5.java
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.beam.sdk.testing;
+
+import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.lang.reflect.Method;
+import org.apache.beam.sdk.options.ApplicationNameOptions;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * An extension of {@link TestPipeline} that implements the JUnit5 Extensions model.
+ *
+ * <p>Usage is the same as {@link TestPipeline}, but the instantiation has to be done via JUnit5's
+ * {@link org.junit.jupiter.api.extension.RegisterExtension} annotation mechanism, like

Review comment:
       It looks like you're missing an example here

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
##########
@@ -107,7 +107,7 @@
 
   private final PipelineOptions options;
 
-  private static class PipelineRunEnforcement {
+  protected static class PipelineRunEnforcement {

Review comment:
       Could these be package-private instead?
   ```suggestion
     static class PipelineRunEnforcement {
   ```

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipelineJunit5.java
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.beam.sdk.testing;
+
+import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.lang.reflect.Method;
+import org.apache.beam.sdk.options.ApplicationNameOptions;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * An extension of {@link TestPipeline} that implements the JUnit5 Extensions model.
+ *
+ * <p>Usage is the same as {@link TestPipeline}, but the instantiation has to be done via JUnit5's
+ * {@link org.junit.jupiter.api.extension.RegisterExtension} annotation mechanism, like
+ *
+ * <p>The {@link NeedsRunner} category tagging is replaced with JUnit5's {@link
+ * org.junit.jupiter.api.Tag} mechanism, the equivalent tag is {@literal needsRunner}.
+ *
+ * <pre><code>
+ * {@literal @RegisterExtension}
+ *  public final transient TestPipelineJunit5 p = TestPipelineJunit5.create();
+ *
+ * {@literal @Test}
+ * {@literal @Tag}("needsRunner")
+ *  public void myPipelineTest() throws Exception {
+ *    final PCollection&lt;String&gt; pCollection = pipeline.apply(...)
+ *    PAssert.that(pCollection).containsInAnyOrder(...);
+ *    pipeline.run();
+ *  }
+ * </code></pre>
+ *
+ * <p>See also the <a href="https://beam.apache.org/contribute/testing/">Testing</a> documentation
+ * section.
+ */
+@SuppressWarnings({
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class TestPipelineJunit5 extends TestPipeline

Review comment:
       Is there any way we could provide a single `TestPipeline` that can be used with both Junit5 and Junit4? I think that would be preferable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org