diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-04-07 23:04:11 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-04-07 23:04:11 +0000 |
commit | 8b26224ffb404f358dbdd7111e6621936bab534b (patch) | |
tree | eb884b3683db7ae1b5e8b7259e47679e17d65541 /vespaclient-container-plugin | |
parent | 3f41436a6f7ebbd83323426379b7b30b60d21a70 (diff) |
Add a basic test for feed soft start.
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r-- | vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java | 2 | ||||
-rw-r--r-- | vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java | 25 |
2 files changed, 21 insertions, 6 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java index 90421b11a78..bcd78c790fe 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java @@ -47,7 +47,7 @@ public class FeedHandlerV3 extends LoggingRequestHandler { private final Object monitor = new Object(); private int remainingThreadsForFeedingAllowance; private final Duration timeBetweenBumpingMaxThreads; - private Instant nextTimeToAllocateAnotherThread; + private Instant nextTimeToAllocateAnotherThread = Instant.now(); private final AtomicInteger threadsAvailableForFeeding; private static final Logger log = Logger.getLogger(FeedHandlerV3.class.getName()); diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java b/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java index 1677c95a54a..0bb42851347 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java @@ -2,6 +2,7 @@ package com.yahoo.feedhandler.v3; import com.google.common.base.Splitter; +import com.yahoo.container.handler.ThreadpoolConfig; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.messagebus.SessionCache; @@ -46,7 +47,7 @@ public class FeedTesterV3 { @Test public void feedOneDocument() throws Exception { - final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(); + final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(null); HttpResponse httpResponse = feedHandlerV3.handle(createRequest(1)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); @@ -56,7 +57,7 @@ public class FeedTesterV3 { @Test public void feedOneBrokenDocument() throws Exception { - final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(); + final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(null); HttpResponse httpResponse = feedHandlerV3.handle(createBrokenRequest()); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); @@ -67,7 +68,7 @@ public class FeedTesterV3 { @Test public void feedManyDocument() throws Exception { - final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(); + final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(null); HttpResponse httpResponse = feedHandlerV3.handle(createRequest(100)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); @@ -76,6 +77,20 @@ public class FeedTesterV3 { assertThat(Splitter.on("\n").splitToList(result).size(), is(101)); } + @Test + public void softRestart() throws Exception { + ThreadpoolConfig.Builder builder = new ThreadpoolConfig.Builder().softStartSeconds(5); + final FeedHandlerV3 feedHandlerV3 = setupFeederHandler(builder.build()); + for (int i= 0; i < 100; i++) { + HttpResponse httpResponse = feedHandlerV3.handle(createRequest(100)); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + httpResponse.render(outStream); + assertThat(httpResponse.getContentType(), is("text/plain")); + String result = Utf8.toString(outStream.toByteArray()); + assertThat(Splitter.on("\n").splitToList(result).size(), is(101)); + } + } + private static DocumentTypeManager createDoctypeManager() { DocumentTypeManager docTypeManager = new DocumentTypeManager(); DocumentType documentType = new DocumentType("testdocument"); @@ -115,14 +130,14 @@ public class FeedTesterV3 { return request; } - private FeedHandlerV3 setupFeederHandler() throws Exception { + private FeedHandlerV3 setupFeederHandler(ThreadpoolConfig threadPoolConfig) throws Exception { Executor threadPool = Executors.newCachedThreadPool(); DocumentmanagerConfig docMan = new DocumentmanagerConfig(new DocumentmanagerConfig.Builder().enablecompression(true)); FeedHandlerV3 feedHandlerV3 = new FeedHandlerV3( new FeedHandlerV3.Context(threadPool, AccessLog.voidAccessLog(), metric), docMan, null /* session cache */, - null /* thread pool config */, + threadPoolConfig /* thread pool config */, new DocumentApiMetrics(MetricReceiver.nullImplementation, "test")) { @Override protected ReferencedResource<SharedSourceSession> retainSource( |