zentol commented on a change in pull request #17556:
URL: https://github.com/apache/flink/pull/17556#discussion_r737291694



##########
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:
       fair enough, let's keep it as is.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to