aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/MonitoringConfigSnoopTest.java
blob: 6e0ab6551286a0740b790d22323f0ee07ea8d901 (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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content;

import com.yahoo.config.model.test.TestDriver;
import com.yahoo.config.model.test.TestRoot;
import com.yahoo.metrics.MetricsmanagerConfig;
import org.junit.Test;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;


/**
 * @author havardpe
 **/
public class MonitoringConfigSnoopTest {

    private TestRoot root;

    public void initRoot(int interval) throws Exception {
        TestDriver tester = new TestDriver();
        root = tester.buildModel(getAdminXml(interval) + getContent());
    }

    private String getAdminXml(int interval) {
        return ""
                + "<admin version='2.0'>"
                + "  <adminserver hostalias='mockhost' />"
                + "  <yamas interval='" + interval + "' systemname='test' />"
                + "</admin>";
    }

    private String getContent() {
        return (
                "<content version='1.0' id='search'>"+
                "    <documents/>"+
                "    <nodes>"+
                "      <node hostalias='mockhost' distribution-key='0' />"+
                "    </nodes>"+
                "</content>");
    }

    private MetricsmanagerConfig getConfig() {
        return root.getConfig(MetricsmanagerConfig.class, "search/storage/0");
    }

    @Test
    public void correct_config_is_snooped() throws Exception {
        initRoot(60);
        assertThat(getConfig().snapshot().periods().size(), is(2));
        assertThat(getConfig().snapshot().periods(0), is(60));
        assertThat(getConfig().snapshot().periods(1), is(300));
    }

    @Test
    public void correct_config_is_snooped_default_interval() throws Exception {
        String getAdminXmlIntervalNotSpecified = "<admin version='2.0'>"
                + "  <adminserver hostalias='mockhost' />"
                + "</admin>";

        TestDriver tester = new TestDriver();
        root = tester.buildModel(getAdminXmlIntervalNotSpecified + getContent());
        assertThat(getConfig().snapshot().periods().size(), is(2));
        assertThat(getConfig().snapshot().periods(0), is(60));
        assertThat(getConfig().snapshot().periods(1), is(300));
    }

    @Test(expected = Exception.class)
    public void invalid_model_1() throws Exception {
        initRoot(120);
    }
}