summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java
blob: a16881033fa27da900333d06079e9c3f4d08aec3 (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
// Copyright 2017 Yahoo Holdings. 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.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequest;

import java.util.Collections;
import java.util.List;

/**
 * Mock client that always returns with config immediately
 *
 * @author hmusum
 */
public class MockConfigSourceClient implements ConfigSourceClient{
    private final ClientUpdater clientUpdater;
    private final MockConfigSource configSource;

    MockConfigSourceClient(ClientUpdater clientUpdater, MockConfigSource configSource) {
        this.clientUpdater = clientUpdater;
        this.configSource = configSource;
    }

    @Override
    public RawConfig getConfig(RawConfig input, JRTServerConfigRequest request) {
        final RawConfig config = getConfig(input.getKey());
        clientUpdater.getMemoryCache().put(config);
        return config;
    }

    private RawConfig getConfig(ConfigKey<?> configKey) {
        return configSource.getConfig(configKey);
    }

    @Override
    public void cancel() {
        configSource.clear();
    }

    @Override
    public void shutdownSourceConnections() {
    }

    @Override
    public String getActiveSourceConnection() {
        return "N/A";
    }

    @Override
    public List<String> getSourceConnections() {
        return Collections.singletonList("N/A");
    }
}