use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class CallableRequestDispatchTestCase method requireThatDispatchIsCalled.
@Test
public void requireThatDispatchIsCalled() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
driver.activateContainer(builder);
assertSame(response, new CallableRequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://host/path"));
}
}.call());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class RequestDeniedTestCase method requireThatRequestDeniedIsThrown.
@Test
public void requireThatRequestDeniedIsThrown() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
RequestHandler requestHandler = new MyRequestHandler();
builder.serverBindings().bind("http://host/path", requestHandler);
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
try {
request.connect(new MyResponseHandler());
fail();
} catch (RequestDeniedException e) {
assertSame(request, e.request());
}
request.release();
driver.close();
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class RequestDeniedTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
RequestDeniedException e = new RequestDeniedException(request);
assertSame(request, e.request());
request.release();
driver.close();
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatRequestAndResponseReachHandlers.
@Test
public void requireThatRequestAndResponseReachHandlers() throws InterruptedException {
MyRequestHandler requestHandler = new MyRequestHandler(newExecutor());
TestDriver driver = newTestDriver("http://localhost/", requestHandler);
MyResponseHandler responseHandler = new MyResponseHandler();
Request request = new Request(driver, URI.create("http://localhost/"));
ContentChannel requestContent = request.connect(responseHandler);
ByteBuffer buf = ByteBuffer.allocate(69);
requestContent.write(buf, null);
requestContent.close(null);
request.release();
requestHandler.entryLatch.countDown();
assertTrue(requestHandler.exitLatch.await(600, TimeUnit.SECONDS));
assertSame(request, requestHandler.request);
assertSame(buf, requestHandler.content.read());
assertNull(requestHandler.content.read());
assertTrue(responseHandler.latch.await(600, TimeUnit.SECONDS));
assertSame(requestHandler.response, responseHandler.response);
assertNull(responseHandler.content.read());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatHandlerSetsRequestTimeout.
@Test
public void requireThatHandlerSetsRequestTimeout() throws InterruptedException {
MyRequestHandler requestHandler = new MyRequestHandler(newExecutor());
requestHandler.setTimeout(600, TimeUnit.SECONDS);
TestDriver driver = newTestDriver("http://localhost/", requestHandler);
MyResponseHandler responseHandler = new MyResponseHandler();
driver.dispatchRequest("http://localhost/", responseHandler);
requestHandler.entryLatch.countDown();
assertTrue(requestHandler.exitLatch.await(600, TimeUnit.SECONDS));
assertNull(requestHandler.content.read());
assertNotNull(requestHandler.request.getTimeout(TimeUnit.MILLISECONDS));
assertTrue(responseHandler.latch.await(600, TimeUnit.SECONDS));
assertNull(responseHandler.content.read());
assertTrue(driver.close());
}
Aggregations