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
57
58
59
60
61
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.maintenance;
import com.yahoo.component.Version;
import com.yahoo.config.provision.CloudName;
import com.yahoo.vespa.hosted.controller.api.integration.artifact.Artifact;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
import com.yahoo.vespa.hosted.controller.integration.ArtifactRegistryMock;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author mpolden
*/
public class ArtifactExpirerTest {
@Test
void maintain() {
DeploymentTester tester = new DeploymentTester();
ArtifactExpirer expirer = new ArtifactExpirer(tester.controller(), Duration.ofDays(1));
ArtifactRegistryMock registry = tester.controllerTester().serviceRegistry().artifactRegistry(CloudName.defaultName()).orElseThrow();
Instant instant = tester.clock().instant();
Artifact image0 = new Artifact("image0", "registry.example.com", "vespa/vespa", "7.1", instant, Version.fromString("7.1"));
Artifact image1 = new Artifact("image1", "registry.example.com", "vespa/vespa", "7.2-amd64", instant, Version.fromString("7.2"));
Artifact image2 = new Artifact("image2", "registry.example.com", "vespa/vespa", "7.4-amd64", instant, Version.fromString("7.4"));
registry.add(image0)
.add(image1)
.add(image2);
// Make one image active
tester.controllerTester().upgradeSystem(image1.version());
// Nothing is expired initially
expirer.maintain();
assertEquals(List.of(image0, image1, image2), registry.list());
// Nothing happens as not enough time has passed since image creation
tester.clock().advance(Duration.ofDays(1));
expirer.maintain();
assertEquals(List.of(image0, image1, image2), registry.list());
// Enough time passes to expire unused image
tester.clock().advance(Duration.ofDays(13).plus(Duration.ofSeconds(1)));
expirer.maintain();
assertEquals(List.of(image1, image2), registry.list());
// A new version becomes active. The active and future version are kept
Artifact image3 = new Artifact("image3", "registry.example.com", "vespa/vespa", "7.3-arm64", tester.clock().instant(), Version.fromString("7.3"));
registry.add(image3);
tester.controllerTester().upgradeSystem(image3.version());
expirer.maintain();
assertEquals(List.of(image3, image2), registry.list());
}
}
|