Search in sources :

Example 31 with Response

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

the class TestDriverTestCase method requireThatDispatchRequestWorks.

@Test
public void requireThatDispatchRequestWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
    assertNotNull(requestHandler.handler);
    assertTrue(requestHandler.content.closed);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Test(org.junit.Test)

Example 32 with Response

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

the class TestDriverTestCase method requireThatConnectRequestWorks.

@Test
public void requireThatConnectRequestWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    ContentChannel content = driver.connectRequest("scheme://host/path", new MyResponseHandler());
    assertNotNull(content);
    content.close(null);
    assertNotNull(requestHandler.handler);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 33 with Response

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

the class MockClient method handleRequest.

@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
    counter.incrementAndGet();
    final ContentChannel responseContentChannel = handler.handleResponse(new Response(200));
    responseContentChannel.close(NOOP_COMPLETION_HANDLER);
    return null;
}
Also used : Response(com.yahoo.jdisc.Response) ContentChannel(com.yahoo.jdisc.handler.ContentChannel)

Example 34 with Response

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

the class ProcessingHandlerTestCase method testResponseDataStatusOverridesErrors.

/**
 * Tests that the ResponseStatus takes precedence over errors
 */
@Test
public void testResponseDataStatusOverridesErrors() throws InterruptedException {
    ProcessingTestDriver.MockResponseHandler responseHandler = null;
    try {
        List<Chain<Processor>> chains = new ArrayList<>();
        chains.add(new Chain<Processor>("default", new ResponseStatusSetter(200), new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
        driver = new ProcessingTestDriver(chains);
        responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
        Response response = responseHandler.getResponse();
        assertEquals(200, response.getStatus());
    } finally {
        if (responseHandler != null)
            responseHandler.readAll();
    }
}
Also used : Response(com.yahoo.jdisc.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 35 with Response

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

the class ProcessingHandlerTestCase method testResponseDataStatus.

@Test
public void testResponseDataStatus() throws InterruptedException {
    ProcessingTestDriver.MockResponseHandler responseHandler = null;
    try {
        List<Chain<Processor>> chains = new ArrayList<>();
        chains.add(new Chain<Processor>("default", new ResponseStatusSetter(429)));
        driver = new ProcessingTestDriver(chains);
        responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
        Response response = responseHandler.getResponse();
        assertEquals(429, response.getStatus());
        assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read());
    } finally {
        if (responseHandler != null)
            responseHandler.readAll();
    }
}
Also used : Response(com.yahoo.jdisc.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) 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