use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class SimpleTripTestCase method testSimpleTrip.
public void testSimpleTrip() throws ListenFailedException, UnknownHostException {
Slobrok slobrok = new Slobrok();
TestServer server = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("srv")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
DestinationSession dst = server.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
SourceSession src = server.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
assertTrue(server.waitSlobrok("srv/session", 1));
assertTrue(src.send(new SimpleMessage("msg"), Route.parse("srv/session")).isAccepted());
Message msg = ((Receptor) dst.getMessageHandler()).getMessage(60);
assertNotNull(msg);
assertEquals(SimpleProtocol.NAME, msg.getProtocol());
assertEquals(SimpleProtocol.MESSAGE, msg.getType());
assertEquals("msg", ((SimpleMessage) msg).getValue());
Reply reply = new SimpleReply("reply");
reply.swapState(msg);
dst.reply(reply);
assertNotNull(reply = ((Receptor) src.getReplyHandler()).getReply(60));
assertEquals(SimpleProtocol.NAME, reply.getProtocol());
assertEquals(SimpleProtocol.REPLY, reply.getType());
assertEquals("reply", ((SimpleReply) reply).getValue());
src.destroy();
dst.destroy();
server.destroy();
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class TraceTripTestCase method testTrip.
public void testTrip() {
Receptor src_rr = new Receptor();
SourceSession src_s = src.mb.createSourceSession(src_rr);
new Proxy(pxy.mb);
assertTrue(src.waitSlobrok("test/pxy/session", 1));
new Server(dst.mb);
assertTrue(src.waitSlobrok("test/dst/session", 1));
assertTrue(pxy.waitSlobrok("test/dst/session", 1));
Message msg = new SimpleMessage("");
msg.getTrace().setLevel(1);
msg.getTrace().trace(1, "Client message", false);
src_s.send(msg, "test");
Reply reply = src_rr.getReply(60);
reply.getTrace().trace(1, "Client reply", false);
assertTrue(reply.getNumErrors() == 0);
TraceNode t = new TraceNode().addChild("Client message").addChild("Proxy message").addChild("Server message").addChild("Server reply").addChild("Proxy reply").addChild("Client reply");
System.out.println("reply: " + reply.getTrace().getRoot().encode());
System.out.println("want : " + t.encode());
assertTrue(reply.getTrace().getRoot().encode().equals(t.encode()));
}
use of com.yahoo.messagebus.test.SimpleMessage in project vespa by vespa-engine.
the class BasicNetworkTestCase method testNetwork.
public void testNetwork() {
// set up receptors
Receptor src_rr = new Receptor();
Receptor pxy_mr = new Receptor();
Receptor pxy_rr = new Receptor();
Receptor dst_mr = new Receptor();
// set up sessions
SourceSessionParams sp = new SourceSessionParams();
sp.setTimeout(30.0);
SourceSession ss = src.mb.createSourceSession(src_rr, sp);
IntermediateSession is = pxy.mb.createIntermediateSession("session", true, pxy_mr, pxy_rr);
DestinationSession ds = dst.mb.createDestinationSession("session", true, dst_mr);
// wait for slobrok registration
assertTrue(src.waitSlobrok("test/pxy/session", 1));
assertTrue(src.waitSlobrok("test/dst/session", 1));
assertTrue(pxy.waitSlobrok("test/dst/session", 1));
// send message on client
ss.send(new SimpleMessage("test message"), "test");
// check message on proxy
Message msg = pxy_mr.getMessage(60);
assertTrue(msg != null);
assertEquals(SimpleProtocol.MESSAGE, msg.getType());
SimpleMessage sm = (SimpleMessage) msg;
assertEquals("test message", sm.getValue());
// forward message on proxy
sm.setValue(sm.getValue() + " pxy");
is.forward(sm);
// check message on server
msg = dst_mr.getMessage(60);
assertTrue(msg != null);
assertEquals(SimpleProtocol.MESSAGE, msg.getType());
sm = (SimpleMessage) msg;
assertEquals("test message pxy", sm.getValue());
// send reply on server
SimpleReply sr = new SimpleReply("test reply");
sm.swapState(sr);
ds.reply(sr);
// check reply on proxy
Reply reply = pxy_rr.getReply(60);
assertTrue(reply != null);
assertEquals(SimpleProtocol.REPLY, reply.getType());
sr = (SimpleReply) reply;
assertEquals("test reply", sr.getValue());
// forward reply on proxy
sr.setValue(sr.getValue() + " pxy");
is.forward(sr);
// check reply on client
reply = src_rr.getReply(60);
assertTrue(reply != null);
assertEquals(SimpleProtocol.REPLY, reply.getType());
sr = (SimpleReply) reply;
assertEquals("test reply pxy", sr.getValue());
ss.destroy();
is.destroy();
ds.destroy();
}
Aggregations