summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java
blob: eeefdb0add4904e1a662c82222154c61cfa1c80b (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
86
87
88
89
90
91
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;

import com.google.common.io.Files;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.config.server.application.PermanentApplicationPackage;
import com.yahoo.vespa.config.server.host.ConfigRequestHostLivenessTracker;
import com.yahoo.vespa.config.server.host.HostRegistries;
import com.yahoo.vespa.config.server.http.v2.SessionActiveHandlerTest;
import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.rpc.RpcServer;
import com.yahoo.vespa.config.server.session.*;
import com.yahoo.vespa.curator.mock.MockCurator;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.model.VespaModelFactory;
import org.junit.Before;
import org.junit.Test;

import java.util.Collections;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
 * @author lulf
 * @since 5.1
 */
public class InjectedGlobalComponentRegistryTest {

    private Curator curator;
    private ConfigCurator configCurator;
    private Metrics metrics;
    private ConfigServerDB serverDB;
    private SessionPreparer sessionPreparer;
    private ConfigserverConfig configserverConfig;
    private RpcServer rpcServer;
    private SuperModelGenerationCounter generationCounter;
    private ConfigDefinitionRepo defRepo;
    private PermanentApplicationPackage permanentApplicationPackage;
    private HostRegistries hostRegistries;
    private GlobalComponentRegistry globalComponentRegistry;
    private ModelFactoryRegistry modelFactoryRegistry;
    private HostProvisionerProvider hostProvisionerProvider;
    private Zone zone;

    @Before
    public void setupRegistry() {
        curator = new MockCurator();
        configCurator = ConfigCurator.create(curator);
        metrics = Metrics.createTestMetrics();
        modelFactoryRegistry = new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())));
        configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder().configServerDBDir(Files.createTempDir().getAbsolutePath()));
        serverDB = new ConfigServerDB(configserverConfig);
        sessionPreparer = new SessionTest.MockSessionPreparer();
        rpcServer = new RpcServer(configserverConfig, null, Metrics.createTestMetrics(), 
                                  new HostRegistries(), new ConfigRequestHostLivenessTracker());
        generationCounter = new SuperModelGenerationCounter(curator);
        defRepo = new StaticConfigDefinitionRepo();
        permanentApplicationPackage = new PermanentApplicationPackage(configserverConfig);
        hostRegistries = new HostRegistries();
        hostProvisionerProvider = HostProvisionerProvider.withProvisioner(new SessionActiveHandlerTest.MockProvisioner());
        zone = Zone.defaultZone();
        globalComponentRegistry = new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, serverDB, sessionPreparer, rpcServer, configserverConfig, generationCounter, defRepo, permanentApplicationPackage, hostRegistries, hostProvisionerProvider, zone);
    }

    @Test
    public void testThatAllComponentsAreSetup() {
        assertThat(globalComponentRegistry.getModelFactoryRegistry(), is(modelFactoryRegistry));
        assertThat(globalComponentRegistry.getServerDB(), is(serverDB));
        assertThat(globalComponentRegistry.getSessionPreparer(), is(sessionPreparer));
        assertThat(globalComponentRegistry.getMetrics(), is(metrics));
        assertThat(globalComponentRegistry.getCurator(), is(curator));
        assertThat(globalComponentRegistry.getConfigserverConfig(), is(configserverConfig));
        assertThat(globalComponentRegistry.getReloadListener().hashCode(), is(rpcServer.hashCode()));
        assertThat(globalComponentRegistry.getTenantListener().hashCode(), is(rpcServer.hashCode()));
        assertThat(globalComponentRegistry.getSuperModelGenerationCounter(), is(generationCounter));
        assertThat(globalComponentRegistry.getConfigDefinitionRepo(), is(defRepo));
        assertThat(globalComponentRegistry.getPermanentApplicationPackage(), is(permanentApplicationPackage));
        assertThat(globalComponentRegistry.getHostRegistries(), is(hostRegistries));
        assertThat(globalComponentRegistry.getZone(), is (zone));
        assertTrue(globalComponentRegistry.getHostProvisioner().isPresent());
    }

}