Search in sources :

Example 6 with RoutingTable

use of com.yahoo.messagebus.routing.RoutingTable in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testExplicitRouteNotOverridden.

/**
 * Test that we don't try to override a valid route in the parameters.
 */
@Test
public void testExplicitRouteNotOverridden() {
    VisitorParameters visitorParameters = createVisitorParameters("");
    visitorParameters.setRoute("mars");
    RoutingTable table = createDummyRoutingTable();
    createDefaultMock(visitorParameters, table);
    assertEquals("mars", visitorParameters.getRoute().toString());
}
Also used : RoutingTable(com.yahoo.messagebus.routing.RoutingTable) Test(org.junit.Test)

Example 7 with RoutingTable

use of com.yahoo.messagebus.routing.RoutingTable in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testDefaultClusterRouteResolutionNullRoute.

/**
 * Test that we try to get a route to the storage cluster automatically if
 * the provided visitor parameter route is null.
 */
@Test
public void testDefaultClusterRouteResolutionNullRoute() {
    VisitorParameters visitorParameters = createVisitorParameters("");
    // ensure route is null
    visitorParameters.setRoute((Route) null);
    RoutingTable table = createDummyRoutingTable();
    createDefaultMock(visitorParameters, table);
    assertEquals("storage/cluster.foo", visitorParameters.getRoute().toString());
}
Also used : RoutingTable(com.yahoo.messagebus.routing.RoutingTable) Test(org.junit.Test)

Example 8 with RoutingTable

use of com.yahoo.messagebus.routing.RoutingTable in project vespa by vespa-engine.

the class SourceSession method send.

/**
 * <p>This is a convenience function to assign a named route to the given
 * message, and then pass it to the other {@link #send(Message)} method of
 * this session. If the route could not be found this methods returns with
 * an appropriate error, unless the 'parseIfNotFound' argument is true. In
 * that case, the route name is passed through to the Route factory method
 * {@link Route#parse}.</p>
 *
 * @param msg             The message to send.
 * @param routeName       The route to assign to the message.
 * @param parseIfNotFound Whether or not to parse routeName as a route if
 *                        it could not be found.
 * @return The immediate result of the attempt to send this message.
 */
public Result send(Message msg, String routeName, boolean parseIfNotFound) {
    boolean found = false;
    RoutingTable table = mbus.getRoutingTable(msg.getProtocol().toString());
    if (table != null) {
        Route route = table.getRoute(routeName);
        if (route != null) {
            msg.setRoute(new Route(route));
            found = true;
        } else if (!parseIfNotFound) {
            return new Result(ErrorCode.ILLEGAL_ROUTE, "Route '" + routeName + "' not found for protocol '" + msg.getProtocol() + "'.");
        }
    } else if (!parseIfNotFound) {
        return new Result(ErrorCode.ILLEGAL_ROUTE, "Protocol '" + msg.getProtocol() + "' has no routing table.");
    }
    if (!found) {
        msg.setRoute(Route.parse(routeName));
    }
    return send(msg);
}
Also used : RoutingTable(com.yahoo.messagebus.routing.RoutingTable) Route(com.yahoo.messagebus.routing.Route)

Aggregations

RoutingTable (com.yahoo.messagebus.routing.RoutingTable)8 Test (org.junit.Test)5 Route (com.yahoo.messagebus.routing.Route)4 RouteSpec (com.yahoo.messagebus.routing.RouteSpec)3 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)3