aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/deployment/BadgeApiTest.java
blob: c195b623c1138b3205876508e8cdf1487ff310fe (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.restapi.deployment;

import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
import com.yahoo.vespa.hosted.controller.application.pkg.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
import com.yahoo.vespa.hosted.controller.restapi.ContainerTester;
import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;

/**
 * @author jonmv
 */
public class BadgeApiTest extends ControllerContainerTest {

    private static final String responseFiles = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/deployment/responses/";

    @Test
    public void testBadgeApi() throws IOException {
        ContainerTester tester = new ContainerTester(container, responseFiles);
        var application = new DeploymentTester(new ControllerTester(tester)).newDeploymentContext("tenant", "application", "default");
        ApplicationPackage applicationPackage = new ApplicationPackageBuilder().systemTest()
                                                                               .parallel("us-west-1", "aws-us-east-1a")
                                                                               .test("us-west-1")
                                                                               .region("ap-southeast-1")
                                                                               .test("ap-southeast-1")
                                                                               .region("eu-west-1")
                                                                               .test("eu-west-1")
                                                                               .build();
        application.submit(applicationPackage).deploy();
        application.submit(applicationPackage)
                   .runJob(JobType.systemTest)
                   .runJob(JobType.stagingTest)
                   .runJob(JobType.productionUsWest1)
                   .runJob(JobType.productionAwsUsEast1a)
                   .runJob(JobType.testUsWest1)
                   .runJob(JobType.productionApSoutheast1)
                   .failDeployment(JobType.testApSoutheast1);
        application.submit(applicationPackage)
                   .failTests(JobType.systemTest, true)
                   .runJob(JobType.stagingTest);
        for (int i = 0; i < 31; i++)
            if ((i & 1) == 0)
                application.failDeployment(JobType.productionUsWest1);
            else
                application.triggerJobs().abortJob(JobType.productionUsWest1);
        application.triggerJobs();
        tester.controller().applications().deploymentTrigger().reTrigger(application.instanceId(), JobType.systemTest, "reason");
        tester.controller().applications().deploymentTrigger().reTrigger(application.instanceId(), JobType.testEuWest1, "reason");

        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default"),
                              Files.readString(Paths.get(responseFiles + "overview.svg")), 200);
        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default/production-us-west-1?historyLength=0"),
                              Files.readString(Paths.get(responseFiles + "single-running.svg")), 200);
        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default/production-us-west-1?historyLength=32"),
                              Files.readString(Paths.get(responseFiles + "history.svg")), 200);

        // New change not reflected before cache entry expires.
        tester.serviceRegistry().clock().advance(Duration.ofSeconds(59));
        application.runJob(JobType.productionUsWest1);
        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default/production-us-west-1?historyLength=32"),
                              Files.readString(Paths.get(responseFiles + "history.svg")), 200);

        // Cached entry refreshed after a minute.
        tester.serviceRegistry().clock().advance(Duration.ofSeconds(1));
        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default/production-us-west-1?historyLength=32"),
                              Files.readString(Paths.get(responseFiles + "history2.svg")), 200);

        tester.assertResponse(authenticatedRequest("http://localhost:8080/badge/v1/tenant/application/default/production-us-west-1?historyLength=0"),
                              Files.readString(Paths.get(responseFiles + "single-done.svg")), 200);
    }

}