use of com.yahoo.component.ComponentId in project vespa by vespa-engine.
the class QueryProfileXMLReader method createQueryProfileTypes.
public List<Element> createQueryProfileTypes(List<NamedReader> queryProfileTypeReaders, QueryProfileTypeRegistry registry) {
List<Element> queryProfileTypeElements = new ArrayList<>(queryProfileTypeReaders.size());
for (NamedReader reader : queryProfileTypeReaders) {
Element root = XML.getDocument(reader).getDocumentElement();
if (!root.getNodeName().equals("query-profile-type")) {
throw new IllegalArgumentException("Root tag in '" + reader.getName() + "' must be 'query-profile-type', not '" + root.getNodeName() + "'");
}
String idString = root.getAttribute("id");
if (idString == null || idString.equals(""))
throw new IllegalArgumentException("'" + reader.getName() + "' has no 'id' attribute in the root element");
ComponentId id = new ComponentId(idString);
validateFileNameToId(reader.getName(), id, "query profile type");
QueryProfileType type = new QueryProfileType(id);
type.setMatchAsPath(XML.getChild(root, "match") != null);
type.setStrict(XML.getChild(root, "strict") != null);
registry.register(type);
queryProfileTypeElements.add(root);
}
return queryProfileTypeElements;
}
use of com.yahoo.component.ComponentId in project vespa by vespa-engine.
the class DuplicateSourceTestCase method testDuplicateSource.
@Test
public void testDuplicateSource() {
// Set up a single cluster and chain (chain1), containing a MockBackendSearcher and having 2 doc types (doc1, doc2)
MockBackendSearcher mockBackendSearcher = new MockBackendSearcher();
SearchChainRegistry searchChains = new SearchChainRegistry();
searchChains.register(new Chain<>("chain1", mockBackendSearcher));
IndexFacts indexFacts = new IndexFacts();
Map<String, List<String>> clusters = new HashMap<>();
clusters.put("chain1", ImmutableList.of("doc1", "doc2"));
indexFacts.setClusters(clusters);
SearchChainResolver resolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2")).build();
FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver);
Result result = searcher.search(new Query("?query=test&sources=doc1%2cdoc2"), new Execution(Execution.Context.createContextStub(searchChains, indexFacts)));
assertNull(result.hits().getError());
assertEquals(1, mockBackendSearcher.getInvocationCount());
}
use of com.yahoo.component.ComponentId in project vespa by vespa-engine.
the class FederationSearcherTestCase method addChained.
private void addChained(final Searcher searcher, final String sourceName) {
builder.target(new FederationConfig.Target.Builder().id(sourceName).searchChain(new FederationConfig.Target.SearchChain.Builder().searchChainId(sourceName).timeoutMillis(10000).useByDefault(true)));
chainRegistry.register(new ComponentId(sourceName), createSearchChain(new ComponentId(sourceName), searcher));
}
use of com.yahoo.component.ComponentId in project vespa by vespa-engine.
the class FederationSearcherTestCase method createMultiProviderFederationSearcher.
private FederationSearcher createMultiProviderFederationSearcher() {
FederationOptions options = new FederationOptions();
SearchChainResolver.Builder builder = new SearchChainResolver.Builder();
ComponentId provider1 = new ComponentId("provider1");
ComponentId provider2 = new ComponentId("provider2");
ComponentId news = new ComponentId("news");
builder.addSearchChain(provider1, options, Collections.<String>emptyList());
builder.addSearchChain(provider2, options, Collections.<String>emptyList());
builder.addSourceForProvider(news, provider1, provider1, true, options, Collections.<String>emptyList());
builder.addSourceForProvider(news, provider2, provider2, false, options, Collections.<String>emptyList());
return new FederationSearcher(new ComponentId("federation"), builder.build());
}
use of com.yahoo.component.ComponentId in project vespa by vespa-engine.
the class ClusteredConnectionTestCase method testClustering.
public void testClustering() {
Connection connection0 = new Connection("0");
Connection connection1 = new Connection("1");
Connection connection2 = new Connection("2");
List<Connection> connections = new ArrayList<>();
connections.add(connection0);
connections.add(connection1);
connections.add(connection2);
MyBackend myBackend = new MyBackend(new ComponentId("test"), connections);
Result r;
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals("from:2", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
assertEquals("from:1", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
connection2.setInService(false);
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
assertEquals("from:1", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
connection1.setInService(false);
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
connection0.setInService(false);
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("Failed calling connection '2' in searcher 'test' for query 'NULL': Connection failed", r.hits().getError().getDetailedMessage());
connection0.setInService(true);
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
connection1.setInService(true);
connection2.setInService(true);
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals("from:2", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
assertEquals("from:1", r.hits().get(0).getId().stringValue());
r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
assertEquals("from:0", r.hits().get(0).getId().stringValue());
}
Aggregations