use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class TimeoutManagerImplTestCase method requireThatManagedHandlerForwardsAllCalls.
@Test
public void requireThatManagedHandlerForwardsAllCalls() throws InterruptedException {
Request request = NonWorkingRequest.newInstance(REQUEST_URI);
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
TimeoutManagerImpl timeoutManager = new TimeoutManagerImpl(Executors.defaultThreadFactory(), new SystemTimer());
RequestHandler managedHandler = timeoutManager.manageHandler(requestHandler);
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
ContentChannel requestContent = managedHandler.handleRequest(request, responseHandler);
assertNotNull(requestContent);
ByteBuffer buf = ByteBuffer.allocate(69);
requestContent.write(buf, null);
assertSame(buf, requestHandler.content.buf);
MyCompletion writeCompletion = new MyCompletion();
requestContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
assertSame(buf, requestHandler.content.buf);
requestHandler.content.writeCompletion.completed();
assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
MyCompletion closeCompletion = new MyCompletion();
requestContent.close(closeCompletion);
requestHandler.content.closeCompletion.completed();
assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
managedHandler.release();
assertTrue(requestHandler.destroyed);
Response response = new Response(Response.Status.OK);
ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
assertNotNull(responseContent);
responseContent.write(buf = ByteBuffer.allocate(69), null);
assertSame(buf, responseHandler.content.buf);
responseContent.write(buf = ByteBuffer.allocate(69), writeCompletion = new MyCompletion());
assertSame(buf, responseHandler.content.buf);
responseHandler.content.writeCompletion.completed();
assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
responseContent.close(closeCompletion = new MyCompletion());
responseHandler.content.closeCompletion.completed();
assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
assertSame(response, responseHandler.response.get());
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatRequestHandlerIsProxied.
@Test
public void requireThatRequestHandlerIsProxied() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
Request request = newRequest(driver, requestHandler);
RequestHandler resolvedHandler = new ProxyRequestHandler(request.container().resolveHandler(request));
MyResponseHandler responseHandler = MyResponseHandler.newEagerCompletion();
resolvedHandler.handleRequest(request, responseHandler).close(null);
request.release();
assertNotNull(requestHandler.handler);
resolvedHandler.handleTimeout(request, responseHandler);
assertTrue(requestHandler.timeout);
requestHandler.respond();
requestHandler.release();
final ResourceReference resolvedHandlerReference = resolvedHandler.refer();
// release installed ref
assertTrue(driver.close());
assertFalse(requestHandler.destroyed);
resolvedHandlerReference.close();
assertTrue(requestHandler.destroyed);
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class ActiveContainerTestCase method requireThatServerBindingAccessorWorks.
@Test
public void requireThatServerBindingAccessorWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
RequestHandler foo = new NonWorkingRequestHandler();
RequestHandler bar = new NonWorkingRequestHandler();
builder.serverBindings().bind("http://host/foo", foo);
builder.serverBindings("bar").bind("http://host/bar", bar);
ActiveContainer container = new ActiveContainer(builder);
Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
assertNotNull(bindings);
assertEquals(2, bindings.size());
BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
assertNotNull(set);
Iterator<Map.Entry<UriPattern, RequestHandler>> it = set.iterator();
assertNotNull(it);
assertTrue(it.hasNext());
Map.Entry<UriPattern, RequestHandler> entry = it.next();
assertNotNull(entry);
assertEquals(new UriPattern("http://host/foo"), entry.getKey());
assertSame(foo, entry.getValue());
assertFalse(it.hasNext());
assertNotNull(set = bindings.get("bar"));
assertNotNull(it = set.iterator());
assertTrue(it.hasNext());
assertNotNull(entry = it.next());
assertEquals(new UriPattern("http://host/bar"), entry.getKey());
assertSame(bar, entry.getValue());
assertFalse(it.hasNext());
assertNotNull(bindings = container.clientBindings());
assertEquals(1, bindings.size());
assertNotNull(set = bindings.get(BindingSet.DEFAULT));
assertNotNull(it = set.iterator());
assertFalse(it.hasNext());
driver.close();
}
use of com.yahoo.jdisc.handler.RequestHandler 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.handler.RequestHandler in project vespa by vespa-engine.
the class BindingRepositoryTestCase method requireThatPatternCannotBeStolen.
@Test
public void requireThatPatternCannotBeStolen() {
final String pattern = "http://host/path";
final RequestHandler originallyBoundHandler = new NonWorkingRequestHandler();
BindingRepository<Object> bindings = new BindingRepository<>();
bindings.bind(pattern, originallyBoundHandler);
bindings.bind(pattern, new PatternStealingRequestHandler());
BindingSet<?> bindingSet = bindings.activate();
assertEquals(originallyBoundHandler, bindingSet.resolve(URI.create(pattern)));
}
Aggregations