diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-01-21 13:28:18 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-01-21 14:22:25 +0100 |
commit | b1bbb58449af091cf20f296ba19130b446d68022 (patch) | |
tree | 572838f05c7f0d081ed05d1b566d9d92377f4305 /container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java | |
parent | 4c514714e3e739c66f0107629d44ef5e5877403a (diff) |
Replace AccessLogEntry with non-blocking RequestLogEntry
Keep AccessLogEntry as interface for adding extra information in handlers, but use the new RequestLogEntry for access log serialization.
Introduce new interface RequestLog that AccessLog class implements (to simplify unit testing).
Rename AccessLogInterface to RequestLogHandler.
Remove unused class AccessLogSampler.
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java | 82 |
1 files changed, 21 insertions, 61 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java index 92fe347f7d1..734b3fa11af 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java @@ -1,51 +1,43 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetSocketAddress; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - import com.google.inject.Key; +import com.yahoo.component.provider.ComponentRegistry; +import com.yahoo.container.handler.Coverage; +import com.yahoo.container.handler.Timing; +import com.yahoo.container.logging.AccessLog; import com.yahoo.container.logging.HitCounts; +import com.yahoo.container.logging.RequestLogHandler; import com.yahoo.jdisc.Container; import com.yahoo.jdisc.References; import com.yahoo.jdisc.ResourceReference; +import com.yahoo.jdisc.handler.CompletionHandler; +import com.yahoo.jdisc.handler.ContentChannel; import com.yahoo.jdisc.handler.RequestHandler; +import com.yahoo.jdisc.handler.ResponseHandler; import com.yahoo.jdisc.service.CurrentContainer; -import java.net.URI; import org.junit.After; import org.junit.Before; -import org.junit.Test; -import com.yahoo.component.ComponentId; -import com.yahoo.component.provider.ComponentRegistry; -import com.yahoo.container.handler.Coverage; -import com.yahoo.container.handler.Timing; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.container.logging.AccessLogEntry; -import com.yahoo.container.logging.AccessLogInterface; -import com.yahoo.jdisc.handler.BufferedContentChannel; -import com.yahoo.jdisc.handler.CompletionHandler; -import com.yahoo.jdisc.handler.ContentChannel; -import com.yahoo.jdisc.handler.ResponseHandler; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.ByteBuffer; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static org.junit.Assert.fail; /** * Test contracts in LoggingRequestHandler. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class LoggingRequestHandlerTestCase { - StartTimePusher accessLogging; AccessLogTestHandler handler; ExecutorService executor; @@ -121,21 +113,9 @@ public class LoggingRequestHandlerTestCase { } - static final class StartTimePusher implements AccessLogInterface { - - public final ArrayBlockingQueue<Long> starts = new ArrayBlockingQueue<>(1); - - @Override - public void log(final AccessLogEntry accessLogEntry) { - starts.offer(Long.valueOf(accessLogEntry.getTimeStampMillis())); - } - } - @Before public void setUp() throws Exception { - accessLogging = new StartTimePusher(); - ComponentRegistry<AccessLogInterface> implementers = new ComponentRegistry<>(); - implementers.register(new ComponentId("nalle"), accessLogging); + ComponentRegistry<RequestLogHandler> implementers = new ComponentRegistry<>(); implementers.freeze(); executor = Executors.newCachedThreadPool(); handler = new AccessLogTestHandler(executor, new AccessLog(implementers)); @@ -143,31 +123,11 @@ public class LoggingRequestHandlerTestCase { @After public void tearDown() throws Exception { - accessLogging = null; handler = null; executor.shutdown(); executor = null; } - @Test - public final void checkStartIsNotZeroWithoutTimingInstance() throws InterruptedException { - Long startTime; - - MockResponseHandler responseHandler = new MockResponseHandler(); - com.yahoo.jdisc.http.HttpRequest request = createRequest(); - BufferedContentChannel requestContent = new BufferedContentChannel(); - requestContent.close(null); - handler.handleRequest(request, requestContent, responseHandler); - startTime = accessLogging.starts.poll(5, TimeUnit.MINUTES); - if (startTime == null) { - // test timed out, ignoring - } else { - assertFalse( - "Start time was 0, that should never happen after the first millisecond of 1970.", - startTime.longValue() == 0L); - } - } - public static com.yahoo.jdisc.http.HttpRequest createRequest() { return createRequest("http://localhost/search/?query=geewhiz"); } |