ruanhang1993 commented on a change in pull request #17556: URL: https://github.com/apache/flink/pull/17556#discussion_r737048082
########## 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: I keep the same logic in `ZooKeeperExtension`, which invokes this method in its `before()` method. I am not sure what will happen if we remove this code. -- 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org