Skip to content

Commit

Permalink
#22 Fixed integration tests (do not interrupt main thread in http-ser…
Browse files Browse the repository at this point in the history
…ver)
  • Loading branch information
Evgeniy Sinev committed Dec 8, 2020
1 parent a2ba0aa commit 8aef910
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<id>spring.test-mvc</id>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>

<repository>
<id>mpos-pne</id>
<url>https://mpos.pne.io/maven2</url>
</repository>
</repositories>


Expand Down Expand Up @@ -491,7 +496,7 @@
<dependency>
<groupId>com.payneteasy.http-server</groupId>
<artifactId>http-server-impl</artifactId>
<version>1.0-1</version>
<version>1.0-4</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
Expand All @@ -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
Expand All @@ -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
);
Expand All @@ -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");
}
}
}

0 comments on commit 8aef910

Please sign in to comment.