use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class ChokeTestCase method testMaxSize.
@Test
public void testMaxSize() {
int size = createMessage("msg").getApproxSize();
int max = size * 10;
dstServer.mb.setMaxPendingSize(max);
List<Message> lst = new ArrayList<>();
for (int i = 0; i < max * 2; i += size) {
if (i < max) {
assertEquals(i, dstServer.mb.getPendingSize());
} else {
assertEquals(max, dstServer.mb.getPendingSize());
}
assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
if (i < max) {
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
lst.add(msg);
} else {
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
assertEquals(1, reply.getNumErrors());
assertEquals(ErrorCode.SESSION_BUSY, reply.getError(0).getCode());
}
}
for (int i = 0; i < 5; ++i) {
Message msg = lst.remove(0);
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
assertFalse(reply.hasErrors());
assertNotNull(msg = reply.getMessage());
assertTrue(srcSession.send(msg, Route.parse("dst/session")).isAccepted());
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
lst.add(msg);
}
while (!lst.isEmpty()) {
assertEquals(size * lst.size(), dstServer.mb.getPendingSize());
Message msg = lst.remove(0);
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
assertFalse(reply.hasErrors());
}
assertEquals(0, dstServer.mb.getPendingSize());
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutableTestCase method testMessageContext.
public void testMessageContext() throws ListenFailedException, UnknownHostException {
Slobrok slobrok = new Slobrok();
TestServer srcServer = new TestServer("src", null, slobrok, null);
TestServer dstServer = new TestServer("dst", null, slobrok, null);
SourceSession srcSession = srcServer.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(600.0));
DestinationSession dstSession = dstServer.mb.createDestinationSession("session", true, new Receptor());
assertTrue(srcServer.waitSlobrok("dst/session", 1));
Object context = new Object();
Message msg = new SimpleMessage("msg");
msg.setContext(context);
assertTrue(srcSession.send(msg, "dst/session", true).isAccepted());
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
assertSame(reply.getContext(), context);
srcSession.destroy();
srcServer.destroy();
dstSession.destroy();
dstServer.destroy();
slobrok.stop();
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutableTestCase method testReplyDiscard.
public void testReplyDiscard() {
Receptor handler = new Receptor();
Message msg = new SimpleMessage("foo");
msg.pushHandler(handler);
Reply reply = new SimpleReply("bar");
reply.swapState(msg);
reply.discard();
assertNull(handler.getReply(0));
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutableTestCase method testMessageDiscard.
public void testMessageDiscard() {
Receptor handler = new Receptor();
Message msg = new SimpleMessage("foo");
msg.pushHandler(handler);
msg.discard();
assertNull(handler.getReply(0));
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class BasicNetworkTestCase method testTimeoutsFollowMessage.
public void testTimeoutsFollowMessage() {
SourceSessionParams params = new SourceSessionParams().setTimeout(600.0);
SourceSession ss = src.mb.createSourceSession(new Receptor(), params);
DestinationSession ds = dst.mb.createDestinationSession("session", true, new Receptor());
assertTrue(src.waitSlobrok("test/dst/session", 1));
// Test default timeouts being set.
Message msg = new SimpleMessage("msg");
msg.getTrace().setLevel(9);
long now = SystemTimer.INSTANCE.milliTime();
assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
assertTrue(msg.getTimeReceived() >= now);
assertTrue(params.getTimeout() * 1000 >= msg.getTimeRemaining());
ds.acknowledge(msg);
assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
// Test default timeouts being overwritten.
msg = new SimpleMessage("msg");
msg.getTrace().setLevel(9);
msg.setTimeRemaining(2 * (long) (params.getTimeout() * 1000));
assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
assertTrue(params.getTimeout() * 1000 < msg.getTimeRemaining());
ds.acknowledge(msg);
assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
ss.destroy();
ds.destroy();
}
Aggregations