Search in sources :

Example 1 with RequestDispatch

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

the class TimeoutManagerImplTestCase method requireThatNoEntryIsMadeIfTimeoutHandlerHasBeenSet.

@Test
public void requireThatNoEntryIsMadeIfTimeoutHandlerHasBeenSet() {
    final Context ctx = new Context(MyRequestHandler.newInstance());
    new RequestDispatch() {

        @Override
        protected Request newRequest() {
            Request request = new Request(ctx.driver, URI.create(REQUEST_URI));
            request.setTimeout(10, TimeUnit.MILLISECONDS);
            request.setTimeoutManager(new TimeoutManager() {

                @Override
                public void scheduleTimeout(Request request) {
                }
            });
            return request;
        }
    }.dispatch();
    assertFalse(ctx.awaitQueueSize(1, 100, TimeUnit.MILLISECONDS));
    assertTrue(ctx.awaitQueueSize(0, 600, TimeUnit.SECONDS));
    ctx.requestHandler.respond();
    assertTrue(ctx.close());
}
Also used : RequestDispatch(com.yahoo.jdisc.handler.RequestDispatch) TimeoutManager(com.yahoo.jdisc.TimeoutManager) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 2 with RequestDispatch

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

the class TimeoutManagerImplTestCase method requireThatTimeoutOccursAtExpectedTime.

@Test
public void requireThatTimeoutOccursAtExpectedTime() throws InterruptedException {
    final Context ctx = new Context(MyRequestHandler.newInstance());
    final MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    ctx.forwardToTime(100);
    new RequestDispatch() {

        @Override
        protected Request newRequest() {
            Request request = new Request(ctx.driver, URI.create(REQUEST_URI));
            request.setTimeout(300, TimeUnit.MILLISECONDS);
            return request;
        }

        @Override
        public ContentChannel handleResponse(Response response) {
            return responseHandler.handleResponse(response);
        }
    }.dispatch();
    ctx.forwardToTime(300);
    assertFalse(responseHandler.await(100, TimeUnit.MILLISECONDS));
    ctx.forwardToTime(400);
    assertTrue(responseHandler.await(600, TimeUnit.SECONDS));
    Response response = responseHandler.response.get();
    assertNotNull(response);
    assertEquals(Response.Status.GATEWAY_TIMEOUT, response.getStatus());
    assertTrue(ctx.close());
}
Also used : Response(com.yahoo.jdisc.Response) RequestDispatch(com.yahoo.jdisc.handler.RequestDispatch) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 3 with RequestDispatch

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

the class MbusRequestHandlerTestCase method requireThatNonMbusRequestThrows.

@Test
public void requireThatNonMbusRequestThrows() throws Exception {
    final TestDriver driver = newTestDriver(SameThreadReplier.INSTANCE);
    try {
        new RequestDispatch() {

            @Override
            protected Request newRequest() {
                return new Request(driver, URI.create("mbus://localhost/"));
            }
        }.connect();
        fail();
    } catch (UnsupportedOperationException e) {
        assertEquals("Expected MbusRequest, got com.yahoo.jdisc.Request.", e.getMessage());
    }
    assertTrue(driver.close());
}
Also used : RequestDispatch(com.yahoo.jdisc.handler.RequestDispatch) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

Request (com.yahoo.jdisc.Request)3 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)3 Test (org.junit.Test)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)2 Response (com.yahoo.jdisc.Response)1 TimeoutManager (com.yahoo.jdisc.TimeoutManager)1 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)1 TestDriver (com.yahoo.jdisc.test.TestDriver)1