use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class TimeoutManagerImplTestCase method requireThatResponseHandlerIsWellBehavedAfterTimeout.
@Test
public void requireThatResponseHandlerIsWellBehavedAfterTimeout() throws InterruptedException {
Context ctx = new Context(MyRequestHandler.newInstance());
assertEquals(Response.Status.GATEWAY_TIMEOUT, ctx.awaitResponse(69L, MyResponseHandler.newInstance()));
ContentChannel content = ctx.requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
assertNotNull(content);
content.write(ByteBuffer.allocate(69), null);
MyCompletion completion = new MyCompletion();
content.write(ByteBuffer.allocate(69), completion);
assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
completion = new MyCompletion();
content.close(completion);
assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
assertTrue(ctx.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestExceptionAfterResponseWriteWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestExceptionAfterResponseWriteWithAsyncHandleResponse(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 {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
writeResponse(out);
closeResponse(out);
return null;
}
});
responseWritten.await();
throw new ConformanceException();
}
});
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class LatencyTestCase method measureLatency.
private static TimeFrame measureLatency(CurrentContainer container, MyRequestHandler requestHandler) {
TimeFrame frame = new TimeFrame();
Request request = null;
ContentChannel requestContent = null;
MyResponseHandler responseHandler = new MyResponseHandler();
try {
URI uri = URI.create(requestHandler.uri);
request = new Request(container, uri);
frame.handleRequestBegin = System.nanoTime();
requestContent = request.connect(responseHandler);
frame.handleRequestEnd = requestHandler.handleTime;
} finally {
if (request != null) {
request.release();
}
}
ByteBuffer buf = ByteBuffer.allocate(69);
MyCompletion requestWrite = new MyCompletion();
frame.requestWriteBegin = System.nanoTime();
requestContent.write(buf, requestWrite);
frame.requestWriteEnd = requestHandler.requestContent.writeTime;
frame.requestWriteCompletionBegin = System.nanoTime();
requestHandler.requestContent.writeCompletion.completed();
frame.requestWriteCompletionEnd = requestWrite.completedTime;
MyCompletion requestClose = new MyCompletion();
frame.requestCloseBegin = System.nanoTime();
requestContent.close(requestClose);
frame.requestCloseEnd = requestHandler.requestContent.closeTime;
frame.requestCloseCompletionBegin = System.nanoTime();
requestHandler.requestContent.closeCompletion.completed();
frame.requestCloseCompletionEnd = requestClose.completedTime;
Response response = new Response(Response.Status.OK);
frame.handleResponseBegin = System.nanoTime();
ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
frame.handleResponseEnd = responseHandler.handleTime;
MyCompletion responseWrite = new MyCompletion();
frame.responseWriteBegin = System.nanoTime();
responseContent.write(buf, responseWrite);
frame.responseWriteEnd = responseHandler.responseContent.writeTime;
frame.responseWriteCompletionBegin = System.nanoTime();
responseHandler.responseContent.writeCompletion.completed();
frame.responseWriteCompletionEnd = responseWrite.completedTime;
MyCompletion responseClose = new MyCompletion();
frame.responseCloseBegin = System.nanoTime();
responseContent.close(responseClose);
frame.responseCloseEnd = responseHandler.responseContent.closeTime;
frame.responseCloseCompletionBegin = System.nanoTime();
responseHandler.responseContent.closeCompletion.completed();
frame.responseCloseCompletionEnd = responseClose.completedTime;
return frame;
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ApplicationRestartTestCase method assertGracefulStop.
private static void assertGracefulStop(ApplicationLoader loader) throws Exception {
MyRequestHandler requestHandler = new MyRequestHandler();
ContainerBuilder builder = loader.newContainerBuilder();
builder.serverBindings().bind("http://host/path", requestHandler);
loader.activateContainer(builder);
MyResponseHandler responseHandler = new MyResponseHandler();
Request request = new Request(loader, URI.create("http://host/path"));
request.connect(responseHandler).close(null);
request.release();
StopTask task = new StopTask(loader);
task.start();
assertFalse(task.latch.await(100, TimeUnit.MILLISECONDS));
requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(task.latch.await(600, TimeUnit.SECONDS));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ApplicationLoaderTestCase method requireThatApplicationDestroyIsCalledAfterContainerTermination.
@Test
public void requireThatApplicationDestroyIsCalledAfterContainerTermination() throws InterruptedException {
MyApplication app = MyApplication.newInstance();
TestDriver driver = TestDriver.newInjectedApplicationInstance(app);
ContainerBuilder builder = driver.newContainerBuilder();
MyRequestHandler requestHandler = new MyRequestHandler();
builder.serverBindings().bind("scheme://host/path", requestHandler);
driver.activateContainer(builder);
driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
driver.scheduleClose();
assertFalse(app.destroy.await(100, TimeUnit.MILLISECONDS));
requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(app.destroy.await(600, TimeUnit.SECONDS));
}
Aggregations