diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-07-04 15:32:33 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-07-04 15:32:33 +0200 |
commit | 629b0329fbedf764e938c892a0a6ef29ed2a125f (patch) | |
tree | 92049c09a91ee1344583387209ddea6e206d23e1 /container-core | |
parent | 1cd8287f435ae60afdbc4178bcc585836183dcb8 (diff) |
Don't use separate renderer threads in unit tests
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java | 3 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java | 23 |
2 files changed, 22 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java b/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java index 6b06b872770..8de5aa18305 100644 --- a/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java +++ b/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java @@ -12,6 +12,7 @@ import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.jrt.slobrok.api.Register; import com.yahoo.jrt.slobrok.api.SlobrokList; +import com.yahoo.net.HostName; import com.yahoo.net.LinuxInetAddress; import com.yahoo.log.LogLevel; import com.yahoo.osgi.Osgi; @@ -44,7 +45,7 @@ public class ContainerRpcAdaptor extends AbstractRpcAdaptor { public ContainerRpcAdaptor(Osgi osgi) { this.osgi = osgi; this.supervisor = new Supervisor(new Transport()); - this.hostname = LinuxInetAddress.getLocalHost().getCanonicalHostName(); + this.hostname = HostName.getLocalhost(); bindCommands(supervisor); } diff --git a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java index eeb4a2ef36d..8e0c1d99a81 100644 --- a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java +++ b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java @@ -113,7 +113,8 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e // Rendering threads should never block so use one thread per core. // We should complete any work we have already started so use an unbounded queue. // The executor SHOULD be reused across all instances having the same prototype - private final ThreadPoolExecutor renderingExecutor = createExecutor(); + private final Executor renderingExecutor; + private static ThreadPoolExecutor createExecutor() { int threadCount = Runtime.getRuntime().availableProcessors(); ThreadPoolExecutor executor = new ThreadPoolExecutor(threadCount, threadCount, 1L, TimeUnit.SECONDS, @@ -138,7 +139,18 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e * before use. */ public AsynchronousSectionedRenderer() { + this(null); + } + + /** + * Create an renderer using the specified executor instead of the default one which should be used for production. + * Using a custom executor is useful for tests to avoid creating new threads for each renderer registry. + * + * @param executor the executor to use or null to use the default executor suitable for production + */ + public AsynchronousSectionedRenderer(Executor executor) { isInitialized = false; + renderingExecutor = executor==null ? createExecutor() : executor; } /** @@ -172,9 +184,14 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e @Override public void deconstruct() { super.deconstruct(); - renderingExecutor.shutdown(); + if (renderingExecutor instanceof ThreadPoolExecutor) + shutdown((ThreadPoolExecutor) renderingExecutor); + } + + private void shutdown(ThreadPoolExecutor executor) { + executor.shutdown(); try { - if (renderingExecutor.awaitTermination(30, TimeUnit.SECONDS)) + if (executor.awaitTermination(30, TimeUnit.SECONDS)) throw new RuntimeException("Rendering thread pool did not shutdown in 30 seconds"); } catch (InterruptedException e) { |