diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-02 12:53:24 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-02 12:53:24 +0200 |
commit | 9d6a39e6d35c6e85dc42277377bb008b7f634e35 (patch) | |
tree | 92d3271332a0a7abdfc67f2d267d33c39870b16e /container-search | |
parent | dae02c48c5799da0b955520f87856a9031dc43d4 (diff) |
Avoid timing sensitivity
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/searchchain/FutureResult.java | 7 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTest.java | 6 |
2 files changed, 7 insertions, 6 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/FutureResult.java b/container-search/src/main/java/com/yahoo/search/searchchain/FutureResult.java index 4f76c05ac65..310de200910 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/FutureResult.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/FutureResult.java @@ -64,7 +64,7 @@ public class FutureResult extends FutureTask<Result> { } /** - * Same as get(timeout, timeunit) but returns Optiona.empty instead of a result with error if the result is + * Same as get(timeout, timeunit) but returns Optional.empty instead of a result with error if the result is * not available in time */ public Optional<Result> getIfAvailable(long timeout, TimeUnit timeunit) { @@ -75,9 +75,12 @@ public class FutureResult extends FutureTask<Result> { return Optional.of(new Result(getQuery(), createInterruptedError(e))); } catch (ExecutionException e) { + // allow searchers to explicitly signal timeout rather than actually time out (useful for testing) + if (e.getCause() instanceof com.yahoo.search.federation.TimeoutException) + return Optional.empty(); return Optional.of(new Result(getQuery(), createExecutionError(e))); } - catch (TimeoutException e) { + catch (TimeoutException | com.yahoo.search.federation.TimeoutException e) { return Optional.empty(); } } diff --git a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTest.java b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTest.java index 74eb83cea90..d799363949d 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTest.java +++ b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTest.java @@ -1,8 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.federation.test; -import java.util.Optional; - import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; import com.yahoo.component.provider.ComponentRegistry; @@ -14,6 +12,7 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.federation.FederationConfig; import com.yahoo.search.federation.FederationSearcher; +import com.yahoo.search.federation.TimeoutException; import com.yahoo.search.federation.selection.FederationTarget; import com.yahoo.search.federation.selection.TargetSelector; import com.yahoo.search.federation.StrictContractsConfig; @@ -88,7 +87,7 @@ public class FederationSearcherTest { @Override public void fill(Result result, String summaryClass, Execution execution) { - try { Thread.sleep(500); } catch (InterruptedException e) {} + throw new TimeoutException("TimeoutInFillSearcher always time out in fill"); } } @@ -173,7 +172,6 @@ public class FederationSearcherTest { tester.addSearchChain("chain2", new TimeoutInFillSearcher()); Query query = new Query(); - query.setTimeout(50); Result result = tester.search(query); tester.fill(result); assertEquals(1, result.hits().getConcreteSize()); |