diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-12-01 12:31:24 -0800 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-12-01 12:31:24 -0800 |
commit | 872994569344340f13519c92324bf177fc666ac9 (patch) | |
tree | fd859c0a38ed68300c743b54ee5ab41a986e273f /container-search/src/test/java/com/yahoo/search/searchchain | |
parent | ce9f57d123d835cc698adf2febe4aae47128031d (diff) |
Revert "Merge pull request #7835 from vespa-engine/revert-7833-bratseth/remove-unused-rpc-server-take-2"
This reverts commit ce9f57d123d835cc698adf2febe4aae47128031d, reversing
changes made to c2af67b3d11da53655a0750d2e288b584c7b938c.
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/searchchain')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java index e9eb90378f4..699e8619cd0 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java @@ -3,7 +3,7 @@ package com.yahoo.search.searchchain.config.test; import com.yahoo.config.search.IntConfig; import com.yahoo.config.search.StringConfig; -import com.yahoo.container.config.testutil.TestUtil; +import com.yahoo.container.core.config.HandlersConfigurerDi; import com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -19,6 +19,8 @@ import org.junit.Test; import java.io.*; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -50,7 +52,7 @@ public class SearchChainConfigurerTestCase { } @AfterClass - public static void removeDefaultComponentsConfigs() throws IOException { + public static void removeDefaultComponentsConfigs() { new File(testDir + "components.cfg").delete(); } @@ -60,7 +62,7 @@ public class SearchChainConfigurerTestCase { } @Test - public synchronized void testConfiguration() throws Exception { + public synchronized void testConfiguration() { HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + testDir); SearchChain simple=getSearchChainRegistryFrom(configurer).getComponent("simple"); @@ -182,7 +184,7 @@ public class SearchChainConfigurerTestCase { * and that a searcher that has been removed from the configuration is not in the new registry. */ @Test - public void testChainsConfigUpdate() throws IOException, InterruptedException { + public void testChainsConfigUpdate() throws IOException { File cfgDir = getCfgDir(); copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg"); copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg"); @@ -266,7 +268,7 @@ public class SearchChainConfigurerTestCase { //// Helper methods - public static void printFile(File f, String content) throws IOException, InterruptedException { + public static void printFile(File f, String content) throws IOException { OutputStream out = new FileOutputStream(f); out.write(content.getBytes()); out.close(); @@ -300,8 +302,58 @@ public class SearchChainConfigurerTestCase { * Also adds the default SearchHandler. */ public static void createComponentsConfig(String chainsFile, String handlersFile, String componentsFile) throws IOException { - TestUtil.createComponentsConfig(handlersFile, componentsFile, "handler"); - TestUtil.createComponentsConfig(chainsFile, componentsFile, "components", true); + createComponentsConfig(handlersFile, componentsFile, "handler", false); + createComponentsConfig(chainsFile, componentsFile, "components", true); + } + + /** + * Copies the component ids from another config, e.g. 'handlers' to a 'components' array in a new components file, + * to avoid a manually written 'components' file for tests where the bundle spec is given by the component id. + * @param configFile Full path to the original config file, e.g. 'handlers' + * @param componentsFile Full path to the new 'components' file + * @param componentType The type of component, e.g. 'handler' + * @param append 'true' will append to an already existing 'componentsFile' + */ + public static void createComponentsConfig(String configFile, + String componentsFile, + String componentType, + boolean append) throws IOException { + StringBuilder buf = new StringBuilder(); + String line; + int i = 0; + if (append) { + Pattern p = Pattern.compile("^[a-z]+" + "\\[\\d+\\]\\.id (.+)"); + BufferedReader reader = new BufferedReader(new InputStreamReader( + new FileInputStream(new File(componentsFile)), "UTF-8")); + while ((line = reader.readLine()) != null) { + Matcher m = p.matcher(line); + if (m.matches() && !m.group(1).equals(HandlersConfigurerDi.RegistriesHack.class.getName())) { + buf.append("components[").append(i).append("].id ").append(m.group(1)).append("\n"); + i++; + } + } + reader.close(); + } + BufferedReader reader = new BufferedReader(new InputStreamReader( + new FileInputStream(new File(configFile)), "UTF-8")); + Pattern component = Pattern.compile("^" + componentType + "\\[\\d+\\]\\.id (.+)"); + while ((line = reader.readLine()) != null) { + Matcher m = component.matcher(line); + if (m.matches()) { + buf.append("components[").append(i).append("].id ").append(m.group(1)).append("\n"); + i++; + } + } + buf.append("components[").append(i).append("].id "). + append(HandlersConfigurerDi.RegistriesHack.class.getName()).append("\n"); + i++; + reader.close(); + buf.insert(0, "components["+i+"]\n"); + + Writer writer = new OutputStreamWriter(new FileOutputStream(new File(componentsFile)), "UTF-8"); + writer.write(buf.toString()); + writer.flush(); + writer.close(); } } |