Search in sources :

Example 11 with TestServer

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();
}
Also used : TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Test(org.junit.Test)

Example 12 with TestServer

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();
}
Also used : Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Test(org.junit.Test)

Example 13 with TestServer

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();
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Test(org.junit.Test)

Example 14 with TestServer

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();
}
Also used : Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Test(org.junit.Test)

Example 15 with TestServer

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));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Before(org.junit.Before)

Aggregations

TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)24 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)23 Receptor (com.yahoo.messagebus.test.Receptor)17 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)10 Identity (com.yahoo.messagebus.network.Identity)9 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)8 Test (org.junit.Test)8 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)6 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)4 Before (org.junit.Before)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)2 SimpleReply (com.yahoo.messagebus.test.SimpleReply)2 RetryTransientErrorsPolicy (com.yahoo.messagebus.routing.RetryTransientErrorsPolicy)1 QueueAdapter (com.yahoo.messagebus.test.QueueAdapter)1 Utf8String (com.yahoo.text.Utf8String)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1