aboutsummaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java
blob: baafe2ae2dd3dbd7dcb6409860449216c26f44e3 (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
// Copyright Vespa.ai. 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;
import java.util.Optional;

/**
 * Mock client that always returns with config immediately
 *
 * @author hmusum
 */
public class MockConfigSourceClient implements ConfigSourceClient{
    private final MockConfigSource configSource;
    private final MemoryCache memoryCache;
    private final DelayedResponses delayedResponses = new DelayedResponses();

    MockConfigSourceClient(MockConfigSource configSource) {
        this.configSource = configSource;
        this.memoryCache = new MemoryCache();
    }

    @Override
    public Optional<RawConfig> getConfig(RawConfig input, JRTServerConfigRequest request) {
        RawConfig config = getConfig(input.getKey());
        memoryCache.update(config);
        return Optional.of(config);
    }

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

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

    @Override
    public void shutdownSourceConnections() {
    }

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

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

    @Override
    public DelayedResponses delayedResponses() { return delayedResponses; }

    @Override
    public MemoryCache memoryCache() { return memoryCache; }

}