aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidatorTest.java
blob: 689643e550d1e37a7ec2c74c37df385d652ea447 (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
// 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.search;

import com.yahoo.config.application.api.ValidationId;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.Arrays;
import java.util.List;

import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction;
import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newReindexAction;
import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRestartAction;

public class DocumentDatabaseChangeValidatorTest {

    private static class Fixture extends ContentClusterFixture {
        DocumentDatabaseChangeValidator validator;

        public Fixture(String currentSd, String nextSd) throws Exception {
            super(currentSd, nextSd);
            validator = new DocumentDatabaseChangeValidator(ClusterSpec.Id.from("test"),
                                                            currentDb(),
                                                            currentDocType(),
                                                            nextDb(),
                                                            nextDocType(),
                                                            new DeployState.Builder().build());
        }

        @Override
        public List<VespaConfigChangeAction> validate() {
            return validator.validate();
        }

    }

    @Test
    void requireThatAttributeIndexAndDocumentTypeChangesAreDiscovered() throws Exception {
        Fixture f = new Fixture("struct s { field s1 type string {} } " +
                "field f1 type string { indexing: summary } " +
                "field f2 type string { indexing: summary } " +
                "field f3 type int { indexing: summary } " +
                "field f4 type array<s> { } ",
                "struct s { field s1 type string {} } " +
                        "field f1 type string { indexing: attribute | summary } " +
                        "field f2 type string { indexing: index | summary } " +
                        "field f3 type string { indexing: summary } " +
                        "field f4 type array<s> { struct-field s1 { indexing: attribute } }");
        Instant.now();
        f.assertValidation(Arrays.asList(
                newRestartAction(ClusterSpec.Id.from("test"),
                        "Field 'f1' changed: add attribute aspect"),
                newRestartAction(ClusterSpec.Id.from("test"),
                        "Field 'f4.s1' changed: add attribute aspect"),
                newReindexAction(ClusterSpec.Id.from("test"),
                        ValidationId.indexingChange,
                        "Field 'f2' changed: add index aspect, indexing script: '{ input f2 | summary f2; }' -> " +
                                "'{ input f2 | tokenize normalize stem:\"BEST\" | index f2 | summary f2; }'"),
                newRefeedAction(ClusterSpec.Id.from("test"), ValidationId.fieldTypeChange, "Field 'f3' changed: data type: 'int' -> 'string'")));
    }

    @Test
    void requireThatRemovingAttributeAspectFromIndexFieldIsOk() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: index | attribute }",
                "field f1 type string { indexing: index }");
        f.assertValidation();
    }

}