summaryrefslogtreecommitdiffstats
path: root/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java
blob: be09aa861346db604548af51b60c8d20c000cd5c (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
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.hosted.cd;

import ai.vespa.cloud.Zone;
import ai.vespa.hosted.cd.internal.TestRuntimeProvider;
import org.osgi.framework.BundleReference;

import java.util.Optional;
import java.util.ServiceLoader;
import java.util.logging.Logger;

/**
 * The place to obtain environment-dependent configuration for test of a Vespa deployment.
 *
 * @author jvenstad
 * @author mortent
 */
public interface TestRuntime {
    static final Logger logger = Logger.getLogger(TestRuntime.class.getName());
    static TestRuntime get() {
        var classloader = TestRuntime.class.getClassLoader();

        if (classloader instanceof BundleReference) {
            logger.info("Loading Test runtime from TestRuntimeProvider");
            return Optional.ofNullable(TestRuntimeProvider.getTestRuntime())
                    .orElseThrow(() -> new RuntimeException("Component graph not ready, retrying"));
        } else {
            logger.info("Loading Test runtime from ServiceLoader");
            ServiceLoader<TestRuntime> serviceLoader = ServiceLoader.load(TestRuntime.class, TestRuntime.class.getClassLoader());
            return serviceLoader.findFirst().orElseThrow(() -> new RuntimeException("No TestRuntime implementation found"));
        }
    }

    Deployment deploymentToTest();

    Zone zone();

}