Search in sources :

Example 1 with SearcherRegistry

use of com.yahoo.search.searchchain.SearcherRegistry in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testSearcherConfigUpdate.

/**
 * Verifies that only searchers with updated config are re-instantiated after a config update
 * that does not contain any bootstrap configs.
 */
@Test
public void testSearcherConfigUpdate() throws IOException, InterruptedException {
    File cfgDir = getCfgDir();
    copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg");
    copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg");
    copyFile(testDir + "qr-searchers.cfg", cfgDir + "/qr-searchers.cfg");
    copyFile(testDir + "index-info.cfg", cfgDir + "/index-info.cfg");
    copyFile(testDir + "specialtokens.cfg", cfgDir + "/specialtokens.cfg");
    copyFile(testDir + "three-searchers.cfg", cfgDir + "/chains.cfg");
    copyFile(testDir + "container-http.cfg", cfgDir + "/container-http.cfg");
    createComponentsConfig(testDir + "three-searchers.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    printFile(new File(cfgDir + "/int.cfg"), "intVal 16\n");
    printFile(new File(cfgDir + "/string.cfg"), "stringVal \"testSearcherConfigUpdate\"\n");
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
    SearcherRegistry searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    IntSearcher intSearcher = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    assertThat(intSearcher.intConfig.intVal(), is(16));
    StringSearcher stringSearcher = (StringSearcher) searchers.getComponent(StringSearcher.class.getName());
    DeclaredTestSearcher noConfigSearcher = (DeclaredTestSearcher) searchers.getComponent(DeclaredTestSearcher.class.getName());
    // Update int config for IntSearcher,
    printFile(new File(cfgDir + "/int.cfg"), "intVal 17\n");
    configurer.reloadConfig();
    // Registry is rebuilt
    assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
    searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    // Searcher with updated config is re-instantiated.
    IntSearcher intSearcher2 = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    assertThat(intSearcher2, not(sameInstance(intSearcher)));
    assertThat(intSearcher2.intConfig.intVal(), is(17));
    // Searchers with unchanged config (or that takes no config) are the same as before.
    Searcher s = searchers.getComponent(DeclaredTestSearcher.class.getName());
    assertThat((DeclaredTestSearcher) s, sameInstance(noConfigSearcher));
    s = searchers.getComponent(StringSearcher.class.getName());
    assertThat((StringSearcher) s, sameInstance(stringSearcher));
    configurer.shutdown();
    cleanup(cfgDir);
}
Also used : SearcherRegistry(com.yahoo.search.searchchain.SearcherRegistry) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) Searcher(com.yahoo.search.Searcher) Test(org.junit.Test)

Example 2 with SearcherRegistry

use of com.yahoo.search.searchchain.SearcherRegistry in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testChainsConfigUpdate.

/**
 * Updates the chains config, while the searcher configs are unchanged.
 * Verifies that a new searcher that was not in the old config is instantiated,
 * and that a searcher that has been removed from the configuration is not in the new registry.
 */
@Test
public void testChainsConfigUpdate() throws IOException, InterruptedException {
    File cfgDir = getCfgDir();
    copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg");
    copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg");
    copyFile(testDir + "qr-searchers.cfg", cfgDir + "/qr-searchers.cfg");
    copyFile(testDir + "index-info.cfg", cfgDir + "/index-info.cfg");
    copyFile(testDir + "specialtokens.cfg", cfgDir + "/specialtokens.cfg");
    copyFile(testDir + "chainsConfigUpdate_1.cfg", cfgDir + "/chains.cfg");
    copyFile(testDir + "container-http.cfg", cfgDir + "/container-http.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_1.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
    SearchChainRegistry scReg = getSearchChainRegistryFrom(configurer);
    SearcherRegistry searchers = scReg.getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(2));
    assertThat(searchers.getComponent(IntSearcher.class.getName()), instanceOf(IntSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), instanceOf(StringSearcher.class));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), nullValue());
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), nullValue());
    IntSearcher intSearcher = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    // Update chains config
    copyFile(testDir + "chainsConfigUpdate_2.cfg", cfgDir + "/chains.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_2.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    configurer.reloadConfig();
    assertThat(getSearchChainRegistryFrom(configurer), not(scReg));
    // In the new registry, the correct searchers are removed and added
    assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
    searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    assertThat((IntSearcher) searchers.getComponent(IntSearcher.class.getName()), sameInstance(intSearcher));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), instanceOf(ConfigurableSearcher.class));
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), instanceOf(DeclaredTestSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), nullValue());
    configurer.shutdown();
    cleanup(cfgDir);
}
Also used : SearcherRegistry(com.yahoo.search.searchchain.SearcherRegistry) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) Test(org.junit.Test)

Aggregations

HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)2 SearcherRegistry (com.yahoo.search.searchchain.SearcherRegistry)2 Test (org.junit.Test)2 Searcher (com.yahoo.search.Searcher)1 SearchChainRegistry (com.yahoo.search.searchchain.SearchChainRegistry)1