You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/10/26 17:55:24 UTC
[GitHub] [flink] zentol commented on a change in pull request #17556: [FLINK-24627][tests] add some Junit5 extensions to replace the existed Junit4 rules
zentol commented on a change in pull request #17556:
URL: https://github.com/apache/flink/pull/17556#discussion_r735366139
##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/zookeeper/ZooKeeperExtension.java
##########
@@ -0,0 +1,64 @@
+package org.apache.flink.runtime.zookeeper;
+
+import org.apache.flink.core.testutils.CustomExtension;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.curator.test.TestingServer;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+
+/**
+ * {@link org.junit.jupiter.api.extension.Extension} which starts a {@link
+ * org.apache.zookeeper.server.ZooKeeperServer}.
+ */
+public class ZooKeeperExtension implements CustomExtension {
+ private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperExtension.class);
+
+ @Nullable private TestingServer zooKeeperServer;
+
+ public String getConnectString() {
+ verifyIsRunning();
+ return zooKeeperServer.getConnectString();
+ }
+
+ private void verifyIsRunning() {
+ Preconditions.checkState(zooKeeperServer != null);
+ }
+
+ private void terminateZooKeeperServer() throws IOException {
+ if (zooKeeperServer != null) {
+ zooKeeperServer.stop();
+ zooKeeperServer = null;
+ }
+ }
+
+ @Override
+ public void after(ExtensionContext context) throws Exception {
+ try {
+ terminateZooKeeperServer();
+ } catch (IOException e) {
+ LOG.warn("Could not properly terminate the {}.", getClass().getSimpleName(), e);
+ }
+ }
+
+ @Override
+ public void before(ExtensionContext context) throws Exception {
+ terminateZooKeeperServer();
Review comment:
Why is this necessary?
##########
File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/AllCallbackWrapper.java
##########
@@ -0,0 +1,25 @@
+package org.apache.flink.core.testutils;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/** An extension wrap logic for {@link BeforeAllCallback} and {@link AfterAllCallback}. */
+public class AllCallbackWrapper<T extends CustomExtension>
Review comment:
The generic type doesn't seem to get us anything, because T is not returned anywhere.
##########
File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/RetryTestExecutionExtension.java
##########
@@ -0,0 +1,103 @@
+package org.apache.flink.testutils.junit;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ConditionEvaluationResult;
+import org.junit.jupiter.api.extension.ExecutionCondition;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
+import org.opentest4j.TestAbortedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+import static org.apache.flink.testutils.junit.RetryExtension.RETRY_KEY;
+import static org.apache.flink.testutils.junit.RetryExtension.RETRY_NAMESPACE;
+import static org.apache.flink.testutils.junit.RetryExtension.getTestMethodKey;
+
+/** Extension to decide whether a retry test should run. */
+public class RetryTestExecutionExtension
+ implements ExecutionCondition, TestExecutionExceptionHandler, AfterEachCallback {
+ public static final Logger LOG = LoggerFactory.getLogger(RetryTestExecutionExtension.class);
+ private int retryIndex;
+ private int totalTimes;
Review comment:
```suggestion
private final int retryIndex;
private final int totalTimes;
```
##########
File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/AllCallbackWrapper.java
##########
@@ -0,0 +1,25 @@
+package org.apache.flink.core.testutils;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/** An extension wrap logic for {@link BeforeAllCallback} and {@link AfterAllCallback}. */
+public class AllCallbackWrapper<T extends CustomExtension>
+ implements BeforeAllCallback, AfterAllCallback {
+ private T customExtension;
Review comment:
```suggestion
private final T customExtension;
```
##########
File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/EachCallbackWrapper.java
##########
@@ -0,0 +1,25 @@
+package org.apache.flink.core.testutils;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/** An extension wrap logic for {@link BeforeEachCallback} and {@link AfterEachCallback}. */
+public class EachCallbackWrapper<T extends CustomExtension>
+ implements BeforeEachCallback, AfterEachCallback {
+ private T customExtension;
Review comment:
```suggestion
private final T customExtension;
```
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org