aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java
blob: 6d009d2fd8880598e986ce669dfc43ead9220712 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.service;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

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

/**
 * @author Unknown
 */
public class ConfigSentinelClientTest {

    @Test
    public void testConfigSentinelClient() {
        ConfigSentinelDummy configsentinel = new ConfigSentinelDummy();
        List<VespaService> services = new ArrayList<>();
        VespaService docproc = new VespaService("docprocservice", "docproc/cluster.x.indexing/0");
        VespaService searchnode4 = new VespaService("searchnode4", "search/cluster.x/g0/c1/r1");
        VespaService qrserver = new VespaService("qrserver", "container/qrserver.0");

        services.add(searchnode4);
        services.add(qrserver);
        services.add(docproc);

        try (MockConfigSentinelClient client = new MockConfigSentinelClient(configsentinel)) {
            client.updateServiceStatuses(services);

            assertThat(qrserver.getPid(), is(6520));
            assertThat(qrserver.getState(), is("RUNNING"));
            assertThat(qrserver.isAlive(), is(true));
            assertThat(searchnode4.getPid(), is(6534));
            assertThat(searchnode4.getState(), is("RUNNING"));
            assertThat(searchnode4.isAlive(), is(true));

            assertThat(docproc.getPid(), is(-1));
            assertThat(docproc.getState(), is("FINISHED"));
            assertThat(docproc.isAlive(), is(false));


            configsentinel.reConfigure();

            client.ping(docproc);
            assertThat(docproc.getPid(), is(100));
            assertThat(docproc.getState(), is("RUNNING"));
            assertThat(docproc.isAlive(), is(true));

            //qrserver has yet not been checked
            assertThat(qrserver.isAlive(), is(true));

            client.updateServiceStatuses(services);

            assertThat(docproc.getPid(), is(100));
            assertThat(docproc.getState(), is("RUNNING"));
            assertThat(docproc.isAlive(), is(true));
            //qrserver is no longer running on this node - so should be false
            assertThat(qrserver.isAlive(), is(false));
        }
    }

    @Test
    public void testElastic() {
        String response = "container state=RUNNING mode=AUTO pid=14338 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"get/container.0\"\n" +
                "container-clustercontroller state=RUNNING mode=AUTO pid=25020 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/cluster-controllers/0\"\n" +
                "distributor state=RUNNING mode=AUTO pid=25024 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/distributor/0\"\n" +
                "docprocservice state=RUNNING mode=AUTO pid=11973 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"docproc/cluster.search.indexing/0\"\n" +
                "logd state=RUNNING mode=AUTO pid=25016 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/vespa19.dev.gq1.yahoo.com/logd\"\n" +
                "logserver state=RUNNING mode=AUTO pid=25018 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/logserver\"\n" +
                "metricsproxy state=RUNNING mode=AUTO pid=13107 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/vespa19.dev.gq1.yahoo.com/metricsproxy\"\n" +
                "searchnode state=RUNNING mode=AUTO pid=25023 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/search/cluster.search/0\"\n" +
                "slobrok state=RUNNING mode=AUTO pid=25019 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"client\"\n" +
                "\n";

        ConfigSentinelDummy configsentinel = new ConfigSentinelDummy(response);
        List<VespaService> services = new ArrayList<>();

        VespaService container = VespaService.create("container", "get/container.0", -1);

        VespaService containerClusterController =
                VespaService.create("container-clustercontroller", "get/container.0", -1);

        VespaService notPresent = VespaService.create("dummy","fake", -1);

        services.add(container);
        services.add(containerClusterController);
        services.add(notPresent);

        try (MockConfigSentinelClient client = new MockConfigSentinelClient(configsentinel)) {
            client.updateServiceStatuses(services);
            assertThat(container.isAlive(),is(true));
            assertThat(container.getPid(),is(14338));
            assertThat(container.getState(),is("RUNNING"));

            assertThat(containerClusterController.isAlive(),is(true));
            assertThat(containerClusterController.getPid(),is(25020));
            assertThat(containerClusterController.getState(),is("RUNNING"));
        }
    }

}