Search in sources :

Example 36 with Request

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

the class ClientTestDriver method newClientRequest.

public Request newClientRequest(Message msg) {
    msg.setRoute(Route.parse(server.connectionSpec()));
    if (msg.getTrace().getLevel() == 0) {
        msg.getTrace().setLevel(9);
    }
    final Request parent = newServerRequest();
    try (final ResourceReference ref = References.fromResource(parent)) {
        return new MbusRequest(parent, URI.create("mbus://remotehost/"), msg);
    }
}
Also used : MbusRequest(com.yahoo.messagebus.jdisc.MbusRequest) MbusRequest(com.yahoo.messagebus.jdisc.MbusRequest) Request(com.yahoo.jdisc.Request) ResourceReference(com.yahoo.jdisc.ResourceReference)

Example 37 with Request

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

the class MbusClientTestCase method requireThatRequestContentDoesNotSupportWrite.

@Test
public void requireThatRequestContentDoesNotSupportWrite() throws InterruptedException {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Request request = null;
    ContentChannel content;
    try {
        request = driver.newClientRequest(new SimpleMessage("foo"));
        content = request.connect(responseHandler);
    } finally {
        if (request != null) {
            request.release();
        }
    }
    try {
        content.write(ByteBuffer.allocate(69), null);
        fail();
    } catch (UnsupportedOperationException e) {
    }
    content.close(null);
    assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
    assertNotNull(responseHandler.awaitResponse());
    assertTrue(driver.close());
}
Also used : ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 38 with Request

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

the class MbusClientTestCase method requireThatStateIsTransferredToTimeoutResponse.

@Test
public void requireThatStateIsTransferredToTimeoutResponse() throws InterruptedException {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Message msg = new SimpleMessage("foo");
    ReplyHandler pushedHandler = new MyReplyHandler();
    Object pushedCtx = new Object();
    msg.setContext(pushedCtx);
    msg.pushHandler(pushedHandler);
    Object currentCtx = new Object();
    msg.setContext(currentCtx);
    msg.getTrace().setLevel(6);
    Request request = driver.newClientRequest(msg);
    request.setTimeout(1, TimeUnit.MILLISECONDS);
    assertTrue(driver.sendRequest(request, responseHandler));
    request.release();
    Response response = responseHandler.awaitResponse();
    assertNotNull(response);
    assertTrue(response.getClass().getName(), response instanceof MbusResponse);
    Reply reply = ((MbusResponse) response).getReply();
    assertSame(currentCtx, reply.getContext());
    assertEquals(6, reply.getTrace().getLevel());
    assertSame(pushedHandler, reply.popHandler());
    assertSame(pushedCtx, reply.getContext());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Request(com.yahoo.jdisc.Request) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 39 with Request

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

the class BindingNotFoundTestCase method requireThatBindingNotFoundIsThrown.

@Test
public void requireThatBindingNotFoundIsThrown() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request request = new Request(driver, URI.create("http://host/path"));
    try {
        request.connect(new MyResponseHandler());
        fail();
    } catch (BindingNotFoundException e) {
        assertEquals(request.getUri(), e.uri());
    }
    request.release();
    driver.close();
}
Also used : Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 40 with Request

use of com.yahoo.jdisc.Request 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

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