Search in sources :

Example 1 with ClientTestDriver

use of com.yahoo.messagebus.jdisc.test.ClientTestDriver in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatRequestResponseWorks.

@Test
public void requireThatRequestResponseWorks() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
    Response response = responseHandler.awaitResponse();
    assertNotNull(response);
    assertEquals(Response.Status.OK, response.getStatus());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Test(org.junit.Test)

Example 2 with ClientTestDriver

use of com.yahoo.messagebus.jdisc.test.ClientTestDriver in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatNonMbusRequestIsDenied.

@Test
public void requireThatNonMbusRequestIsDenied() throws InterruptedException {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    Request serverReq = null;
    Request clientReq = null;
    try {
        serverReq = driver.newServerRequest();
        clientReq = new Request(serverReq, URI.create("mbus://host/path"));
        clientReq.connect(MyResponseHandler.newInstance());
        fail();
    } catch (RequestDeniedException e) {
        System.out.println(e.getMessage());
    } finally {
        if (serverReq != null) {
            serverReq.release();
        }
        if (clientReq != null) {
            clientReq.release();
        }
    }
    assertTrue(driver.close());
}
Also used : ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 3 with ClientTestDriver

use of com.yahoo.messagebus.jdisc.test.ClientTestDriver in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatResponseIsMbus.

@Test
public void requireThatResponseIsMbus() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
    Response response = responseHandler.awaitResponse();
    assertTrue(response instanceof MbusResponse);
    Reply reply = ((MbusResponse) response).getReply();
    assertTrue(reply instanceof EmptyReply);
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 4 with ClientTestDriver

use of com.yahoo.messagebus.jdisc.test.ClientTestDriver 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 5 with ClientTestDriver

use of com.yahoo.messagebus.jdisc.test.ClientTestDriver in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatStateIsTransferredToResponse.

@Test
public void requireThatStateIsTransferredToResponse() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Message msg = new SimpleMessage("foo");
    Object pushedCtx = new Object();
    msg.setContext(pushedCtx);
    ReplyHandler pushedHandler = new MyReplyHandler();
    msg.pushHandler(pushedHandler);
    Object currentCtx = new Object();
    msg.setContext(currentCtx);
    msg.getTrace().setLevel(6);
    assertTrue(driver.sendMessage(msg, responseHandler));
    assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
    Response response = responseHandler.awaitResponse();
    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) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Aggregations

ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)10 Test (org.junit.Test)10 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)9 Response (com.yahoo.jdisc.Response)7 SimpleReply (com.yahoo.messagebus.test.SimpleReply)7 Request (com.yahoo.jdisc.Request)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)1 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)1