blob: bec33a7dbfdfb399eff354a4ccb8015d6ecf2e56 (
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
|
// 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);
StateV1HealthUpdater updater = new StateV1HealthUpdater("https://foo/state/v1/health", client, false);
RunletExecutor executor = new RunletExecutorImpl(2);
try (StateV1HealthMonitor monitor = new StateV1HealthMonitor(updater, executor, Duration.ofMillis(10))) {
assertEquals(ServiceStatus.NOT_CHECKED, monitor.getStatus().serviceStatus());
when(client.get()).thenReturn(HealthInfo.fromHealthStatusCode(HealthInfo.UP_STATUS_CODE));
while (monitor.getStatus().serviceStatus() != ServiceStatus.UP) {
try { Thread.sleep(2); } catch (InterruptedException ignored) { }
}
when(client.get()).thenReturn(HealthInfo.fromException(new IllegalStateException("foo")));
while (monitor.getStatus().serviceStatus() != ServiceStatus.DOWN) {
try { Thread.sleep(2); } catch (InterruptedException ignored) { }
}
}
}
}
|