aboutsummaryrefslogtreecommitdiffstats
path: root/service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModelTest.java
blob: 829b1fe5859e406b43f4f32e95f04074b1c96579 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.vespa.service.model;

import com.yahoo.config.model.api.ApplicationInfo;
import com.yahoo.config.model.api.HostInfo;
import com.yahoo.config.model.api.ServiceInfo;
import org.junit.Test;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;

public class ExampleModelTest {
    @Test
    public void testEmptyApplication() {
        ApplicationInfo application = ExampleModel
                .createApplication(
                        "tenant",
                        "app")
                .build();

        assertEquals("tenant.app", application.getApplicationId().toString());
        assertEquals(1, application.getGeneration());
        assertEquals(0, application.getModel().getHosts().size());
    }

    @Test
    public void test() {
        List<String> contentNodes = Stream.of("host1", "host2").toList();
        List<String> containerNodes = Stream.of("host3", "host4").toList();

        ApplicationInfo application = ExampleModel
                .createApplication(
                        "tenant",
                        "app")
                .addServiceCluster(
                        "product-controllers",
                        "container-clustercontroller.1",
                        "container-clustercontroller",
                        contentNodes)
                .then()
                .addServiceCluster(
                        "product",
                        "searchnode.1",
                        "searchnode",
                        contentNodes)
                .then()
                .addServiceCluster(
                        "admin",
                        "slobrok.1",
                        "slobrok",
                        containerNodes)
                .then()
                .addServiceCluster(
                        "default",
                        "container.1",
                        "container",
                        containerNodes)
                .then()
                .build();

        assertEquals("tenant.app", application.getApplicationId().toString());

        Collection<HostInfo> hostInfos = application.getModel().getHosts();
        assertEquals(containerNodes.size() + contentNodes.size(), hostInfos.size());

        HostInfo host1 = hostInfos.stream()
                .filter(hostInfo -> hostInfo.getHostname().equals("host1"))
                .findAny()
                .orElseThrow(() -> new RuntimeException());
        ServiceInfo controller1 = host1.getServices().stream()
                .filter(i -> i.getServiceType().equals("container-clustercontroller"))
                .findAny()
                .orElseThrow(() -> new RuntimeException());

        assertEquals("container-clustercontroller", controller1.getServiceType());
        assertEquals("configid/1", controller1.getConfigId());

        HostInfo host4 = hostInfos.stream()
                .filter(hostInfo -> hostInfo.getHostname().equals("host4"))
                .findAny()
                .orElseThrow(() -> new RuntimeException());
        ServiceInfo slobrok2 = host4.getServices().stream()
                .filter(i -> i.getServiceType().equals("slobrok"))
                .findAny()
                .orElseThrow(() -> new RuntimeException());
        assertEquals("configid/2", slobrok2.getConfigId());
    }
}