aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/xml/RoutingBuilderTest.java
blob: 2bf50103b10003e00fe5a2daee11f68421ae5d51 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;

import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.deploy.TestProperties;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.model.test.MockRoot;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.model.container.ApplicationContainer;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author mortent
 */
public class RoutingBuilderTest extends ContainerModelBuilderTestBase {

    @Test
    void setsRotationActive() {
        Element clusterElem = DomBuilderTest.parse(
                "<container id='default' version='1.0'><search /></container>");

        String deploymentSpec = """
                <deployment>
                  <prod>
                    <region>us-north-1</region>
                    <parallel>
                      <region>us-north-2</region>
                      <region>us-north-3</region>
                    </parallel>
                    <region>us-north-4</region>
                  </prod>
                </deployment>""";

        ApplicationPackage applicationPackage = new MockApplicationPackage.Builder()
                .withDeploymentSpec(deploymentSpec)
                .build();

        for (String region : List.of("us-north-1", "us-north-2", "us-north-3", "us-north-4")) {
            ApplicationContainer container = getContainer(applicationPackage, region, clusterElem);
            assertEquals("true",
                    container.getServicePropertyString("activeRotation"),
                    "Region " + region + " is active");
        }
    }


    private ApplicationContainer getContainer(ApplicationPackage applicationPackage, String region, Element clusterElem) {
        DeployState deployState = new DeployState.Builder()
                .applicationPackage(applicationPackage)
                .zone(new Zone(Environment.prod, RegionName.from(region)))
                .properties(new TestProperties().setHostedVespa(true))
                .build();

        root = new MockRoot("root", deployState);
        createModel(root, deployState, null, clusterElem);
        ApplicationContainerCluster cluster = getContainerCluster("default");
        return cluster.getContainers().get(0);

    }
}