use of com.yahoo.messagebus.test.SimpleMessage 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.test.SimpleMessage 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.test.SimpleMessage in project vespa by vespa-engine.
the class ServerThreadingTestCase method requireThatServerIsThreadSafe.
@Test
public void requireThatServerIsThreadSafe() throws Exception {
final LocalWire wire = new LocalWire();
final Client client = new Client(wire);
final Server server = new Server(wire);
for (int i = 0; i < NUM_REQUESTS; ++i) {
final Message msg = new SimpleMessage("foo");
msg.setRoute(Route.parse(server.delegate.connectionSpec()));
msg.pushHandler(client);
assertThat(client.session.send(msg).isAccepted(), is(true));
}
for (int i = 0; i < NUM_REQUESTS; ++i) {
final Reply reply = client.replies.poll(600, TimeUnit.SECONDS);
assertThat(reply, instanceOf(EmptyReply.class));
assertThat(reply.hasErrors(), is(false));
}
assertThat(client.close(), is(true));
assertThat(server.close(), is(true));
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class SharedIntermediateSessionTestCase method requireThatSessionRepliesIfMessageHandlerIsNull.
@Test
public void requireThatSessionRepliesIfMessageHandlerIsNull() throws InterruptedException {
SharedIntermediateSession session = newIntermediateSession();
Message msg = new SimpleMessage("foo");
ReplyQueue queue = new ReplyQueue();
msg.pushHandler(queue);
session.handleMessage(msg);
Reply reply = queue.awaitReply(60, TimeUnit.SECONDS);
assertNotNull(reply);
assertEquals(1, reply.getNumErrors());
assertEquals(ErrorCode.SESSION_BUSY, reply.getError(0).getCode());
session.release();
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class SharedIntermediateSessionTestCase method requireThatSessionCanSendMessage.
@Test
public void requireThatSessionCanSendMessage() throws InterruptedException {
RemoteServer server = RemoteServer.newInstanceWithInternSlobrok();
SharedIntermediateSession session = newIntermediateSession(server.slobrokId(), new IntermediateSessionParams());
ReplyQueue queue = new ReplyQueue();
Message msg = new SimpleMessage("foo").setRoute(Route.parse(server.connectionSpec()));
msg.setTimeReceivedNow();
msg.setTimeRemaining(60000);
msg.getTrace().setLevel(9);
msg.pushHandler(queue);
assertTrue(session.sendMessage(msg).isAccepted());
assertNotNull(msg = server.awaitMessage(60, TimeUnit.SECONDS));
server.ackMessage(msg);
assertNotNull(queue.awaitReply(60, TimeUnit.SECONDS));
session.release();
server.close();
}
Aggregations