From 0fe03b2b89b0c752860758af2051d6f26b2b85f4 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Wed, 5 Apr 2017 08:34:32 +0200 Subject: Testing changes: Rename config source class, add client class --- .../config/proxy/DelayedResponseHandlerTest.java | 2 +- .../vespa/config/proxy/MapBackedConfigSource.java | 67 ---------------------- .../yahoo/vespa/config/proxy/MockConfigSource.java | 39 +++++++++++++ .../vespa/config/proxy/MockConfigSourceClient.java | 51 ++++++++++++++++ .../yahoo/vespa/config/proxy/ProxyServerTest.java | 6 +- 5 files changed, 95 insertions(+), 70 deletions(-) delete mode 100644 config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java create mode 100644 config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSource.java create mode 100644 config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java (limited to 'config-proxy') diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java index 826a6d58639..ee05e26c37d 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java @@ -14,7 +14,7 @@ import static org.junit.Assert.assertThat; */ public class DelayedResponseHandlerTest { - private final MapBackedConfigSource source = new MapBackedConfigSource(new MockClientUpdater(new MemoryCache())); + private final MockConfigSource source = new MockConfigSource(new MockClientUpdater(new MemoryCache())); @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); 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 deleted file mode 100644 index 4863fd24d4e..00000000000 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MapBackedConfigSource.java +++ /dev/null @@ -1,67 +0,0 @@ -// 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, 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() { - } - - void clear() { - backing.clear(); - } - - @Override - public String getActiveSourceConnection() { - return "N/A"; - } - - @Override - public List getSourceConnections() { - return Collections.singletonList("N/A"); - } -} diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSource.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSource.java new file mode 100644 index 00000000000..c7f12e671f4 --- /dev/null +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSource.java @@ -0,0 +1,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, 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(); + } + +} diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java new file mode 100644 index 00000000000..6f673bb3f16 --- /dev/null +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java @@ -0,0 +1,51 @@ +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; + +/** + * @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 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 4375eb5a7d4..be47a37d6b2 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 @@ -22,7 +22,9 @@ import static org.junit.Assert.*; public class ProxyServerTest { private final MemoryCache memoryCache = new MemoryCache(); - private final MapBackedConfigSource source = new MapBackedConfigSource(new MockClientUpdater(memoryCache)); + private MockClientUpdater clientUpdater = new MockClientUpdater(memoryCache); + private final MockConfigSource source = new MockConfigSource(clientUpdater); + private MockConfigSourceClient client = new MockConfigSourceClient(clientUpdater, source); private final ConfigProxyStatistics statistics = new ConfigProxyStatistics(); private ProxyServer proxy; @@ -42,7 +44,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, source, memoryCache, statistics); + proxy = ProxyServer.createTestServer(source, client, memoryCache, statistics); } @After -- cgit v1.2.3