Search in sources :

Example 31 with RequestHandler

use of com.yahoo.jdisc.handler.RequestHandler 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 32 with RequestHandler

use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.

the class SearchHandlerTestCase method assertHandlerResponse.

private void assertHandlerResponse(int status, String responseData, String handlerName) throws Exception {
    RequestHandler forwardingHandler = configurer.getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.test.SearchHandlerTestCase$" + handlerName + "Handler");
    try (RequestHandlerTestDriver forwardingDriver = new RequestHandlerTestDriver(forwardingHandler)) {
        RequestHandlerTestDriver.MockResponseHandler response = forwardingDriver.sendRequest("http://localhost/" + handlerName + "?query=test");
        response.awaitResponse();
        assertEquals("Expected HTTP status", status, response.getStatus());
        if (responseData == null)
            assertEquals("Connection closed with no data", null, response.read());
        else
            assertEquals(responseData, response.readAll());
    }
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ThreadedHttpRequestHandler(com.yahoo.container.jdisc.ThreadedHttpRequestHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver)

Example 33 with RequestHandler

use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatPatternResolutionWorksForWildCards.

@Test
public void requireThatPatternResolutionWorksForWildCards() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host:*/bar"), foo);
    RequestHandler bob = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://*abc:*/*bar"), bob);
    RequestHandler car = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("*://*:21/*"), car);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host:8080/bar"));
    assertNotNull(match);
    assertEquals(1, match.groupCount());
    assertEquals("8080", match.group(0));
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host:8080/bar")));
    match = bindings.match(URI.create("http://host:8080/foo/bar"));
    assertNull(match);
    match = bindings.match(URI.create("http://xyzabc:8080/pqrbar"));
    assertNotNull(match);
    assertSame(bob, match.target());
    match = bindings.match(URI.create("ftp://lmn:21/abc"));
    assertNotNull(match);
    assertSame(car, match.target());
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 34 with RequestHandler

use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatTreeSplitCanBeBoundForWildcards.

@Test
public void requireThatTreeSplitCanBeBoundForWildcards() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo8080 = new NonWorkingRequestHandler();
    RequestHandler foo80 = new NonWorkingRequestHandler();
    RequestHandler foobar = new NonWorkingRequestHandler();
    RequestHandler foopqrbar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host:8080/foo"), foo8080);
    handlers.put(new UriPattern("http://host:708/foo"), foo80);
    handlers.put(new UriPattern("http://host:80/foobar"), foobar);
    handlers.put(new UriPattern("http://hos*:708/foo"), foopqrbar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    assertNotNull(bindings);
    assertSame(foopqrbar, bindings.resolve(URI.create("http://hostabc:708/foo")));
    assertSame(foo80, bindings.resolve(URI.create("http://host:708/foo")));
    assertSame(foo8080, bindings.resolve(URI.create("http://host:8080/foo")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 35 with RequestHandler

use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatPatternResolutionWorksForFilters.

@Test
public void requireThatPatternResolutionWorksForFilters() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://*/filtered/*"), foo);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://localhost:80/status.html"));
    assertNull(match);
    match = bindings.match(URI.create("http://localhost/filtered/status.html"));
    assertNotNull(match);
    assertSame(foo, match.target());
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

RequestHandler (com.yahoo.jdisc.handler.RequestHandler)43 Test (org.junit.Test)33 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)23 LinkedHashMap (java.util.LinkedHashMap)19 TestDriver (com.yahoo.jdisc.test.TestDriver)6 Map (java.util.Map)6 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)5 ComponentId (com.yahoo.component.ComponentId)4 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)4 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 Container (com.yahoo.container.Container)2 RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)2 ThreadedHttpRequestHandler (com.yahoo.container.jdisc.ThreadedHttpRequestHandler)2 DocumentProcessingHandler (com.yahoo.docproc.jdisc.DocumentProcessingHandler)2 Request (com.yahoo.jdisc.Request)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)2 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)2 JSONArray (org.json.JSONArray)2