use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ContainerSnapshotTestCase method requireThatClientBindingsAreUsed.
@Test
public void requireThatClientBindingsAreUsed() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.clientBindings().bind("http://host/path", MyRequestHandler.newInstance());
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
assertNull(request.container().resolveHandler(request));
request.setServerRequest(false);
assertNotNull(request.container().resolveHandler(request));
request.release();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request 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());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ContainerSnapshotTestCase method requireThatNewRequestHasSameSnapshot.
@Test
public void requireThatNewRequestHasSameSnapshot() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request foo = new Request(driver, URI.create("http://host/foo"));
Request bar = new Request(foo, URI.create("http://host/bar"));
assertSame(foo.container(), bar.container());
foo.release();
bar.release();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatDispatchHandlesConnectException.
@Test
public void requireThatDispatchHandlesConnectException() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://localhost/", new AbstractRequestHandler() {
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
throw new RuntimeException();
}
});
driver.activateContainer(builder);
try {
driver.newRequestDispatch("http://localhost/", new FutureResponse()).dispatch();
fail();
} catch (RuntimeException e) {
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class NonWorkingRequest method newInstance.
/**
* <p>Factory method to create a {@link Request} without an associated {@link Container}. The design of jDISC does
* not allow this, so this method internally creates TestDriver, activates a Container, and creates a new Request
* from that Container. Before returning, this method {@link Request#release() closes} the Request, and calls {@link
* TestDriver#close()} on the TestDriver. This means that you MUST NOT attempt to access any Container features
* through the created Request. This factory is only for directed feature tests that require a non-null
* Request.</p>
*
* @param uri The URI string to assign to the Request.
* @param guiceModules The guice modules to inject into the {@link Application}.
* @return A non-working Request.
*/
public static Request newInstance(String uri, Module... guiceModules) {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(guiceModules);
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create(uri));
request.release();
driver.close();
return request;
}
Aggregations