ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/valves/TesterAccessLogValve.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/valves/TesterAccessLogValve.java
Status
scanned
Type
file
Name
TesterAccessLogValve.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4299 (4.2 KB)
MD5
652d75f2cc7bad344dac450a1e967a5d
SHA1
2ffa552b48aa56bfaa2a34492273fa96c208af3a
SHA256
7df1b9bfc3fbe52a6ef8f6cb3f52aa081c78a0921462a8ef89d3a2ecff200f91
SHA512

      
    
SHA1_git
8e6f9a02d80164cdb2de7c478fd2fb9522c495f8
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterAccessLogValve.java | 4.2 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.valves; import java.io.IOException; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.TimeUnit; import jakarta.servlet.ServletException; import org.junit.Assert; import org.apache.catalina.AccessLog; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; public class TesterAccessLogValve extends ValveBase implements AccessLog { private static final boolean RELAX_TIMING = Boolean.getBoolean("tomcat.test.relaxTiming"); // Timing tests need an error margin to prevent failures. private static final long ERROR_MARGIN = RELAX_TIMING ? 2000 : 100; private final Queue<Entry> entries = new ConcurrentLinkedQueue<>(); public TesterAccessLogValve() { // Async requests are supported super(true); } @Override public void log(Request request, Response response, long time) { entries.add(new Entry(request.getRequestURI(), response.getStatus(), TimeUnit.NANOSECONDS.toMillis(time))); } @Override public void setRequestAttributesEnabled(boolean requestAttributesEnabled) { // NOOP - test code } @Override public boolean getRequestAttributesEnabled() { // Always false - test code return false; } @Override public void invoke(Request request, Response response) throws IOException, ServletException { // Just invoke next - access logging happens via log() method getNext().invoke(request, response); } public int getEntryCount() { return entries.size(); } public void validateAccessLog(int count, int status, long minTime, long maxTime) throws Exception { // Wait (but not too long) until all expected entries appear (access log // entry will be made after response has been returned to user) for (int i = 0; i < 10 && entries.size() < count; i++) { Thread.sleep(100); } StringBuilder entriesLog = new StringBuilder(); for (Entry entry : entries) { entriesLog.append(entry.toString()); entriesLog.append(System.lineSeparator()); } Assert.assertEquals(entriesLog.toString(), count, entries.size()); for (Entry entry : entries) { Assert.assertEquals(status, entry.getStatus()); Assert.assertTrue(entry.toString() + " duration is not >= " + (minTime - ERROR_MARGIN), entry.getTime() >= minTime - ERROR_MARGIN); Assert.assertTrue(entry.toString() + " duration is not < " + (maxTime + ERROR_MARGIN), entry.getTime() < maxTime + ERROR_MARGIN); } } public static class Entry { private final String uri; private final int status; private final long time; public Entry(String uri, int status, long time) { this.uri = uri; this.status = status; this.time = time; } public String getUri() { return uri; } public int getStatus() { return status; } public long getTime() { return time; } @Override public String toString() { return "Uri: " + uri + ", Status: " + status + ", Time: " + time; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
25.98
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9