Search in sources :

Example 31 with Request

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

the class ServerProviderConformanceTest method testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse.

private <T extends ServerProvider, U, V> void testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
    runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {

        @Override
        public ContentChannel handle(final Request request, final ResponseHandler handler) {
            final Event exceptionHandledByFramework = new Event();
            callInOtherThread(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    exceptionHandledByFramework.await();
                    try {
                        final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
                        exceptionHandledByFramework.await();
                        writeResponse(out);
                        closeResponse(out);
                    } catch (Throwable ignored) {
                    }
                    return null;
                }
            });
            throw new ConformanceException(exceptionHandledByFramework);
        }
    });
}
Also used : Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) Callable(java.util.concurrent.Callable)

Example 32 with Request

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

the class NonWorkingRequestTestCase method requireThatGuiceModulesAreInjected.

@Test
public void requireThatGuiceModulesAreInjected() {
    Request request = NonWorkingRequest.newInstance("scheme://host/path", new AbstractModule() {

        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("foo")).toInstance("bar");
        }
    });
    assertEquals("bar", request.container().getInstance(Key.get(String.class, Names.named("foo"))));
}
Also used : Request(com.yahoo.jdisc.Request) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 33 with Request

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

the class ThreadedRequestHandlerTestCase method requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun.

@Test
public void requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun() throws Exception {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    final AtomicInteger baseRetainCount = new AtomicInteger();
    builder.serverBindings().bind("http://localhost/base", new AbstractRequestHandler() {

        @Override
        public ContentChannel handleRequest(Request request, ResponseHandler handler) {
            baseRetainCount.set(request.retainCount());
            handler.handleResponse(new Response(Response.Status.OK)).close(null);
            return null;
        }
    });
    final CountDownLatch entryLatch = new CountDownLatch(1);
    final CountDownLatch exitLatch = new CountDownLatch(1);
    final AtomicInteger testRetainCount = new AtomicInteger();
    builder.serverBindings().bind("http://localhost/test", new ThreadedRequestHandler(newExecutor()) {

        @Override
        public void handleRequest(Request request, ReadableContentChannel requestContent, ResponseHandler responseHandler) {
            try {
                entryLatch.await(600, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                return;
            }
            testRetainCount.set(request.retainCount());
            responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
            // drain content to call completion handlers
            requestContent.read();
            exitLatch.countDown();
        }
    });
    driver.activateContainer(builder);
    dispatchRequest(driver, "http://localhost/base");
    dispatchRequest(driver, "http://localhost/test");
    entryLatch.countDown();
    exitLatch.await(600, TimeUnit.SECONDS);
    assertEquals(baseRetainCount.get(), testRetainCount.get());
    assertTrue(driver.close());
}
Also used : Request(com.yahoo.jdisc.Request) CountDownLatch(java.util.concurrent.CountDownLatch) TestDriver(com.yahoo.jdisc.test.TestDriver) Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 34 with Request

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

the class RequestViewImplTest method newRequestView.

private static RequestView newRequestView(HeaderFields parentHeaders) {
    Request request = mock(Request.class);
    when(request.headers()).thenReturn(parentHeaders);
    return new RequestViewImpl(request);
}
Also used : RequestViewImpl(com.yahoo.jdisc.http.filter.SecurityResponseFilterChain.RequestViewImpl) Request(com.yahoo.jdisc.Request)

Example 35 with Request

use of com.yahoo.jdisc.Request 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)44 Test (org.junit.Test)31 TestDriver (com.yahoo.jdisc.test.TestDriver)22 Response (com.yahoo.jdisc.Response)17 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)16 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 ByteBuffer (java.nio.ByteBuffer)7 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)4 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)3 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)3 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Callable (java.util.concurrent.Callable)3 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 HttpRequest (com.yahoo.jdisc.http.HttpRequest)2 URI (java.net.URI)2 Executor (java.util.concurrent.Executor)2 Test (org.testng.annotations.Test)2 AbstractModule (com.google.inject.AbstractModule)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1