Skip to content

Commit

Permalink
More than one connection open at one time for ESMockAPIBasedRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Nov 30, 2020
1 parent 0023f77 commit 40dab2d
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.mocksocket.MockHttpServer;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.repositories.Repository;
import org.elasticsearch.repositories.RepositoryMissingException;
import org.elasticsearch.repositories.RepositoryStats;
import org.elasticsearch.test.BackgroundIndexer;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -55,6 +58,9 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -83,20 +89,27 @@ protected interface BlobStoreHttpHandler extends HttpHandler {
private static final byte[] BUFFER = new byte[1024];

private static HttpServer httpServer;
private static ExecutorService executorService;
protected Map<String, HttpHandler> handlers;

private static final Logger log = LogManager.getLogger();

@BeforeClass
public static void startHttpServer() throws Exception {
httpServer = MockHttpServer.createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
ThreadFactory threadFactory = EsExecutors.daemonThreadFactory("[" + ESMockAPIBasedRepositoryIntegTestCase.class.getName() + "]");
// the EncryptedRepository can require more than one connection open at one time
executorService = EsExecutors.newScaling(ESMockAPIBasedRepositoryIntegTestCase.class.getName(), 0, 2, 60,
TimeUnit.SECONDS, threadFactory, new ThreadContext(Settings.EMPTY));
httpServer.setExecutor(r -> {
try {
r.run();
} catch (Throwable t) {
log.error("Error in execution on mock http server IO thread", t);
throw t;
}
executorService.execute(() -> {
try {
r.run();
} catch (Throwable t) {
log.error("Error in execution on mock http server IO thread", t);
throw t;
}
});
});
httpServer.start();
}
Expand All @@ -111,6 +124,7 @@ public void setUpHttpServer() {
@AfterClass
public static void stopHttpServer() {
httpServer.stop(0);
ThreadPool.terminate(executorService, 10, TimeUnit.SECONDS);
httpServer = null;
}

Expand Down

0 comments on commit 40dab2d

Please sign in to comment.