diff options
author | Håkon Hallingstad <hakon@oath.com> | 2018-12-17 10:34:40 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2018-12-17 10:34:40 +0100 |
commit | 3e01a6396bd6150ec69d272ff8a39a78e2a7e10d (patch) | |
tree | ae9a56e0dda80de12d0b4a40163aa718774b4b63 /service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java | |
parent | ffffe2f773f3c6ab82823f41e349033356e45bc7 (diff) |
Use thread pool for health monitoring in service-monitor
This is necessary to avoid using too many threads when monitoring the
host-admin on the tenant Docker hosts.
Diffstat (limited to 'service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java')
-rw-r--r-- | service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java new file mode 100644 index 00000000000..c892118990f --- /dev/null +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthMonitorTest.java @@ -0,0 +1,37 @@ +// 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.health; + +import com.yahoo.vespa.applicationmodel.ServiceStatus; +import com.yahoo.vespa.service.executor.RunletExecutor; +import com.yahoo.vespa.service.executor.RunletExecutorImpl; +import org.junit.Test; + +import java.time.Duration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class StateV1HealthMonitorTest { + @Test + public void downThenUpThenDown() throws Exception { + StateV1HealthClient client = mock(StateV1HealthClient.class); + when(client.get()).thenReturn(HealthInfo.empty()); + + StateV1HealthUpdater updater = new StateV1HealthUpdater(client); + RunletExecutor executor = new RunletExecutorImpl(2); + try (StateV1HealthMonitor monitor = new StateV1HealthMonitor(updater, executor, Duration.ofMillis(10))) { + assertEquals(ServiceStatus.DOWN, monitor.getStatus()); + + when(client.get()).thenReturn(HealthInfo.fromHealthStatusCode(HealthInfo.UP_STATUS_CODE)); + while (monitor.getStatus() != ServiceStatus.UP) { + try { Thread.sleep(2); } catch (InterruptedException ignored) { } + } + + when(client.get()).thenReturn(HealthInfo.fromException(new IllegalStateException("foo"))); + while (monitor.getStatus() != ServiceStatus.DOWN) { + try { Thread.sleep(2); } catch (InterruptedException ignored) { } + } + } + } +}
\ No newline at end of file |