diff options
author | HÃ¥kon Hallingstad <hakon@oath.com> | 2018-12-03 20:40:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-03 20:40:06 +0100 |
commit | 45907798a1cf2c5364c9e0f24c7815adf7110c87 (patch) | |
tree | 1e2f4d9ac716a7e6983a55d034a6c2f3aa3f07d8 /service-monitor/src/test/java | |
parent | 9c5f6713a54387b035a565e62ff30bb0a7b54cf8 (diff) |
Revert "Revert "Add infrastructure applications to DuperModel""
Diffstat (limited to 'service-monitor/src/test/java')
7 files changed, 105 insertions, 56 deletions
diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/ApplicationInstanceGeneratorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/ApplicationInstanceGeneratorTest.java index 899cc59bb34..4608e8b0aa8 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/ApplicationInstanceGeneratorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/ApplicationInstanceGeneratorTest.java @@ -42,7 +42,7 @@ public class ApplicationInstanceGeneratorTest { configServer2, configServer3); Zone zone = mock(Zone.class); - ApplicationInfo configServer = CONFIG_SERVER_APPLICATION.makeApplicationInfo(config); + ApplicationInfo configServer = CONFIG_SERVER_APPLICATION.makeApplicationInfoFromConfig(config); ApplicationInstance applicationInstance = new ApplicationInstanceGenerator(configServer, zone) .makeApplicationInstance(statusProvider); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/DuperModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/DuperModelTest.java new file mode 100644 index 00000000000..40204c0de8e --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/DuperModelTest.java @@ -0,0 +1,95 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.service.monitor.application; + +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.model.api.SuperModel; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.HostName; +import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.service.monitor.ServiceStatusProvider; +import com.yahoo.vespa.service.monitor.internal.ConfigserverUtil; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author hakon + */ +public class DuperModelTest { + private final ServiceStatusProvider statusProvider = mock(ServiceStatusProvider.class); + private final ConfigserverConfig configserverConfig = ConfigserverUtil.createExampleConfigserverConfig(); + private final ApplicationInfo configServerApplicationInfo = new ConfigServerApplication().makeApplicationInfoFromConfig(configserverConfig); + private final SuperModel superModel = mock(SuperModel.class); + + @Before + public void setUp() { + when(statusProvider.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.NOT_CHECKED); + } + + @Test + public void toApplicationInstance() { + DuperModel duperModel = new DuperModel(false, true, true, configServerApplicationInfo); + ApplicationInfo superModelApplicationInfo = mock(ApplicationInfo.class); + when(superModel.getAllApplicationInfos()).thenReturn(Collections.singletonList(superModelApplicationInfo)); + List<ApplicationInfo> applicationInfos = duperModel.getApplicationInfos(superModel); + assertEquals(2, applicationInfos.size()); + assertEquals(ConfigServerApplication.CONFIG_SERVER_APPLICATION.getApplicationId(), applicationInfos.get(0).getApplicationId()); + assertSame(superModelApplicationInfo, applicationInfos.get(1)); + } + + @Test + public void toApplicationInstanceInSingleTenantMode() { + DuperModel duperModel = new DuperModel(false, true, false, configServerApplicationInfo); + ApplicationInfo superModelApplicationInfo = mock(ApplicationInfo.class); + when(superModel.getAllApplicationInfos()).thenReturn(Collections.singletonList(superModelApplicationInfo)); + List<ApplicationInfo> applicationInfos = duperModel.getApplicationInfos(superModel); + assertEquals(1, applicationInfos.size()); + assertSame(superModelApplicationInfo, applicationInfos.get(0)); + } + + @Test + public void testInfraApplications() { + DuperModel duperModel = new DuperModel(true, true, true, configServerApplicationInfo); + ApplicationInfo infraApplicationInfo = mock(ApplicationInfo.class); + when(superModel.getAllApplicationInfos()).thenReturn(Collections.emptyList()); + + List<ApplicationInfo> applicationInfos = duperModel.getApplicationInfos(superModel); + assertEquals(1, applicationInfos.size()); + assertEquals(duperModel.getConfigServerApplication().getApplicationId(), applicationInfos.get(0).getApplicationId()); + + List<InfraApplicationApi> infraApis = duperModel.getSupportedInfraApplications(); + assertEquals(5, infraApis.size()); + + InfraApplication proxyHostApp = duperModel.getProxyHostApplication(); + assertFalse(duperModel.infraApplicationIsActive(proxyHostApp.getApplicationId())); + + List<HostName> hostnames = Stream.of("host1").map(HostName::from).collect(Collectors.toList()); + duperModel.infraApplicationActivated(proxyHostApp.getApplicationId(), hostnames); + + assertTrue(duperModel.infraApplicationIsActive(proxyHostApp.getApplicationId())); + applicationInfos = duperModel.getApplicationInfos(superModel); + assertEquals(2, applicationInfos.size()); + List<ApplicationId> applicationIds = applicationInfos.stream() + .map(ApplicationInfo::getApplicationId) + .collect(Collectors.toList()); + assertThat(applicationIds, hasItem(proxyHostApp.getApplicationId())); + + duperModel.infraApplicationRemoved(proxyHostApp.getApplicationId()); + assertFalse(duperModel.infraApplicationIsActive(proxyHostApp.getApplicationId())); + } +} diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ConfigserverUtil.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ConfigserverUtil.java index 85df02949a6..16963797ac8 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ConfigserverUtil.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ConfigserverUtil.java @@ -38,7 +38,7 @@ public class ConfigserverUtil { String configServerHostname1, String configServerHostname2, String configServerHostname3) { - return ConfigServerApplication.CONFIG_SERVER_APPLICATION.makeApplicationInfo(create( + return ConfigServerApplication.CONFIG_SERVER_APPLICATION.makeApplicationInfoFromConfig(create( true, true, configServerHostname1, diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/DuperModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/DuperModelTest.java deleted file mode 100644 index c9d19d0ccd9..00000000000 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/DuperModelTest.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.service.monitor.internal; - -import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.model.api.ApplicationInfo; -import com.yahoo.config.model.api.SuperModel; -import com.yahoo.vespa.applicationmodel.ServiceStatus; -import com.yahoo.vespa.service.monitor.ServiceStatusProvider; -import com.yahoo.vespa.service.monitor.application.ConfigServerApplication; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author hakon - */ -public class DuperModelTest { - private final ServiceStatusProvider statusProvider = mock(ServiceStatusProvider.class); - - @Test - public void toApplicationInstance() { - when(statusProvider.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.NOT_CHECKED); - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); - DuperModel duperModel = new DuperModel(config); - SuperModel superModel = mock(SuperModel.class); - ApplicationInfo superModelApplicationInfo = mock(ApplicationInfo.class); - when(superModel.getAllApplicationInfos()).thenReturn(Collections.singletonList(superModelApplicationInfo)); - List<ApplicationInfo> applicationInfos = duperModel.getApplicationInfos(superModel); - assertEquals(2, applicationInfos.size()); - assertEquals(ConfigServerApplication.CONFIG_SERVER_APPLICATION.getApplicationId(), applicationInfos.get(0).getApplicationId()); - assertSame(superModelApplicationInfo, applicationInfos.get(1)); - } - - @Test - public void toApplicationInstanceInSingleTenantMode() { - when(statusProvider.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.NOT_CHECKED); - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(true, false); - DuperModel duperModel = new DuperModel(config); - SuperModel superModel = mock(SuperModel.class); - ApplicationInfo superModelApplicationInfo = mock(ApplicationInfo.class); - when(superModel.getAllApplicationInfos()).thenReturn(Collections.singletonList(superModelApplicationInfo)); - List<ApplicationInfo> applicationInfos = duperModel.getApplicationInfos(superModel); - assertEquals(1, applicationInfos.size()); - assertSame(superModelApplicationInfo, applicationInfos.get(0)); - } -} diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ModelGeneratorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ModelGeneratorTest.java index 5a57451a298..275fa8568c2 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ModelGeneratorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ModelGeneratorTest.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.service.monitor.internal; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.SuperModel; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; @@ -11,6 +12,7 @@ import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference; import com.yahoo.vespa.applicationmodel.ServiceCluster; import com.yahoo.vespa.applicationmodel.ServiceInstance; import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.service.monitor.application.DuperModel; import com.yahoo.vespa.service.monitor.ServiceModel; import com.yahoo.vespa.service.monitor.application.ConfigServerApplication; import com.yahoo.vespa.service.monitor.internal.slobrok.SlobrokMonitorManagerImpl; @@ -36,7 +38,8 @@ public class ModelGeneratorTest { SuperModel superModel = ExampleModel.createExampleSuperModelWithOneRpcPort(HOSTNAME, PORT); ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); - DuperModel duperModel = new DuperModel(config); + ApplicationInfo configServerInfo = new ConfigServerApplication().makeApplicationInfoFromConfig(config); + DuperModel duperModel = new DuperModel(false, true, true, configServerInfo); ModelGenerator modelGenerator = new ModelGenerator(); Zone zone = new Zone(Environment.from(ENVIRONMENT), RegionName.from(REGION)); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java index eb6d6d583f7..e2da7b98f56 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java @@ -5,6 +5,7 @@ import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.SuperModel; import com.yahoo.config.model.api.SuperModelProvider; import com.yahoo.config.provision.Zone; +import com.yahoo.vespa.service.monitor.application.DuperModel; import com.yahoo.vespa.service.monitor.ServiceModel; import com.yahoo.vespa.service.monitor.internal.slobrok.SlobrokMonitorManagerImpl; import org.junit.Test; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/ApplicationHealthMonitorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/ApplicationHealthMonitorTest.java index b0fdb14726f..945d6c633af 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/ApplicationHealthMonitorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/ApplicationHealthMonitorTest.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.service.monitor.internal.health; import com.yahoo.vespa.applicationmodel.ServiceStatus; import com.yahoo.vespa.service.monitor.application.ConfigServerApplication; +import com.yahoo.vespa.service.monitor.application.DuperModel; import com.yahoo.vespa.service.monitor.internal.ConfigserverUtil; import org.junit.Test; @@ -36,6 +37,8 @@ public class ApplicationHealthMonitorTest { ConfigserverUtil.makeExampleConfigServer(), monitorFactory); + ConfigServerApplication configServerApplication = new ConfigServerApplication(); + ServiceStatus status1 = applicationMonitor.getStatus( ConfigServerApplication.CONFIG_SERVER_APPLICATION.getApplicationId(), ConfigServerApplication.CLUSTER_ID, |