diff --git a/fe/src/main/java/org/apache/doris/http/HttpServer.java b/fe/src/main/java/org/apache/doris/http/HttpServer.java index b52c480bf4..37d7c5e1b5 100644 --- a/fe/src/main/java/org/apache/doris/http/HttpServer.java +++ b/fe/src/main/java/org/apache/doris/http/HttpServer.java @@ -75,6 +75,7 @@ import org.apache.logging.log4j.Logger; import java.io.File; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -94,6 +95,8 @@ public class HttpServer { private Thread serverThread; + private AtomicBoolean isStarted = new AtomicBoolean(false); + public HttpServer(int port) { this.port = port; controller = new ActionController(); @@ -202,8 +205,11 @@ public class HttpServer { .channel(NioServerSocketChannel.class) .childHandler(new PaloHttpServerInitializer()); Channel ch = serverBootstrap.bind(port).sync().channel(); + + isStarted.set(true); + LOG.info("HttpServer started with port {}", port); + // block until server is closed ch.closeFuture().sync(); - LOG.info("HttpServer started with port: {}", port); } catch (Exception e) { LOG.error("Fail to start FE query http server[port: " + port + "] ", e); System.exit(-1); @@ -220,6 +226,7 @@ public class HttpServer { Future future = serverBootstrap.config().group().shutdownGracefully(0, 1, TimeUnit.SECONDS).syncUninterruptibly(); try { future.get(); + isStarted.set(false); LOG.info("HttpServer was closed completely"); } catch (Throwable e) { LOG.warn("Exception happened when close HttpServer", e); @@ -228,6 +235,10 @@ public class HttpServer { } } + public boolean isStarted() { + return isStarted.get(); + } + public static void main(String[] args) throws Exception { HttpServer httpServer = new HttpServer(8080); httpServer.setup(); diff --git a/fe/src/test/java/org/apache/doris/http/DorisHttpTestCase.java b/fe/src/test/java/org/apache/doris/http/DorisHttpTestCase.java index 57040cdc5f..e628939a5e 100644 --- a/fe/src/test/java/org/apache/doris/http/DorisHttpTestCase.java +++ b/fe/src/test/java/org/apache/doris/http/DorisHttpTestCase.java @@ -255,7 +255,9 @@ abstract public class DorisHttpTestCase { httpServer.setup(); httpServer.start(); // must ensure the http server started before any unit test - Thread.sleep(5000); + while (!httpServer.isStarted()) { + Thread.sleep(500); + } doSetUp(); }