Search in sources :

Example 1 with RequestHandlerTestDriver

use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.

the class SearchHandlerTestCase method testInvalidYqlQuery.

@Test
public void testInvalidYqlQuery() throws Exception {
    IOUtils.copyDirectory(new File(testDir, "config_yql"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(newSearchHandler)) {
        RequestHandlerTestDriver.MockResponseHandler responseHandler = newDriver.sendRequest("http://localhost/search/?yql=select%20*%20from%20foo%20where%20bar%20%3E%201453501295%27%3B");
        responseHandler.readAll();
        assertThat(responseHandler.getStatus(), is(400));
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Test(org.junit.Test)

Example 2 with RequestHandlerTestDriver

use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.

the class SearchHandlerTestCase method testWorkingReconfiguration.

@Test
public synchronized void testWorkingReconfiguration() throws Exception {
    assertJsonResult("http://localhost?query=abc", driver);
    // reconfiguration
    IOUtils.copyDirectory(new File(testDir, "handlers2"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    // ...and check the resulting config
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
    assertNotNull("Have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("hello"));
    assertNull("Don't have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("classLoadingError"));
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
        assertJsonResult("http://localhost?query=abc", newDriver);
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Test(org.junit.Test)

Example 3 with RequestHandlerTestDriver

use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.

the class SearchHandlerTestCase method testInvalidQueryParam.

private void testInvalidQueryParam(final RequestHandlerTestDriver testDriver) {
    RequestHandlerTestDriver.MockResponseHandler responseHandler = testDriver.sendRequest("http://localhost/search/?query=status_code%3A0&hits=20&offset=-20");
    String response = responseHandler.readAll();
    assertThat(responseHandler.getStatus(), is(400));
    assertThat(response, containsString("offset"));
    assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER.code));
}
Also used : RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 4 with RequestHandlerTestDriver

use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.

the class SearchHandlerTestCase method testFailedReconfiguration.

@Test
// TODO: Must be done at the ConfiguredApplication level, not handlers configurer? Also, this must be rewritten as the above
@Ignore
public synchronized void testFailedReconfiguration() throws Exception {
    assertXmlResult(driver);
    // attempt reconfiguration
    IOUtils.copyDirectory(new File(testDir, "handlersInvalid"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    RequestHandler newMockHandler = configurer.getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.test.MockHandler");
    assertTrue("Reconfiguration failed: Kept the existing instance of the search handler", searchHandler == newSearchHandler);
    assertNull("Reconfiguration failed: No mock handler", newMockHandler);
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
        assertXmlResult(newDriver);
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ThreadedHttpRequestHandler(com.yahoo.container.jdisc.ThreadedHttpRequestHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with RequestHandlerTestDriver

use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.

the class SearchHandlerTestCase method startUp.

@Before
public void startUp() throws IOException {
    File cfgDir = tempfolder.newFolder("SearchHandlerTestCase");
    tempDir = cfgDir.getAbsolutePath();
    configId = "dir:" + tempDir;
    // make configs active
    IOUtils.copyDirectory(new File(testDir), cfgDir, 1);
    generateComponentsConfigForActive();
    configurer = new HandlersConfigurerTestWrapper(new Container(), configId);
    searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    driver = new RequestHandlerTestDriver(searchHandler);
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Before(org.junit.Before)

Aggregations

RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)7 SearchHandler (com.yahoo.search.handler.SearchHandler)5 File (java.io.File)5 Test (org.junit.Test)3 ThreadedHttpRequestHandler (com.yahoo.container.jdisc.ThreadedHttpRequestHandler)2 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 Container (com.yahoo.container.Container)1 HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1