use of com.yahoo.messagebus.test.SimpleMessage 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.test.SimpleMessage 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.test.SimpleMessage 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());
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatRequestResponseWorks.
@Test
public void requireThatRequestResponseWorks() {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
assertTrue(requestHandler.sendResponse(new Response(Response.Status.OK)));
assertNotNull(driver.awaitSuccess());
assertTrue(driver.close());
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatResponseContentDoesNotSupportWrite.
@Test
public void requireThatResponseContentDoesNotSupportWrite() throws InterruptedException {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
ContentChannel content = requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
assertNotNull(content);
try {
content.write(ByteBuffer.allocate(69), null);
fail();
} catch (UnsupportedOperationException e) {
}
content.close(null);
assertNotNull(driver.awaitSuccess());
assertTrue(driver.close());
}
Aggregations