use of com.yahoo.messagebus.network.rpc.test.TestServer in project vespa by vespa-engine.
the class PolicyTestCase method testExternSend.
@Test
public void testExternSend() throws Exception {
// Setup local source node.
Slobrok local = new Slobrok();
TestServer src = new TestServer("src", null, local, new DocumentProtocol(manager));
SourceSession ss = src.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(TIMEOUT));
// Setup remote cluster with routing config.
Slobrok slobrok = new Slobrok();
TestServer itr = new TestServer("itr", new RoutingTableSpec(DocumentProtocol.NAME).addRoute(new RouteSpec("default").addHop("dst")).addHop(new HopSpec("dst", "dst/session")), slobrok, new DocumentProtocol(manager));
IntermediateSession is = itr.mb.createIntermediateSession("session", true, new Receptor(), new Receptor());
TestServer dst = new TestServer("dst", null, slobrok, new DocumentProtocol(manager));
DestinationSession ds = dst.mb.createDestinationSession("session", true, new Receptor());
// Send message from local node to remote cluster and resolve route there.
Message msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
msg.getTrace().setLevel(9);
msg.setRoute(Route.parse("[Extern:tcp/localhost:" + slobrok.port() + ";itr/session] default"));
assertTrue(ss.send(msg).isAccepted());
assertNotNull(msg = ((Receptor) is.getMessageHandler()).getMessage(TIMEOUT));
is.forward(msg);
assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(TIMEOUT));
ds.acknowledge(msg);
Reply reply = ((Receptor) is.getReplyHandler()).getReply(TIMEOUT);
assertNotNull(reply);
is.forward(reply);
assertNotNull(reply = ((Receptor) ss.getReplyHandler()).getReply(TIMEOUT));
System.out.println(reply.getTrace().toString());
// Perform necessary cleanup.
src.destroy();
itr.destroy();
dst.destroy();
slobrok.stop();
local.stop();
}
use of com.yahoo.messagebus.network.rpc.test.TestServer in project vespa by vespa-engine.
the class PolicyTestCase method requireThatExternPolicyMergesOneReplyAsProtocol.
@Test
public void requireThatExternPolicyMergesOneReplyAsProtocol() throws Exception {
PolicyTestFrame frame = newPutDocumentFrame("doc:scheme:");
Slobrok slobrok = new Slobrok();
TestServer server = new TestServer("docproc/cluster.default/0", null, slobrok, new DocumentProtocol(manager));
server.net.registerSession("chain.default");
setupExternPolicy(frame, slobrok, "docproc/cluster.default/*/chain.default", 1);
frame.assertMergeOneReply(server.net.getConnectionSpec() + "/chain.default");
server.destroy();
frame.destroy();
}
use of com.yahoo.messagebus.network.rpc.test.TestServer in project vespa by vespa-engine.
the class PolicyTestCase method testExternMultipleSlobroks.
@Test
public void testExternMultipleSlobroks() throws ListenFailedException {
Slobrok local = new Slobrok();
TestServer srcServer = new TestServer("src", null, local, new DocumentProtocol(manager));
SourceSession srcSession = srcServer.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(TIMEOUT));
Slobrok extern = new Slobrok();
String spec = "tcp/localhost:" + extern.port();
TestServer dstServer = new TestServer("dst", null, extern, new DocumentProtocol(manager));
Receptor dstHandler = new Receptor();
DestinationSession dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
Message msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
msg.setRoute(Route.parse("[Extern:" + spec + ";dst/session]"));
assertTrue(srcSession.send(msg).isAccepted());
assertNotNull(msg = dstHandler.getMessage(TIMEOUT));
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT);
assertNotNull(reply);
extern.stop();
dstSession.destroy();
dstServer.destroy();
dstHandler.reset();
assertNull(dstHandler.getMessage(0));
extern = new Slobrok();
spec += ",tcp/localhost:" + extern.port();
dstServer = new TestServer("dst", null, extern, new DocumentProtocol(manager));
dstHandler = new Receptor();
dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
msg.setRoute(Route.parse("[Extern:" + spec + ";dst/session]"));
assertTrue(srcSession.send(msg).isAccepted());
assertNotNull(msg = dstHandler.getMessage(TIMEOUT));
dstSession.acknowledge(msg);
reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT);
assertNotNull(reply);
extern.stop();
dstSession.destroy();
dstServer.destroy();
local.stop();
srcSession.destroy();
srcServer.destroy();
}
use of com.yahoo.messagebus.network.rpc.test.TestServer in project vespa by vespa-engine.
the class PolicyTestCase method requireThatExternPolicySelectsFromExternSlobrok.
@Test
public void requireThatExternPolicySelectsFromExternSlobrok() throws Exception {
PolicyTestFrame frame = newPutDocumentFrame("doc:scheme:");
Slobrok slobrok = new Slobrok();
List<TestServer> servers = new ArrayList<>();
for (int i = 0; i < 10; ++i) {
TestServer server = new TestServer("docproc/cluster.default/" + i, null, slobrok, new DocumentProtocol(manager));
server.net.registerSession("chain.default");
servers.add(server);
}
setupExternPolicy(frame, slobrok, "docproc/cluster.default/*/chain.default", 10);
Set<String> lst = new HashSet<>();
for (int i = 0; i < 10; ++i) {
RoutingNode leaf = frame.select(1).get(0);
String recipient = leaf.getRoute().toString();
lst.add(recipient);
leaf.handleReply(new EmptyReply());
assertNotNull(frame.getReceptor().getReply(TIMEOUT));
}
assertEquals(10, lst.size());
for (TestServer server : servers) {
server.destroy();
}
frame.destroy();
}
use of com.yahoo.messagebus.network.rpc.test.TestServer in project vespa by vespa-engine.
the class SendAdapterTestCase method setUp.
@Before
public void setUp() throws ListenFailedException, UnknownHostException {
slobrok = new Slobrok();
dstServer = new TestServer(new MessageBusParams().addProtocol(dstProtocol = new TestProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
itrServer = new TestServer(new MessageBusParams().addProtocol(itrProtocol = new TestProtocol()), new RPCNetworkParams().setIdentity(new Identity("itr")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
itrSession = itrServer.mb.createIntermediateSession(new IntermediateSessionParams().setName("session").setMessageHandler(new Receptor()).setReplyHandler(new Receptor()));
srcServer = new TestServer(new MessageBusParams().addProtocol(srcProtocol = new TestProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
assertTrue(srcServer.waitSlobrok("*/session", 2));
}
Aggregations