summaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployerTest.java
blob: d9846dd37eeac1b9cc6e543a5b6ae5c6ebd8c3e2 (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
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
82
83
84
// 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.Environment;
import com.yahoo.vespa.hosted.controller.Application;
import com.yahoo.vespa.hosted.controller.api.integration.BuildService;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.Change;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.SourceRevision;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
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();

        tester.createAndDeploy("app1", 11, applicationPackage);
        tester.createAndDeploy("app2", 22, applicationPackage);

        Version version = new Version(6, 2);
        tester.deploymentTrigger().triggerChange(tester.application("app1").id(), Change.of(version));
        tester.deploymentTrigger().triggerReadyJobs();

        assertEquals(Change.of(version), tester.application("app1").change());
        assertFalse(tester.application("app1").outstandingChange().isPresent());

        tester.jobCompletion(JobType.component)
              .application(tester.application("app1"))
              .sourceRevision(new SourceRevision("repository1","master", "cafed00d"))
              .nextBuildNumber()
              .uploadArtifact(applicationPackage)
              .submit();

        Application app = tester.application("app1");
        assertTrue(app.outstandingChange().isPresent());
        assertEquals("1.0.43-cafed00d", app.outstandingChange().application().get().id());
        assertEquals(2, tester.buildService().jobs().size());

        deployer.maintain();
        tester.deploymentTrigger().triggerReadyJobs();
        assertEquals("No effect as job is in progress", 2, tester.buildService().jobs().size());
        assertEquals("1.0.43-cafed00d", app.outstandingChange().application().get().id());

        tester.deployAndNotify(app, applicationPackage, true, JobType.systemTest);
        tester.deployAndNotify(app, applicationPackage, true, JobType.stagingTest);
        tester.deployAndNotify(app, applicationPackage, true, JobType.productionUsWest1);
        tester.deployAndNotify(app, applicationPackage, true, JobType.systemTest);
        tester.deployAndNotify(app, applicationPackage, true, JobType.stagingTest);
        assertEquals("Upgrade done", 0, tester.buildService().jobs().size());

        deployer.maintain();
        tester.deploymentTrigger().triggerReadyJobs();
        app = tester.application("app1");
        assertEquals("1.0.43-cafed00d", app.change().application().get().id());
        List<BuildService.BuildJob> jobs = tester.buildService().jobs();
        assertEquals(1, jobs.size());
        assertEquals(JobType.productionUsWest1.jobName(), jobs.get(0).jobName());
        assertEquals(11, jobs.get(0).projectId());
        assertFalse(tester.application("app1").outstandingChange().isPresent());
    }

}