diff options
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java index 91f12184884..71a8556fb00 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java @@ -16,9 +16,11 @@ public class MockFS4ResourcePool extends FS4ResourcePool { private final Map<String, Integer> requestsPerBackend = new HashMap<>(); private final Set<String> nonRespondingBackends = new HashSet<>(); private final Map<String, Long> activeDocumentsInBackend = new HashMap<>(); - + private final long testingThreadId; + public MockFS4ResourcePool() { super(1); + this.testingThreadId = Thread.currentThread().getId(); } @Override @@ -31,17 +33,23 @@ public class MockFS4ResourcePool extends FS4ResourcePool { () -> new MockFSChannel(activeDocumentsInBackend.getOrDefault(hostname, 0L))); } - /** Returns the number of times a backend for this hostname and port has been requested */ + /** + * Returns the number of times a backend for this hostname and port has been requested + * from the thread creating this + */ public int requestCount(String hostname, int port) { return requestsPerBackend.getOrDefault(hostname + ":" + port, 0); } - /** sets the number of active documents the given host will report to have in ping responses */ + /** Sets the number of active documents the given host will report to have in ping responses */ public void setActiveDocuments(String hostname, long activeDocuments) { activeDocumentsInBackend.put(hostname, activeDocuments); } private void countRequest(String hostAndPort) { + // ignore requests from the ping thread to avoid timing issues + if (Thread.currentThread().getId() != testingThreadId) return; + requestsPerBackend.put(hostAndPort, requestsPerBackend.getOrDefault(hostAndPort, 0) + 1); } |