Search in sources :

Example 1 with DocumentrouteselectorpolicyConfig

use of com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig in project vespa by vespa-engine.

the class StorageContentTest method doTestRouting.

public void doTestRouting(String cluster1docs, String cluster2docs, String expectedRoutes) throws Exception {
    VespaModel model = getStorageVespaModel(cluster1docs, cluster2docs);
    if (expectedRoutes == null) {
        return;
    }
    Routing routing = model.getRouting();
    assertNotNull(routing);
    assertEquals(0, routing.getErrors().size());
    assertEquals(1, routing.getProtocols().size());
    DocumentProtocol protocol = (DocumentProtocol) routing.getProtocols().get(0);
    RoutingTableSpec spec = protocol.getRoutingTableSpec();
    assertEquals(1, spec.getNumHops());
    assertEquals("indexing", spec.getHop(0).getName());
    assertEquals("[DocumentRouteSelector]", spec.getHop(0).getSelector());
    Map<String, RouteSpec> routes = new TreeMap<>();
    for (int i = 0; i < spec.getNumRoutes(); ++i) {
        RouteSpec r = spec.getRoute(i);
        routes.put(r.getName(), r);
    }
    {
        RouteSpec r = routes.get("default");
        assertEquals(1, r.getNumHops());
        assertEquals("indexing", r.getHop(0));
    }
    Set<String> configuredRoutes = new TreeSet<>();
    DocumentrouteselectorpolicyConfig.Builder builder = new DocumentrouteselectorpolicyConfig.Builder();
    protocol.getConfig(builder);
    DocumentrouteselectorpolicyConfig config = new DocumentrouteselectorpolicyConfig(builder);
    for (DocumentrouteselectorpolicyConfig.Route r : config.route()) {
        configuredRoutes.add(r.name() + " : " + r.selector());
    }
    StringBuilder routeStr = new StringBuilder();
    for (String r : configuredRoutes) {
        routeStr.append(r).append('\n');
    }
    assertEquals(expectedRoutes, routeStr.toString());
}
Also used : Routing(com.yahoo.vespa.model.routing.Routing) RouteSpec(com.yahoo.messagebus.routing.RouteSpec) DocumentProtocol(com.yahoo.vespa.model.routing.DocumentProtocol) DocumentrouteselectorpolicyConfig(com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig) RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) VespaModel(com.yahoo.vespa.model.VespaModel)

Example 2 with DocumentrouteselectorpolicyConfig

use of com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig in project vespa by vespa-engine.

the class RoutingTestCase method assertApplication.

/**
 * Tests whether or not the given application produces the expected output. When creating new tests, create an
 * application directory containing the necessary setup files, and call this method with a TRUE create flag.
 *
 * @param application The application directory.
 */
private static void assertApplication(File application) throws IOException {
    assertTrue(application.isDirectory());
    String applicationName = application.getName();
    Map<String, File> files = new HashMap<>();
    for (File file : application.listFiles(new ContentFilter())) {
        files.put(file.getName(), file);
    }
    String path = null;
    try {
        path = application.getCanonicalPath();
    } catch (IOException e) {
        fail("Could not resolve path for application '" + applicationName + "'.");
    }
    VespaModelCreatorWithFilePkg creator = new VespaModelCreatorWithFilePkg(path);
    VespaModel model = creator.create();
    List<String> errors = model.getRouting().getErrors();
    if (errors.isEmpty()) {
        if (files.containsKey("errors.txt")) {
            if (WRITE_FILES) {
                files.remove("errors.txt").delete();
            } else {
                fail("Route verification did not fail.");
            }
        }
        MessagebusConfig.Builder mBusB = new MessagebusConfig.Builder();
        model.getConfig(mBusB, "");
        MessagebusConfig mBus = new MessagebusConfig(mBusB);
        assertConfigFileContains(application, files, "messagebus.cfg", mBus);
        DocumentrouteselectorpolicyConfig.Builder drB = new DocumentrouteselectorpolicyConfig.Builder();
        model.getConfig(drB, "");
        DocumentrouteselectorpolicyConfig dr = new DocumentrouteselectorpolicyConfig(drB);
        assertConfigFileContains(application, files, "documentrouteselectorpolicy.cfg", dr);
    } else {
        StringBuilder msg = new StringBuilder();
        for (String error : errors) {
            msg.append(error).append("\n");
        }
        assertFileContains(application, files, "errors.txt", msg.toString());
    }
}
Also used : VespaModelCreatorWithFilePkg(com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg) HashMap(java.util.HashMap) DocumentrouteselectorpolicyConfig(com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig) MessagebusConfig(com.yahoo.messagebus.MessagebusConfig) VespaModel(com.yahoo.vespa.model.VespaModel)

Aggregations

DocumentrouteselectorpolicyConfig (com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig)2 VespaModel (com.yahoo.vespa.model.VespaModel)2 MessagebusConfig (com.yahoo.messagebus.MessagebusConfig)1 RouteSpec (com.yahoo.messagebus.routing.RouteSpec)1 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)1 DocumentProtocol (com.yahoo.vespa.model.routing.DocumentProtocol)1 Routing (com.yahoo.vespa.model.routing.Routing)1 VespaModelCreatorWithFilePkg (com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg)1 HashMap (java.util.HashMap)1