diff options
Diffstat (limited to 'service-monitor/src/test/java/com/yahoo')
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java | 184 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelTest.java | 63 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/health/ApplicationHealthMonitorTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/ApplicationHealthMonitorTest.java) | 7 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthClientTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthClientTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorManagerTest.java) | 25 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/manager/UnionMonitorManagerTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManagerTest.java) | 10 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ApplicationInstanceGeneratorTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/ApplicationInstanceGeneratorTest.java) | 7 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModel.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModel.java) | 4 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModelTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModelTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/LatencyMeasurementTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/LatencyMeasurementTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ModelGeneratorTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ModelGeneratorTest.java) | 34 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelCacheTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceModelCacheTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelProviderTest.java | 44 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceMonitorMetricsTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorMetricsTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ConfigserverUtil.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ConfigserverUtil.java) | 11 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/DuperModelTest.java | 104 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java | 56 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorManagerImplTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorManagerImplTest.java) | 2 | ||||
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorTest.java (renamed from service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorTest.java) | 4 |
20 files changed, 338 insertions, 229 deletions
diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java new file mode 100644 index 00000000000..da693df77ce --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java @@ -0,0 +1,184 @@ +// 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.duper; + +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.model.api.SuperModel; +import com.yahoo.config.model.api.SuperModelListener; +import com.yahoo.config.model.api.SuperModelProvider; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.HostName; +import com.yahoo.vespa.service.monitor.ConfigserverUtil; +import org.junit.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * @author hakonhall + */ +public class DuperModelManagerTest { + private final ConfigserverConfig configserverConfig = ConfigserverUtil.createExampleConfigserverConfig(); + private final ApplicationInfo configServerApplicationFromConfig = new ConfigServerApplication().makeApplicationInfoFromConfig(configserverConfig); + private final SuperModelProvider superModelProvider = mock(SuperModelProvider.class); + private final SuperModel superModel = mock(SuperModel.class); + private final DuperModel duperModel = mock(DuperModel.class); + + private DuperModelManager manager; + private SuperModelListener superModelListener; + + private void makeManager() { + makeManager(true); + } + + private void makeManager(boolean containsInfra) { + makeManager(containsInfra, true); + } + + private void makeManager(boolean containsInfra, boolean useConfigServerConfig) { + manager = new DuperModelManager( + containsInfra, + useConfigServerConfig, + true, + configServerApplicationFromConfig, + superModelProvider, + duperModel); + + when(superModelProvider.getSuperModel()).thenReturn(superModel); + verify(duperModel, times(useConfigServerConfig ? 1 : 0)).add(any()); + + ArgumentCaptor<SuperModelListener> superModelListenerCaptor = ArgumentCaptor.forClass(SuperModelListener.class); + verify(superModelProvider, times(1)).registerListener(superModelListenerCaptor.capture()); + superModelListener = superModelListenerCaptor.getValue(); + } + + @Test + public void testSuperModelAffectsDuperModel() { + makeManager(); + + superModelListener.applicationActivated(superModel, mock(ApplicationInfo.class)); + verify(duperModel, times(2)).add(any()); + + verify(duperModel, times(0)).remove(any()); + superModelListener.applicationRemoved(superModel, ApplicationId.from("tenant", "app", "default")); + verify(duperModel, times(1)).remove(any()); + } + + @Test + public void testInfraApplicationsAffectsDuperModel() { + makeManager(); + + ApplicationId id = manager.getProxyHostApplication().getApplicationId(); + List<HostName> proxyHostHosts = Stream.of("proxyhost1", "proxyhost2").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(id, proxyHostHosts); + verify(duperModel, times(2)).add(any()); + when(duperModel.contains(id)).thenReturn(true); + + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(id); + verify(duperModel, times(1)).remove(any()); + } + + @Test + public void testDisableInfraApplications() { + makeManager(false); + + List<HostName> proxyHostHosts = Stream.of("proxyhost1", "proxyhost2").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(manager.getProxyHostApplication().getApplicationId(), proxyHostHosts); + verify(duperModel, times(1)).add(any()); + + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(manager.getProxyHostApplication().getApplicationId()); + verify(duperModel, times(0)).remove(any()); + } + + @Test + public void testConfigServerInfraApplications() { + makeManager(); + testConfigServerLikeInfraApplication(manager.getConfigServerApplication().getApplicationId()); + } + + @Test + public void testControllerInfraApplications() { + makeManager(); + testConfigServerLikeInfraApplication(manager.getControllerApplication().getApplicationId()); + } + + private void testConfigServerLikeInfraApplication(ApplicationId configServerLikeId) { + List<HostName> hostnames = Stream.of("node1", "node2").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(configServerLikeId, hostnames); + verify(duperModel, times(1)).add(any()); + + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(configServerLikeId); + verify(duperModel, times(0)).remove(any()); + } + + @Test + public void testEnabledConfigServerInfraApplications() { + makeManager(true, false); + testEnabledConfigServerLikeInfraApplication( + manager.getConfigServerApplication().getApplicationId(), + manager.getControllerApplication().getApplicationId()); + } + + @Test + public void testEnabledControllerInfraApplications() { + makeManager(true, false); + testEnabledConfigServerLikeInfraApplication( + manager.getControllerApplication().getApplicationId(), + manager.getConfigServerApplication().getApplicationId()); + } + + private void testEnabledConfigServerLikeInfraApplication(ApplicationId firstId, ApplicationId secondId) { + List<HostName> hostnames1 = Stream.of("node11", "node12").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(firstId, hostnames1); + verify(duperModel, times(1)).add(any()); + when(duperModel.contains(firstId)).thenReturn(true); + + // Adding the second config server like application will be ignored + List<HostName> hostnames2 = Stream.of("node21", "node22").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(secondId, hostnames2); + verify(duperModel, times(1)).add(any()); + + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(firstId); + verify(duperModel, times(1)).remove(any()); + when(duperModel.contains(firstId)).thenReturn(false); + + // Removing the second config server like application cannot be removed since it wasn't added + verify(duperModel, times(1)).remove(any()); + manager.infraApplicationRemoved(secondId); + verify(duperModel, times(1)).remove(any()); + } + + @Test + public void testSingleTenant() { + manager = new DuperModelManager( + true, + true, + false, + configServerApplicationFromConfig, + superModelProvider, + duperModel); + + when(superModelProvider.getSuperModel()).thenReturn(superModel); + verify(duperModel, times(0)).add(any()); + + List<HostName> hostnames = Stream.of("node1", "node2").map(HostName::from).collect(Collectors.toList()); + manager.infraApplicationActivated(manager.getConfigServerApplication().getApplicationId(), hostnames); + verify(duperModel, times(0)).add(any()); + + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(manager.getConfigServerApplication().getApplicationId()); + verify(duperModel, times(0)).remove(any()); + } +}
\ No newline at end of file diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelTest.java new file mode 100644 index 00000000000..31fd266649a --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelTest.java @@ -0,0 +1,63 @@ +// 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.duper; + +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.provision.ApplicationId; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +/** + * @author hakonhall + */ +public class DuperModelTest { + private final DuperModel duperModel = new DuperModel(); + private final ApplicationInfo application1 = mock(ApplicationInfo.class); + private final ApplicationId id1 = ApplicationId.fromSerializedForm("tenant:app1:default"); + private final ApplicationId id2 = ApplicationId.fromSerializedForm("tenant:app2:default"); + private final ApplicationInfo application2 = mock(ApplicationInfo.class); + private final DuperModelListener listener1 = mock(DuperModelListener.class); + + @Before + public void setUp() { + when(application1.getApplicationId()).thenReturn(id1); + when(application2.getApplicationId()).thenReturn(id2); + } + + @Test + public void test() { + duperModel.add(application1); + assertTrue(duperModel.contains(id1)); + assertEquals(Arrays.asList(application1), duperModel.getApplicationInfos()); + + duperModel.registerListener(listener1); + verify(listener1, times(1)).applicationActivated(application1); + verifyNoMoreInteractions(listener1); + + duperModel.remove(id2); + verifyNoMoreInteractions(listener1); + + duperModel.add(application2); + verify(listener1, times(1)).applicationActivated(application2); + verifyNoMoreInteractions(listener1); + + duperModel.remove(id1); + assertFalse(duperModel.contains(id1)); + verify(listener1, times(1)).applicationRemoved(id1); + verifyNoMoreInteractions(listener1); + assertEquals(Arrays.asList(application2), duperModel.getApplicationInfos()); + + duperModel.remove(id1); + verifyNoMoreInteractions(listener1); + } +}
\ No newline at end of file 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/health/ApplicationHealthMonitorTest.java index 945d6c633af..078f34b84d1 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/health/ApplicationHealthMonitorTest.java @@ -1,10 +1,9 @@ // 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.health; +package com.yahoo.vespa.service.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 com.yahoo.vespa.service.duper.ConfigServerApplication; +import com.yahoo.vespa.service.monitor.ConfigserverUtil; import org.junit.Test; import java.util.HashMap; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthClientTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthClientTest.java index 43200a8fa2e..157b5565071 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthClientTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthClientTest.java @@ -1,5 +1,5 @@ // 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.health; +package com.yahoo.vespa.service.health; import com.yahoo.config.provision.HostName; import com.yahoo.vespa.applicationmodel.ServiceStatus; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java index b9d25406f9b..0b9d7e123b5 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorManagerTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java @@ -1,14 +1,13 @@ // 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.health; +package com.yahoo.vespa.service.health; -import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.vespa.applicationmodel.ClusterId; import com.yahoo.vespa.applicationmodel.ConfigId; import com.yahoo.vespa.applicationmodel.ServiceStatus; import com.yahoo.vespa.applicationmodel.ServiceType; -import com.yahoo.vespa.service.monitor.application.ZoneApplication; -import com.yahoo.vespa.service.monitor.internal.ConfigserverUtil; +import com.yahoo.vespa.service.duper.ZoneApplication; +import com.yahoo.vespa.service.monitor.ConfigserverUtil; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -16,29 +15,15 @@ import static org.junit.Assert.assertEquals; public class HealthMonitorManagerTest { @Test public void addRemove() { - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); - HealthMonitorManager manager = new HealthMonitorManager(config); + HealthMonitorManager manager = new HealthMonitorManager(); ApplicationInfo applicationInfo = ConfigserverUtil.makeExampleConfigServer(); manager.applicationActivated(applicationInfo); manager.applicationRemoved(applicationInfo.getApplicationId()); } @Test - public void withNodeAdmin() { - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); - HealthMonitorManager manager = new HealthMonitorManager(config); - ServiceStatus status = manager.getStatus( - ZoneApplication.ZONE_APPLICATION_ID, - ClusterId.NODE_ADMIN, - ServiceType.CONTAINER, - new ConfigId("config-id-1")); - assertEquals(ServiceStatus.NOT_CHECKED, status); - } - - @Test public void withHostAdmin() { - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(false, true); - HealthMonitorManager manager = new HealthMonitorManager(config); + HealthMonitorManager manager = new HealthMonitorManager(); ServiceStatus status = manager.getStatus( ZoneApplication.ZONE_APPLICATION_ID, ClusterId.NODE_ADMIN, diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorTest.java index 2a203027353..94ba4726ad0 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/health/HealthMonitorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorTest.java @@ -1,5 +1,5 @@ // 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.health; +package com.yahoo.vespa.service.health; import com.yahoo.vespa.applicationmodel.ServiceStatus; import org.junit.Test; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/manager/UnionMonitorManagerTest.java index 79916e43712..a0c7aca5869 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/UnionMonitorManagerTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/manager/UnionMonitorManagerTest.java @@ -1,18 +1,18 @@ // 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; +package com.yahoo.vespa.service.manager; import com.yahoo.vespa.applicationmodel.ConfigId; import com.yahoo.vespa.applicationmodel.ServiceStatus; -import com.yahoo.vespa.service.monitor.internal.health.HealthMonitorManager; -import com.yahoo.vespa.service.monitor.internal.slobrok.SlobrokMonitorManagerImpl; +import com.yahoo.vespa.service.health.HealthMonitorManager; +import com.yahoo.vespa.service.slobrok.SlobrokMonitorManagerImpl; import org.junit.Test; import static com.yahoo.vespa.applicationmodel.ClusterId.NODE_ADMIN; -import static com.yahoo.vespa.applicationmodel.ServiceStatus.*; +import static com.yahoo.vespa.applicationmodel.ServiceStatus.DOWN; import static com.yahoo.vespa.applicationmodel.ServiceStatus.NOT_CHECKED; import static com.yahoo.vespa.applicationmodel.ServiceStatus.UP; import static com.yahoo.vespa.applicationmodel.ServiceType.CONTAINER; -import static com.yahoo.vespa.service.monitor.application.ZoneApplication.ZONE_APPLICATION_ID; +import static com.yahoo.vespa.service.duper.ZoneApplication.ZONE_APPLICATION_ID; import static org.junit.Assert.assertSame; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; 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/model/ApplicationInstanceGeneratorTest.java index 4608e8b0aa8..a59206d14e2 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/model/ApplicationInstanceGeneratorTest.java @@ -1,5 +1,5 @@ // 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.application; +package com.yahoo.vespa.service.model; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ApplicationInfo; @@ -7,14 +7,15 @@ import com.yahoo.config.provision.Zone; import com.yahoo.vespa.applicationmodel.ApplicationInstance; import com.yahoo.vespa.applicationmodel.ServiceStatus; import com.yahoo.vespa.service.monitor.ServiceStatusProvider; -import com.yahoo.vespa.service.monitor.internal.ConfigserverUtil; +import com.yahoo.vespa.service.monitor.ConfigserverUtil; +import com.yahoo.vespa.service.duper.ConfigServerApplication; import org.junit.Test; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.yahoo.vespa.service.monitor.application.ConfigServerApplication.CONFIG_SERVER_APPLICATION; +import static com.yahoo.vespa.service.duper.ConfigServerApplication.CONFIG_SERVER_APPLICATION; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModel.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModel.java index 2fb7828821d..96e69f3cb69 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModel.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModel.java @@ -1,5 +1,5 @@ // 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.internal; +package com.yahoo.vespa.service.model; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; @@ -9,7 +9,7 @@ import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.config.model.api.SuperModel; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.InstanceName; -import com.yahoo.vespa.service.monitor.internal.slobrok.SlobrokMonitor; +import com.yahoo.vespa.service.slobrok.SlobrokMonitor; import java.util.ArrayList; import java.util.Arrays; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModelTest.java index 64ba2ba5097..59a0d520918 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ExampleModelTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ExampleModelTest.java @@ -1,6 +1,6 @@ // 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.internal; +package com.yahoo.vespa.service.model; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/LatencyMeasurementTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/LatencyMeasurementTest.java index 6efde340a16..4ec4f3cec9c 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/LatencyMeasurementTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/LatencyMeasurementTest.java @@ -1,6 +1,6 @@ // 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.internal; +package com.yahoo.vespa.service.model; import com.yahoo.jdisc.Timer; import org.junit.Test; 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/model/ModelGeneratorTest.java index 6574f592b60..bcc136f80e3 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/model/ModelGeneratorTest.java @@ -1,9 +1,8 @@ // 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.internal; +package com.yahoo.vespa.service.model; 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; import com.yahoo.config.provision.Zone; @@ -12,14 +11,15 @@ 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.flags.FeatureFlag; import com.yahoo.vespa.service.monitor.ServiceModel; -import com.yahoo.vespa.service.monitor.application.ConfigServerApplication; -import com.yahoo.vespa.service.monitor.application.DuperModel; -import com.yahoo.vespa.service.monitor.internal.slobrok.SlobrokMonitorManagerImpl; +import com.yahoo.vespa.service.monitor.ConfigserverUtil; +import com.yahoo.vespa.service.duper.ConfigServerApplication; +import com.yahoo.vespa.service.slobrok.SlobrokMonitorManagerImpl; import org.junit.Test; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -36,15 +36,6 @@ public class ModelGeneratorTest { @Test public void toApplicationModel() throws Exception { - SuperModel superModel = ExampleModel.createExampleSuperModelWithOneRpcPort(HOSTNAME, PORT); - - ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); - ApplicationInfo configServerInfo = new ConfigServerApplication().makeApplicationInfoFromConfig(config); - FeatureFlag containsInfra = mock(FeatureFlag.class); - when(containsInfra.value()).thenReturn(false); - FeatureFlag useConfigserverConfig = mock(FeatureFlag.class); - when(useConfigserverConfig.value()).thenReturn(true); - DuperModel duperModel = new DuperModel(containsInfra, useConfigserverConfig, true, configServerInfo); ModelGenerator modelGenerator = new ModelGenerator(); Zone zone = new Zone(Environment.from(ENVIRONMENT), RegionName.from(REGION)); @@ -55,7 +46,7 @@ public class ModelGeneratorTest { ServiceModel serviceModel = modelGenerator.toServiceModel( - duperModel.getApplicationInfos(superModel), + getExampleApplicationInfos(), zone, slobrokMonitorManager); @@ -66,7 +57,7 @@ public class ModelGeneratorTest { assertEquals(2, applicationInstances.size()); Iterator<Map.Entry<ApplicationInstanceReference, - ApplicationInstance>> iterator = + ApplicationInstance>> iterator = applicationInstances.entrySet().iterator(); ApplicationInstance applicationInstance1 = iterator.next().getValue(); @@ -82,6 +73,14 @@ public class ModelGeneratorTest { } } + private List<ApplicationInfo> getExampleApplicationInfos() { + List<ApplicationInfo> applicationInfos = new ArrayList<>(); + ConfigserverConfig config = ConfigserverUtil.createExampleConfigserverConfig(); + applicationInfos.add(new ConfigServerApplication().makeApplicationInfoFromConfig(config)); + applicationInfos.addAll(ExampleModel.createExampleSuperModelWithOneRpcPort(HOSTNAME, PORT).getAllApplicationInfos()); + return applicationInfos; + } + private void verifyOtherApplication(ApplicationInstance applicationInstance) { assertEquals(String.format("%s:%s:%s:%s:%s", ExampleModel.TENANT, @@ -112,5 +111,4 @@ public class ModelGeneratorTest { assertEquals(ConfigServerApplication.APPLICATION_INSTANCE_ID, applicationInstance.applicationInstanceId()); } - } diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceModelCacheTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelCacheTest.java index 2ba6ce0deb8..2d6921df374 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceModelCacheTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelCacheTest.java @@ -1,6 +1,6 @@ // 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.internal; +package com.yahoo.vespa.service.model; import com.yahoo.jdisc.Timer; import com.yahoo.vespa.service.monitor.ServiceModel; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelProviderTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelProviderTest.java new file mode 100644 index 00000000000..13f6da1534d --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceModelProviderTest.java @@ -0,0 +1,44 @@ +// 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.model; + +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.provision.Zone; +import com.yahoo.vespa.service.monitor.ServiceModel; +import com.yahoo.vespa.service.duper.DuperModelManager; +import com.yahoo.vespa.service.slobrok.SlobrokMonitorManagerImpl; +import org.junit.Test; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ServiceModelProviderTest { + @Test + public void sanityCheck() { + SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class); + DuperModelManager duperModelManager = mock(DuperModelManager.class); + ModelGenerator modelGenerator = mock(ModelGenerator.class); + Zone zone = mock(Zone.class); + ServiceModelProvider provider = new ServiceModelProvider( + slobrokMonitorManager, + mock(ServiceMonitorMetrics.class), + duperModelManager, + modelGenerator, + zone); + + ApplicationInfo application1 = mock(ApplicationInfo.class); + ApplicationInfo application2 = mock(ApplicationInfo.class); + List<ApplicationInfo> applications = Stream.of(application1, application2) + .collect(Collectors.toList()); + when(duperModelManager.getApplicationInfos()).thenReturn(applications); + + ServiceModel serviceModel = provider.get(); + verify(duperModelManager, times(1)).getApplicationInfos(); + verify(modelGenerator).toServiceModel(applications, zone, slobrokMonitorManager); + } +}
\ No newline at end of file diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorMetricsTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceMonitorMetricsTest.java index 45920a436cf..8654068d7d1 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/ServiceMonitorMetricsTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ServiceMonitorMetricsTest.java @@ -1,6 +1,6 @@ // 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.internal; +package com.yahoo.vespa.service.model; import com.yahoo.jdisc.Metric; import com.yahoo.jdisc.Timer; 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/ConfigserverUtil.java index 16963797ac8..c334fad2334 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/ConfigserverUtil.java @@ -1,9 +1,9 @@ // 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; +package com.yahoo.vespa.service.monitor; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ApplicationInfo; -import com.yahoo.vespa.service.monitor.application.ConfigServerApplication; +import com.yahoo.vespa.service.duper.ConfigServerApplication; /** * @author hakon @@ -26,12 +26,7 @@ public class ConfigserverUtil { } public static ConfigserverConfig createExampleConfigserverConfig() { - return create(true, true, "cfg1", "cfg2", "cfg3"); - } - - public static ConfigserverConfig createExampleConfigserverConfig(boolean nodeAdminInContainer, - boolean multitenant) { - return create(nodeAdminInContainer, multitenant, "cfg1", "cfg2", "cfg3"); + return create(false, true, "cfg1", "cfg2", "cfg3"); } public static ApplicationInfo makeConfigServerApplicationInfo( 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 deleted file mode 100644 index 9801f80acc9..00000000000 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/application/DuperModelTest.java +++ /dev/null @@ -1,104 +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.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.flags.FeatureFlag; -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); - private final FeatureFlag containsInfra = mock(FeatureFlag.class); - private final FeatureFlag useConfigserverConfig = mock(FeatureFlag.class); - - @Before - public void setUp() { - when(statusProvider.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.NOT_CHECKED); - } - - @Test - public void toApplicationInstance() { - when(containsInfra.value()).thenReturn(false); - when(useConfigserverConfig.value()).thenReturn(true); - DuperModel duperModel = new DuperModel(containsInfra, useConfigserverConfig, 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() { - when(containsInfra.value()).thenReturn(false); - when(useConfigserverConfig.value()).thenReturn(true); - DuperModel duperModel = new DuperModel(containsInfra, useConfigserverConfig, 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() { - when(containsInfra.value()).thenReturn(true); - when(useConfigserverConfig.value()).thenReturn(true); - DuperModel duperModel = new DuperModel(containsInfra, useConfigserverConfig, 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/SuperModelListenerImplTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java deleted file mode 100644 index e2da7b98f56..00000000000 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/SuperModelListenerImplTest.java +++ /dev/null @@ -1,56 +0,0 @@ -// 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.internal; - -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; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class SuperModelListenerImplTest { - @Test - public void sanityCheck() { - SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class); - ServiceMonitorMetrics metrics = mock(ServiceMonitorMetrics.class); - DuperModel duperModel = mock(DuperModel.class); - ModelGenerator modelGenerator = mock(ModelGenerator.class); - Zone zone = mock(Zone.class); - SuperModelListenerImpl listener = new SuperModelListenerImpl( - slobrokMonitorManager, - metrics, - duperModel, - modelGenerator, - zone); - - SuperModelProvider superModelProvider = mock(SuperModelProvider.class); - SuperModel superModel = mock(SuperModel.class); - when(superModelProvider.snapshot(listener)).thenReturn(superModel); - - ApplicationInfo application1 = mock(ApplicationInfo.class); - ApplicationInfo application2 = mock(ApplicationInfo.class); - List<ApplicationInfo> applications = Stream.of(application1, application2) - .collect(Collectors.toList()); - when(duperModel.getApplicationInfos(superModel)).thenReturn(applications); - - listener.start(superModelProvider); - verify(duperModel, times(1)).getApplicationInfos(superModel); - verify(slobrokMonitorManager).applicationActivated(application1); - verify(slobrokMonitorManager).applicationActivated(application2); - - ServiceModel serviceModel = listener.get(); - verify(duperModel, times(2)).getApplicationInfos(superModel); - verify(modelGenerator).toServiceModel(applications, zone, slobrokMonitorManager); - } -}
\ No newline at end of file diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorManagerImplTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorManagerImplTest.java index a567559980b..c3ee1d078bf 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorManagerImplTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorManagerImplTest.java @@ -1,5 +1,5 @@ // 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.slobrok; +package com.yahoo.vespa.service.slobrok; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.provision.ApplicationId; diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorTest.java index 5b230e81cf7..907e52298bf 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/internal/slobrok/SlobrokMonitorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/slobrok/SlobrokMonitorTest.java @@ -1,10 +1,10 @@ // 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.slobrok; +package com.yahoo.vespa.service.slobrok; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.jrt.slobrok.api.Mirror; import com.yahoo.jrt.slobrok.api.SlobrokList; -import com.yahoo.vespa.service.monitor.internal.ExampleModel; +import com.yahoo.vespa.service.model.ExampleModel; import org.junit.Test; import static org.mockito.Mockito.mock; |