blob: 4b2f63d6b898b69059ef3230f10051b9047fadcd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.dispatch.searchcluster.Node;
import com.yahoo.search.result.Coverage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
class MockInvoker extends SearchInvoker {
private final Coverage coverage;
private Query query;
private List<Hit> hits;
protected MockInvoker(int key, Coverage coverage) {
super(Optional.of(new Node(key, "?", 0, 0)));
this.coverage = coverage;
}
protected MockInvoker(int key) {
this(key, null);
}
MockInvoker setHits(List<Hit> hits) {
this.hits = hits;
return this;
}
@Override
protected void sendSearchRequest(Query query) throws IOException {
this.query = query;
}
@Override
protected Result getSearchResult(Execution execution) throws IOException {
Result ret = new Result(query);
if (coverage != null) {
ret.setCoverage(coverage);
}
if (hits != null) {
ret.hits().addAll(hits);
}
return ret;
}
@Override
protected void release() {
}
}
|