diff options
Diffstat (limited to 'service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ExampleModelTest.java')
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ExampleModelTest.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ExampleModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ExampleModelTest.java new file mode 100644 index 00000000000..bcd4eae1b4e --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ExampleModelTest.java @@ -0,0 +1,93 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.vespa.service.monitor; + +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").collect(Collectors.toList()); + List<String> containerNodes = Stream.of("host3", "host4").collect(Collectors.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()); + } +} |