summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2017-03-08 08:15:22 +0100
committerHarald Musum <musum@yahoo-inc.com>2017-03-08 08:15:22 +0100
commit970218183ff6bf1b90c56fc00b9482e3b5f64348 (patch)
treedc59a5181b464d06142458d89608fbc1a3ced4c2 /config-proxy/src/test
parent12d429744ccdf13c2ff5aa6d343b7b823d93b33d (diff)
Avoid race when getting config
* Always add to delayed responses (we remove instead if we find config in cache) This is to avoid a race where we might end up not adding to delayed responses nor subscribing to config if another request for the same config happens at the same time * Add to cache only in one place * Remove meaningless test
Diffstat (limited to 'config-proxy/src/test')
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java2
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java27
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java10
3 files changed, 10 insertions, 29 deletions
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 f063427d808..7ba4d676000 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(UpstreamConfigSubscriberTest.MockClientUpdater.create());
+ private final MapBackedConfigSource source = new MapBackedConfigSource(UpstreamConfigSubscriberTest.MockClientUpdater.create(new MemoryCache()));
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
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 ed6d2056733..47b4dd4d1ea 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
@@ -21,8 +21,9 @@ import static org.junit.Assert.*;
*/
public class ProxyServerTest {
- private final MapBackedConfigSource source = new MapBackedConfigSource(UpstreamConfigSubscriberTest.MockClientUpdater.create());
- private ProxyServer proxy = ProxyServer.createTestServer(source);
+ MemoryCache memoryCache = new MemoryCache();
+ private final MapBackedConfigSource source = new MapBackedConfigSource(UpstreamConfigSubscriberTest.MockClientUpdater.create(memoryCache));
+ private ProxyServer proxy = ProxyServer.createTestServer(source, memoryCache);
static final RawConfig fooConfig = Helper.fooConfigV2;
@@ -40,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);
+ proxy = ProxyServer.createTestServer(source, memoryCache);
}
@After
@@ -81,26 +82,6 @@ public class ProxyServerTest {
}
/**
- * Tests that the proxy server can be tested with a MapBackedConfigSource,
- * which is a simple hash map with configs
- */
- @Test
- public void testRawConfigSetBasics() {
- ConfigTester tester = new ConfigTester();
- JRTServerConfigRequest errorConfigRequest = tester.createRequest(errorConfig);
-
- assertTrue(proxy.getMode().isDefault());
- RawConfig config = proxy.resolveConfig(Helper.fooConfigRequest);
- assertThat(config, is(createConfigWithNextConfigGeneration(Helper.fooConfig, 0)));
-
- config = proxy.resolveConfig(Helper.barConfigRequest);
- assertNull(config);
-
- config = proxy.resolveConfig(errorConfigRequest);
- assertThat(config.errorCode(), is(ErrorCode.UNKNOWN_DEFINITION));
- }
-
- /**
* Verifies that config is retrieved from the real server when it is not found in the cache,
* that the cache is populated with the config and that the entry in the cache is used
* when it is found there.
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java
index 27ee550d956..e566df8bb2a 100644
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java
@@ -43,7 +43,7 @@ public class UpstreamConfigSubscriberTest {
@Before
public void setup() {
- clientUpdater = MockClientUpdater.create();
+ clientUpdater = MockClientUpdater.create(new MemoryCache());
sourceResponses = new MapBackedConfigSource(clientUpdater);
ConfigPayload payload = getConfigPayload("bar", "value");
@@ -147,14 +147,14 @@ public class UpstreamConfigSubscriberTest {
static class MockClientUpdater extends ClientUpdater {
private RawConfig lastConfig;
- private MockClientUpdater(ConfigProxyStatistics statistics, Mode mode) {
- super(new MemoryCache(), new MockRpcServer(), statistics, new DelayedResponses(statistics), mode);
+ private MockClientUpdater(ConfigProxyStatistics statistics, Mode mode, MemoryCache memoryCache) {
+ super(memoryCache, new MockRpcServer(), statistics, new DelayedResponses(statistics), mode);
}
- public static MockClientUpdater create() {
+ static MockClientUpdater create(MemoryCache memoryCache) {
Mode mode = new Mode();
ConfigProxyStatistics statistics = new ConfigProxyStatistics();
- return new MockClientUpdater(statistics, mode);
+ return new MockClientUpdater(statistics, mode, memoryCache);
}
@Override