From 947e67fa76a6904efde7227e935f00fe1a321b3a Mon Sep 17 00:00:00 2001 From: wxy Date: Wed, 2 Nov 2022 08:42:35 +0800 Subject: [PATCH] [enhancement](test) retry start be or fe when port has been bind. (#13860) Co-authored-by: wangxiangyu@360shuke.com --- .../apache/doris/utframe/UtFrameUtils.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/utframe/UtFrameUtils.java b/fe/fe-core/src/test/java/org/apache/doris/utframe/UtFrameUtils.java index 7e048e116c..adc5a86a39 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/utframe/UtFrameUtils.java +++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/UtFrameUtils.java @@ -149,6 +149,19 @@ public class UtFrameUtils { public static int startFEServer(String runningDir) throws EnvVarNotSetException, IOException, FeStartException, NotInitException, DdlException, InterruptedException { + IOException exception = null; + for (int i = 0; i <= 3; i++) { + try { + return startFEServerWithoutRetry(runningDir); + } catch (IOException ignore) { + exception = ignore; + } + } + throw exception; + } + + private static int startFEServerWithoutRetry(String runningDir) throws EnvVarNotSetException, IOException, + FeStartException, NotInitException { // get DORIS_HOME String dorisHome = System.getenv("DORIS_HOME"); if (Strings.isNullOrEmpty(dorisHome)) { @@ -232,6 +245,18 @@ public class UtFrameUtils { } public static Backend createBackend(String beHost, int feRpcPort) throws IOException, InterruptedException { + IOException exception = null; + for (int i = 0; i <= 3; i++) { + try { + return createBackendWithoutRetry(beHost, feRpcPort); + } catch (IOException ignore) { + exception = ignore; + } + } + throw exception; + } + + private static Backend createBackendWithoutRetry(String beHost, int feRpcPort) throws IOException { int beHeartbeatPort = findValidPort(); int beThriftPort = findValidPort(); int beBrpcPort = findValidPort(); @@ -240,7 +265,7 @@ public class UtFrameUtils { // start be MockedBackend backend = MockedBackendFactory.createBackend(beHost, beHeartbeatPort, beThriftPort, beBrpcPort, beHttpPort, new DefaultHeartbeatServiceImpl(beThriftPort, beHttpPort, beBrpcPort), - new DefaultBeThriftServiceImpl(), new DefaultPBackendServiceImpl()); + new DefaultBeThriftServiceImpl(), new DefaultPBackendServiceImpl()); backend.setFeAddress(new TNetworkAddress("127.0.0.1", feRpcPort)); backend.start();