use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
final Event exceptionHandledByFramework = new Event();
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
exceptionHandledByFramework.await();
try {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
exceptionHandledByFramework.await();
writeResponse(out);
closeResponse(out);
} catch (Throwable ignored) {
}
return null;
}
});
throw new ConformanceException(exceptionHandledByFramework);
}
});
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class NonWorkingRequestTestCase method requireThatGuiceModulesAreInjected.
@Test
public void requireThatGuiceModulesAreInjected() {
Request request = NonWorkingRequest.newInstance("scheme://host/path", new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Names.named("foo")).toInstance("bar");
}
});
assertEquals("bar", request.container().getInstance(Key.get(String.class, Names.named("foo"))));
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun.
@Test
public void requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
final AtomicInteger baseRetainCount = new AtomicInteger();
builder.serverBindings().bind("http://localhost/base", new AbstractRequestHandler() {
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
baseRetainCount.set(request.retainCount());
handler.handleResponse(new Response(Response.Status.OK)).close(null);
return null;
}
});
final CountDownLatch entryLatch = new CountDownLatch(1);
final CountDownLatch exitLatch = new CountDownLatch(1);
final AtomicInteger testRetainCount = new AtomicInteger();
builder.serverBindings().bind("http://localhost/test", new ThreadedRequestHandler(newExecutor()) {
@Override
public void handleRequest(Request request, ReadableContentChannel requestContent, ResponseHandler responseHandler) {
try {
entryLatch.await(600, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return;
}
testRetainCount.set(request.retainCount());
responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
// drain content to call completion handlers
requestContent.read();
exitLatch.countDown();
}
});
driver.activateContainer(builder);
dispatchRequest(driver, "http://localhost/base");
dispatchRequest(driver, "http://localhost/test");
entryLatch.countDown();
exitLatch.await(600, TimeUnit.SECONDS);
assertEquals(baseRetainCount.get(), testRetainCount.get());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestViewImplTest method newRequestView.
private static RequestView newRequestView(HeaderFields parentHeaders) {
Request request = mock(Request.class);
when(request.headers()).thenReturn(parentHeaders);
return new RequestViewImpl(request);
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class MbusRequestHandlerTestCase method requireThatNonMbusRequestThrows.
@Test
public void requireThatNonMbusRequestThrows() throws Exception {
final TestDriver driver = newTestDriver(SameThreadReplier.INSTANCE);
try {
new RequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("mbus://localhost/"));
}
}.connect();
fail();
} catch (UnsupportedOperationException e) {
assertEquals("Expected MbusRequest, got com.yahoo.jdisc.Request.", e.getMessage());
}
assertTrue(driver.close());
}
Aggregations