diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-09-13 23:04:07 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-09-14 07:27:23 +0200 |
commit | bb54881376421e09daa8287173e06458b0c1f45a (patch) | |
tree | ec65a19ce5ad918fa181c9d76b3664f3390d9a80 /container-search/src/test/java/com/yahoo/search | |
parent | 04c3414342c1cc296f8a56d4112f77b1a463cc70 (diff) |
Factor out timeout and coverage handling to make the InterleavedSearchInvoker easier to understand and modify.
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/InterleavedSearchInvokerTest.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/InterleavedSearchInvokerTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/InterleavedSearchInvokerTest.java index a88046197e0..b935e07cf4d 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/InterleavedSearchInvokerTest.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/InterleavedSearchInvokerTest.java @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.dispatch; +import com.yahoo.concurrent.MonotonicTimer; +import com.yahoo.concurrent.Timer; import com.yahoo.document.GlobalId; import com.yahoo.document.idstring.IdString; import com.yahoo.prelude.fastsearch.FastHit; @@ -23,6 +25,7 @@ import com.yahoo.test.ManualClock; import org.junit.jupiter.api.Test; import java.io.IOException; +import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -33,6 +36,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.function.ToLongFunction; import java.util.stream.StreamSupport; import static com.yahoo.container.handler.Coverage.DEGRADED_BY_MATCH_PHASE; @@ -347,7 +351,7 @@ public class InterleavedSearchInvokerTest { .addAggregationResult(new MinAggregationResult().setMin(new IntegerResultNode(6)).setTag(3)))); invokers.add(new MockInvoker(0).setHits(List.of(new GroupingListHit(List.of(grouping2))))); - InterleavedSearchInvoker invoker = new InterleavedSearchInvoker(invokers, cluster, new Group(0, List.of()), Collections.emptySet()); + InterleavedSearchInvoker invoker = new InterleavedSearchInvoker(new MonotonicTimer(), invokers, cluster, new Group(0, List.of()), Collections.emptySet()); invoker.responseAvailable(invokers.get(0)); invoker.responseAvailable(invokers.get(1)); Result result = invoker.search(query, null); @@ -360,7 +364,7 @@ public class InterleavedSearchInvokerTest { List<SearchInvoker> invokers = new ArrayList<>(); invokers.add(createInvoker(a, 0)); invokers.add(createInvoker(b, 1)); - InterleavedSearchInvoker invoker = new InterleavedSearchInvoker(invokers, cluster, group, Collections.emptySet()); + InterleavedSearchInvoker invoker = new InterleavedSearchInvoker(new MonotonicTimer(), invokers, cluster, group, Collections.emptySet()); invoker.responseAvailable(invokers.get(0)); invoker.responseAvailable(invokers.get(1)); return invoker; @@ -406,17 +410,22 @@ public class InterleavedSearchInvokerTest { assertTrue(cov.isDegradedByTimeout()); } + private static class ClockAsTimer implements Timer { + private final Clock clock; + ClockAsTimer(Clock clock) { this.clock = clock; } + + @Override + public long milliTime() { + return clock.millis(); + } + } + private InterleavedSearchInvoker createInterleavedInvoker(SearchCluster searchCluster, Group group, int numInvokers) { for (int i = 0; i < numInvokers; i++) { invokers.add(new MockInvoker(i)); } - return new InterleavedSearchInvoker(invokers, searchCluster, group,null) { - - @Override - protected long currentTime() { - return clock.millis(); - } + return new InterleavedSearchInvoker(new ClockAsTimer(clock), invokers, searchCluster, group,null) { @Override protected LinkedBlockingQueue<SearchInvoker> newQueue() { |