diff options
author | Harald Musum <musum@yahooinc.com> | 2021-12-10 10:17:55 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2021-12-10 10:17:55 +0100 |
commit | f149bd11e4289b5a994d7d1d9c11d6c7995ecbf3 (patch) | |
tree | cb19b746fb874ad936c3262d7028c65d9f2c0424 /config-proxy/src/test/java/com/yahoo | |
parent | cfd3c3a096eae48543fce849c9d5fc43dc73823a (diff) |
Decouple rpc server and rpc client by using a ResponseHandler
Diffstat (limited to 'config-proxy/src/test/java/com/yahoo')
4 files changed, 12 insertions, 34 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 c2a0282fd05..8a668b34fd0 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,8 +6,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; /** * @author hmusum @@ -29,16 +28,15 @@ public class DelayedResponseHandlerTest { public void basic() { ConfigTester tester = new ConfigTester(); DelayedResponses delayedResponses = new DelayedResponses(); - final MockRpcServer mockRpcServer = new MockRpcServer(); - final MemoryCache memoryCache = new MemoryCache(); + MemoryCache memoryCache = new MemoryCache(); memoryCache.update(ConfigTester.fooConfig); - final DelayedResponseHandler delayedResponseHandler = new DelayedResponseHandler(delayedResponses, memoryCache, mockRpcServer); + DelayedResponseHandler delayedResponseHandler = new DelayedResponseHandler(delayedResponses, memoryCache, new ResponseHandler()); 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(); - assertThat(mockRpcServer.responses, is(1L)); + assertEquals(1, delayedResponseHandler.sentResponses()); } } 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 deleted file mode 100644 index 56fcca191de..00000000000 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockRpcServer.java +++ /dev/null @@ -1,23 +0,0 @@ -// 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 9c36190da34..172abff6237 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,7 +2,10 @@ package com.yahoo.vespa.config.proxy; import com.yahoo.config.subscription.ConfigSourceSet; -import com.yahoo.vespa.config.*; +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.protocol.JRTServerConfigRequest; import com.yahoo.vespa.config.protocol.Payload; import org.junit.After; 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 f452289c6d8..ada98f4b30e 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 MockRpcServer rpcServer; + private ResponseHandler responseHandler; private RpcConfigSourceClient rpcConfigSourceClient; @Rule @@ -26,8 +26,8 @@ public class RpcConfigSourceClientTest { @Before public void setup() { - rpcServer = new MockRpcServer(); - rpcConfigSourceClient = new RpcConfigSourceClient(rpcServer, new MockConfigSource()); + responseHandler = new ResponseHandler(true); + rpcConfigSourceClient = new RpcConfigSourceClient(responseHandler, new MockConfigSource()); } @Test @@ -90,7 +90,7 @@ public class RpcConfigSourceClientTest { } private void assertSentResponses(int expected) { - assertEquals(expected, rpcServer.responses); + assertEquals(expected, responseHandler.sentResponses()); } private void simulateClientRequestingConfig(RawConfig config) { |