aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/docproc/StandaloneDocprocContainerTest.java
blob: 5bb93255a8f5c13a2844bf6551f0de6c0c68898d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.docproc;

import com.yahoo.component.ComponentId;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.ContainerModel;
import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilder;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilder.Networking;
import org.junit.Test;
import org.w3c.dom.Element;

import java.util.Map;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * @author Einar M R Rosenvinge
 */
public class StandaloneDocprocContainerTest extends DomBuilderTest {

    public ContainerCluster setupCluster(boolean standalone) {
        ContainerModelBuilder builder = new ContainerModelBuilder(standalone, Networking.disable);
        ContainerModel model = builder.build(DeployState.createTestState(), null, null, root, servicesXml());

        if (!standalone)
            model.getCluster().getDocproc().getChains().addServersAndClientsForChains();

        root.freezeModelTopology();
        return model.getCluster();
    }

    private Element servicesXml() {
        return parse("" +
                "<container version=\"1.0\">\n" +
                "    <document-processing>\n" +
                "        <chain id=\"foo\">\n" +
                "            <documentprocessor id=\"MyDocproc\"/>\n" +
                "        </chain>\n" +
                "    </document-processing>\n" +
                "    <nodes>\n" +
                "        <node hostalias=\"node01\"/>\n" +
                "    </nodes>\n" +
                "</container>\n");
    }

    @Test
    public void requireMbusProvidersWhenNonStandalone() {
        ContainerCluster containerCluster = setupCluster(false);
        Map<ComponentId, Component<?, ?>> components = containerCluster.getComponentsMap();

        boolean foundAtLeastOneClient = false;
        boolean foundAtLeastOneServer = false;

        for (ComponentId componentId : components.keySet()) {
            if (componentId.stringValue().contains("MbusClient")) foundAtLeastOneClient = true;
            if (componentId.stringValue().contains("MbusServer")) foundAtLeastOneServer = true;
        }
        assertTrue(foundAtLeastOneClient);
        assertTrue(foundAtLeastOneServer);

    }

    @Test
    public void requireNoMbusProvidersWhenStandalone() {
        ContainerCluster containerCluster = setupCluster(true);
        Map<ComponentId, Component<?, ?>> components = containerCluster.getComponentsMap();

        boolean foundAtLeastOneClient = false;
        boolean foundAtLeastOneServer = false;

        for (ComponentId componentId : components.keySet()) {
            if (componentId.stringValue().contains("MbusClient")) foundAtLeastOneClient = true;
            if (componentId.stringValue().contains("MbusServer")) foundAtLeastOneServer = true;
        }
        assertFalse(foundAtLeastOneClient);
        assertFalse(foundAtLeastOneServer);
    }
}