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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2017 Yahoo Holdings. 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.ApplicationId;
import com.yahoo.config.provision.Environment;
import com.yahoo.vespa.hosted.controller.Application;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.SourceRevision;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.Change;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
import com.yahoo.vespa.hosted.controller.deployment.Run;
import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb;
import org.junit.Test;
import java.time.Duration;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author bratseth
*/
public class OutstandingChangeDeployerTest {
@Test
public void testChangeDeployer() {
DeploymentTester tester = new DeploymentTester();
OutstandingChangeDeployer deployer = new OutstandingChangeDeployer(tester.controller(), Duration.ofMinutes(10),
new JobControl(new MockCuratorDb()));
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.region("us-west-1")
.build();
Application app1 = tester.createApplication("tenant", "app1", "default");
tester.deployNewSubmission(app1.id(), tester.newSubmission(app1.id(), applicationPackage));
Version version = new Version(6, 2);
tester.deploymentTrigger().triggerChange(app1.id(), Change.of(version));
tester.deploymentTrigger().triggerReadyJobs();
assertEquals(Change.of(version), tester.application(app1.id()).change());
assertFalse(tester.application(app1.id()).outstandingChange().hasTargets());
assertEquals(1, tester.application(app1.id()).latestVersion().get().buildNumber().getAsLong());
tester.newSubmission(app1.id(), applicationPackage, new SourceRevision("repository1", "master", "cafed00d"));
ApplicationId instanceId = app1.id().defaultInstance();
assertTrue(tester.application(app1.id()).outstandingChange().hasTargets());
assertEquals("1.0.2-cafed00d", tester.application(app1.id()).outstandingChange().application().get().id());
tester.assertRunning(instanceId, JobType.systemTest);
tester.assertRunning(instanceId, JobType.stagingTest);
assertEquals(2, tester.jobs().active().size());
deployer.maintain();
tester.deploymentTrigger().triggerReadyJobs();
assertEquals("No effect as job is in progress", 2, tester.jobs().active().size());
assertEquals("1.0.2-cafed00d", tester.application(app1.id()).outstandingChange().application().get().id());
tester.runJob(instanceId, JobType.systemTest);
tester.runJob(instanceId, JobType.stagingTest);
tester.runJob(instanceId, JobType.productionUsWest1);
tester.runJob(instanceId, JobType.systemTest);
tester.runJob(instanceId, JobType.stagingTest);
assertEquals("Upgrade done", 0, tester.jobs().active().size());
deployer.maintain();
tester.deploymentTrigger().triggerReadyJobs();
assertEquals("1.0.2-cafed00d", tester.application(app1.id()).change().application().get().id());
List<Run> runs = tester.jobs().active();
assertEquals(1, runs.size());
tester.assertRunning(instanceId, JobType.productionUsWest1);
assertFalse(tester.application(app1.id()).outstandingChange().hasTargets());
}
}
|