Search in sources :

Example 81 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatResponseWriteCompletionCanOnlyBeCalledOnce.

@Test
public void requireThatResponseWriteCompletionCanOnlyBeCalledOnce() {
    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.write(ByteBuffer.allocate(0), completion);
    assertEquals(0, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    responseHandler.content.writeCompletion.completed();
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        responseHandler.content.writeCompletion.completed();
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        responseHandler.content.writeCompletion.failed(new Throwable());
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    resolvedContent.close(null);
    responseHandler.content.closeCompletion.completed();
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 82 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatResponseContentFailedIsProxied.

@Test
public void requireThatResponseContentFailedIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    request.connect(responseHandler).close(null);
    request.release();
    Response response = new Response(Response.Status.OK);
    ContentChannel resolvedContent = requestHandler.handler.handleResponse(response);
    assertSame(response, responseHandler.response);
    ByteBuffer buf = ByteBuffer.allocate(69);
    resolvedContent.write(buf, null);
    assertSame(buf, responseHandler.content.writeBuf);
    responseHandler.content.writeCompletion.completed();
    MyCompletion writeCompletion = new MyCompletion();
    resolvedContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
    assertSame(buf, responseHandler.content.writeBuf);
    assertFalse(writeCompletion.completed);
    assertNull(writeCompletion.failed);
    MyException writeFailed = new MyException();
    responseHandler.content.writeCompletion.failed(writeFailed);
    assertFalse(writeCompletion.completed);
    assertSame(writeFailed, writeCompletion.failed);
    MyCompletion closeCompletion = new MyCompletion();
    resolvedContent.close(closeCompletion);
    assertTrue(responseHandler.content.closed);
    assertFalse(closeCompletion.completed);
    assertNull(closeCompletion.failed);
    MyException closeFailed = new MyException();
    responseHandler.content.closeCompletion.failed(closeFailed);
    assertFalse(closeCompletion.completed);
    assertSame(closeFailed, closeCompletion.failed);
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 83 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatUncaughtCompletionFailureIsLogged.

@Test
public void requireThatUncaughtCompletionFailureIsLogged() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    Request request = newRequest(driver, requestHandler);
    ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
    request.release();
    MyLogHandler logHandler = new MyLogHandler();
    Logger.getLogger(ProxyRequestHandler.class.getName()).addHandler(logHandler);
    resolvedContent.write(ByteBuffer.allocate(69), null);
    MyException writeFailed = new MyException();
    requestHandler.content.writeCompletion.failed(writeFailed);
    assertNotNull(logHandler.record);
    assertSame(writeFailed, logHandler.record.getThrown());
    resolvedContent.close(null);
    MyException closeFailed = new MyException();
    requestHandler.content.closeCompletion.failed(closeFailed);
    assertNotNull(logHandler.record);
    assertSame(closeFailed, logHandler.record.getThrown());
    requestHandler.respond();
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 84 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatRequestContentFailedIsProxied.

@Test
public void requireThatRequestContentFailedIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    Request request = newRequest(driver, requestHandler);
    ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
    request.release();
    assertSame(request, requestHandler.request);
    ByteBuffer buf = ByteBuffer.allocate(69);
    resolvedContent.write(buf, null);
    assertSame(buf, requestHandler.content.writeBuf);
    requestHandler.content.writeCompletion.completed();
    MyCompletion writeCompletion = new MyCompletion();
    resolvedContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
    assertSame(buf, requestHandler.content.writeBuf);
    assertFalse(writeCompletion.completed);
    assertNull(writeCompletion.failed);
    MyException writeFailed = new MyException();
    requestHandler.content.writeCompletion.failed(writeFailed);
    assertFalse(writeCompletion.completed);
    assertSame(writeFailed, writeCompletion.failed);
    MyCompletion closeCompletion = new MyCompletion();
    resolvedContent.close(closeCompletion);
    assertTrue(requestHandler.content.closed);
    assertFalse(closeCompletion.completed);
    assertNull(closeCompletion.failed);
    MyException closeFailed = new MyException();
    requestHandler.content.closeCompletion.failed(closeFailed);
    assertFalse(writeCompletion.completed);
    assertSame(closeFailed, closeCompletion.failed);
    requestHandler.respond();
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 85 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatRequestCloseCompletionCanOnlyBeCalledOnce.

@Test
public void requireThatRequestCloseCompletionCanOnlyBeCalledOnce() {
    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.close(completion);
    assertEquals(0, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    requestHandler.content.closeCompletion.completed();
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        requestHandler.content.closeCompletion.completed();
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    try {
        requestHandler.content.closeCompletion.failed(new Throwable());
        fail();
    } catch (IllegalStateException e) {
    // ignore
    }
    assertEquals(1, completion.numCompleted.get());
    assertEquals(0, completion.numFailed.get());
    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