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

import com.yahoo.config.model.provision.InMemoryProvisioner;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.container.ComponentsConfig;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.application.validation.ValidationTester;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author bratseth
 */
public class RestartChangesDefersConfigChangesTest {

    @Test
    void changes_requiring_restart_defers_config_changes() {
        ValidationTester tester = new ValidationTester(new InMemoryProvisioner(5,
                new NodeResources(1, 3, 9, 1),
                true));
        VespaModel gen1 = tester.deploy(null, getServices(5, 3), Environment.prod, null).getFirst();

        // Change node count - no restart
        VespaModel gen2 = tester.deploy(gen1, getServices(4, 3), Environment.prod, null).getFirst();
        var config2 = new ComponentsConfig.Builder();
        gen2.getContainerClusters().get("default").getContainers().get(0).getConfig(config2);
        assertFalse(config2.getApplyOnRestart());

        // Change memory amount - requires restart
        VespaModel gen3 = tester.deploy(gen2, getServices(4, 2), Environment.prod, null).getFirst();
        var config3 = new ComponentsConfig.Builder();
        gen3.getContainerClusters().get("default").getContainers().get(0).getConfig(config3);
        assertTrue(config3.getApplyOnRestart());
    }

    private static String getServices(int nodes, int memory) {
        return "<services version='1.0'>" +
               "  <container id='default' version='1.0'>" +
               "    <nodes count='" + nodes + "'><resources vcpu='1' memory='" + memory + "Gb' disk='9Gb'/></nodes>" +
               "   </container>" +
               "</services>";
    }

}