summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSource.java
blob: c7f12e671f4c707c16990d6e4be31963095dec76 (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
// 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.proxy;

import com.yahoo.config.subscription.ConfigSource;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;

import java.util.HashMap;

/**
 * A simple class to be able to test config proxy without having an RPC config
 * source.
 *
 * @author hmusum
 * @since 5.1.10
 */
class MockConfigSource implements ConfigSource {
    private final HashMap<ConfigKey<?>, RawConfig> backing = new HashMap<>();
    private final ClientUpdater clientUpdater;

    MockConfigSource(ClientUpdater clientUpdater) {
        this.clientUpdater = clientUpdater;
    }

    MockConfigSource put(ConfigKey<?> key, RawConfig config) {
        backing.put(key, config);
        clientUpdater.updateSubscribers(config);
        return this;
    }

    RawConfig getConfig(ConfigKey<?> key) {
        return backing.get(key);
    }

    void clear() {
        backing.clear();
    }

}