From 8aef910c82fecf7f48a1eefe3dd08065d63af4bc Mon Sep 17 00:00:00 2001 From: Evgeniy Sinev Date: Wed, 9 Dec 2020 00:19:12 +0300 Subject: [PATCH] #22 Fixed integration tests (do not interrupt main thread in http-server) --- pom.xml | 7 ++++++- .../srvlog/adapter/json/SaveLogsStarter.java | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e905369..6b7487c 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,11 @@ spring.test-mvc http://repo.springsource.org/libs-milestone + + + mpos-pne + https://mpos.pne.io/maven2 + @@ -491,7 +496,7 @@ com.payneteasy.http-server http-server-impl - 1.0-1 + 1.0-4 diff --git a/srvlog-service/src/main/java/com/payneteasy/srvlog/adapter/json/SaveLogsStarter.java b/srvlog-service/src/main/java/com/payneteasy/srvlog/adapter/json/SaveLogsStarter.java index 97a0edd..91da1be 100644 --- a/srvlog-service/src/main/java/com/payneteasy/srvlog/adapter/json/SaveLogsStarter.java +++ b/srvlog-service/src/main/java/com/payneteasy/srvlog/adapter/json/SaveLogsStarter.java @@ -4,7 +4,6 @@ import com.payneteasy.startup.parameters.StartupParametersFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,6 +11,7 @@ import javax.annotation.PreDestroy; import java.io.IOException; import java.net.InetSocketAddress; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @Service @@ -25,8 +25,9 @@ public class SaveLogsStarter { private final String token; private final String path; - private HttpServer server; - private Thread thread; + private HttpServer server; + private Thread thread; + private ExecutorService clientExecutor; @Autowired public SaveLogsStarter(ISaveLogsService saveLogsService @@ -47,11 +48,13 @@ public void startup() { SaveLogsHttpRequestHandler handler = new SaveLogsHttpRequestHandler(saveLogsService, path, token); + clientExecutor = Executors.newCachedThreadPool(); + try { server = new HttpServer( new InetSocketAddress(ipAddress, port) , new HttpLoggerSlf() - , Executors.newCachedThreadPool() + , clientExecutor , handler , 10_000 ); @@ -69,15 +72,24 @@ public void startup() { public void destroy() { LOG.info("Shutting down json adapter ..."); if(server != null) { + LOG.debug("Stopping server ..."); server.stop(); } else { LOG.warn("Server is null"); } if(thread != null) { + LOG.debug("Interrupting thread ..."); thread.interrupt(); } else { LOG.warn("Thread is null"); } + + if(clientExecutor != null) { + LOG.debug("Shutdown executor ..."); + clientExecutor.shutdown(); + } else { + LOG.warn("Executors is null"); + } } }