diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-08-31 17:19:44 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-08-31 17:19:44 +0200 |
commit | efd1227b1e839691832f56a5d252e7c11a496b25 (patch) | |
tree | 8f9e9e439a47324507d8109622e13b6605e04c1e /container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java | |
parent | 6b5474b527417e41f6d8ef2ef922899c5accc2c5 (diff) |
Mak log handler wait for network IO on every flush
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java index 97aa8864eae..afe57579a97 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java @@ -1,17 +1,19 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.handler; +import com.yahoo.container.jdisc.AsyncHttpResponse; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; +import com.yahoo.jdisc.handler.ReadableContentChannel; +import com.yahoo.yolean.Exceptions; import org.junit.Test; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.time.Instant; import java.util.Optional; import java.util.concurrent.Executor; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -24,20 +26,20 @@ public class LogHandlerTest { { String uri = "http://myhost.com:1111/logs?from=1000&to=2000"; - HttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - response.render(bos); + AsyncHttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); + ReadableContentChannel out = new ReadableContentChannel(); + new Thread(() -> Exceptions.uncheck(() -> response.render(null, out, null))).start(); String expectedResponse = "newer log"; - assertEquals(expectedResponse, bos.toString()); + assertEquals(expectedResponse, new String(out.toStream().readAllBytes(), UTF_8)); } { String uri = "http://myhost.com:1111/logs?from=0&to=1000"; - HttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - response.render(bos); + AsyncHttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); + ReadableContentChannel out = new ReadableContentChannel(); + new Thread(() -> Exceptions.uncheck(() -> response.render(null, out, null))).start(); String expectedResponse = "older log"; - assertEquals(expectedResponse, bos.toString()); + assertEquals(expectedResponse, new String(out.toStream().readAllBytes(), UTF_8)); } } |