summaryrefslogtreecommitdiffstats
path: root/config-proxy
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2017-04-05 08:17:39 +0200
committerHarald Musum <musum@yahoo-inc.com>2017-04-05 08:17:39 +0200
commit053113bbbbf841a3d4f40421f33ed6a83fabba3a (patch)
tree9781f5c2c7a015dc2f8ed63d47e3e4fabc7b5435 /config-proxy
parente9c418d113cee3075d07279f3589fa6a144e593b (diff)
Move statistics testing, remove some duplicate cach testing
Diffstat (limited to 'config-proxy')
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java6
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java21
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java2
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyStatisticsTest.java46
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java35
5 files changed, 44 insertions, 66 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
index 1502e01a4b0..07d553f42e3 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
@@ -85,14 +85,14 @@ public class ProxyServer implements Runnable {
}
static ProxyServer createTestServer(ConfigSourceSet source) {
- return createTestServer(source, null, new MemoryCache());
+ return createTestServer(source, null, new MemoryCache(), new ConfigProxyStatistics());
}
static ProxyServer createTestServer(ConfigSource source,
ConfigSourceClient configSourceClient,
- MemoryCache memoryCache)
+ MemoryCache memoryCache,
+ ConfigProxyStatistics statistics)
{
- final ConfigProxyStatistics statistics = new ConfigProxyStatistics();
final boolean delayedResponseHandling = false;
return new ProxyServer(null, new DelayedResponses(statistics),
source, statistics, defaultTimingValues(), delayedResponseHandling,
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java
index da691981d01..0abc63d089c 100644
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java
@@ -11,8 +11,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import static junit.framework.TestCase.assertNull;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
/**
@@ -48,21 +49,21 @@ public class ClientUpdaterTest {
clientUpdater.updateSubscribers(fooConfig);
// No delayed response, so not returned
- assertResponseAndCache(rpcServer, memoryCache, fooConfig, 0, 1);
+ assertEquals(0, rpcServer.responses);
delayedResponses.add(new DelayedResponse(JRTServerConfigRequestV3.createFromRequest(JRTConfigRequestFactory.createFromRaw(fooConfig, -10L).getRequest())));
clientUpdater.updateSubscribers(fooConfig);
- assertResponseAndCache(rpcServer, memoryCache, fooConfig, 1, 1);
+ assertEquals(1, rpcServer.responses);
// Will not find bar config in delayed responses
RawConfig barConfig = new RawConfig(new ConfigKey<>("bar", "id", "namespace"), fooConfig.getDefMd5());
clientUpdater.updateSubscribers(barConfig);
- assertResponseAndCache(rpcServer, memoryCache, barConfig, 1, 2);
+ assertEquals(1, rpcServer.responses);
mode = new Mode(Mode.ModeName.MEMORYCACHE);
// Nothing should be returned, so still 1 response
- assertResponseAndCache(rpcServer, memoryCache, fooConfig, 1, 2);
+ assertEquals(1, rpcServer.responses);
assertThat(statistics.errors(), is(0L));
}
@@ -93,13 +94,5 @@ public class ClientUpdaterTest {
assertThat(statistics.errors(), is(1L));
}
- private static void assertResponseAndCache(MockRpcServer rpcServer,
- MemoryCache memoryCache,
- RawConfig expectedConfig,
- long expectedResponses,
- int cacheSize) {
- assertThat(rpcServer.responses, is(expectedResponses));
- assertThat(memoryCache.size(), is(cacheSize));
- assertThat(memoryCache.get(new ConfigCacheKey(expectedConfig.getKey(), expectedConfig.getDefMd5())), is(expectedConfig));
- }
+
}
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 8e96d32329b..db4a0dc357f 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
@@ -22,7 +22,7 @@ public class ConfigProxyRpcServerTest {
private static final String hostname = "localhost";
private static final int port = 12345;
private static final String address = "tcp/" + hostname + ":" + port;
- ProxyServer proxyServer;
+ private ProxyServer proxyServer;
private ConfigProxyRpcServer rpcServer;
@Before
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyStatisticsTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyStatisticsTest.java
deleted file mode 100644
index a9ce5bf24f2..00000000000
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyStatisticsTest.java
+++ /dev/null
@@ -1,46 +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 org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author hmusum
- * @since 5.1.9
- */
-public class ConfigProxyStatisticsTest {
-
- @Test
- public void basic() {
- ConfigProxyStatistics statistics = new ConfigProxyStatistics();
- assertThat(statistics.getEventInterval(), is(ConfigProxyStatistics.defaultEventInterval));
- assertThat(statistics.processedRequests(), is(0L));
- assertThat(statistics.errors(), is(0L));
- assertThat(statistics.delayedResponses(), is(0L));
-
- statistics.delayedResponses(1);
- statistics.incProcessedRequests();
- statistics.incRpcRequests();
- statistics.incErrorCount();
-
- assertThat(statistics.processedRequests(), is(1L));
- assertThat(statistics.rpcRequests(), is(1L));
- assertThat(statistics.errors(), is(1L));
- assertThat(statistics.delayedResponses(), is(1L));
-
- statistics.decDelayedResponses();
- assertThat(statistics.delayedResponses(), is(0L));
-
-
- Long eventInterval = 1L;
- statistics = new ConfigProxyStatistics(eventInterval);
- assertThat(statistics.getEventInterval(), is(eventInterval));
-
- Thread t = new Thread(statistics);
- t.start();
-
- statistics.stop();
- }
-}
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 f148e4951e1..4375eb5a7d4 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,8 @@ public class ProxyServerTest {
private final MemoryCache memoryCache = new MemoryCache();
private final MapBackedConfigSource source = new MapBackedConfigSource(new MockClientUpdater(memoryCache));
- private ProxyServer proxy = ProxyServer.createTestServer(source, source, memoryCache);
+ private final ConfigProxyStatistics statistics = new ConfigProxyStatistics();
+ private ProxyServer proxy;
static final RawConfig fooConfig = Helper.fooConfig;
@@ -41,7 +42,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);
+ proxy = ProxyServer.createTestServer(source, source, memoryCache, statistics);
}
@After
@@ -54,6 +55,36 @@ public class ProxyServerTest {
assertTrue(proxy.getMode().isDefault());
assertThat(proxy.getMemoryCache().size(), is(0));
assertThat(proxy.getTimingValues(), is(ProxyServer.defaultTimingValues()));
+
+ ConfigTester tester = new ConfigTester();
+ final MemoryCache memoryCache = proxy.getMemoryCache();
+ assertEquals(0, memoryCache.size());
+ RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig));
+ assertNotNull(res);
+ assertThat(res.getPayload().toString(), is(Helper.fooPayload.toString()));
+ assertEquals(1, memoryCache.size());
+ assertThat(memoryCache.get(new ConfigCacheKey(fooConfig.getKey(), fooConfig.getDefMd5())), is(res));
+
+
+ assertEquals(1, statistics.processedRequests());
+ assertEquals(0, statistics.rpcRequests());
+ assertEquals(0, statistics.errors());
+ assertEquals(0, statistics.delayedResponses());
+
+ statistics.incProcessedRequests();
+ statistics.incRpcRequests();
+ statistics.incErrorCount();
+ statistics.delayedResponses(1);
+
+ assertEquals(2, statistics.processedRequests());
+ assertEquals(1, statistics.rpcRequests());
+ assertEquals(1, statistics.errors());
+ assertEquals(1, statistics.delayedResponses());
+
+ statistics.decDelayedResponses();
+ assertEquals(0, statistics.delayedResponses());
+
+ assertEquals(ConfigProxyStatistics.defaultEventInterval, statistics.getEventInterval().longValue());
}
/**