Search in sources :

Example 46 with Response

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

the class MbusServerTestCase method requireThatRequestResponseWorks.

@Test
public void requireThatRequestResponseWorks() {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    assertTrue(requestHandler.sendResponse(new Response(Response.Status.OK)));
    assertNotNull(driver.awaitSuccess());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Example 47 with Response

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

the class MbusServerTestCase method requireThatResponseContentDoesNotSupportWrite.

@Test
public void requireThatResponseContentDoesNotSupportWrite() throws InterruptedException {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    ContentChannel content = requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
    assertNotNull(content);
    try {
        content.write(ByteBuffer.allocate(69), null);
        fail();
    } catch (UnsupportedOperationException e) {
    }
    content.close(null);
    assertNotNull(driver.awaitSuccess());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Example 48 with Response

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

the class CallableResponseDispatchTestCase method requireThatDispatchIsCalled.

@Test
public void requireThatDispatchIsCalled() throws Exception {
    final Response response = new Response(Response.Status.OK);
    FutureResponse handler = new FutureResponse();
    new CallableResponseDispatch(handler) {

        @Override
        protected Response newResponse() {
            return response;
        }
    }.call();
    assertSame(response, handler.get(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) Test(org.junit.Test)

Example 49 with Response

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

the class FutureResponseTestCase method requireThatResponseCanBeListenedTo.

@Test
public void requireThatResponseCanBeListenedTo() throws InterruptedException {
    FutureResponse response = new FutureResponse();
    RunnableLatch listener = new RunnableLatch();
    response.addListener(listener, MoreExecutors.directExecutor());
    assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
    response.handleResponse(new Response(Response.Status.OK));
    assertTrue(listener.await(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) Test(org.junit.Test)

Example 50 with Response

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

the class RequestDispatchTestCase method requireThatRequestCanBeDispatched.

@Test
public void requireThatRequestCanBeDispatched() throws Exception {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    final List<ByteBuffer> writtenContent = Arrays.asList(ByteBuffer.allocate(6), ByteBuffer.allocate(9));
    ReadableContentChannel receivedContent = new ReadableContentChannel();
    ContainerBuilder builder = driver.newContainerBuilder();
    Response response = new Response(Response.Status.OK);
    builder.serverBindings().bind("http://localhost/", new MyRequestHandler(receivedContent, response));
    driver.activateContainer(builder);
    RequestDispatch dispatch = new RequestDispatch() {

        @Override
        protected Request newRequest() {
            return new Request(driver, URI.create("http://localhost/"));
        }

        @Override
        protected Iterable<ByteBuffer> requestContent() {
            return writtenContent;
        }
    };
    dispatch.dispatch();
    assertFalse(dispatch.isDone());
    assertSame(writtenContent.get(0), receivedContent.read());
    assertFalse(dispatch.isDone());
    assertSame(writtenContent.get(1), receivedContent.read());
    assertFalse(dispatch.isDone());
    assertNull(receivedContent.read());
    assertTrue(dispatch.isDone());
    assertSame(response, dispatch.get(600, TimeUnit.SECONDS));
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

Response (com.yahoo.jdisc.Response)52 Test (org.junit.Test)39 Request (com.yahoo.jdisc.Request)17 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)14 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)11 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)11 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 ByteBuffer (java.nio.ByteBuffer)6 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)5 Chain (com.yahoo.component.chain.Chain)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)3 Reply (com.yahoo.messagebus.Reply)3 Processor (com.yahoo.processing.Processor)3 Callable (java.util.concurrent.Callable)3 Test (org.testng.annotations.Test)3