Search in sources :

Example 16 with RequestHandler

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

the class TimeoutManagerImplTestCase method requireThatManagedHandlerForwardsAllCalls.

@Test
public void requireThatManagedHandlerForwardsAllCalls() throws InterruptedException {
    Request request = NonWorkingRequest.newInstance(REQUEST_URI);
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    TimeoutManagerImpl timeoutManager = new TimeoutManagerImpl(Executors.defaultThreadFactory(), new SystemTimer());
    RequestHandler managedHandler = timeoutManager.manageHandler(requestHandler);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    ContentChannel requestContent = managedHandler.handleRequest(request, responseHandler);
    assertNotNull(requestContent);
    ByteBuffer buf = ByteBuffer.allocate(69);
    requestContent.write(buf, null);
    assertSame(buf, requestHandler.content.buf);
    MyCompletion writeCompletion = new MyCompletion();
    requestContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
    assertSame(buf, requestHandler.content.buf);
    requestHandler.content.writeCompletion.completed();
    assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
    MyCompletion closeCompletion = new MyCompletion();
    requestContent.close(closeCompletion);
    requestHandler.content.closeCompletion.completed();
    assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
    managedHandler.release();
    assertTrue(requestHandler.destroyed);
    Response response = new Response(Response.Status.OK);
    ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
    assertNotNull(responseContent);
    responseContent.write(buf = ByteBuffer.allocate(69), null);
    assertSame(buf, responseHandler.content.buf);
    responseContent.write(buf = ByteBuffer.allocate(69), writeCompletion = new MyCompletion());
    assertSame(buf, responseHandler.content.buf);
    responseHandler.content.writeCompletion.completed();
    assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
    responseContent.close(closeCompletion = new MyCompletion());
    responseHandler.content.closeCompletion.completed();
    assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
    assertSame(response, responseHandler.response.get());
}
Also used : Response(com.yahoo.jdisc.Response) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 17 with RequestHandler

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

the class ProxyRequestHandlerTestCase method requireThatRequestHandlerIsProxied.

@Test
public void requireThatRequestHandlerIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    RequestHandler resolvedHandler = new ProxyRequestHandler(request.container().resolveHandler(request));
    MyResponseHandler responseHandler = MyResponseHandler.newEagerCompletion();
    resolvedHandler.handleRequest(request, responseHandler).close(null);
    request.release();
    assertNotNull(requestHandler.handler);
    resolvedHandler.handleTimeout(request, responseHandler);
    assertTrue(requestHandler.timeout);
    requestHandler.respond();
    requestHandler.release();
    final ResourceReference resolvedHandlerReference = resolvedHandler.refer();
    // release installed ref
    assertTrue(driver.close());
    assertFalse(requestHandler.destroyed);
    resolvedHandlerReference.close();
    assertTrue(requestHandler.destroyed);
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 18 with RequestHandler

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

the class ActiveContainerTestCase method requireThatServerBindingAccessorWorks.

@Test
public void requireThatServerBindingAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler foo = new NonWorkingRequestHandler();
    RequestHandler bar = new NonWorkingRequestHandler();
    builder.serverBindings().bind("http://host/foo", foo);
    builder.serverBindings("bar").bind("http://host/bar", bar);
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
    assertNotNull(bindings);
    assertEquals(2, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertNotNull(set);
    Iterator<Map.Entry<UriPattern, RequestHandler>> it = set.iterator();
    assertNotNull(it);
    assertTrue(it.hasNext());
    Map.Entry<UriPattern, RequestHandler> entry = it.next();
    assertNotNull(entry);
    assertEquals(new UriPattern("http://host/foo"), entry.getKey());
    assertSame(foo, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(set = bindings.get("bar"));
    assertNotNull(it = set.iterator());
    assertTrue(it.hasNext());
    assertNotNull(entry = it.next());
    assertEquals(new UriPattern("http://host/bar"), entry.getKey());
    assertSame(bar, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(bindings = container.clientBindings());
    assertEquals(1, bindings.size());
    assertNotNull(set = bindings.get(BindingSet.DEFAULT));
    assertNotNull(it = set.iterator());
    assertFalse(it.hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) UriPattern(com.yahoo.jdisc.application.UriPattern) TestDriver(com.yahoo.jdisc.test.TestDriver) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Map(java.util.Map) Test(org.junit.Test)

Example 19 with RequestHandler

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

the class ContainerSnapshotTestCase method requireThatBindingMatchIsSetByResolveHandler.

@Test
public void requireThatBindingMatchIsSetByResolveHandler() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://*/*", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://localhost:69/status.html"));
    assertNotNull(request.container().resolveHandler(request));
    BindingMatch<RequestHandler> match = request.getBindingMatch();
    assertNotNull(match);
    assertEquals(3, match.groupCount());
    assertEquals("localhost", match.group(0));
    assertEquals("69", match.group(1));
    assertEquals("status.html", match.group(2));
    request.release();
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 20 with RequestHandler

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

the class BindingRepositoryTestCase method requireThatPatternCannotBeStolen.

@Test
public void requireThatPatternCannotBeStolen() {
    final String pattern = "http://host/path";
    final RequestHandler originallyBoundHandler = new NonWorkingRequestHandler();
    BindingRepository<Object> bindings = new BindingRepository<>();
    bindings.bind(pattern, originallyBoundHandler);
    bindings.bind(pattern, new PatternStealingRequestHandler());
    BindingSet<?> bindingSet = bindings.activate();
    assertEquals(originallyBoundHandler, bindingSet.resolve(URI.create(pattern)));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) 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