use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class MessageBusTestCase method testConnectionSpec.
@Test
public void testConnectionSpec() throws ListenFailedException, UnknownHostException {
// Setup servers and sessions.
Slobrok slobrok = new Slobrok();
List<TestServer> servers = new ArrayList<>();
TestServer srcServer = new TestServer("feeder", null, slobrok, null);
servers.add(srcServer);
SourceSession src = servers.get(0).mb.createSourceSession(new Receptor());
List<IntermediateSession> sessions = new ArrayList<>();
for (int i = 0; i < 10; ++i) {
TestServer server = new TestServer("intermediate/" + i, null, slobrok, null);
servers.add(server);
sessions.add(server.mb.createIntermediateSession("session", true, new Receptor(), new Receptor()));
}
TestServer dstServer = new TestServer("destination", null, slobrok, null);
DestinationSession dst = dstServer.mb.createDestinationSession("session", true, new Receptor());
assertTrue(srcServer.waitSlobrok("intermediate/*/session", sessions.size()));
assertTrue(srcServer.waitSlobrok("destination/session", 1));
StringBuilder route = new StringBuilder();
for (int i = 0; i < sessions.size(); i++) {
route.append("intermediate/").append(i).append("/session ");
route.append(sessions.get(i).getConnectionSpec()).append(" ");
}
route.append(dst.getConnectionSpec());
Message msg = new SimpleMessage("empty");
assertTrue(src.send(msg, Route.parse(route.toString())).isAccepted());
for (IntermediateSession itr : sessions) {
// Received using session name.
assertNotNull(msg = ((Receptor) itr.getMessageHandler()).getMessage(60));
itr.forward(msg);
// Received using connection spec.
assertNotNull(msg = ((Receptor) itr.getMessageHandler()).getMessage(60));
itr.forward(msg);
}
assertNotNull(msg = ((Receptor) dst.getMessageHandler()).getMessage(60));
dst.acknowledge(msg);
for (int i = sessions.size(); --i >= 0; ) {
IntermediateSession itr = sessions.get(i);
// Received for connection spec.
Reply reply = ((Receptor) itr.getReplyHandler()).getReply(60);
assertNotNull(reply);
itr.forward(reply);
// Received for session name.
assertNotNull(reply = ((Receptor) itr.getReplyHandler()).getReply(60));
itr.forward(reply);
}
assertNotNull(((Receptor) src.getReplyHandler()).getReply(60));
// Cleanup.
for (IntermediateSession session : sessions) {
session.destroy();
}
for (TestServer server : servers) {
server.destroy();
}
slobrok.stop();
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutingContextTestCase method testMoreDirectives.
public void testMoreDirectives() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false, Arrays.asList("foo", "foo/bar", "foo/bar0/baz", "foo/bar1/baz", "foo/bar/baz/cox"), Arrays.asList("foo/bar0/baz", "foo/bar1/baz")));
srcServer.mb.putProtocol(protocol);
srcServer.setupRouting(new RoutingTableSpec(SimpleProtocol.NAME).addRoute(new RouteSpec("myroute").addHop("myhop")).addHop(new HopSpec("myhop", "foo/[Custom]/baz").addRecipient("foo").addRecipient("foo/bar").addRecipient("foo/bar0/baz").addRecipient("foo/bar1/baz").addRecipient("foo/bar/baz/cox")));
for (int i = 0; i < 2; ++i) {
assertTrue(srcSession.send(createMessage("msg"), "myroute").isAccepted());
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT_SECS);
assertNotNull(reply);
System.out.println(reply.getTrace());
assertFalse(reply.hasErrors());
}
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutingContextTestCase method testConstRoute.
public void testConstRoute() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("DocumentRouteSelector", new CustomPolicyFactory(true, Arrays.asList("dst"), Arrays.asList("dst")));
srcServer.mb.putProtocol(protocol);
srcServer.setupRouting(new RoutingTableSpec(SimpleProtocol.NAME).addRoute(new RouteSpec("default").addHop("indexing")).addHop(new HopSpec("indexing", "[DocumentRouteSelector]").addRecipient("dst")).addHop(new HopSpec("dst", "dst/session")));
for (int i = 0; i < 2; ++i) {
assertTrue(srcSession.send(createMessage("msg"), Route.parse("route:default")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(TIMEOUT_SECS);
assertNotNull(msg);
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT_SECS);
assertNotNull(reply);
System.out.println(reply.getTrace());
assertFalse(reply.hasErrors());
}
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutingTestCase method requireThatIgnoreFlagIsSerializedWithMessage.
@Test
public void requireThatIgnoreFlagIsSerializedWithMessage() {
assertSend("dst/session foo ?bar");
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
Route route = msg.getRoute();
assertEquals(2, route.getNumHops());
Hop hop = route.getHop(0);
assertEquals("foo", hop.toString());
assertFalse(hop.getIgnoreResult());
hop = route.getHop(1);
assertEquals("?bar", hop.toString());
assertTrue(hop.getIgnoreResult());
dstSession.acknowledge(msg);
assertTrace("-Ignoring errors in reply.");
}
use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.
the class RoutingTestCase method requireThatRouteCanBeEmptyInDestination.
@Test
public void requireThatRouteCanBeEmptyInDestination() {
assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
assertNull(msg.getRoute());
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
System.out.println(reply.getTrace());
}
Aggregations