Search in sources :

Example 6 with ClientTestDriver

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

the class MbusClientTestCase method requireThatStateIsTransferredToSyncMbusSendFailureResponse.

@Test
public void requireThatStateIsTransferredToSyncMbusSendFailureResponse() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    driver.sourceSession().close();
    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);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    driver.sendMessage(msg, responseHandler);
    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) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 7 with ClientTestDriver

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

the class MbusClientTestCase method requireThatSyncMbusSendFailureRespondsWithError.

@Test
public void requireThatSyncMbusSendFailureRespondsWithError() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    driver.sourceSession().close();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    driver.sendMessage(new SimpleMessage("foo"), responseHandler);
    Response response = responseHandler.awaitResponse();
    assertNotNull(response);
    assertTrue(response.getClass().getName(), response instanceof MbusResponse);
    Reply reply = ((MbusResponse) response).getReply();
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.SEND_QUEUE_CLOSED, reply.getError(0).getCode());
    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 8 with ClientTestDriver

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

the class MbusClientTestCase method requireThatServerReceivesGivenMessage.

@Test
public void requireThatServerReceivesGivenMessage() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    Message msg = driver.awaitMessage();
    assertTrue(msg instanceof SimpleMessage);
    assertEquals("foo", ((SimpleMessage) msg).getValue());
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    driver.sendReply(reply);
    assertNotNull(responseHandler.awaitResponse());
    assertTrue(driver.close());
}
Also used : 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)

Example 9 with ClientTestDriver

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

the class MbusClientTestCase method requireThatClientReceivesGivenReply.

@Test
public void requireThatClientReceivesGivenReply() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    // TODO: Timing sensitive
    Message msg = driver.awaitMessage();
    assertNotNull(msg);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    driver.sendReply(reply);
    Response response = responseHandler.awaitResponse();
    assertTrue(response instanceof MbusResponse);
    reply = ((MbusResponse) response).getReply();
    assertTrue(reply instanceof SimpleReply);
    assertEquals("bar", ((SimpleReply) reply).getValue());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleReply(com.yahoo.messagebus.test.SimpleReply) 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)

Example 10 with ClientTestDriver

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

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