aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StateRestApiV2HandlerTest.java
blob: d6896aac1795c18876f3b2c325a0a87087991b06 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.apps.clustercontroller;

import com.yahoo.cloud.config.ClusterInfoConfig;
import com.yahoo.vespa.clustercontroller.core.restapiv2.ClusterControllerStateRestAPI;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.TreeMap;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class StateRestApiV2HandlerTest {

    @Test
    void testNoMatchingSockets() {
        ClusterController controller = new ClusterController();
        ClusterInfoConfig config = new ClusterInfoConfig(
                new ClusterInfoConfig.Builder().clusterId("cluster-id").nodeCount(1));
        new StateRestApiV2Handler(controller, config, StateRestApiV2Handler.testContext());
    }

    @Test
    void testMappingOfIndexToClusterControllers() {
        ClusterInfoConfig.Builder builder = new ClusterInfoConfig.Builder()
                .clusterId("cluster-id")
                .nodeCount(1)
                .services(new ClusterInfoConfig.Services.Builder()
                        .index(1)
                        .hostname("host-1")
                        .ports(new ClusterInfoConfig.Services.Ports.Builder().number(80).tags("state http"))
                        .ports(new ClusterInfoConfig.Services.Ports.Builder().number(81).tags("ignored port http")))
                .services(new ClusterInfoConfig.Services.Builder()
                        .index(3)
                        .hostname("host-3")
                        .ports(new ClusterInfoConfig.Services.Ports.Builder().number(85).tags("state http"))
                        .ports(new ClusterInfoConfig.Services.Ports.Builder().number(86).tags("foo http bar state")));

        ClusterInfoConfig config = new ClusterInfoConfig(builder);
        Map<Integer, ClusterControllerStateRestAPI.Socket> mapping = StateRestApiV2Handler.getClusterControllerSockets(config);
        Map<Integer, ClusterControllerStateRestAPI.Socket> expected = new TreeMap<>();

        expected.put(1, new ClusterControllerStateRestAPI.Socket("host-1", 80));
        expected.put(3, new ClusterControllerStateRestAPI.Socket("host-3", 85));

        assertEquals(expected, mapping);
    }

}