Search in sources :

Example 76 with TestDriver

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

Example 77 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ContainerTestCase method requireThatInjectionWorks.

@Test
public void requireThatInjectionWorks() throws BindingSetNotFoundException {
    final Object foo = new Object();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Object.class).toInstance(foo);
        }
    });
    driver.activateContainer(driver.newContainerBuilder());
    Request request = new Request(driver, URI.create("http://host/path"));
    assertSame(foo, request.container().getInstance(Object.class));
    request.release();
    driver.close();
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 78 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ContainerTestCase method requireThatNewRequestsReferenceSameSnapshot.

@Test
public void requireThatNewRequestsReferenceSameSnapshot() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request foo = new Request(driver, URI.create("http://foo"));
    Request bar = new Request(foo, URI.create("http://bar"));
    assertNotNull(foo.container());
    assertSame(foo.container(), bar.container());
    foo.release();
    bar.release();
    driver.close();
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 79 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ProxyRequestHandlerTestCase method requireThatResponseCloseCompletionCanOnlyBeCalledOnce.

@Test
public void requireThatResponseCloseCompletionCanOnlyBeCalledOnce() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Request request = newRequest(driver, requestHandler);
    request.connect(responseHandler).close(null);
    request.release();
    ContentChannel resolvedContent = requestHandler.handler.handleResponse(new Response(Response.Status.OK));
    CountingCompletionHandler completion = new CountingCompletionHandler();
    resolvedContent.close(completion);
    assertEquals(0, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    responseHandler.content.closeCompletion.completed();
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        responseHandler.content.closeCompletion.completed();
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        responseHandler.content.closeCompletion.failed(new Throwable());
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 80 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ProxyRequestHandlerTestCase method requireThatRequestWriteCompletionCanOnlyBeCalledOnce.

@Test
public void requireThatRequestWriteCompletionCanOnlyBeCalledOnce() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    Request request = newRequest(driver, requestHandler);
    ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
    request.release();
    CountingCompletionHandler completion = new CountingCompletionHandler();
    resolvedContent.write(ByteBuffer.allocate(0), completion);
    assertEquals(0, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    requestHandler.content.writeCompletion.completed();
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        requestHandler.content.writeCompletion.completed();
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        requestHandler.content.writeCompletion.failed(new Throwable());
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    resolvedContent.close(null);
    requestHandler.content.closeCompletion.completed();
    requestHandler.respond();
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

TestDriver (com.yahoo.jdisc.test.TestDriver)134 Test (org.junit.Test)128 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)39 Request (com.yahoo.jdisc.Request)22 Bundle (org.osgi.framework.Bundle)14 AbstractModule (com.google.inject.AbstractModule)13 ByteBuffer (java.nio.ByteBuffer)12 Response (com.yahoo.jdisc.Response)10 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)6 Executor (java.util.concurrent.Executor)6 LinkedList (java.util.LinkedList)5 BundleContext (org.osgi.framework.BundleContext)4 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ServerProvider (com.yahoo.jdisc.service.ServerProvider)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BundleException (org.osgi.framework.BundleException)3 Module (com.google.inject.Module)2