summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahoo-inc.com>2017-03-09 08:33:29 +0100
committerArne H Juul <arnej@yahoo-inc.com>2017-03-09 08:33:29 +0100
commit61a205c08d1e32b7c325119762b180030a28cad3 (patch)
treef8481688aa39458e779701c98d9f76ee4c187446 /config-proxy/src/test
parent2feba06b4e861e5b87c5e56d086461e0414b2254 (diff)
move MapBackedConfigSource to src/test
Diffstat (limited to 'config-proxy/src/test')
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java67
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java4
2 files changed, 69 insertions, 2 deletions
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java
new file mode 100644
index 00000000000..83e11e343be
--- /dev/null
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java
@@ -0,0 +1,67 @@
+// 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 com.yahoo.vespa.config.protocol.JRTServerConfigRequest;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * A simple class to be able to test config proxy without having an RPC config
+ * source.
+ *
+ * @author hmusum
+ * @since 5.1.10
+ */
+public class MapBackedConfigSource implements ConfigSource, ConfigSourceClient {
+ private final HashMap<ConfigKey<?>, RawConfig> backing = new HashMap<>();
+ private final ClientUpdater clientUpdater;
+
+ MapBackedConfigSource(ClientUpdater clientUpdater) {
+ this.clientUpdater = clientUpdater;
+ }
+
+ MapBackedConfigSource put(ConfigKey<?> key, RawConfig config) {
+ backing.put(key, config);
+ clientUpdater.updateSubscribers(config);
+ return this;
+ }
+
+ @Override
+ public RawConfig getConfig(RawConfig input, JRTServerConfigRequest request) {
+ final RawConfig config = getConfig(input.getKey());
+ clientUpdater.getMemoryCache().put(config);
+ return config;
+ }
+
+ RawConfig getConfig(ConfigKey<?> configKey) {
+ return backing.get(configKey);
+ }
+
+ @Override
+ public void cancel() {
+ clear();
+ }
+
+ @Override
+ public void shutdownSourceConnections() {
+ }
+
+ public void clear() {
+ backing.clear();
+ }
+
+ @Override
+ public String getActiveSourceConnection() {
+ return "N/A";
+ }
+
+ @Override
+ public List<String> getSourceConnections() {
+ return Collections.singletonList("N/A");
+ }
+}
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
index 47b4dd4d1ea..c21fad062eb 100644
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
@@ -23,7 +23,7 @@ public class ProxyServerTest {
MemoryCache memoryCache = new MemoryCache();
private final MapBackedConfigSource source = new MapBackedConfigSource(UpstreamConfigSubscriberTest.MockClientUpdater.create(memoryCache));
- private ProxyServer proxy = ProxyServer.createTestServer(source, memoryCache);
+ private ProxyServer proxy = ProxyServer.createTestServer(source, source, memoryCache);
static final RawConfig fooConfig = Helper.fooConfigV2;
@@ -41,7 +41,7 @@ public class ProxyServerTest {
source.clear();
source.put(fooConfig.getKey(), createConfigWithNextConfigGeneration(fooConfig, 0));
source.put(errorConfigKey, createConfigWithNextConfigGeneration(fooConfig, ErrorCode.UNKNOWN_DEFINITION));
- proxy = ProxyServer.createTestServer(source, memoryCache);
+ proxy = ProxyServer.createTestServer(source, source, memoryCache);
}
@After