Search in sources :

Example 41 with Receptor

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();
}
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 42 with Receptor

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());
    }
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor)

Example 43 with Receptor

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());
    }
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor)

Example 44 with Receptor

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.");
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Test(org.junit.Test)

Example 45 with Receptor

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());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Test(org.junit.Test)

Aggregations

Receptor (com.yahoo.messagebus.test.Receptor)69 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)46 Test (org.junit.Test)35 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)30 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)18 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)17 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)12 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)10 Error (com.yahoo.messagebus.Error)9 Identity (com.yahoo.messagebus.network.Identity)9 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 Route (com.yahoo.messagebus.routing.Route)2 Version (com.yahoo.component.Version)1 VersionSpecification (com.yahoo.component.VersionSpecification)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 DocumentReply (com.yahoo.documentapi.messagebus.protocol.DocumentReply)1