Search in sources :

Example 6 with TestDriver

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

the class RequestTestCase method requireThatTimeoutCausesCancel.

@Test
public void requireThatTimeoutCausesCancel() {
    MyTimer timer = new MyTimer();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(timer);
    Request request = newRequest(driver);
    request.setTimeout(10, TimeUnit.MILLISECONDS);
    assertFalse(request.isCancelled());
    timer.currentTime = 10;
    assertTrue(request.isCancelled());
    request.release();
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 7 with TestDriver

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

the class RequestTestCase method requireThatNullTimeoutManagerThrowsException.

@Test
public void requireThatNullTimeoutManagerThrowsException() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    Request request = newRequest(driver);
    try {
        request.setTimeoutManager(null);
        fail();
    } catch (NullPointerException e) {
    }
    request.release();
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 8 with TestDriver

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

the class RequestTestCase method requireThatCancelWorks.

@Test
public void requireThatCancelWorks() {
    MyTimer timer = new MyTimer();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(timer);
    Request request = newRequest(driver);
    assertFalse(request.isCancelled());
    request.cancel();
    assertTrue(request.isCancelled());
    request.release();
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 9 with TestDriver

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

the class AbstractApplicationTestCase method requireThatTerminationCanBeWaitedForWithoutTimeout.

@Test
public void requireThatTerminationCanBeWaitedForWithoutTimeout() throws InterruptedException {
    TestDriver driver = TestDriver.newInjectedApplicationInstance(MyApplication.class);
    final MyApplication app = (MyApplication) driver.application();
    final CountDownLatch latch = new CountDownLatch(1);
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                app.awaitTermination();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            latch.countDown();
        }
    });
    assertFalse(latch.await(100, TimeUnit.MILLISECONDS));
    assertTrue(driver.close());
    assertTrue(latch.await(600, TimeUnit.SECONDS));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 10 with TestDriver

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

the class AbstractApplicationTestCase method requireThatTerminationCanBeWaitedForWithTimeout.

@Test
public void requireThatTerminationCanBeWaitedForWithTimeout() throws InterruptedException {
    TestDriver driver = TestDriver.newInjectedApplicationInstance(MyApplication.class);
    final MyApplication app = (MyApplication) driver.application();
    final CountDownLatch latch = new CountDownLatch(1);
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                app.awaitTermination(600, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            latch.countDown();
        }
    });
    assertFalse(latch.await(100, TimeUnit.MILLISECONDS));
    assertTrue(driver.close());
    assertTrue(latch.await(600, TimeUnit.SECONDS));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) 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