aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfileVariantsTestCase.java
blob: 0098cc921f297d9d44b90dc14c12f2acc8402cf0 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.search.test;

import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.logging.Level;

import static helpers.CompareConfigTestHelper.assertSerializedConfigFileEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

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

    private final String root = "src/test/java/com/yahoo/vespa/model/container/search/test/";

    @Test
    void testConfigCreation() throws IOException {
        QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "queryprofilevariants");
        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "query-profile-variants-configuration.cfg", profiles.getConfig().toString());
    }

    @Test
    void testConfigCreation2() throws IOException {
        QueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/vespa/model/container/search/test/queryprofilevariants2");
        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "query-profile-variants2-configuration.cfg", profiles.getConfig().toString());
    }

    @Test
    void testConfigCreationNewsBESimple() throws IOException {
        QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "newsbesimple");
        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "newsbe-query-profiles-simple.cfg", profiles.getConfig().toString());
    }

    @Test
    void testConfigCreationNewsFESimple() throws IOException {
        QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "newsfesimple");
        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "newsfe-query-profiles-simple.cfg", profiles.getConfig().toString());
    }

    @Test
    void testVariantsOfExplicitCompound() throws IOException {
        QueryProfileRegistry registry = new QueryProfileRegistry();

        QueryProfile a1 = new QueryProfile("a1");
        a1.set("b", "a1.b", registry);

        QueryProfile profile = new QueryProfile("test");
        profile.setDimensions(new String[]{"x"});
        profile.set("a", a1, registry);
        profile.set("a.b", "a.b.x1", new String[]{"x1"}, registry);
        profile.set("a.b", "a.b.x2", new String[]{"x2"}, registry);

        registry.register(a1);
        registry.register(profile);

        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "variants-of-explicit-compound.cfg", profiles.getConfig().toString());
    }

    @Test
    void testVariantsOfExplicitCompoundWithVariantReference() throws IOException {
        QueryProfileRegistry registry = new QueryProfileRegistry();

        QueryProfile a1 = new QueryProfile("a1");
        a1.set("b", "a1.b", registry);

        QueryProfile a2 = new QueryProfile("a2");
        a2.set("b", "a2.b", registry);

        QueryProfile profile = new QueryProfile("test");
        profile.setDimensions(new String[]{"x"});
        profile.set("a", a1, registry);
        profile.set("a", a2, new String[]{"x1"}, registry);
        profile.set("a.b", "a.b.x1", new String[]{"x1"}, registry);
        profile.set("a.b", "a.b.x2", new String[]{"x2"}, registry);

        registry.register(a1);
        registry.register(a2);
        registry.register(profile);

        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "variants-of-explicit-compound-with-reference.cfg", profiles.getConfig().toString());
    }

    /** For comparison with the above */
    @Test
    void testExplicitReferenceOverride() throws IOException {
        QueryProfileRegistry registry = new QueryProfileRegistry();

        QueryProfile a1 = new QueryProfile("a1");
        a1.set("b", "a1.b", registry);

        QueryProfile profile = new QueryProfile("test");
        profile.set("a", a1, registry);
        profile.set("a.b", "a.b", registry);
        assertEquals("a.b", profile.get("a.b"));

        registry.register(a1);
        registry.register(profile);

        QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger());
        assertSerializedConfigFileEquals(root + "explicit-reference-override.cfg", profiles.getConfig().toString());
    }

    private static class SilentDeployLogger implements DeployLogger {

        @Override
        public void log(Level level, String message) {}

    }

}