aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java
blob: fb052e023bb0e0e0b3f82c06befc29a04ba85b34 (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
// 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.provision.Environment;
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.*;

/**
 * Test that global attribute changes are detected by change validator.
 */
public class GlobalDocumentChangeValidatorTest {

    @Test
    void testChangGlobalAttribute() {
        testChangeGlobalAttribute(true, false, false, null);
        testChangeGlobalAttribute(true, true, true, null);
        testChangeGlobalAttribute(false, false, true, null);
        testChangeGlobalAttribute(false, true, false, null);
        testChangeGlobalAttribute(true, false, true, globalDocumentValidationOverrides);
        testChangeGlobalAttribute(true, true, false, globalDocumentValidationOverrides);
    }

    private void testChangeGlobalAttribute(boolean allowed, boolean oldGlobal, boolean newGlobal, String validationOverrides) {
        ValidationTester tester = new ValidationTester();
        VespaModel oldModel = tester.deploy(null, getServices(oldGlobal), Environment.prod, validationOverrides).getFirst();
        try {
            tester.deploy(oldModel, getServices(newGlobal), Environment.prod, validationOverrides).getSecond();
            assertTrue(allowed);
        } catch (IllegalStateException e) {
            assertFalse(allowed);
            assertEquals("Document type music in cluster default changed global from " + oldGlobal + " to " + newGlobal + ". " +
                    "Add validation override 'global-document-change' to force this change through. " +
                    "First, stop services on all content nodes. Then, deploy with validation override. Finally, start services on all content nodes.",
                    e.getMessage());
        }
    }
    private static final String getServices(boolean isGlobal) {
        return "<services version='1.0'>" +
                "  <content id='default' version='1.0'>" +
                "    <redundancy>1</redundancy>" +
                "    <documents>" +
                "      <document type='music' mode='index' global='" +
                isGlobal + "'/>" +
                "    </documents>" +
                "    <nodes count='1'/>" +
                "   </content>" +
                "</services>";
    }

    private static final String globalDocumentValidationOverrides =
            "<validation-overrides>\n" +
                    "    <allow until='2000-01-14' comment='test override'>global-document-change</allow>\n" +
                    "</validation-overrides>\n";

}