Search in sources :

Example 36 with Slobrok

use of com.yahoo.jrt.slobrok.server.Slobrok 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();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ArrayList(java.util.ArrayList) 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 37 with Slobrok

use of com.yahoo.jrt.slobrok.server.Slobrok in project vespa by vespa-engine.

the class ErrorTestCase method requireThatErrorIsPropagated.

@Test
public void requireThatErrorIsPropagated() throws Exception {
    RoutingTableSpec table = new RoutingTableSpec(SimpleProtocol.NAME);
    table.addHop("itr", "test/itr/session", Arrays.asList("test/itr/session"));
    table.addHop("dst", "test/dst/session", Arrays.asList("test/dst/session"));
    table.addRoute("test", Arrays.asList("itr", "dst"));
    Slobrok slobrok = new Slobrok();
    TestServer src = new TestServer("test/src", table, slobrok, null);
    TestServer itr = new TestServer("test/itr", table, slobrok, null);
    TestServer dst = new TestServer("test/dst", table, slobrok, null);
    Receptor ss_rr = new Receptor();
    SourceSession ss = src.mb.createSourceSession(ss_rr);
    Receptor is_mr = new Receptor();
    Receptor is_rr = new Receptor();
    IntermediateSession is = itr.mb.createIntermediateSession("session", true, is_mr, is_rr);
    Receptor ds_mr = new Receptor();
    DestinationSession ds = dst.mb.createDestinationSession("session", true, ds_mr);
    src.waitSlobrok("test/itr/session", 1);
    src.waitSlobrok("test/dst/session", 1);
    itr.waitSlobrok("test/dst/session", 1);
    for (int i = 0; i < 5; i++) {
        assertTrue(ss.send(new SimpleMessage("msg"), "test").isAccepted());
        Message msg = is_mr.getMessage(60);
        assertNotNull(msg);
        is.forward(msg);
        assertNotNull(msg = ds_mr.getMessage(60));
        Reply reply = new EmptyReply();
        msg.swapState(reply);
        reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatality"));
        ds.reply(reply);
        assertNotNull(reply = is_rr.getReply(60));
        assertEquals(reply.getNumErrors(), 1);
        assertEquals(reply.getError(0).getService(), "test/dst/session");
        reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatality"));
        is.forward(reply);
        assertNotNull(reply = ss_rr.getReply(60));
        assertEquals(reply.getNumErrors(), 2);
        assertEquals(reply.getError(0).getService(), "test/dst/session");
        assertEquals(reply.getError(1).getService(), "test/itr/session");
    }
    ss.destroy();
    is.destroy();
    ds.destroy();
    dst.destroy();
    itr.destroy();
    src.destroy();
    slobrok.stop();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Test(org.junit.Test)

Example 38 with Slobrok

use of com.yahoo.jrt.slobrok.server.Slobrok in project vespa by vespa-engine.

the class SendProxyTestCase method setUp.

@Override
public void setUp() throws UnknownHostException, ListenFailedException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    srcServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setThrottlePolicy(null).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Example 39 with Slobrok

use of com.yahoo.jrt.slobrok.server.Slobrok 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();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Identity(com.yahoo.messagebus.network.Identity)

Example 40 with Slobrok

use of com.yahoo.jrt.slobrok.server.Slobrok in project vespa by vespa-engine.

the class ServiceAddressTestCase method setUp.

public void setUp() throws ListenFailedException, UnknownHostException {
    slobrok = new Slobrok();
    network = new RPCNetwork(new RPCNetworkParams().setIdentity(new Identity("foo")).setSlobrokConfigId("raw:slobrok[1]\nslobrok[0].connectionspec \"" + new Spec("localhost", slobrok.port()).toString() + "\"\n"));
}
Also used : Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) Spec(com.yahoo.jrt.Spec)

Aggregations

Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)43 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)23 Test (org.junit.Test)20 Receptor (com.yahoo.messagebus.test.Receptor)17 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)15 Identity (com.yahoo.messagebus.network.Identity)12 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)11 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)6 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)4 Before (org.junit.Before)4 ListenFailedException (com.yahoo.jrt.ListenFailedException)3 Spec (com.yahoo.jrt.Spec)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)2 MessageBusParams (com.yahoo.messagebus.MessageBusParams)2 SourceSessionParams (com.yahoo.messagebus.SourceSessionParams)2 SimpleReply (com.yahoo.messagebus.test.SimpleReply)2 MessageBusDocumentAccess (com.yahoo.documentapi.messagebus.MessageBusDocumentAccess)1 MessageBusParams (com.yahoo.documentapi.messagebus.MessageBusParams)1 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)1