Search in sources :

Example 21 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder 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));
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 22 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class RequestDispatchTestCase method requireThatStreamCanBeConnected.

@Test
public void requireThatStreamCanBeConnected() throws IOException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ReadableContentChannel content = new ReadableContentChannel();
    MyRequestHandler requestHandler = new MyRequestHandler(content, new Response(Response.Status.OK));
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    OutputStream out = new FastContentOutputStream(driver.newRequestDispatch("http://localhost/", new FutureResponse()).connect());
    out.write(6);
    out.write(9);
    out.close();
    InputStream in = content.toStream();
    assertEquals(6, in.read());
    assertEquals(9, in.read());
    assertEquals(-1, in.read());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 23 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class RequestDispatchTestCase method requireThatDispatchHandlesConnectException.

@Test
public void requireThatDispatchHandlesConnectException() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new AbstractRequestHandler() {

        @Override
        public ContentChannel handleRequest(Request request, ResponseHandler handler) {
            throw new RuntimeException();
        }
    });
    driver.activateContainer(builder);
    try {
        driver.newRequestDispatch("http://localhost/", new FutureResponse()).dispatch();
        fail();
    } catch (RuntimeException e) {
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 24 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class DocumentProcessingHandlerTestBase method createHandler.

@Before
public void createHandler() {
    documentTypeManager.register(getType());
    Protocol protocol = new DocumentProtocol(documentTypeManager);
    driver = ServerTestDriver.newInactiveInstanceWithProtocol(protocol);
    sessionCache = new SessionCache("raw:", driver.client().slobrokId(), "test", "raw:", null, "raw:", documentTypeManager);
    ContainerBuilder builder = driver.parent().newContainerBuilder();
    ComponentRegistry<DocprocService> registry = new ComponentRegistry<>();
    handler = new DocumentProcessingHandler(registry, new ComponentRegistry<>(), new ComponentRegistry<>(), new DocumentProcessingHandlerParameters().setDocumentTypeManager(documentTypeManager).setContainerDocumentConfig(new ContainerDocumentConfig(new ContainerDocumentConfig.Builder())));
    builder.serverBindings().bind("mbus://*/*", handler);
    ReferencedResource<SharedSourceSession> sessionRef = sessionCache.retainSource(new SourceSessionParams());
    MbusClient sourceClient = new MbusClient(sessionRef.getResource());
    builder.clientBindings().bind("mbus://*/source", sourceClient);
    builder.clientBindings().bind("mbus://*/" + MbusRequestContext.internalNoThrottledSource, sourceClient);
    sourceClient.start();
    List<Pair<String, CallStack>> callStacks = getCallStacks();
    List<AbstractResource> resources = new ArrayList<>();
    for (Pair<String, CallStack> callStackPair : callStacks) {
        DocprocService service = new DocprocService(callStackPair.getFirst());
        service.setCallStack(callStackPair.getSecond());
        service.setInService(true);
        ComponentId serviceId = new ComponentId(service.getName());
        registry.register(serviceId, service);
        ComponentId sessionName = ComponentId.fromString("chain." + serviceId);
        MbusServerProvider serviceProvider = new MbusServerProvider(sessionName, sessionCache, driver.parent());
        serviceProvider.get().start();
        serviceProviders.add(serviceProvider);
        MbusClient intermediateClient = new MbusClient(serviceProvider.getSession());
        builder.clientBindings().bind("mbus://*/" + sessionName.stringValue(), intermediateClient);
        intermediateClient.start();
        resources.add(intermediateClient);
    }
    driver.parent().activateContainer(builder);
    sessionRef.getReference().close();
    sourceClient.release();
    for (AbstractResource resource : resources) {
        resource.release();
    }
    remoteServer = RemoteServer.newInstance(driver.client().slobrokId(), "foobar", protocol);
}
Also used : CallStack(com.yahoo.docproc.CallStack) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ArrayList(java.util.ArrayList) AbstractResource(com.yahoo.jdisc.AbstractResource) DocprocService(com.yahoo.docproc.DocprocService) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) Protocol(com.yahoo.messagebus.Protocol) Pair(com.yahoo.collections.Pair) ContainerDocumentConfig(com.yahoo.container.core.document.ContainerDocumentConfig) MbusClient(com.yahoo.messagebus.jdisc.MbusClient) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) MbusServerProvider(com.yahoo.container.jdisc.messagebus.MbusServerProvider) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) ComponentId(com.yahoo.component.ComponentId) Before(org.junit.Before)

Example 25 with ContainerBuilder

use of com.yahoo.jdisc.application.ContainerBuilder in project vespa by vespa-engine.

the class AbstractRequestHandlerTestCase method requireThatForwardWorks.

@Test
public void requireThatForwardWorks() throws InterruptedException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new ForwardHandler());
    builder.clientBindings().bind("http://remotehost/", new EchoHandler());
    driver.activateContainer(builder);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        MyResponseHandler responseHandler = new MyResponseHandler();
        RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", responseHandler);
        FastContentWriter requestContent = dispatch.connectFastWriter();
        ByteBuffer buf = ByteBuffer.allocate(69);
        requestContent.write(buf);
        requestContent.close();
        assertSame(buf, responseHandler.content.read());
        assertNull(responseHandler.content.read());
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)53 Test (org.junit.Test)41 TestDriver (com.yahoo.jdisc.test.TestDriver)40 Request (com.yahoo.jdisc.Request)16 Response (com.yahoo.jdisc.Response)12 ByteBuffer (java.nio.ByteBuffer)7 Executor (java.util.concurrent.Executor)6 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)4 AbstractModule (com.google.inject.AbstractModule)3 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 Container (com.yahoo.jdisc.Container)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 Map (java.util.Map)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Module (com.google.inject.Module)1 Pair (com.yahoo.collections.Pair)1