use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ConnectToHandlerTestCase method requireThatConnectToHandlerWorks.
@Test
public void requireThatConnectToHandlerWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContent());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://host/*", requestHandler);
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
MyResponseHandler responseHandler = new MyResponseHandler();
ContentChannel content = request.connect(responseHandler);
request.release();
assertNotNull(content);
content.close(null);
assertNotNull(requestHandler.handler);
assertSame(request, requestHandler.request);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
driver.close();
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestNondeterministicExceptionWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestNondeterministicExceptionWithAsyncHandleResponse(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) {
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
closeResponse(out);
} catch (Throwable ignored) {
}
return null;
}
});
throw new ConformanceException();
}
});
}
use of com.yahoo.jdisc.Response 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.Response 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.Response in project vespa by vespa-engine.
the class MbusRequestHandlerTestCase method requireThatHandlerCanRespondInOtherThread.
@Test
public void requireThatHandlerCanRespondInOtherThread() throws Exception {
TestDriver driver = newTestDriver(ThreadedReplier.INSTANCE);
Response response = dispatchMessage(driver, new SimpleMessage("msg")).get(60, TimeUnit.SECONDS);
assertTrue(response instanceof MbusResponse);
assertEquals(Response.Status.OK, response.getStatus());
Reply reply = ((MbusResponse) response).getReply();
assertTrue(reply instanceof EmptyReply);
assertFalse(reply.hasErrors());
assertTrue(driver.close());
}
Aggregations