summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java
blob: 2a3e2dad26570756fe1f292be27fc0b36d17b8ad (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
85
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.tenant;

import com.yahoo.concurrent.InThreadExecutorService;
import com.yahoo.concurrent.StripedExecutor;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory;
import com.yahoo.vespa.config.server.host.HostRegistry;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import com.yahoo.vespa.flags.FlagSource;
import com.yahoo.vespa.flags.InMemoryFlagSource;

/**
 *
 * @author hmusum
 */
public class TestTenantRepository extends TenantRepository {

    public TestTenantRepository(GlobalComponentRegistry componentRegistry,
                                HostRegistry hostRegistry,
                                Curator curator,
                                Metrics metrics,
                                FileDistributionFactory fileDistributionFactory,
                                FlagSource flagSource) {
        super(componentRegistry,
              hostRegistry,
              curator,
              metrics,
              new StripedExecutor<>(new InThreadExecutorService()),
              fileDistributionFactory,
              flagSource,
              new InThreadExecutorService());
    }

    public static class Builder {

        GlobalComponentRegistry componentRegistry;
        HostRegistry hostRegistry = new HostRegistry();
        Curator curator = new MockCurator();
        Metrics metrics = Metrics.createTestMetrics();
        FileDistributionFactory fileDistributionFactory = null;
        FlagSource flagSource = new InMemoryFlagSource();


        public Builder withFlagSource(FlagSource flagSource) {
            this.flagSource = flagSource;
            return this;
        }

        public Builder withComponentRegistry(GlobalComponentRegistry componentRegistry) {
            this.componentRegistry = componentRegistry;
            return this;
        }

        public Builder withHostRegistry(HostRegistry hostRegistry) {
            this.hostRegistry = hostRegistry;
            return this;
        }

        public Builder withCurator(Curator curator) {
            this.curator = curator;
            return this;
        }

        public Builder withFileDistributionFactory(FileDistributionFactory fileDistributionFactory) {
            this.fileDistributionFactory = fileDistributionFactory;
            return this;
        }

        public TenantRepository build() {
            if (fileDistributionFactory == null)
                fileDistributionFactory = new FileDistributionFactory(componentRegistry.getConfigserverConfig());
            return new TestTenantRepository(componentRegistry,
                                            hostRegistry,
                                            curator,
                                            metrics,
                                            fileDistributionFactory,
                                            flagSource);
        }

    }

}