use of com.yahoo.messagebus.jdisc.test.ServerTestDriver in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatNoBindingSetSelectedExceptionIsCaught.
@Test
public void requireThatNoBindingSetSelectedExceptionIsCaught() {
ServerTestDriver driver = ServerTestDriver.newUnboundInstance(new MySelector(null));
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(driver.awaitErrors(ErrorCode.APP_FATAL_ERROR));
assertTrue(driver.close());
}
use of com.yahoo.messagebus.jdisc.test.ServerTestDriver in project vespa by vespa-engine.
the class MbusServerTestCase method assertError.
private static void assertError(List<Integer> expectedErrors, int responseStatus, int... responseErrors) {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
Reply reply = new SimpleReply("bar");
reply.swapState(((MbusRequest) requestHandler.request).getMessage());
for (int err : responseErrors) {
reply.addError(new Error(err, "err"));
}
assertTrue(requestHandler.sendResponse(new MbusResponse(responseStatus, reply)));
assertNotNull(reply = driver.awaitReply());
List<Integer> actual = new LinkedList<>();
for (int i = 0; i < reply.getNumErrors(); ++i) {
actual.add(reply.getError(i).getCode());
}
assertEquals(expectedErrors, actual);
assertTrue(driver.close());
}
use of com.yahoo.messagebus.jdisc.test.ServerTestDriver 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.jdisc.test.ServerTestDriver 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());
}
use of com.yahoo.messagebus.jdisc.test.ServerTestDriver in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatReplyInsideMbusResponseIsUsed.
@Test
public void requireThatReplyInsideMbusResponseIsUsed() {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
Reply reply = new SimpleReply("bar");
reply.swapState(((MbusRequest) requestHandler.request).getMessage());
assertTrue(requestHandler.sendResponse(new MbusResponse(Response.Status.OK, reply)));
reply = driver.awaitSuccess();
assertTrue(reply instanceof SimpleReply);
assertEquals("bar", ((SimpleReply) reply).getValue());
assertTrue(driver.close());
}
Aggregations