diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-12-10 14:25:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 14:25:46 +0100 |
commit | 134121cc3b046de15c5ba4360c84586eb8fe0836 (patch) | |
tree | 42bc56808476261b9e96243792aff84b241dda71 /config-proxy/src/test | |
parent | 13fb8a9a0f83d1d880e6cabcaf883c1af0dae1dd (diff) |
Revert "Hmusum/refactor config proxy [run-systemtest]"
Diffstat (limited to 'config-proxy/src/test')
7 files changed, 75 insertions, 38 deletions
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java index 691bc6c43a7..1bcf8d5d8be 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java @@ -92,7 +92,7 @@ public class ConfigProxyRpcServerTest { assertThat(ret.length, is(0)); final RawConfig config = ProxyServerTest.fooConfig; - server.proxyServer().memoryCache().update(config); + server.proxyServer().getMemoryCache().update(config); req = new Request("listCachedConfig"); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); @@ -119,7 +119,7 @@ public class ConfigProxyRpcServerTest { assertThat(ret.length, is(0)); final RawConfig config = ProxyServerTest.fooConfig; - server.proxyServer().memoryCache().update(config); + server.proxyServer().getMemoryCache().update(config); req = new Request("listCachedConfigFull"); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); @@ -133,7 +133,7 @@ public class ConfigProxyRpcServerTest { } /** - * Tests listSourceConnections RPC command + * Tests printStatistics RPC command */ @Test public void testRpcMethodListSourceConnections() throws ListenFailedException { @@ -151,6 +151,20 @@ public class ConfigProxyRpcServerTest { } /** + * Tests printStatistics RPC command + */ + @Test + public void testRpcMethodPrintStatistics() { + Request req = new Request("printStatistics"); + client.invoke(req); + assertFalse(req.errorMessage(), req.isError()); + assertThat(req.returnValues().size(), is(1)); + assertThat(req.returnValues().get(0).asString(), is("\n" + + "Delayed responses queue size: 0\n" + + "Contents: ")); + } + + /** * Tests invalidateCache RPC command */ @Test @@ -261,7 +275,7 @@ public class ConfigProxyRpcServerTest { } private static ProxyServer createTestServer(ConfigSourceSet source) { - return new ProxyServer(null, source, new RpcConfigSourceClient(new ResponseHandler(), source)); + return new ProxyServer(null, source, new MemoryCache(), null); } private static class TestServer implements AutoCloseable { 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 8a668b34fd0..c2a0282fd05 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 @@ -6,7 +6,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; /** * @author hmusum @@ -28,15 +29,16 @@ public class DelayedResponseHandlerTest { public void basic() { ConfigTester tester = new ConfigTester(); DelayedResponses delayedResponses = new DelayedResponses(); - MemoryCache memoryCache = new MemoryCache(); + final MockRpcServer mockRpcServer = new MockRpcServer(); + final MemoryCache memoryCache = new MemoryCache(); memoryCache.update(ConfigTester.fooConfig); - DelayedResponseHandler delayedResponseHandler = new DelayedResponseHandler(delayedResponses, memoryCache, new ResponseHandler()); + final DelayedResponseHandler delayedResponseHandler = new DelayedResponseHandler(delayedResponses, memoryCache, mockRpcServer); delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.fooConfig, 0))); delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.fooConfig, 1200000))); // should not be returned yet delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.errorConfig, 0))); // will not give a config when resolving delayedResponseHandler.checkDelayedResponses(); - assertEquals(1, delayedResponseHandler.sentResponses()); + assertThat(mockRpcServer.responses, is(1L)); } } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClientTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClientTest.java index ae7350b11e0..51d0b983764 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClientTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClientTest.java @@ -16,8 +16,9 @@ public class MemoryCacheConfigClientTest { @Test public void basic() { - MemoryCacheConfigClient client = new MemoryCacheConfigClient(); - client.memoryCache().update(ConfigTester.fooConfig); + MemoryCache cache = new MemoryCache(); + cache.update(ConfigTester.fooConfig); + MemoryCacheConfigClient client = new MemoryCacheConfigClient(cache); assertThat(client.getConfig(ConfigTester.fooConfig, null), is(ConfigTester.fooConfig)); assertNull(client.getConfig(ConfigTester.barConfig, null)); 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 index d0724b9dbd0..c0efc1cb355 100644 --- 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 @@ -18,9 +18,9 @@ public class MockConfigSourceClient implements ConfigSourceClient{ private final MemoryCache memoryCache; private final DelayedResponses delayedResponses = new DelayedResponses(); - MockConfigSourceClient(MockConfigSource configSource) { + MockConfigSourceClient(MockConfigSource configSource, MemoryCache memoryCache) { this.configSource = configSource; - this.memoryCache = new MemoryCache(); + this.memoryCache = memoryCache; } @Override @@ -35,7 +35,7 @@ public class MockConfigSourceClient implements ConfigSourceClient{ } @Override - public void shutdown() { + public void cancel() { configSource.clear(); } @@ -56,7 +56,4 @@ public class MockConfigSourceClient implements ConfigSourceClient{ @Override public DelayedResponses delayedResponses() { return delayedResponses; } - @Override - public MemoryCache memoryCache() { return memoryCache; } - } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockRpcServer.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockRpcServer.java new file mode 100644 index 00000000000..56fcca191de --- /dev/null +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockRpcServer.java @@ -0,0 +1,23 @@ +// Copyright Yahoo. 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.RawConfig; +import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; + +/** + * @author hmusum + */ +public class MockRpcServer implements RpcServer { + + volatile long responses = 0; + volatile long errorResponses = 0; + + public void returnOkResponse(JRTServerConfigRequest request, RawConfig config) { + responses++; + } + + public void returnErrorResponse(JRTServerConfigRequest request, int errorCode, String message) { + responses++; + errorResponses++; + } +} 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 15de93b748f..cdda2bf6e77 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 @@ -2,10 +2,7 @@ package com.yahoo.vespa.config.proxy; import com.yahoo.config.subscription.ConfigSourceSet; -import com.yahoo.vespa.config.ConfigCacheKey; -import com.yahoo.vespa.config.ConfigKey; -import com.yahoo.vespa.config.ErrorCode; -import com.yahoo.vespa.config.RawConfig; +import com.yahoo.vespa.config.*; import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; import com.yahoo.vespa.config.protocol.Payload; import org.junit.After; @@ -28,8 +25,9 @@ import static org.junit.Assert.assertTrue; */ public class ProxyServerTest { + private final MemoryCache memoryCache = new MemoryCache(); private final MockConfigSource source = new MockConfigSource(); - private final ConfigSourceClient client = new MockConfigSourceClient(source); + private final MockConfigSourceClient client = new MockConfigSourceClient(source, memoryCache); private ProxyServer proxy; static final RawConfig fooConfig = ConfigTester.fooConfig; @@ -48,7 +46,7 @@ public class ProxyServerTest { source.clear(); source.put(fooConfig.getKey(), createConfigWithNextConfigGeneration(fooConfig, 0)); source.put(errorConfigKey, createConfigWithNextConfigGeneration(fooConfig, ErrorCode.UNKNOWN_DEFINITION)); - proxy = createTestServer(source, client); + proxy = createTestServer(source, client, memoryCache); } @After @@ -59,10 +57,10 @@ public class ProxyServerTest { @Test public void basic() { assertTrue(proxy.getMode().isDefault()); - assertThat(proxy.memoryCache().size(), is(0)); + assertThat(proxy.getMemoryCache().size(), is(0)); ConfigTester tester = new ConfigTester(); - MemoryCache memoryCache = proxy.memoryCache(); + final MemoryCache memoryCache = proxy.getMemoryCache(); assertEquals(0, memoryCache.size()); RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig)); assertNotNull(res); @@ -76,7 +74,7 @@ public class ProxyServerTest { */ @Test public void testModeSwitch() { - ProxyServer proxy = createTestServer(source, client); + ProxyServer proxy = createTestServer(source, client, new MemoryCache()); assertTrue(proxy.getMode().isDefault()); for (String mode : Mode.modes()) { @@ -111,7 +109,7 @@ public class ProxyServerTest { @Test public void testGetConfigAndCaching() { ConfigTester tester = new ConfigTester(); - MemoryCache memoryCache = proxy.memoryCache(); + final MemoryCache memoryCache = proxy.getMemoryCache(); assertEquals(0, memoryCache.size()); RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig)); assertNotNull(res); @@ -136,14 +134,14 @@ public class ProxyServerTest { // Simulate an error response source.put(fooConfig.getKey(), createConfigWithNextConfigGeneration(fooConfig, ErrorCode.INTERNAL_ERROR)); - MemoryCache memoryCache = proxy.memoryCache(); - assertEquals(0, memoryCache.size()); + final MemoryCache cacheManager = proxy.getMemoryCache(); + assertEquals(0, cacheManager.size()); RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig)); assertNotNull(res); assertNotNull(res.getPayload()); assertTrue(res.isError()); - assertEquals(0, memoryCache.size()); + assertEquals(0, cacheManager.size()); // Put a version of the same config into backend without error and see that it now works (i.e. we are // not getting a cached response (of the error in the previous request) @@ -154,12 +152,12 @@ public class ProxyServerTest { assertNotNull(res); assertNotNull(res.getPayload().getData()); assertThat(res.getPayload().toString(), is(ConfigTester.fooPayload.toString())); - assertEquals(1, memoryCache.size()); + assertEquals(1, cacheManager.size()); JRTServerConfigRequest newRequestBasedOnResponse = tester.createRequest(res); RawConfig res2 = proxy.resolveConfig(newRequestBasedOnResponse); assertFalse(ProxyServer.configOrGenerationHasChanged(res2, newRequestBasedOnResponse)); - assertEquals(1, memoryCache.size()); + assertEquals(1, cacheManager.size()); } /** @@ -171,7 +169,7 @@ public class ProxyServerTest { @Test public void testNoCachingOfEmptyConfig() { ConfigTester tester = new ConfigTester(); - MemoryCache cache = proxy.memoryCache(); + MemoryCache cache = proxy.getMemoryCache(); assertEquals(0, cache.size()); RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig)); @@ -224,8 +222,10 @@ public class ProxyServerTest { assertThat(properties.configSources[0], is(ProxyServer.DEFAULT_PROXY_CONFIG_SOURCES)); } - private static ProxyServer createTestServer(ConfigSourceSet source, ConfigSourceClient configSourceClient) { - return new ProxyServer(null, source, configSourceClient); + private static ProxyServer createTestServer(ConfigSourceSet source, + ConfigSourceClient configSourceClient, + MemoryCache memoryCache) { + return new ProxyServer(null, source, memoryCache, configSourceClient); } static RawConfig createConfigWithNextConfigGeneration(RawConfig config, int errorCode) { diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java index ada98f4b30e..372c8c41c99 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java @@ -17,7 +17,7 @@ import static org.junit.Assert.assertEquals; */ public class RpcConfigSourceClientTest { - private ResponseHandler responseHandler; + private MockRpcServer rpcServer; private RpcConfigSourceClient rpcConfigSourceClient; @Rule @@ -26,8 +26,8 @@ public class RpcConfigSourceClientTest { @Before public void setup() { - responseHandler = new ResponseHandler(true); - rpcConfigSourceClient = new RpcConfigSourceClient(responseHandler, new MockConfigSource()); + rpcServer = new MockRpcServer(); + rpcConfigSourceClient = new RpcConfigSourceClient(rpcServer, new MockConfigSource(), new MemoryCache()); } @Test @@ -90,7 +90,7 @@ public class RpcConfigSourceClientTest { } private void assertSentResponses(int expected) { - assertEquals(expected, responseHandler.sentResponses()); + assertEquals(expected, rpcServer.responses); } private void simulateClientRequestingConfig(RawConfig config) { |