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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations