From 629b0329fbedf764e938c892a0a6ef29ed2a125f Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 4 Jul 2016 15:32:33 +0200 Subject: Don't use separate renderer threads in unit tests --- .../com/yahoo/vespa/config/util/ConfigUtils.java | 4 ++-- .../vespa/config/server/GetConfigProcessor.java | 4 ++-- .../yahoo/container/osgi/ContainerRpcAdaptor.java | 3 ++- .../rendering/AsynchronousSectionedRenderer.java | 23 +++++++++++++++++++--- .../yahoo/search/rendering/DefaultRenderer.java | 14 +++++++++++++ .../com/yahoo/search/rendering/JsonRenderer.java | 10 ++++++++++ .../yahoo/search/rendering/RendererRegistry.java | 22 +++++++++++++++++++-- .../java/com/yahoo/fs4/mplex/BackendTestCase.java | 5 ++++- .../fastsearch/test/PartialFillTestCase.java | 3 ++- .../test/FieldCollapsingSearcherTestCase.java | 3 ++- .../prelude/searcher/test/PosSearcherTestCase.java | 3 ++- .../test/QuerySnapshotSearcherTestCase.java | 3 ++- .../test/QueryValidatingSearcherTestCase.java | 3 ++- .../searcher/test/QuotingSearcherTestCase.java | 3 ++- .../test/ValidatePredicateSearcherTestCase.java | 3 ++- .../test/ValidateSortingSearcherTestCase.java | 3 ++- .../semantics/test/BacktrackingTestCase.java | 3 ++- .../semantics/test/ConfigurationTestCase.java | 3 ++- .../semantics/test/InheritanceTestCase.java | 3 ++- .../semantics/test/RuleBaseAbstractTestCase.java | 4 +++- .../semantics/test/SemanticSearcherTestCase.java | 3 ++- .../prelude/templates/test/TilingTestCase.java | 3 ++- .../prelude/test/RankFeatureDumpTestCase.java | 3 ++- .../test/ValidateMatchPhaseSearcherTestCase.java | 3 ++- .../com/yahoo/messagebus/network/Identity.java | 8 ++------ .../com/yahoo/vespa/http/server/FeedHandler.java | 4 ++-- 26 files changed, 111 insertions(+), 35 deletions(-) diff --git a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java index b8051fe1085..52df1cff117 100644 --- a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java +++ b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java @@ -5,13 +5,13 @@ import com.yahoo.collections.Tuple2; import com.yahoo.config.codegen.CNode; import com.yahoo.io.HexDump; import com.yahoo.io.IOUtils; +import com.yahoo.net.HostName; import com.yahoo.slime.JsonFormat; import com.yahoo.text.Utf8; import com.yahoo.text.Utf8Array; import com.yahoo.vespa.config.*; import java.io.*; -import java.net.UnknownHostException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.DecimalFormat; @@ -424,7 +424,7 @@ public class ConfigUtils { } public static String getCanonicalHostName() { - return com.yahoo.net.LinuxInetAddress.getLocalHost().getCanonicalHostName(); + return HostName.getLocalhost(); } /** diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/GetConfigProcessor.java b/configserver/src/main/java/com/yahoo/vespa/config/server/GetConfigProcessor.java index 1861965947c..a25ebde8d54 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/GetConfigProcessor.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/GetConfigProcessor.java @@ -6,6 +6,7 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Version; import com.yahoo.jrt.Request; import com.yahoo.log.LogLevel; +import com.yahoo.net.HostName; import com.yahoo.net.LinuxInetAddress; import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.ErrorCode; @@ -150,10 +151,9 @@ class GetConfigProcessor implements Runnable { /** * Done in a static block to prevent people invoking this directly. - * Do not call java.net.Inet4AddressImpl.getLocalHostName() on each request, as this causes CPU bottlenecks. */ static { - localHostName = LinuxInetAddress.getLocalHost().getHostName(); + localHostName = HostName.getLocalhost(); } static boolean logDebug(Trace trace) { 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 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 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 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) { diff --git a/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java index de817d95393..3cf5d2cb3e5 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.rendering; +import com.fasterxml.jackson.core.JsonFactory; import com.yahoo.concurrent.CopyOnWriteHashMap; import com.yahoo.io.ByteWriter; import com.yahoo.net.URI; @@ -29,6 +30,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.Iterator; import java.util.Map; +import java.util.concurrent.Executor; // TODO: Rename to XmlRenderer and make this a deprecated empty subclass. @@ -73,6 +75,18 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer private XMLWriter writer; + public DefaultRenderer() { + this(null); + } + + /** + * Creates a json renderer using a custom executor. + * Using a custom executor is useful for tests to avoid creating new threads for each renderer registry. + */ + public DefaultRenderer(Executor executor) { + super(executor); + } + @Override public void init() { super.init(); diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java index 94fe5dd446d..3111074b1fc 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.Deque; import java.util.Map; import java.util.Set; +import java.util.concurrent.Executor; import java.util.function.LongSupplier; import org.json.JSONArray; @@ -269,6 +270,15 @@ public class JsonRenderer extends AsynchronousSectionedRenderer { } public JsonRenderer() { + this(null); + } + + /** + * Creates a json renderer using a custom executor. + * Using a custom executor is useful for tests to avoid creating new threads for each renderer registry. + */ + public JsonRenderer(Executor executor) { + super(executor); generatorFactory = new JsonFactory(); generatorFactory.setCodec(createJsonCodec()); } diff --git a/container-search/src/main/java/com/yahoo/search/rendering/RendererRegistry.java b/container-search/src/main/java/com/yahoo/search/rendering/RendererRegistry.java index b60c58fd90f..c1b15ecbbc2 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/RendererRegistry.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/RendererRegistry.java @@ -13,6 +13,7 @@ import com.yahoo.search.Result; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.Executor; /** * Holds all configured and built-in renderers. @@ -31,15 +32,32 @@ public final class RendererRegistry extends ComponentRegistry renderers) { + this(renderers, null); + } + + /** + * Creates a registry of the given renderers plus the built-in ones, using a custom executor. + * Using a custom executor is useful for tests to avoid creating new threads for each renderer registry. + */ + public RendererRegistry(Collection renderers, Executor executor) { // add json renderer - Renderer jsonRenderer = new JsonRenderer(); + Renderer jsonRenderer = new JsonRenderer(executor); jsonRenderer.initId(RendererRegistry.jsonRendererId); register(jsonRenderer.getId(), jsonRenderer); // Add xml renderer - Renderer xmlRenderer = new DefaultRenderer(); + Renderer xmlRenderer = new DefaultRenderer(executor); xmlRenderer.initId(xmlRendererId); register(xmlRenderer.getId(), xmlRenderer); diff --git a/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java b/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java index c3e74ddce3d..a1d10a5eb8c 100644 --- a/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -13,6 +14,7 @@ import java.nio.ByteBuffer; import java.util.logging.Logger; import com.yahoo.container.search.Fs4Config; +import com.yahoo.net.HostName; import com.yahoo.net.LinuxInetAddress; import com.yahoo.prelude.fastsearch.FS4ResourcePool; import org.junit.After; @@ -111,7 +113,8 @@ public class BackendTestCase { public MockDispatch dispatch; public MockServer() throws IOException { - ServerSocket socket = new ServerSocket(0, 50, LinuxInetAddress.getLocalHost()); + System.out.println("Setting up server at " + HostName.getLocalhost()); + ServerSocket socket = new ServerSocket(0, 50, InetAddress.getByName(HostName.getLocalhost())); host = (InetSocketAddress) socket.getLocalSocketAddress(); dispatch = new MockDispatch(socket); worker = new Thread(dispatch); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java index ea1494f6168..9b75c3224cd 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.prelude.fastsearch.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.fs4.QueryPacket; import com.yahoo.language.Linguistics; @@ -147,7 +148,7 @@ public class PartialFillTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java index 8642adfd2d4..8171ff43a52 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -449,7 +450,7 @@ public class FieldCollapsingSearcherTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher, Map chained) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher, chained), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java index 0eb0953511b..c6e30b9a4b8 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -179,7 +180,7 @@ public class PosSearcherTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java index 2cda888a2e2..3b292dc3966 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -36,7 +37,7 @@ public class QuerySnapshotSearcherTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java index ee69fa92a17..2720f6c3562 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -73,7 +74,7 @@ public class QueryValidatingSearcherTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher, Map chained) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher, chained), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java index 4dd8480c84c..76c48368cf3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; @@ -133,7 +134,7 @@ public class QuotingSearcherTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher, Map chained) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher, chained), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java index 3c3c6c921e3..7dec7aed8a2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; @@ -59,7 +60,7 @@ public class ValidatePredicateSearcherTestCase { Map searchDefinitionMap = new HashMap<>(); searchDefinitionMap.put("document", searchDefinition); IndexFacts indexFacts = new IndexFacts(new IndexModel(masterClusters, searchDefinitionMap, searchDefinition)); - Execution.Context context = new Execution.Context(null, indexFacts, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, indexFacts, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(searcher, context).search(query); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java index 143604844df..10e0342ef93 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -107,7 +108,7 @@ public class ValidateSortingSearcherTestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java index eac1c0cf002..5b64d240042 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -90,7 +91,7 @@ public class BacktrackingTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java index 4619a07ad74..2a0bfe81222 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; import com.yahoo.language.Linguistics; @@ -120,7 +121,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java index c86db996f68..9f865c21ca6 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -155,7 +156,7 @@ public class InheritanceTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java index 102f4c95926..87835c08127 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -15,6 +16,7 @@ import com.yahoo.search.test.QueryTestCase; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; /** * Tests semantic searching @@ -71,7 +73,7 @@ public abstract class RuleBaseAbstractTestCase extends junit.framework.TestCase } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java index 8d4ef630fe7..0cb3f5dcba1 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -151,7 +152,7 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java index d7134ebe405..40d68a29a71 100644 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.templates.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.io.IOUtils; import com.yahoo.language.Linguistics; @@ -67,7 +68,7 @@ public class TilingTestCase extends junit.framework.TestCase { } private Result callSearchAndSetRenderer(Chain chain, Query query) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); Result result = new Execution(chain, context).search(query); result.getTemplating().setRenderer(new SearchRendererAdaptor(new TiledTemplateSet())); return result; diff --git a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java index 16d1b92260f..42acf0f7a1b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -56,7 +57,7 @@ public class RankFeatureDumpTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/search/searchers/test/ValidateMatchPhaseSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/searchers/test/ValidateMatchPhaseSearcherTestCase.java index 6453c3928de..31457c51011 100644 --- a/container-search/src/test/java/com/yahoo/search/searchers/test/ValidateMatchPhaseSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchers/test/ValidateMatchPhaseSearcherTestCase.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.searchers.test; +import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; import com.yahoo.config.subscription.RawSource; @@ -107,7 +108,7 @@ public class ValidateMatchPhaseSearcherTestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java b/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java index 4753fc1db1f..6baf0ef771e 100644 --- a/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java @@ -2,6 +2,7 @@ package com.yahoo.messagebus.network; import com.yahoo.log.LogLevel; +import com.yahoo.net.HostName; import com.yahoo.net.LinuxInetAddress; import java.net.Inet6Address; @@ -30,12 +31,7 @@ public class Identity { * @param configId The config identifier for the application. */ public Identity(String configId) { - InetAddress addr = LinuxInetAddress.getLocalHost(); - if (addr instanceof Inet6Address) { - log.log(LogLevel.WARNING, "Local host resolved to IPv6 address '" + addr.getHostAddress() + - "', this might be problematic."); - } - hostname = addr.getCanonicalHostName(); + hostname = HostName.getLocalhost(); servicePrefix = configId; } diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java index 2e16b4a2dd0..7e743109ac4 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java @@ -16,6 +16,7 @@ import com.yahoo.jdisc.http.HttpResponse.Status; import com.yahoo.log.LogLevel; import com.yahoo.messagebus.ReplyHandler; import com.yahoo.messagebus.SourceSessionParams; +import com.yahoo.net.HostName; import com.yahoo.net.LinuxInetAddress; import com.yahoo.yolean.Exceptions; import com.yahoo.vespa.http.client.core.Headers; @@ -278,8 +279,7 @@ public class FeedHandler extends LoggingRequestHandler { } private static String resolveLocalHostname() { - InetAddress inetAddress = LinuxInetAddress.getLocalHost(); - String hostname = inetAddress.getCanonicalHostName(); + String hostname = HostName.getLocalhost(); if (hostname.equals("localhost")) { return ""; } -- cgit v1.2.3