aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java
blob: fb93f04af74e103efe2501ac40ddc7b4e38f6ee2 (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.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

/**
 * @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 container = new VespaService("container", "container/default.0");

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

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

            assertEquals(6520, container.getPid());
            assertEquals("RUNNING", container.getState());
            assertTrue(container.isAlive());
            assertEquals(6534, searchnode4.getPid());
            assertEquals("RUNNING", searchnode4.getState());
            assertTrue(searchnode4.isAlive());

            assertEquals(-1, docproc.getPid());
            assertEquals("FINISHED", docproc.getState());
            assertFalse(docproc.isAlive());


            configsentinel.reConfigure();

            client.ping(docproc);
            assertEquals(100, docproc.getPid());
            assertEquals("RUNNING", docproc.getState());
            assertTrue(docproc.isAlive());

            // container has yet not been checked
            assertTrue(container.isAlive());

            client.updateServiceStatuses(services);

            assertEquals(100, docproc.getPid());
            assertEquals("RUNNING", docproc.getState());
            assertTrue(docproc.isAlive());
            // container is no longer running on this node - so should be false
            assertFalse(container.isAlive());
        }
    }

    @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);
            assertTrue(container.isAlive());
            assertEquals(14338, container.getPid());
            assertEquals("RUNNING", container.getState());

            assertTrue(containerClusterController.isAlive());
            assertEquals(25020, containerClusterController.getPid());
            assertEquals("RUNNING", containerClusterController.getState());
        }
    }

}