blob: f233c028b25a4996b38727033bc1629cfa6f1175 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.status;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceId;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.applicationmodel.TenantId;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.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 HostInfosCacheTest {
@Test
public void test() {
MockCurator curator = new MockCurator();
HostInfosService service = mock(HostInfosService.class);
HostInfosCache cache = new HostInfosCache(curator, service);
ApplicationInstanceReference application = new ApplicationInstanceReference(
new TenantId("tenantid"),
new ApplicationInstanceId("application:dev:region:default"));
HostInfos hostInfos = mock(HostInfos.class);
when(service.getHostInfos(application)).thenReturn(hostInfos);
// cache miss
HostInfos hostInfos1 = cache.getHostInfos(application);
verify(service, times(1)).getHostInfos(any());
assertSame(hostInfos1, hostInfos);
// cache hit
HostInfos hostInfos2 = cache.getHostInfos(application);
verify(service, times(1)).getHostInfos(any());
assertSame(hostInfos2, hostInfos);
when(service.setHostStatus(any(), any(), any())).thenReturn(true);
boolean modified = cache.setHostStatus(application, new HostName("hostname1"), HostStatus.ALLOWED_TO_BE_DOWN);
verify(service, times(1)).getHostInfos(any());
assertTrue(modified);
// cache miss
HostInfos hostInfos3 = cache.getHostInfos(application);
verify(service, times(2)).getHostInfos(any());
assertSame(hostInfos1, hostInfos);
}
}
|